PageRenderTime 68ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/js_composer/assets/js/backend/composer-tools.js

https://gitlab.com/haque.mdmanzurul/barongbarong
JavaScript | 358 lines | 284 code | 38 blank | 36 comment | 112 complexity | 228db96f1a84bfb1789b816407b33d73 MD5 | raw file
  1. function setCookie(c_name, value, exdays) {
  2. var exdate = new Date();
  3. exdate.setDate(exdate.getDate() + exdays);
  4. var c_value = encodeURIComponent(value) + ((exdays === null) ? "" : "; expires=" + exdate.toUTCString());
  5. document.cookie = c_name + "=" + c_value;
  6. }
  7. function getCookie(c_name) {
  8. var i, x, y, ARRcookies = document.cookie.split(";");
  9. for (i = 0; i < ARRcookies.length; i++) {
  10. x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
  11. y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
  12. x = x.replace(/^\s+|\s+$/g, "");
  13. if (x == c_name) {
  14. return decodeURIComponent(y);
  15. }
  16. }
  17. }
  18. (function ($) {
  19. $.expr[':'].containsi = function (a, i, m) {
  20. return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
  21. };
  22. window.vc_get_column_size = function ($column) {
  23. if ($column.hasClass("vc_span12")) //full-width
  24. return "1/1";
  25. else if ($column.hasClass("vc_span11")) //three-fourth
  26. return "11/12";
  27. else if ($column.hasClass("vc_span10")) //three-fourth
  28. return "4/6";
  29. else if ($column.hasClass("vc_span9")) //three-fourth
  30. return "3/4";
  31. else if ($column.hasClass("vc_span8")) //three-fourth
  32. return "5/6";
  33. else if ($column.hasClass("vc_span8")) //two-third
  34. return "2/3";
  35. else if ($column.hasClass("vc_span7")) // 7/12
  36. return "7/12";
  37. else if ($column.hasClass("vc_span6")) //one-half
  38. return "1/2";
  39. else if ($column.hasClass("vc_span5")) //one-half
  40. return "5/12";
  41. else if ($column.hasClass("vc_span4")) // one-third
  42. return "1/3";
  43. else if ($column.hasClass("vc_span3")) // one-fourth
  44. return "1/4";
  45. else if ($column.hasClass("vc_span2")) // one-fourth
  46. return "1/6";
  47. else if ($column.hasClass("vc_span1")) // one-fourth
  48. return "1/12";
  49. else
  50. return false;
  51. };
  52. $('#vc-license-activation-close').click(function(e){
  53. e.preventDefault();
  54. window.setCookie('vchideactivationmsg', 1, 14);
  55. $(this).parent().slideUp();
  56. });
  57. })(window.jQuery);
  58. function vc_convert_column_size(width) {
  59. var prefix = 'vc_span',
  60. numbers = width ? width.split('/') : [1,1],
  61. range = _.range(1,13),
  62. num = !_.isUndefined(numbers[0]) && _.indexOf(range, parseInt(numbers[0], 10)) >=0 ? parseInt(numbers[0], 10) : false,
  63. dev = !_.isUndefined(numbers[1]) && _.indexOf(range, parseInt(numbers[1], 10)) >=0 ? parseInt(numbers[1], 10) : false;
  64. if(num!==false && dev!==false) {
  65. return prefix + (12*num/dev);
  66. }
  67. return prefix + '12';
  68. }
  69. /**
  70. * @deprecated
  71. * @param width
  72. * @return {*}
  73. */
  74. function vc_column_size(width) {
  75. return vc_convert_column_size(width);
  76. }
  77. function vc_convert_column_span_size(width) {
  78. width = width.replace(/^vc_/, '');
  79. if (width == "span12")
  80. return '1/1';
  81. else if (width == "span11")
  82. return '11/12';
  83. else if (width == "span10") //three-fourth
  84. return '5/6';
  85. else if (width == "span9") //three-fourth
  86. return '3/4';
  87. else if (width == "span8") //two-third
  88. return '2/3';
  89. else if (width == "span7")
  90. return '7/12';
  91. else if (width == "span6") //one-half
  92. return '1/2';
  93. else if (width == "span5") //one-half
  94. return '5/12';
  95. else if (width == "span4") // one-third
  96. return '1/3';
  97. else if (width == "span3") // one-fourth
  98. return '1/4';
  99. else if (width == "span2") // one-fourth
  100. return '1/6';
  101. else if(width == "span1")
  102. return '1/12';
  103. return false;
  104. }
  105. function vc_get_column_mask(cells) {
  106. var columns = cells.split('_'),
  107. columns_count = columns.length,
  108. numbers_sum = 0,
  109. i;
  110. for(i in columns) {
  111. if (!isNaN(parseFloat(columns[i])) && isFinite(columns[i])) {
  112. var sp = columns[i].match(/(\d{1,2})(\d{1,2})/);
  113. numbers_sum = _.reduce(sp.slice(1), function(memo, num) {
  114. return memo + parseInt(num, 10);
  115. }, numbers_sum); //TODO: jshint
  116. }
  117. }
  118. return columns_count + '' + numbers_sum;
  119. }
  120. /**
  121. * Create Unique id for records in storage.
  122. * Generate a pseudo-GUID by concatenating random hexadecimal.
  123. * @return {String}
  124. */
  125. function vc_guid() {
  126. return (VCS4() + VCS4() + "-" + VCS4());
  127. }
  128. // Generate four random hex digits.
  129. function VCS4() {
  130. return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  131. }
  132. /**
  133. * Taxonomies filter
  134. *
  135. * Show or hide taxonomies depending on selected post types
  136. * @param $element - post type checkbox object
  137. * @param $object -
  138. */
  139. var wpb_grid_post_types_for_taxonomies_handler = function () {
  140. var $labels = this.$content.find('.wpb_el_type_taxonomies label[data-post-type]'),
  141. $ = jQuery;
  142. $labels.hide();
  143. $('.grid_posttypes:checkbox', this.$content).change(function () {
  144. if ($(this).is(':checked')) {
  145. $labels.filter('[data-post-type=' + $(this).val() + ']').show();
  146. } else {
  147. $labels.filter('[data-post-type=' + $(this).val() + ']').hide();
  148. }
  149. }).each(function () {
  150. if ($(this).is(':checked')) $labels.filter('[data-post-type=' + $(this).val() + ']').show();
  151. });
  152. };
  153. var wpb_single_image_img_link_dependency_callback = function () {
  154. var $img_link_large = this.$content.find('#img_link_large-yes'),
  155. $ = jQuery,
  156. $img_link_target = this.$content.find('[name=img_link_target]').parents('.vc-shortcode-param:first'),
  157. params = this.model.get('params'),
  158. old_param_value = '';
  159. this.$content.find('#img_link_large-yes').change(function () {
  160. var checked = $(this).is(':checked');
  161. if (checked) {
  162. $img_link_target.show();
  163. } else {
  164. if ($('.wpb-edit-form [name=link]').val().length > 0) {
  165. $img_link_target.show();
  166. } else {
  167. $img_link_target.hide();
  168. }
  169. }
  170. });
  171. $('.wpb-edit-form [name=link]').change(function () {
  172. if ($(this).val().length > 0) {
  173. $img_link_target.show();
  174. } else {
  175. $img_link_target.hide();
  176. }
  177. });
  178. if (this.$content.find('#img_link_large-yes').is(':checked')) {
  179. $img_link_target.show();
  180. } else {
  181. if ($('.wpb-edit-form [name=link]').length && $('.wpb-edit-form [name=link]').val().length > 0) {
  182. $img_link_target.show();
  183. } else {
  184. $img_link_target.hide();
  185. }
  186. }
  187. if( params.img_link && params.img_link.length && !params.link ) {
  188. old_param_value = params.img_link;
  189. if(!old_param_value.match(/^https?\:\/\//)) old_param_value = 'http://' + old_param_value;
  190. $('.wpb-edit-form [name=link]').val(old_param_value);
  191. }
  192. vc.edit_form_callbacks.push(function() {
  193. if(this.params.img_link) this.params.img_link = '';
  194. });
  195. };
  196. var vc_wpnop = function(content) {
  197. var blocklist1, blocklist2, preserve_linebreaks = false, preserve_br = false;
  198. // Protect pre|script tags
  199. if ( content.indexOf('<pre') != -1 || content.indexOf('<script') != -1 ) {
  200. preserve_linebreaks = true;
  201. content = content.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
  202. a = a.replace(/<br ?\/?>(\r\n|\n)?/g, '<wp-temp-lb>');
  203. return a.replace(/<\/?p( [^>]*)?>(\r\n|\n)?/g, '<wp-temp-lb>');
  204. });
  205. }
  206. // keep <br> tags inside captions and remove line breaks
  207. if ( content.indexOf('[caption') != -1 ) {
  208. preserve_br = true;
  209. content = content.replace(/\[caption[\s\S]+?\[\/caption\]/g, function(a) {
  210. return a.replace(/<br([^>]*)>/g, '<wp-temp-br$1>').replace(/[\r\n\t]+/, '');
  211. });
  212. }
  213. // Pretty it up for the source editor
  214. blocklist1 = 'blockquote|ul|ol|li|table|thead|tbody|tfoot|tr|th|td|div|h[1-6]|p|fieldset';
  215. content = content.replace(new RegExp('\\s*</('+blocklist1+')>\\s*', 'g'), '</$1>\n');
  216. content = content.replace(new RegExp('\\s*<((?:'+blocklist1+')(?: [^>]*)?)>', 'g'), '\n<$1>');
  217. // Mark </p> if it has any attributes.
  218. content = content.replace(/(<p [^>]+>.*?)<\/p>/g, '$1</p#>');
  219. // Sepatate <div> containing <p>
  220. content = content.replace(/<div( [^>]*)?>\s*<p>/gi, '<div$1>\n\n');
  221. // Remove <p> and <br />
  222. content = content.replace(/\s*<p>/gi, '');
  223. content = content.replace(/\s*<\/p>\s*/gi, '\n\n');
  224. content = content.replace(/\n[\s\u00a0]+\n/g, '\n\n');
  225. content = content.replace(/\s*<br ?\/?>\s*/gi, '\n');
  226. // Fix some block element newline issues
  227. content = content.replace(/\s*<div/g, '\n<div');
  228. content = content.replace(/<\/div>\s*/g, '</div>\n');
  229. content = content.replace(/\s*\[caption([^\[]+)\[\/caption\]\s*/gi, '\n\n[caption$1[/caption]\n\n');
  230. content = content.replace(/caption\]\n\n+\[caption/g, 'caption]\n\n[caption');
  231. blocklist2 = 'blockquote|ul|ol|li|table|thead|tbody|tfoot|tr|th|td|h[1-6]|pre|fieldset';
  232. content = content.replace(new RegExp('\\s*<((?:'+blocklist2+')(?: [^>]*)?)\\s*>', 'g'), '\n<$1>');
  233. content = content.replace(new RegExp('\\s*</('+blocklist2+')>\\s*', 'g'), '</$1>\n');
  234. content = content.replace(/<li([^>]*)>/g, '\t<li$1>');
  235. if ( content.indexOf('<hr') != -1 ) {
  236. content = content.replace(/\s*<hr( [^>]*)?>\s*/g, '\n\n<hr$1>\n\n');
  237. }
  238. if ( content.indexOf('<object') != -1 ) {
  239. content = content.replace(/<object[\s\S]+?<\/object>/g, function(a){
  240. return a.replace(/[\r\n]+/g, '');
  241. });
  242. }
  243. // Unmark special paragraph closing tags
  244. content = content.replace(/<\/p#>/g, '</p>\n');
  245. content = content.replace(/\s*(<p [^>]+>[\s\S]*?<\/p>)/g, '\n$1');
  246. // Trim whitespace
  247. content = content.replace(/^\s+/, '');
  248. content = content.replace(/[\s\u00a0]+$/, '');
  249. // put back the line breaks in pre|script
  250. if ( preserve_linebreaks )
  251. content = content.replace(/<wp-temp-lb>/g, '\n');
  252. // and the <br> tags in captions
  253. if ( preserve_br )
  254. content = content.replace(/<wp-temp-br([^>]*)>/g, '<br$1>');
  255. return content;
  256. };
  257. var vc_wpautop = function(pee) {
  258. var preserve_linebreaks = false, preserve_br = false,
  259. blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary';
  260. if ( pee.indexOf('<object') != -1 ) {
  261. pee = pee.replace(/<object[\s\S]+?<\/object>/g, function(a){
  262. return a.replace(/[\r\n]+/g, '');
  263. });
  264. }
  265. pee = pee.replace(/<[^<>]+>/g, function(a){
  266. return a.replace(/[\r\n]+/g, ' ');
  267. });
  268. // Protect pre|script tags
  269. if ( pee.indexOf('<pre') != -1 || pee.indexOf('<script') != -1 ) {
  270. preserve_linebreaks = true;
  271. pee = pee.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
  272. return a.replace(/(\r\n|\n)/g, '<wp-temp-lb>');
  273. });
  274. }
  275. // keep <br> tags inside captions and convert line breaks
  276. if ( pee.indexOf('[caption') != -1 ) {
  277. preserve_br = true;
  278. pee = pee.replace(/\[caption[\s\S]+?\[\/caption\]/g, function(a) {
  279. // keep existing <br>
  280. a = a.replace(/<br([^>]*)>/g, '<wp-temp-br$1>');
  281. // no line breaks inside HTML tags
  282. a = a.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(b){
  283. return b.replace(/[\r\n\t]+/, ' ');
  284. });
  285. // convert remaining line breaks to <br>
  286. return a.replace(/\s*\n\s*/g, '<wp-temp-br />');
  287. });
  288. }
  289. pee = pee + '\n\n';
  290. pee = pee.replace(/<br \/>\s*<br \/>/gi, '\n\n');
  291. pee = pee.replace(new RegExp('(<(?:'+blocklist+')(?: [^>]*)?>)', 'gi'), '\n$1');
  292. pee = pee.replace(new RegExp('(</(?:'+blocklist+')>)', 'gi'), '$1\n\n');
  293. pee = pee.replace(/<hr( [^>]*)?>/gi, '<hr$1>\n\n'); // hr is self closing block element
  294. pee = pee.replace(/\r\n|\r/g, '\n');
  295. pee = pee.replace(/\n\s*\n+/g, '\n\n');
  296. pee = pee.replace(/([\s\S]+?)\n\n/g, '<p>$1</p>\n');
  297. pee = pee.replace(/<p>\s*?<\/p>/gi, '');
  298. pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')(?: [^>]*)?>)\\s*</p>', 'gi'), "$1");
  299. pee = pee.replace(/<p>(<li.+?)<\/p>/gi, '$1');
  300. pee = pee.replace(/<p>\s*<blockquote([^>]*)>/gi, '<blockquote$1><p>');
  301. pee = pee.replace(/<\/blockquote>\s*<\/p>/gi, '</p></blockquote>');
  302. pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')(?: [^>]*)?>)', 'gi'), "$1");
  303. pee = pee.replace(new RegExp('(</?(?:'+blocklist+')(?: [^>]*)?>)\\s*</p>', 'gi'), "$1");
  304. pee = pee.replace(/\s*\n/gi, '<br />\n');
  305. pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1");
  306. pee = pee.replace(/<br \/>(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)/gi, '$1');
  307. pee = pee.replace(/(?:<p>|<br ?\/?>)*\s*\[caption([^\[]+)\[\/caption\]\s*(?:<\/p>|<br ?\/?>)*/gi, '[caption$1[/caption]');
  308. pee = pee.replace(/(<(?:div|th|td|form|fieldset|dd)[^>]*>)(.*?)<\/p>/g, function(a, b, c) {
  309. if ( c.match(/<p( [^>]*)?>/) )
  310. return a;
  311. return b + '<p>' + c + '</p>';
  312. });
  313. // put back the line breaks in pre|script
  314. if ( preserve_linebreaks )
  315. pee = pee.replace(/<wp-temp-lb>/g, '\n');
  316. if ( preserve_br )
  317. pee = pee.replace(/<wp-temp-br([^>]*)>/g, '<br$1>');
  318. return pee;
  319. };