| @@ -1,0 +1,509 @@ | ||
| 1 | +jQuery(document).ready(function ($) { | |
| 2 | + "use strict"; | |
| 3 | + | |
| 4 | + let globalS = '.global-condition-select', | |
| 5 | + archiveS = '.archives-condition-select', | |
| 6 | + singleS = '.singles-condition-select', | |
| 7 | + inputIDs = '.king-addons-pb-condition-input-ids'; | |
| 8 | + | |
| 9 | + let conditionsID = $('#king_addons_pb_popup_conditions'); | |
| 10 | + let conditionPopup = $('.king-addons-pb-condition-popup-wrap'); | |
| 11 | + let template_title = $('.king-addons-pb-user-template-title'); | |
| 12 | + let currentTab = 'popup'; | |
| 13 | + | |
| 14 | + function getActiveFilter() { | |
| 15 | + let type = currentTab.replace(/\W+/g, '-').toLowerCase(); | |
| 16 | + if ($('.template-filters').length > 0) { | |
| 17 | + type = $('.template-filters .active-filter').last().attr('data-class'); | |
| 18 | + type = type.substring(0, type.length - 1); | |
| 19 | + } | |
| 20 | + return type; | |
| 21 | + } | |
| 22 | + | |
| 23 | + function renderUserTemplate(type, title, slug, id) { | |
| 24 | + let html = ''; | |
| 25 | + | |
| 26 | + html += '<li>'; | |
| 27 | + html += '<h3 class="king-addons-pb-title">' + title + '</h3>'; | |
| 28 | + html += '<div class="king-addons-pb-action-buttons">'; | |
| 29 | + html += '<span class="king-addons-pb-template-conditions button-primary" data-slug="' + slug + '">Manage Conditions</span>'; | |
| 30 | + html += '<a href="post.php?post=' + id + '&action=elementor" class="king-addons-pb-edit-template button-primary">Edit Popup</a>'; | |
| 31 | + html += '<span class="king-addons-pb-delete-template button-primary" data-slug="' + slug + '" data-warning="Are you sure you want to delete this popup?"><span class="dashicons dashicons-no-alt"></span></span>'; | |
| 32 | + html += '</div>'; | |
| 33 | + html += '</li>'; | |
| 34 | + | |
| 35 | + $('.king-addons-pb-my-templates-list.king-addons-pb-' + getActiveFilter() + '-templates-list').prepend(html); | |
| 36 | + | |
| 37 | + let empty_msg = $('.king-addons-pb-empty-templates-message'); | |
| 38 | + if (empty_msg.length) { | |
| 39 | + empty_msg.remove(); | |
| 40 | + } | |
| 41 | + | |
| 42 | + changeTemplateConditions(); | |
| 43 | + deleteTemplate(); | |
| 44 | + } | |
| 45 | + | |
| 46 | + function createUserTemplate() { | |
| 47 | + let library = 'my_templates' === getActiveFilter() ? 'elementor_library' : 'king_addons_ext_pb'; | |
| 48 | + let title = template_title.val(); | |
| 49 | + let slug = 'user-' + getActiveFilter() + '-' + title.replace(/\W+/g, '-').toLowerCase(); | |
| 50 | + | |
| 51 | + if ('elementor_library' === library) { | |
| 52 | + slug = getActiveFilter() + '-' + title.replace(/\W+/g, '-').toLowerCase(); | |
| 53 | + } | |
| 54 | + | |
| 55 | + // noinspection JSUnresolvedReference | |
| 56 | + let data = { | |
| 57 | + action: 'king_addons_pb_create_template', | |
| 58 | + nonce: KingAddonsPopupBuilderOptions.nonce, | |
| 59 | + user_template_library: library, | |
| 60 | + user_template_title: title, | |
| 61 | + user_template_slug: slug, | |
| 62 | + user_template_type: getActiveFilter(), | |
| 63 | + }; | |
| 64 | + | |
| 65 | + $.post(ajaxurl, data, function (response) { | |
| 66 | + | |
| 67 | + $('.king-addons-pb-user-template-popup-wrap').fadeOut(); | |
| 68 | + | |
| 69 | + setTimeout(function () { | |
| 70 | + let id = response.substring(0, response.length - 1); | |
| 71 | + | |
| 72 | + if ('my_templates' === currentTab.replace(/\W+/g, '-').toLowerCase()) { | |
| 73 | + window.location.href = 'post.php?post=' + id + '&action=elementor'; | |
| 74 | + return; | |
| 75 | + } | |
| 76 | + | |
| 77 | + $('.king-addons-pb-save-conditions').attr('data-slug', slug).attr('data-id', id); | |
| 78 | + | |
| 79 | + renderUserTemplate(getActiveFilter(), template_title.val(), slug, id); | |
| 80 | + | |
| 81 | + let no_templates = $('.king-addons-pb-no-templates'); | |
| 82 | + | |
| 83 | + if (no_templates.length) { | |
| 84 | + no_templates.hide(); | |
| 85 | + } | |
| 86 | + | |
| 87 | + openConditionsPopup(slug); | |
| 88 | + conditionPopup.addClass('editor-redirect'); | |
| 89 | + }, 500); | |
| 90 | + }); | |
| 91 | + } | |
| 92 | + | |
| 93 | + | |
| 94 | + $('.king-addons-pb-user-template').on('click', function () { | |
| 95 | + if ($(this).find('div').length) { | |
| 96 | + alert('Please Install/Activate WooCommerce plugin'); | |
| 97 | + return; | |
| 98 | + } | |
| 99 | + template_title.val(''); | |
| 100 | + $('.king-addons-pb-user-template-popup-wrap').fadeIn(); | |
| 101 | + }); | |
| 102 | + | |
| 103 | + $('.king-addons-pb-user-template-popup').find('.close-popup').on('click', function () { | |
| 104 | + $('.king-addons-pb-user-template-popup-wrap').fadeOut(); | |
| 105 | + }); | |
| 106 | + | |
| 107 | + $('.king-addons-pb-create-template').on('click', function () { | |
| 108 | + if ('' === template_title.val()) { | |
| 109 | + template_title.css('border-color', '#FF4040'); | |
| 110 | + let fill_out_the_title = $('.king-addons-pb-fill-out-the-title'); | |
| 111 | + | |
| 112 | + if (fill_out_the_title.length < 1) { | |
| 113 | + $('.king-addons-pb-create-template').before('<p class="king-addons-pb-fill-out-the-title">Please fill Popup Title field</p>'); | |
| 114 | + fill_out_the_title.css('margin-top', '10px'); | |
| 115 | + fill_out_the_title.css({'color': '#FF4040', 'font-size': '14px', 'font-weight': '500'}); | |
| 116 | + } | |
| 117 | + } else { | |
| 118 | + template_title.removeAttr('style'); | |
| 119 | + $('.king-addons-pb-create-template + p').remove(); | |
| 120 | + | |
| 121 | + createUserTemplate(); | |
| 122 | + } | |
| 123 | + }); | |
| 124 | + | |
| 125 | + template_title.keypress(function (e) { | |
| 126 | + if (e.which === 13) { | |
| 127 | + e.preventDefault(); | |
| 128 | + createUserTemplate(); | |
| 129 | + } | |
| 130 | + }); | |
| 131 | + | |
| 132 | + function deleteTemplate() { | |
| 133 | + $('.king-addons-pb-delete-template').on('click', function () { | |
| 134 | + | |
| 135 | + let deleteButton = $(this); | |
| 136 | + | |
| 137 | + if (!confirm(deleteButton.data('warning'))) { | |
| 138 | + return; | |
| 139 | + } | |
| 140 | + | |
| 141 | + let library = 'my_templates' === getActiveFilter() ? 'elementor_library' : 'king_addons_ext_pb'; | |
| 142 | + let slug = deleteButton.attr('data-slug'); | |
| 143 | + let oneTimeNonce = deleteButton.attr('data-nonce'); | |
| 144 | + | |
| 145 | + let data = { | |
| 146 | + nonce: oneTimeNonce, | |
| 147 | + action: 'king_addons_pb_delete_template', | |
| 148 | + template_slug: slug, | |
| 149 | + template_library: library, | |
| 150 | + }; | |
| 151 | + | |
| 152 | + $.post(ajaxurl, data, function () { | |
| 153 | + deleteButton.closest('li').remove(); | |
| 154 | + }); | |
| 155 | + | |
| 156 | + $.post(ajaxurl, data, function () { | |
| 157 | + setTimeout(function () { | |
| 158 | + if ($('.king-addons-pb-my-templates-list li').length === 0) { | |
| 159 | + $('.king-addons-pb-my-templates-list').append('<li class="king-addons-pb-no-templates">You don\'t have any popups yet</li>'); | |
| 160 | + } | |
| 161 | + }, 500); | |
| 162 | + }); | |
| 163 | + | |
| 164 | + if ('my_templates' !== getActiveFilter()) { | |
| 165 | + let conditions = JSON.parse(conditionsID.val()); | |
| 166 | + delete conditions[slug]; | |
| 167 | + | |
| 168 | + conditionsID.val(JSON.stringify(conditions)); | |
| 169 | + | |
| 170 | + // noinspection JSUnresolvedReference | |
| 171 | + let data = { | |
| 172 | + action: 'king_addons_pb_save_template_conditions', | |
| 173 | + nonce: KingAddonsPopupBuilderOptions.nonce, | |
| 174 | + }; | |
| 175 | + data['king_addons_pb_' + currentTab + '_conditions'] = JSON.stringify(conditions); | |
| 176 | + } | |
| 177 | + }); | |
| 178 | + } | |
| 179 | + | |
| 180 | + deleteTemplate(); | |
| 181 | + | |
| 182 | + function changeTemplateConditions() { | |
| 183 | + $('.king-addons-pb-template-conditions').on('click', function () { | |
| 184 | + let template = $(this).attr('data-slug'); | |
| 185 | + | |
| 186 | + $('.king-addons-pb-save-conditions').attr('data-slug', template); | |
| 187 | + | |
| 188 | + openConditionsPopup(template); | |
| 189 | + }); | |
| 190 | + } | |
| 191 | + | |
| 192 | + changeTemplateConditions(); | |
| 193 | + | |
| 194 | + conditionPopup.find('.close-popup').on('click', function () { | |
| 195 | + // noinspection JSValidateTypes | |
| 196 | + conditionPopup.fadeOut(); | |
| 197 | + }); | |
| 198 | + | |
| 199 | + function popupCloneConditions() { | |
| 200 | + $('.king-addons-pb-conditions-wrap').append('<div class="king-addons-pb-conditions">' + $('.king-addons-pb-conditions-sample').html() + '</div>'); | |
| 201 | + | |
| 202 | + let cloneCond = $('.king-addons-pb-conditions'); | |
| 203 | + | |
| 204 | + cloneCond.removeClass('king-addons-pb-tab-' + currentTab).addClass('king-addons-pb-tab-' + currentTab); | |
| 205 | + let clone = cloneCond.last(); | |
| 206 | + | |
| 207 | + clone.find('select').not(':first-child').hide(); | |
| 208 | + clone.hide().fadeIn(); | |
| 209 | + | |
| 210 | + let currentFilter = $('.template-filters .active-filter').attr('data-class'); | |
| 211 | + | |
| 212 | + if (clone.hasClass('king-addons-pb-tab-product_single')) { | |
| 213 | + setTimeout(function () { | |
| 214 | + clone.find('.king-addons-pb-condition-input-ids').each(function () { | |
| 215 | + if (!($(this).val())) { | |
| 216 | + $(this).val('all').show(); | |
| 217 | + } | |
| 218 | + }); | |
| 219 | + }, 600); | |
| 220 | + } | |
| 221 | + | |
| 222 | + if ('blog-posts' === currentFilter || 'custom-posts' === currentFilter) { | |
| 223 | + clone.find('.singles-condition-select').children(':nth-child(1),:nth-child(2),:nth-child(3)').remove(); | |
| 224 | + clone.find('.king-addons-pb-condition-input-ids').val('all').show(); | |
| 225 | + } else if ('woocommerce-products' === currentFilter) { | |
| 226 | + // noinspection JSUnresolvedReference | |
| 227 | + clone.find('.singles-condition-select').children().filter(function () { | |
| 228 | + return 'product' !== $(this).val() | |
| 229 | + }).remove(); | |
| 230 | + clone.find('.king-addons-pb-condition-input-ids').val('all').show(); | |
| 231 | + } else if ('404-pages' === currentFilter) { | |
| 232 | + // noinspection JSUnresolvedReference | |
| 233 | + clone.find('.singles-condition-select').children().filter(function () { | |
| 234 | + return 'page_404' !== $(this).val() | |
| 235 | + }).remove(); | |
| 236 | + } else if ('blog-archives' === currentFilter || 'custom-archives' === currentFilter) { | |
| 237 | + // noinspection JSUnresolvedReference | |
| 238 | + clone.find('.archives-condition-select').children().filter(function () { | |
| 239 | + return 'products' === $(this).val() || 'product_cat' === $(this).val() || 'product_tag' === $(this).val(); | |
| 240 | + }).remove(); | |
| 241 | + } else if ('woocommerce-archives' === currentFilter) { | |
| 242 | + // noinspection JSUnresolvedReference | |
| 243 | + clone.find('.archives-condition-select').children().filter(function () { | |
| 244 | + return 'products' !== $(this).val() && 'product_cat' !== $(this).val() && 'product_tag' !== $(this).val(); | |
| 245 | + }).remove(); | |
| 246 | + } | |
| 247 | + } | |
| 248 | + | |
| 249 | + function popupAddConditions() { | |
| 250 | + $('.king-addons-pb-add-conditions').on('click', function () { | |
| 251 | + popupCloneConditions(); | |
| 252 | + | |
| 253 | + $('.king-addons-pb-conditions').last().find('input').hide(); | |
| 254 | + | |
| 255 | + popupDeleteConditions(); | |
| 256 | + popupMainConditionSelect(); | |
| 257 | + popupSubConditionSelect(); | |
| 258 | + }); | |
| 259 | + } | |
| 260 | + | |
| 261 | + popupAddConditions(); | |
| 262 | + | |
| 263 | + function popupSetConditions(template) { | |
| 264 | + let conditions = conditionsID.val(); | |
| 265 | + conditions = '' !== conditions ? JSON.parse(conditions) : {}; | |
| 266 | + | |
| 267 | + let setCond = $('.king-addons-pb-conditions'); | |
| 268 | + | |
| 269 | + setCond.remove(); | |
| 270 | + | |
| 271 | + if (conditions[template] !== undefined && conditions[template].length > 0) { | |
| 272 | + for (let i = 0; i < conditions[template].length; i++) { | |
| 273 | + popupCloneConditions(); | |
| 274 | + setCond.find('select').hide(); | |
| 275 | + } | |
| 276 | + | |
| 277 | + if (setCond.length) { | |
| 278 | + setCond.each(function (index) { | |
| 279 | + let path = conditions[template][index].split('/'); | |
| 280 | + | |
| 281 | + for (let s = 0; s < path.length; s++) { | |
| 282 | + // noinspection DuplicatedCode | |
| 283 | + if (s === 0) { | |
| 284 | + $(this).find(globalS).val(path[s]).trigger('change'); | |
| 285 | + $(this).find('.' + path[s] + 's-condition-select').show(); | |
| 286 | + } else if (s === 1) { | |
| 287 | + path[s - 1] = 'product_archive' === path[s - 1] ? 'archive' : path[s - 1]; | |
| 288 | + $(this).find('.' + path[s - 1] + 's-condition-select').val(path[s]).trigger('change'); | |
| 289 | + } else if (s === 2) { | |
| 290 | + $(this).find(inputIDs).val(path[s]).trigger('keyup').show(); | |
| 291 | + } | |
| 292 | + } | |
| 293 | + }); | |
| 294 | + } | |
| 295 | + } | |
| 296 | + | |
| 297 | + let conditionsBtn = $('.king-addons-pb-template-conditions[data-slug=' + template + ']'); | |
| 298 | + | |
| 299 | + if ('true' === conditionsBtn.attr('data-show-on-canvas')) { | |
| 300 | + $('.king-addons-pb-canvas-condition').find('input[type=checkbox]').attr('checked', 'checked'); | |
| 301 | + } else { | |
| 302 | + $('.king-addons-pb-canvas-condition').find('input[type=checkbox]').removeAttr('checked'); | |
| 303 | + } | |
| 304 | + } | |
| 305 | + | |
| 306 | + function openConditionsPopup(template) { | |
| 307 | + popupSetConditions(template); | |
| 308 | + popupMainConditionSelect(); | |
| 309 | + popupSubConditionSelect(); | |
| 310 | + showOnCanvasSwitcher(); | |
| 311 | + popupDeleteConditions(); | |
| 312 | + | |
| 313 | + let conditionsWrap = $('.king-addons-pb-conditions'); | |
| 314 | + let conditionCanvas = $('.king-addons-pb-canvas-condition') | |
| 315 | + | |
| 316 | + conditionCanvas.hide(); | |
| 317 | + | |
| 318 | + if ('single' === currentTab || 'product_single' === currentTab) { | |
| 319 | + conditionsWrap.find(singleS).show(); | |
| 320 | + } else if ('archive' === currentTab || 'product_archive' === currentTab) { | |
| 321 | + conditionsWrap.find(archiveS).show(); | |
| 322 | + } else { | |
| 323 | + conditionsWrap.find(globalS).show(); | |
| 324 | + | |
| 325 | + if (conditionsWrap.length) { | |
| 326 | + conditionCanvas.show(); | |
| 327 | + } | |
| 328 | + } | |
| 329 | + | |
| 330 | + $('.king-addons-pb-conditions-wrap').addClass($('.template-filters .active-filter').attr('data-class')); | |
| 331 | + | |
| 332 | + // noinspection JSValidateTypes | |
| 333 | + conditionPopup.fadeIn(); | |
| 334 | + } | |
| 335 | + | |
| 336 | + function popupDeleteConditions() { | |
| 337 | + $('.king-addons-pb-delete-template-conditions').on('click', function () { | |
| 338 | + let current = $(this).parent(), | |
| 339 | + conditions = conditionsID.val(); | |
| 340 | + conditions = '' !== conditions ? JSON.parse(conditions) : {}; | |
| 341 | + | |
| 342 | + conditionsID.val(JSON.stringify(removeConditions(conditions, getConditionsPath(current)))); | |
| 343 | + | |
| 344 | + // noinspection JSValidateTypes | |
| 345 | + current.fadeOut(500, function () { | |
| 346 | + $(this).remove(); | |
| 347 | + | |
| 348 | + if (0 === $('.king-addons-pb-conditions').length) { | |
| 349 | + $('.king-addons-pb-canvas-condition').hide(); | |
| 350 | + } | |
| 351 | + }); | |
| 352 | + | |
| 353 | + }); | |
| 354 | + } | |
| 355 | + | |
| 356 | + function popupMainConditionSelect() { | |
| 357 | + $(globalS).on('change', function () { | |
| 358 | + let current = $(this).parent(); | |
| 359 | + current.find(archiveS).hide(); | |
| 360 | + current.find(singleS).hide(); | |
| 361 | + current.find(inputIDs).hide(); | |
| 362 | + current.find('.' + $(this).val() + 's-condition-select').show(); | |
| 363 | + }); | |
| 364 | + } | |
| 365 | + | |
| 366 | + function popupSubConditionSelect() { | |
| 367 | + $('.archives-condition-select, .singles-condition-select').on('change', function () { | |
| 368 | + let current = $(this).parent(), | |
| 369 | + selected = $('option:selected', this); | |
| 370 | + | |
| 371 | + if (selected.hasClass('custom-ids') || selected.hasClass('custom-type-ids')) { | |
| 372 | + current.find(inputIDs).val('all').trigger('keyup').show(); | |
| 373 | + } else { | |
| 374 | + current.find(inputIDs).hide(); | |
| 375 | + } | |
| 376 | + | |
| 377 | + }); | |
| 378 | + } | |
| 379 | + | |
| 380 | + function showOnCanvasSwitcher() { | |
| 381 | + $('.king-addons-pb-canvas-condition input[type=checkbox]').on('change', function () { | |
| 382 | + $('.king-addons-pb-template-conditions[data-slug=' + $('.king-addons-pb-save-conditions').attr('data-slug') + ']').attr('data-show-on-canvas', $(this).prop('checked')); | |
| 383 | + }); | |
| 384 | + } | |
| 385 | + | |
| 386 | + function removeConditions(conditions, path) { | |
| 387 | + let data = []; | |
| 388 | + | |
| 389 | + $('.king-addons-pb-template-conditions').each(function () { | |
| 390 | + data.push($(this).attr('data-slug')) | |
| 391 | + }); | |
| 392 | + | |
| 393 | + for (let key in conditions) { | |
| 394 | + if (conditions.hasOwnProperty(key)) { | |
| 395 | + for (let i = 0; i < conditions[key].length; i++) { | |
| 396 | + if (path === conditions[key][i]) { | |
| 397 | + if ('popup' !== getActiveFilter()) { | |
| 398 | + conditions[key].splice(i, 1); | |
| 399 | + } | |
| 400 | + } | |
| 401 | + } | |
| 402 | + | |
| 403 | + if (data.indexOf(key) === -1) { | |
| 404 | + delete conditions[key]; | |
| 405 | + } | |
| 406 | + } | |
| 407 | + } | |
| 408 | + | |
| 409 | + return conditions; | |
| 410 | + } | |
| 411 | + | |
| 412 | + function getConditionsPath(current) { | |
| 413 | + let path; | |
| 414 | + let global = 'none' !== current.find(globalS).css('display') ? current.find(globalS).val() : currentTab, | |
| 415 | + archive = current.find(archiveS).val(), | |
| 416 | + single = current.find(singleS).val(), | |
| 417 | + customIds = current.find(inputIDs); | |
| 418 | + | |
| 419 | + // noinspection DuplicatedCode | |
| 420 | + if ('archive' === global || 'product_archive' === global) { | |
| 421 | + if ('none' !== customIds.css('display')) { | |
| 422 | + path = global + '/' + archive + '/' + customIds.val(); | |
| 423 | + } else { | |
| 424 | + path = global + '/' + archive; | |
| 425 | + } | |
| 426 | + } else if ('single' === global || 'product_single' === global) { | |
| 427 | + if ('none' !== customIds.css('display')) { | |
| 428 | + path = global + '/' + single + '/' + customIds.val(); | |
| 429 | + } else { | |
| 430 | + path = global + '/' + single; | |
| 431 | + } | |
| 432 | + } else { | |
| 433 | + path = 'global'; | |
| 434 | + } | |
| 435 | + | |
| 436 | + return path; | |
| 437 | + } | |
| 438 | + | |
| 439 | + function getConditions(template, conditions) { | |
| 440 | + conditions = ('' === conditions || '[]' === conditions) ? {} : JSON.parse(conditions); | |
| 441 | + conditions[template] = []; | |
| 442 | + $('.king-addons-pb-conditions').each(function () { | |
| 443 | + let path = getConditionsPath($(this)); | |
| 444 | + conditions = removeConditions(conditions, path); | |
| 445 | + conditions[template].push(path); | |
| 446 | + }); | |
| 447 | + return conditions; | |
| 448 | + } | |
| 449 | + | |
| 450 | + function saveConditions() { | |
| 451 | + $('.king-addons-pb-save-conditions').on('click', function () { | |
| 452 | + | |
| 453 | + let template = $(this).attr('data-slug'), | |
| 454 | + TemplateID = $(this).attr('data-id'); | |
| 455 | + | |
| 456 | + let conditions = getConditions(template, conditionsID.val()); | |
| 457 | + | |
| 458 | + conditionsID.val(JSON.stringify(conditions)); | |
| 459 | + | |
| 460 | + // noinspection JSUnresolvedReference | |
| 461 | + let data = { | |
| 462 | + action: 'king_addons_pb_save_template_conditions', | |
| 463 | + nonce: KingAddonsPopupBuilderOptions.nonce, | |
| 464 | + template: template | |
| 465 | + }; | |
| 466 | + | |
| 467 | + // Secondary nonce printed by wp_nonce_field() in the form. | |
| 468 | + // Required by PHP handler before it persists options. | |
| 469 | + const popupSettingsNonce = $('#king_addons_popup_nonce').val() || $('input[name="king_addons_popup_nonce"]').val(); | |
| 470 | + if (popupSettingsNonce) { | |
| 471 | + data.king_addons_popup_nonce = popupSettingsNonce; | |
| 472 | + } | |
| 473 | + data['king_addons_pb_' + currentTab + '_conditions'] = JSON.stringify(conditions); | |
| 474 | + | |
| 475 | + let showOnCanvas = $('#king-addons-pb-show-on-canvas'); | |
| 476 | + | |
| 477 | + if (showOnCanvas.length) { | |
| 478 | + data['king_addons_pb_' + currentTab + '_show_on_canvas'] = showOnCanvas.prop('checked'); | |
| 479 | + } | |
| 480 | + | |
| 481 | + $.post(ajaxurl, data, function () { | |
| 482 | + // noinspection JSValidateTypes | |
| 483 | + conditionPopup.fadeOut(); | |
| 484 | + | |
| 485 | + for (let key in conditions) { | |
| 486 | + if (conditions[key] && 0 !== conditions[key].length) { | |
| 487 | + $('.king-addons-pb-delete-template[data-slug="' + key + '"]').closest('li').addClass('king-addons-pb-active-conditions-template'); | |
| 488 | + } else { | |
| 489 | + $('.king-addons-pb-delete-template[data-slug="' + key + '"]').closest('li').removeClass('king-addons-pb-active-conditions-template'); | |
| 490 | + } | |
| 491 | + } | |
| 492 | + | |
| 493 | + if (conditionPopup.hasClass('editor-redirect')) { | |
| 494 | + window.location.href = 'post.php?post=' + TemplateID + '&action=elementor'; | |
| 495 | + } | |
| 496 | + }); | |
| 497 | + }); | |
| 498 | + } | |
| 499 | + | |
| 500 | + saveConditions(); | |
| 501 | + | |
| 502 | + if ($('body').hasClass('toplevel_page_king-addons-popup-builder')) { | |
| 503 | + let conditions = JSON.parse(conditionsID.val() || '{}'); | |
| 504 | + for (let key in conditions) { | |
| 505 | + $('.king-addons-pb-delete-template[data-slug="' + key + '"]').closest('li').addClass('king-addons-pb-active-conditions-template'); | |
| 506 | + } | |
| 507 | + } | |
| 508 | + | |
| 509 | +}); | |