| 1 |
/*! |
| 2 |
* Filter Everything common admin 1.9.7 |
| 3 |
*/ |
| 4 |
(function($) { |
| 5 |
"use strict"; |
| 6 |
|
| 7 |
$(document).ready(function (){ |
| 8 |
let wpcUserAgent = navigator.userAgent.toLowerCase(); |
| 9 |
let wpcIsAndroid = wpcUserAgent.indexOf("android") > -1; |
| 10 |
let wpcAllowSearchField = 0; |
| 11 |
if(wpcIsAndroid) { |
| 12 |
wpcAllowSearchField = Infinity; |
| 13 |
} |
| 14 |
|
| 15 |
// Common JS code |
| 16 |
$(document).on('change', '#mobile_filter_settings', function (e){ |
| 17 |
if($(this).val() === 'show_bottom_widget'){ |
| 18 |
$('#show_open_close_button').parent('label').addClass('wpc-inactive-settings-field'); |
| 19 |
$('.wpc-bottom-widget-compatibility').addClass('wpc-opened'); |
| 20 |
}else{ |
| 21 |
$('#show_open_close_button').parent('label').removeClass('wpc-inactive-settings-field'); |
| 22 |
$('.wpc-bottom-widget-compatibility').removeClass('wpc-opened'); |
| 23 |
} |
| 24 |
}); |
| 25 |
|
| 26 |
$(document).on('click', '#use_color_swatches', function (e){ |
| 27 |
if ( $(this).is(':checked') ) { |
| 28 |
$('.wpc-color-swatches-taxonomies').addClass('wpc-opened'); |
| 29 |
} else { |
| 30 |
$('.wpc-color-swatches-taxonomies').removeClass('wpc-opened'); |
| 31 |
} |
| 32 |
}); |
| 33 |
|
| 34 |
$('#wpc_primary_color').wpColorPicker({ |
| 35 |
defaultColor: '', |
| 36 |
palettes: [ '#0570e2', '#f44336', '#E91E63', '#007cba', '#65BC7B', '#FFEB3B', '#FFC107', '#FF9800', '#607D8B'], |
| 37 |
}); |
| 38 |
|
| 39 |
$('#wpc_term_color').wpColorPicker({ |
| 40 |
defaultColor: '', |
| 41 |
palettes: [ '#0000FF', '#808080', '#008000', '#FF0000', '#FFFF00', '#FFA500', '#00bfff', '#7F00FF', '#FFFFFF'], |
| 42 |
}); |
| 43 |
|
| 44 |
$('.wpc-help-tip, .wpc-icon-help-tip').tipTip({ |
| 45 |
'attribute': 'data-tip', |
| 46 |
'fadeIn': 50, |
| 47 |
'fadeOut': 50, |
| 48 |
'delay': 200, |
| 49 |
'keepAlive': true, |
| 50 |
'maxWidth': "220px", |
| 51 |
}); |
| 52 |
|
| 53 |
$( '.wpc-sortable-table' ).sortable({ |
| 54 |
items: "tr.pro-version.wpc-sortable-row", |
| 55 |
delay: 150, |
| 56 |
placeholder: "wpc-filter-field-shadow", |
| 57 |
refreshPositions: true, |
| 58 |
cursor: 'move', |
| 59 |
handle: ".wpc-order-sortable-handle-icon", |
| 60 |
axis: 'y', |
| 61 |
update: function( event, ui ) { |
| 62 |
renderTableOrder(); |
| 63 |
}, |
| 64 |
|
| 65 |
}); |
| 66 |
|
| 67 |
$("#show_terms_in_content").select2({ |
| 68 |
width: '80%', |
| 69 |
placeholder: wpcFiltersAdminCommon.chipsPlaceholder, |
| 70 |
minimumResultsForSearch: wpcAllowSearchField, |
| 71 |
tags: true |
| 72 |
}); |
| 73 |
|
| 74 |
$("#color_swatches_taxonomies").select2({ |
| 75 |
width: '80%', |
| 76 |
placeholder: wpcFiltersAdminCommon.colorSwatchesPlaceholder, |
| 77 |
minimumResultsForSearch: wpcAllowSearchField, |
| 78 |
tags: false, |
| 79 |
}); |
| 80 |
|
| 81 |
$('body').on('click', '.wpc-notice-dismiss', function (e){ |
| 82 |
e.preventDefault(); |
| 83 |
|
| 84 |
let requestParams = {}; |
| 85 |
requestParams._wpnonce = $(this).data('nonce'); |
| 86 |
let dismissAction = $(this).data('action'); |
| 87 |
|
| 88 |
wp.ajax.post( dismissAction, requestParams ) |
| 89 |
.always( function( response ) { |
| 90 |
// $spinner.removeClass( 'is-active' ); |
| 91 |
var $el = $( '.license-notice' ); |
| 92 |
$el.fadeTo( 100, 0, function() { |
| 93 |
$el.slideUp( 100, function() { |
| 94 |
$el.remove(); |
| 95 |
}); |
| 96 |
}); |
| 97 |
}) |
| 98 |
}); |
| 99 |
|
| 100 |
// on upload button click |
| 101 |
$( document ).on( 'click', '.wpc-upload', function( event ){ |
| 102 |
|
| 103 |
event.preventDefault(); // prevent default link click and page refresh |
| 104 |
|
| 105 |
const button = $(this) |
| 106 |
const imageId = button.next().next().val(); |
| 107 |
|
| 108 |
const customUploader = wp.media({ |
| 109 |
title: 'Insert image', // modal window title |
| 110 |
library : { |
| 111 |
// uploadedTo : wp.media.view.settings.post.id, // attach to the current post? |
| 112 |
type : 'image' |
| 113 |
}, |
| 114 |
button: { |
| 115 |
text: 'Use this image' // button label text |
| 116 |
}, |
| 117 |
multiple: false |
| 118 |
}).on( 'select', function() { // it also has "open" and "close" events |
| 119 |
const attachment = customUploader.state().get( 'selection' ).first().toJSON(); |
| 120 |
button.removeClass( 'button' ).html( '<img src="' + attachment.url + '">'); // add image instead of "Upload Image" |
| 121 |
button.next().show(); // show "Remove image" link |
| 122 |
button.next().next().val( attachment.id ); // Populate the hidden field with image ID |
| 123 |
}) |
| 124 |
|
| 125 |
// already selected images |
| 126 |
customUploader.on( 'open', function() { |
| 127 |
|
| 128 |
if( imageId ) { |
| 129 |
const selection = customUploader.state().get( 'selection' ) |
| 130 |
let attachment = wp.media.attachment( imageId ); |
| 131 |
attachment.fetch(); |
| 132 |
selection.add( attachment ? [attachment] : [] ); |
| 133 |
} |
| 134 |
|
| 135 |
}) |
| 136 |
|
| 137 |
customUploader.open() |
| 138 |
}); |
| 139 |
|
| 140 |
// on remove button click |
| 141 |
$( document ).on( 'click', '.wpc-remove', function( event ){ |
| 142 |
wpcHideTheRemoveButton( $(this) ); |
| 143 |
}); |
| 144 |
|
| 145 |
$( document ).ajaxSuccess( function(e, request, settings) { |
| 146 |
let params = new URLSearchParams( settings.data ); |
| 147 |
let action = params.get('action'); |
| 148 |
|
| 149 |
if( action === 'add-tag' ){ |
| 150 |
// clear form |
| 151 |
$("#wpc_term_img, #wpc_term_color").val(''); |
| 152 |
$(".wpc-remove").hide(); |
| 153 |
wpcHideTheRemoveButton( $("a.wpc-remove") ); |
| 154 |
|
| 155 |
$(".wpc-color-picker .wp-picker-clear").trigger('click'); |
| 156 |
} |
| 157 |
// else { |
| 158 |
// console.log( settings.data ); |
| 159 |
// } |
| 160 |
}); |
| 161 |
|
| 162 |
|
| 163 |
}); // End $(document).ready(); |
| 164 |
|
| 165 |
$(document).ready(function($) { |
| 166 |
const urlParams = new URLSearchParams(window.location.search); |
| 167 |
|
| 168 |
if (urlParams.get('post_type') === 'filter-set' && |
| 169 |
urlParams.get('page') === 'filters-settings' && |
| 170 |
urlParams.get('tab') === 'prefixes') { |
| 171 |
|
| 172 |
const hash = window.location.hash.slice(1); |
| 173 |
if (hash && hash.trim() !== '') { |
| 174 |
let tab = $('a[href="#' + hash + '"]'); |
| 175 |
console.log(tab); |
| 176 |
|
| 177 |
if (tab.length) { |
| 178 |
tab.click(); |
| 179 |
} else { |
| 180 |
console.warn('Tab not found', hash); |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
}); |
| 185 |
|
| 186 |
$(document).on('click', '.wpc-error.is-dismissible > .notice-dismiss', function (e){ |
| 187 |
e.preventDefault(); |
| 188 |
|
| 189 |
let $button = $( this ); |
| 190 |
let $el = $button.parent('.wpc-error'); |
| 191 |
|
| 192 |
$el.fadeTo( 100, 0, function() { |
| 193 |
$el.slideUp( 100, function() { |
| 194 |
$el.remove(); |
| 195 |
}); |
| 196 |
}); |
| 197 |
$el.append( $button ); |
| 198 |
}); |
| 199 |
|
| 200 |
function renderTableOrder() |
| 201 |
{ |
| 202 |
let num = 0; |
| 203 |
$("tr.wpc-sortable-row").each( function ( index, element ) { |
| 204 |
num = (index + 1); |
| 205 |
$(element).find('.wpc-order-td').text(num); |
| 206 |
}); |
| 207 |
} |
| 208 |
|
| 209 |
function wpcHideTheRemoveButton( element ){ |
| 210 |
// event.preventDefault(); |
| 211 |
const button = element; //$(this); |
| 212 |
button.next().val( '' ); // emptying the hidden field |
| 213 |
button.hide().prev().addClass( 'button' ).html( 'Upload image' ); // replace the image with text |
| 214 |
} |
| 215 |
|
| 216 |
$(document).on('click', '#wpc-create-xml', function (e){ |
| 217 |
e.preventDefault(); |
| 218 |
let $btn = $('#wpc-create-xml'); |
| 219 |
let xmlCreateLink = $btn.attr('href'); |
| 220 |
let errorCreateXmlText = $btn.data('errorCreateXmlText'); |
| 221 |
let successCreateXmlText = $btn.data('successCreateXmlText'); |
| 222 |
let progressNoticeText = $btn.data('progressNoticeText'); |
| 223 |
let dismissNoticeText = $btn.data('dismissNoticeText'); |
| 224 |
|
| 225 |
let errTexts = { |
| 226 |
500: $btn.attr('data-err-500'), |
| 227 |
503: $btn.attr('data-err-503'), |
| 228 |
0: $btn.attr('data-err-0'), |
| 229 |
404: $btn.attr('data-err-404'), |
| 230 |
genericPrefix: $btn.attr('data-err-generic-prefix') || 'Error' |
| 231 |
}; |
| 232 |
|
| 233 |
let progressInterval = null; |
| 234 |
|
| 235 |
$('.flrt-notice').remove(); |
| 236 |
$.ajax({ |
| 237 |
'method': 'GET', |
| 238 |
'url': xmlCreateLink, |
| 239 |
'dataType': 'html', |
| 240 |
beforeSend: function () { |
| 241 |
$btn.addClass('wpc-xml-loader').removeAttr('href'); |
| 242 |
$('#wpc-xml-link').addClass('disabled').removeAttr('href'); |
| 243 |
progressInterval = wpcXmlLoadProgress(); |
| 244 |
setTimeout(() => { |
| 245 |
wpcAdminNotificationForXMLProgress(progressNoticeText, dismissNoticeText); |
| 246 |
}, 10000); |
| 247 |
}, |
| 248 |
complete: function () {}, |
| 249 |
success: function (response) { |
| 250 |
clearInterval(progressInterval); |
| 251 |
let response_data = JSON.parse(response); |
| 252 |
$btn.addClass('fill-complete'); |
| 253 |
if(response_data.success){ |
| 254 |
if(response_data.url != ''){ |
| 255 |
$btn.text(successCreateXmlText); |
| 256 |
$('#wpc-xml-link').removeClass('disabled hidden-xml-button').prop('href', response_data.url); |
| 257 |
$('.flrt-xml-progress-notice').remove(); |
| 258 |
} |
| 259 |
setTimeout(() => { |
| 260 |
$btn.removeClass('fill-complete wpc-xml-loader'); |
| 261 |
}, 200); |
| 262 |
setTimeout(() => { |
| 263 |
$btn.text(response_data.update_text); |
| 264 |
}, 2000); |
| 265 |
} else { |
| 266 |
$.each(response_data.data, function (index, error) { |
| 267 |
$('.wp-header-end').after(error.message); |
| 268 |
}); |
| 269 |
$btn.text(errorCreateXmlText).removeClass('fill-complete wpc-xml-loader'); |
| 270 |
} |
| 271 |
$btn.prop('href', xmlCreateLink); |
| 272 |
}, |
| 273 |
error: function (xhr, status, error) { |
| 274 |
clearInterval(progressInterval); |
| 275 |
$btn.removeClass('fill-complete wpc-xml-loader').text(errorCreateXmlText).prop('href', xmlCreateLink); |
| 276 |
$('.flrt-xml-progress-notice').remove(); |
| 277 |
|
| 278 |
let errorMessage = ''; |
| 279 |
if (xhr.status === 500 && errTexts[500]) { |
| 280 |
errorMessage = errTexts[500]; |
| 281 |
} else if (xhr.status === 503 && errTexts[503]) { |
| 282 |
errorMessage = errTexts[503]; |
| 283 |
} else if (xhr.status === 0 && errTexts[0]) { |
| 284 |
errorMessage = errTexts[0]; |
| 285 |
} else if (xhr.status === 404 && errTexts[404]) { |
| 286 |
errorMessage = errTexts[404]; |
| 287 |
} else { |
| 288 |
const prefix = errTexts.genericPrefix || 'Error'; |
| 289 |
errorMessage = `${prefix} ${xhr.status}: ${error}`; |
| 290 |
} |
| 291 |
|
| 292 |
wpcAdminNotificationTemplate(errorMessage, dismissNoticeText, 'notice-error'); |
| 293 |
} |
| 294 |
}); |
| 295 |
}); |
| 296 |
|
| 297 |
window.addEventListener("beforeunload", function (event) { |
| 298 |
if($('#wpc-create-xml').hasClass('wpc-xml-loader')) { |
| 299 |
event.preventDefault(); |
| 300 |
} |
| 301 |
}); |
| 302 |
|
| 303 |
function wpcXmlAnimation(keyframe){ |
| 304 |
const style = document.createElement('style'); |
| 305 |
style.textContent = `.button.wpc-xml-loader{animation: ${keyframe} 2.2s ease-in-out forwards;}`; |
| 306 |
document.head.appendChild(style); |
| 307 |
} |
| 308 |
|
| 309 |
function wpcXmlLoadProgress(){ |
| 310 |
let xmlLoadProgressLink = $('#wpc-create-xml').data('xmlProgressUrl'); |
| 311 |
const pollIntervalMs = 5000; |
| 312 |
wpcXmlAnimation('fillTo10'); |
| 313 |
setInterval(() => { |
| 314 |
if($('#wpc-create-xml').hasClass('wpc-xml-loader')){ |
| 315 |
$.ajax({ |
| 316 |
'method': 'GET', |
| 317 |
'url': xmlLoadProgressLink, |
| 318 |
beforeSend: function () { |
| 319 |
}, |
| 320 |
complete: function () {}, |
| 321 |
success: function (response) { |
| 322 |
if(response.success){ |
| 323 |
wpcXmlAnimation('fillTo' + response.progress); |
| 324 |
} |
| 325 |
}, |
| 326 |
}) |
| 327 |
} |
| 328 |
}, pollIntervalMs); |
| 329 |
} |
| 330 |
|
| 331 |
function wpcAdminNotificationForXMLProgress(progressNoticeText, dismissNoticeText){ |
| 332 |
if($('#wpc-create-xml').hasClass('wpc-xml-loader')){ |
| 333 |
wpcAdminNotificationTemplate(progressNoticeText, dismissNoticeText, 'notice-warning flrt-notice flrt-xml-progress-notice'); |
| 334 |
} |
| 335 |
} |
| 336 |
function wpcAdminNotificationTemplate(message, closeText = 'Dismiss this notice.', className = ''){ |
| 337 |
const errorMessage = `<div class="notice is-dismissible flrt-notice ${className}"><p>${message}</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">${closeText}</span></button></div>`; |
| 338 |
$('.wp-header-end').after(errorMessage); |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
$(document).on('click', '#export_all', function (e){ |
| 343 |
if($('#export_all').prop('checked')){ |
| 344 |
$('form.form_wpc_export_settings input[type=checkbox]').prop('checked', 'checked'); |
| 345 |
}else{ |
| 346 |
$('form.form_wpc_export_settings input[type=checkbox]').prop('checked', ''); |
| 347 |
} |
| 348 |
}); |
| 349 |
|
| 350 |
$(document).on('click', 'form.form_wpc_export_settings input[type=checkbox]', function (e){ |
| 351 |
let checkboxes = $('form.form_wpc_export_settings input[type=checkbox]'); |
| 352 |
let checkedCheckboxes = $('form.form_wpc_export_settings input[type=checkbox]:checked'); |
| 353 |
let newCheckboxes = checkboxes.filter(function( index ) { |
| 354 |
return $( this ).attr( "id" ) !== "export_all"; |
| 355 |
}); |
| 356 |
checkedCheckboxes = checkedCheckboxes.filter(function( index ) { |
| 357 |
return $( this ).attr( "id" ) !== "export_all"; |
| 358 |
}); |
| 359 |
if(newCheckboxes.length === checkedCheckboxes.length){ |
| 360 |
$('#export_all').prop('checked', 'checked'); |
| 361 |
}else{ |
| 362 |
$('#export_all').prop('checked', ''); |
| 363 |
} |
| 364 |
}); |
| 365 |
|
| 366 |
$(document).on('click', '#import_all', function (e){ |
| 367 |
if($('#import_all').prop('checked')){ |
| 368 |
$('form.form_wpc_import_settings input[type=checkbox]').prop('checked', 'checked'); |
| 369 |
}else{ |
| 370 |
$('form.form_wpc_import_settings input[type=checkbox]').prop('checked', ''); |
| 371 |
} |
| 372 |
}); |
| 373 |
|
| 374 |
$(document).on('click', 'form.form_wpc_import_settings input[type=checkbox]', function (e){ |
| 375 |
let checkboxes = $('form.form_wpc_import_settings input[type=checkbox]'); |
| 376 |
let checkedCheckboxes = $('form.form_wpc_import_settings input[type=checkbox]:checked'); |
| 377 |
let newCheckboxes = checkboxes.filter(function( index ) { |
| 378 |
return $( this ).attr( "id" ) !== "import_all"; |
| 379 |
}); |
| 380 |
checkedCheckboxes = checkedCheckboxes.filter(function( index ) { |
| 381 |
return $( this ).attr( "id" ) !== "import_all"; |
| 382 |
}); |
| 383 |
if(newCheckboxes.length === checkedCheckboxes.length){ |
| 384 |
$('#import_all').prop('checked', 'checked'); |
| 385 |
}else{ |
| 386 |
$('#import_all').prop('checked', ''); |
| 387 |
} |
| 388 |
}); |
| 389 |
|
| 390 |
$(document).on('change', 'input[name=wpc_filter_import_export\\[import_file\\]]', function (e){ |
| 391 |
const file = e.target.files[0]; |
| 392 |
if (!file) return; |
| 393 |
|
| 394 |
const fileName = file.name; |
| 395 |
let import_all_checkbox = true; |
| 396 |
|
| 397 |
if (/filters/i.test(fileName)) { |
| 398 |
$('#import_filter_set').prop('checked', 'checked'); |
| 399 |
}else{ |
| 400 |
import_all_checkbox = false; |
| 401 |
$('#import_filter_set').prop('checked', ''); |
| 402 |
} |
| 403 |
|
| 404 |
if (/settings/i.test(fileName)) { |
| 405 |
$('#import_options').prop('checked', 'checked'); |
| 406 |
}else{ |
| 407 |
import_all_checkbox = false; |
| 408 |
$('#import_options').prop('checked', ''); |
| 409 |
} |
| 410 |
|
| 411 |
if (/seo/i.test(fileName)) { |
| 412 |
$('#import_filter_seo_rule').prop('checked', 'checked'); |
| 413 |
}else{ |
| 414 |
import_all_checkbox = false; |
| 415 |
$('#import_filter_seo_rule').prop('checked', ''); |
| 416 |
} |
| 417 |
|
| 418 |
if(import_all_checkbox){ |
| 419 |
$('#import_all').prop('checked', 'checked'); |
| 420 |
}else { |
| 421 |
$('#import_all').prop('checked', ''); |
| 422 |
} |
| 423 |
}); |
| 424 |
|
| 425 |
$(document).on('submit', 'form.form_wpc_import_settings', function(event) { |
| 426 |
$('.nav-tab-wrapper').before('<div id="wpc-loader"></div>'); |
| 427 |
}); |
| 428 |
|
| 429 |
$(document).on('click', 'a', function (e) { |
| 430 |
const href = $(this).attr('href'); |
| 431 |
if (!href) return; |
| 432 |
|
| 433 |
try { |
| 434 |
const url = new URL(href, window.location.origin); |
| 435 |
const params = url.searchParams; |
| 436 |
if (params.get('post_type') === 'filter-set' && params.get('page') === 'flrt-pro') { |
| 437 |
e.preventDefault(); |
| 438 |
wpcGetProVersionPopup(); |
| 439 |
} |
| 440 |
} catch (err) { |
| 441 |
|
| 442 |
} |
| 443 |
}); |
| 444 |
|
| 445 |
$(document).on( 'click', '.free-version .wpc-field-sortable-handle', function (){ |
| 446 |
wpcGetProVersionPopup(); |
| 447 |
}); |
| 448 |
$(document).on('click', '#flrt-close-modal-btn', function (){ |
| 449 |
closeProVersionPopup(); |
| 450 |
}); |
| 451 |
|
| 452 |
$(document).on('click', '#flrt-pro-modal-overlay', function (e) { |
| 453 |
if (e.target === this) { |
| 454 |
closeProVersionPopup(); |
| 455 |
} |
| 456 |
}); |
| 457 |
|
| 458 |
function closeProVersionPopup(){ |
| 459 |
$('#flrt-pro-modal-overlay').css('display', 'none'); |
| 460 |
|
| 461 |
} |
| 462 |
|
| 463 |
window.wpcGetProVersionPopup = function () { |
| 464 |
$('#flrt-pro-modal-overlay').css('display', 'flex'); |
| 465 |
}; |
| 466 |
|
| 467 |
$(document).on('click', '.wpc-create-auto-filter', function (e) { |
| 468 |
if(!$(this).hasClass('disabled')){ |
| 469 |
$(this).addClass('wpc-button-animation-loader'); |
| 470 |
} |
| 471 |
}); |
| 472 |
|
| 473 |
$(document).on('click', '.wpc-seo-setting-head', function (el) { |
| 474 |
if($(this).hasClass('wpc-opened')){ |
| 475 |
$(this).removeClass('wpc-opened'); |
| 476 |
$(this).next('.wpc-filter-body').removeClass('wpc-opened'); |
| 477 |
}else{ |
| 478 |
$(this).addClass('wpc-opened'); |
| 479 |
$(this).next('.wpc-filter-body').addClass('wpc-opened'); |
| 480 |
} |
| 481 |
}); |
| 482 |
|
| 483 |
$('#wpc-seo-settings .nav-tab').on('click', function(e){ |
| 484 |
e.preventDefault(); |
| 485 |
if(!$(this).hasClass('disabled')){ |
| 486 |
$('#wpc-seo-settings .nav-tab').removeClass('nav-tab-active'); |
| 487 |
$(this).addClass('nav-tab-active'); |
| 488 |
$('#wpc-seo-settings .tab-content').hide(); |
| 489 |
$($(this).attr('href')).show(); |
| 490 |
} |
| 491 |
}); |
| 492 |
|
| 493 |
const activeTabHref = $('#wpc-seo-settings .nav-tab-active').attr('href'); |
| 494 |
if(activeTabHref) { |
| 495 |
$(activeTabHref).show(); |
| 496 |
} |
| 497 |
|
| 498 |
$(document).on('click', '#wpc-choose-selector-button', function(e){ |
| 499 |
e.preventDefault(); |
| 500 |
let href = $(this).attr('href'); |
| 501 |
|
| 502 |
// Create modal if it doesn't exist |
| 503 |
if ($('#wpc-modal-overlay').length === 0) { |
| 504 |
$('body').append(`<div id="wpc-modal-overlay"> |
| 505 |
<div class="wpc-modal-content"> |
| 506 |
<div class="wpc-modal-header"> |
| 507 |
<span class="wpc-modal-title"></span> |
| 508 |
<span class="wpc-modal-description">${wpcFiltersAdminCommon.chooseElementHelpText}</span> |
| 509 |
<button id="wpc-modal-close" class="wpc-modal-close">×</button> |
| 510 |
</div> |
| 511 |
<div id="wpc-choose-element-loading-spinner"> |
| 512 |
<div class="choose-element-spinner"></div> |
| 513 |
</div> |
| 514 |
<iframe id="wpc-selector-iframe" src="${href}" style="display: none;"></iframe> |
| 515 |
</div> |
| 516 |
</div>`); |
| 517 |
} else { |
| 518 |
$('#wpc-selector-iframe').attr('src', href); |
| 519 |
$('#wpc-modal-overlay').show(); |
| 520 |
// Show loading spinner and hide iframe |
| 521 |
$('#wpc-choose-element-loading-spinner').show(); |
| 522 |
$('#wpc-selector-iframe').hide(); |
| 523 |
} |
| 524 |
|
| 525 |
// Handle iframe loading |
| 526 |
$('#wpc-selector-iframe').on('load', function() { |
| 527 |
// Hide loading spinner and show iframe |
| 528 |
$('#wpc-choose-element-loading-spinner').hide(); |
| 529 |
$('#wpc-selector-iframe').show(); |
| 530 |
}); |
| 531 |
|
| 532 |
// Close modal event |
| 533 |
$(document).off('click', '#wpc-modal-close').on('click', '#wpc-modal-close', function() { |
| 534 |
$('#wpc-modal-overlay').hide().remove(); |
| 535 |
}); |
| 536 |
|
| 537 |
// Click outside modal to close |
| 538 |
$(document).off('click', '#wpc-modal-overlay').on('click', '#wpc-modal-overlay', function(e) { |
| 539 |
if ($(e.target).is('#wpc-modal-overlay')) { |
| 540 |
$('#wpc-modal-overlay').hide().remove(); |
| 541 |
} |
| 542 |
}); |
| 543 |
|
| 544 |
// Handle selector selection |
| 545 |
const messageHandler = function(e) { |
| 546 |
if (e.data.type === 'SELECTOR_CHOSEN') { |
| 547 |
// Set selector value in multiple fields |
| 548 |
const selector = e.data.elementSelector; |
| 549 |
$('#posts_container').val(selector); |
| 550 |
$('#wpc_set_fields-custom_posts_container').val(selector); |
| 551 |
|
| 552 |
$('#wpc-modal-overlay').hide().remove(); |
| 553 |
window.removeEventListener('message', messageHandler); |
| 554 |
} |
| 555 |
}; |
| 556 |
|
| 557 |
window.removeEventListener('message', messageHandler); |
| 558 |
window.addEventListener('message', messageHandler); |
| 559 |
}); |
| 560 |
|
| 561 |
})(jQuery); |