| 1 |
(function($) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
var EasyElementsAdmin = { |
| 5 |
|
| 6 |
init: function() { |
| 7 |
this.initWidgetToggles(); |
| 8 |
this.initSearchFunctionality(); |
| 9 |
this.initBulkActions(); |
| 10 |
this.initAllExtensions(); |
| 11 |
this.easyEltab(); |
| 12 |
this.easyElFilter(); |
| 13 |
this.easyelVideoPopuo(); |
| 14 |
this.easyelFaq(); |
| 15 |
this.initSettings(); |
| 16 |
this.EasyelWidgetGroupEnable(); |
| 17 |
}, |
| 18 |
|
| 19 |
initWidgetToggles: function() { |
| 20 |
|
| 21 |
$('.easy-widget-item.easyel-pro-enable .widget-toggle-checkbox').each(function() { |
| 22 |
$(this).prop('checked', false).prop('disabled', true); |
| 23 |
}); |
| 24 |
|
| 25 |
$('.widget-toggle-checkbox').on('change', function() { |
| 26 |
var checkbox = $(this); |
| 27 |
var widgetItem = checkbox.closest('.easy-widget-item'); |
| 28 |
|
| 29 |
if (widgetItem.hasClass('easyel-pro-enable')) { |
| 30 |
|
| 31 |
checkbox.prop('checked', false).prop('disabled', true); |
| 32 |
return false; |
| 33 |
} |
| 34 |
|
| 35 |
var widgetKey = checkbox.data('widget-key'); |
| 36 |
var status = checkbox.is(':checked') ? '1' : '0'; |
| 37 |
|
| 38 |
if (!widgetKey) return; |
| 39 |
|
| 40 |
$.post(ajaxurl, { |
| 41 |
action: 'easy_elements_save_widget_setting', |
| 42 |
widget_key: widgetKey, |
| 43 |
status: status, |
| 44 |
nonce: easyElementsData.widget_settings_nonce |
| 45 |
}) |
| 46 |
.done(function(response) { |
| 47 |
if (!response.success) { |
| 48 |
checkbox.prop('checked', !checkbox.is(':checked')); |
| 49 |
} |
| 50 |
}) |
| 51 |
.fail(function() { |
| 52 |
checkbox.prop('checked', !checkbox.is(':checked')); |
| 53 |
}); |
| 54 |
}); |
| 55 |
}, |
| 56 |
|
| 57 |
initSearchFunctionality: function() { |
| 58 |
|
| 59 |
function hideEmptyGroups() { |
| 60 |
$('.easyel-widgets-grid').each(function () { |
| 61 |
var wrapper = $(this); |
| 62 |
var items = wrapper.find('.easy-widget-item'); |
| 63 |
|
| 64 |
var visibleItems = items.filter(function () { |
| 65 |
return $(this).css('display') !== 'none'; |
| 66 |
}).length; |
| 67 |
|
| 68 |
var headingGroup = wrapper.prev('.easyel-widget-heading-group'); |
| 69 |
|
| 70 |
if (visibleItems === 0) { |
| 71 |
headingGroup.hide(); |
| 72 |
wrapper.hide(); |
| 73 |
} else { |
| 74 |
headingGroup.show(); |
| 75 |
wrapper.show(); |
| 76 |
} |
| 77 |
}); |
| 78 |
} |
| 79 |
|
| 80 |
$('#element-search').on('input', function() { |
| 81 |
var searchTerm = $(this).val().toLowerCase(); |
| 82 |
|
| 83 |
$('.easy-widget-item').each(function() { |
| 84 |
var widgetTitle = $(this).find('.widget-header strong').text().toLowerCase(); |
| 85 |
var widgetDesc = $(this).find('.widget-description').text().toLowerCase(); |
| 86 |
|
| 87 |
if (widgetTitle.includes(searchTerm) || widgetDesc.includes(searchTerm)) { |
| 88 |
$(this).show(); |
| 89 |
} else { |
| 90 |
$(this).hide(); |
| 91 |
} |
| 92 |
}); |
| 93 |
|
| 94 |
hideEmptyGroups(); |
| 95 |
}); |
| 96 |
|
| 97 |
hideEmptyGroups(); |
| 98 |
}, |
| 99 |
|
| 100 |
|
| 101 |
initBulkActions: function() { |
| 102 |
$('#activate-all-btn').on('click', function() { |
| 103 |
var currentTab = $('.easyel-nav-tab-active').data('tab'); |
| 104 |
EasyElementsAdmin.performBulkAction('activate_all', currentTab); |
| 105 |
}); |
| 106 |
|
| 107 |
$('#deactivate-all-btn').on('click', function() { |
| 108 |
EasyElementsAdmin.performBulkAction('deactivate_all'); |
| 109 |
}); |
| 110 |
}, |
| 111 |
|
| 112 |
performBulkAction: function(action) { |
| 113 |
|
| 114 |
var currentTab = $('.easyel-nav-tab-active').data('tab'); |
| 115 |
var currentFilter = $('.easyel-action-btn.active').data('filter'); |
| 116 |
var btn = action === 'activate_all' ? $('#activate-all-btn') : $('#deactivate-all-btn'); |
| 117 |
var originalText = btn.text(); |
| 118 |
|
| 119 |
btn.prop('disabled', true).text(easyElementsData.strings.processing); |
| 120 |
|
| 121 |
$.post(ajaxurl, { |
| 122 |
action: 'easy_elements_bulk_action', |
| 123 |
bulk_action: action, |
| 124 |
tab: currentTab, |
| 125 |
filter: currentFilter, |
| 126 |
nonce: easyElementsData.bulk_action_nonce |
| 127 |
}) |
| 128 |
.done(function(response) { |
| 129 |
|
| 130 |
if (response.success) { |
| 131 |
|
| 132 |
$('.widget-toggle-checkbox').each(function() { |
| 133 |
var $checkbox = $(this); |
| 134 |
let item = $checkbox.closest('.easy-widget-item'); |
| 135 |
|
| 136 |
if ($checkbox.data('tab') !== currentTab) { |
| 137 |
return; |
| 138 |
} |
| 139 |
|
| 140 |
let isProWidget = item.hasClass('easyel-pro-widget'); |
| 141 |
|
| 142 |
if (currentFilter === 'easyel_free' && isProWidget) { |
| 143 |
return; |
| 144 |
} |
| 145 |
|
| 146 |
if (currentFilter === 'easyel_pro' && !isProWidget) { |
| 147 |
return; |
| 148 |
} |
| 149 |
|
| 150 |
if (isProWidget && !response.data.is_pro_active) { |
| 151 |
$checkbox.prop('checked', false).prop('disabled', true); |
| 152 |
} else { |
| 153 |
$checkbox.prop('checked', action === 'activate_all'); |
| 154 |
$checkbox.prop('disabled', false); |
| 155 |
} |
| 156 |
|
| 157 |
}); |
| 158 |
|
| 159 |
$('.easyel-group-toggle-widget').each(function() { |
| 160 |
let groupCheckbox = $(this); |
| 161 |
let groupSlug = groupCheckbox.data('group'); |
| 162 |
let groupWrapper = $('.easyel-widgets-grid[data-group="' + groupSlug + '"]'); |
| 163 |
|
| 164 |
let allChecked = true; |
| 165 |
groupWrapper.find('.widget-toggle-checkbox').each(function() { |
| 166 |
if (!$(this).prop('checked') && !$(this).closest('.easyel-widget-item').hasClass('easyel-pro-enable')) { |
| 167 |
allChecked = false; |
| 168 |
return false; |
| 169 |
} |
| 170 |
}); |
| 171 |
|
| 172 |
groupCheckbox.prop('checked', allChecked); |
| 173 |
groupCheckbox.closest('.easyel-toggle-switch-widget').find('.easyel-enable-all-widget').text(allChecked ? 'Disable All' : 'Enable All'); |
| 174 |
}); |
| 175 |
} |
| 176 |
}) |
| 177 |
.always(function() { |
| 178 |
btn.prop('disabled', false).text(originalText); |
| 179 |
}); |
| 180 |
}, |
| 181 |
|
| 182 |
EasyelWidgetGroupEnable: function() { |
| 183 |
|
| 184 |
function EasyupdateEnableAllText2(groupCheckbox, groupWrapper) { |
| 185 |
let allChecked = true; |
| 186 |
groupWrapper.find('.widget-toggle-checkbox').each(function() { |
| 187 |
if (!$(this).prop('checked') && !$(this).closest('.easyel-widget-item').hasClass('easyel-pro-enable')) { |
| 188 |
allChecked = false; |
| 189 |
return false; |
| 190 |
} |
| 191 |
}); |
| 192 |
|
| 193 |
let textSpan = groupCheckbox.closest('.easyel-toggle-switch-widget').find('.easyel-enable-all-widget'); |
| 194 |
|
| 195 |
textSpan.text(allChecked ? 'Disable All' : 'Enable All'); |
| 196 |
groupCheckbox.prop('checked', allChecked); |
| 197 |
} |
| 198 |
|
| 199 |
let groupTabEnable = $(".easyel-tab-panel.widget"); |
| 200 |
|
| 201 |
groupTabEnable.find('.easyel-group-toggle-widget').each(function() { |
| 202 |
let groupCheckbox = $(this); |
| 203 |
let groupSlug = groupCheckbox.data('group'); |
| 204 |
let groupWrapper = $('.easyel-widgets-grid[data-group="' + groupSlug + '"]'); |
| 205 |
|
| 206 |
EasyupdateEnableAllText2(groupCheckbox, groupWrapper); |
| 207 |
}); |
| 208 |
|
| 209 |
groupTabEnable.on('change', '.easyel-group-toggle-widget', function () { |
| 210 |
|
| 211 |
let groupCheckbox = $(this); |
| 212 |
let groupSlug = groupCheckbox.data('group'); |
| 213 |
let groupWrapper = $('.easyel-widgets-grid[data-group="' + groupSlug + '"]'); |
| 214 |
let hiddenField = $('input.easyel-group-hidden[name="easy_element_group_' + groupSlug + '"]'); |
| 215 |
|
| 216 |
let status = groupCheckbox.is(':checked') ? 1 : 0; |
| 217 |
|
| 218 |
groupWrapper.find('.widget-toggle-checkbox').each(function () { |
| 219 |
let checkbox = $(this); |
| 220 |
if (checkbox.closest('.easyel-widget-item').hasClass('easyel-pro-enable')) return; |
| 221 |
checkbox.prop('checked', status === 1); |
| 222 |
}); |
| 223 |
|
| 224 |
hiddenField.val(status); |
| 225 |
|
| 226 |
EasyupdateEnableAllText2( groupCheckbox, groupWrapper ); |
| 227 |
|
| 228 |
let keys = []; |
| 229 |
groupWrapper.find('.widget-toggle-checkbox').each(function() { keys.push($(this).data('key')); }); |
| 230 |
if (keys.length) { |
| 231 |
$.post(ajaxurl, { |
| 232 |
action: 'easy_elements_bulk_group_action', |
| 233 |
group: groupSlug, |
| 234 |
status: status, |
| 235 |
nonce: easyElementsData.bulk_action_nonce |
| 236 |
}); |
| 237 |
} |
| 238 |
}); |
| 239 |
|
| 240 |
}, |
| 241 |
|
| 242 |
initAllExtensions: function() { |
| 243 |
let $extensionsTab = $('.easyel-tab-panel.extensions'); |
| 244 |
|
| 245 |
$('.easyel-extension-toggle').on('change', function () { |
| 246 |
let checkbox = $(this); |
| 247 |
let key = checkbox.data('key'); |
| 248 |
let tab = checkbox.data('tab'); |
| 249 |
let status = checkbox.is(':checked') ? 1 : 0; |
| 250 |
|
| 251 |
$.post(ajaxurl, { |
| 252 |
action: 'easy_elements_save_global_extensions', |
| 253 |
tab: tab, |
| 254 |
key: key, |
| 255 |
status: status, |
| 256 |
nonce: easyElementsData.widget_settings_nonce |
| 257 |
}) |
| 258 |
.fail(function () { |
| 259 |
checkbox.prop('checked', !checkbox.is(':checked')); |
| 260 |
}); |
| 261 |
}); |
| 262 |
|
| 263 |
function EasyupdateEnableAllText(groupCheckbox) { |
| 264 |
let status = groupCheckbox.is(':checked') ? 1 : 0; |
| 265 |
let label = groupCheckbox.closest('.easyel-toggle-switch-extension'); |
| 266 |
let textSpan = label.find('.easyel-enable-all'); |
| 267 |
|
| 268 |
if (status === 1) { |
| 269 |
textSpan.text('Disable All'); |
| 270 |
} else { |
| 271 |
textSpan.text('Enable All'); |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
$extensionsTab.find('.easyel-group-toggle').each(function() { |
| 276 |
EasyupdateEnableAllText($(this)); |
| 277 |
}); |
| 278 |
|
| 279 |
$extensionsTab.on('change', '.easyel-group-toggle', function () { |
| 280 |
let groupCheckbox = $(this); |
| 281 |
let groupSlug = groupCheckbox.data('group'); |
| 282 |
let groupWrapper = $('.easyel-extension-wrapper[data-group="' + groupSlug + '"]'); |
| 283 |
let hiddenField = $('input.easyel-group-hidden[name="easy_element_group_' + groupSlug + '"]'); |
| 284 |
|
| 285 |
let status = groupCheckbox.is(':checked') ? 1 : 0; |
| 286 |
|
| 287 |
EasyupdateEnableAllText(groupCheckbox); |
| 288 |
|
| 289 |
|
| 290 |
groupWrapper.find('.easyel-extension-toggle').each(function () { |
| 291 |
let checkbox = $(this); |
| 292 |
if (checkbox.closest('.easyel-extension-item').hasClass('easyel-pro-enable')) return; |
| 293 |
checkbox.prop('checked', status === 1); |
| 294 |
}); |
| 295 |
|
| 296 |
hiddenField.val(status); |
| 297 |
|
| 298 |
let keys = []; |
| 299 |
groupWrapper.find('.easyel-extension-toggle').each(function() { keys.push($(this).data('key')); }); |
| 300 |
if (keys.length) { |
| 301 |
$.post(ajaxurl, { |
| 302 |
action: 'easy_elements_save_global_extensions_bulk', |
| 303 |
tab: 'extensions', |
| 304 |
keys: keys, |
| 305 |
status: status, |
| 306 |
group: groupSlug, |
| 307 |
nonce: easyElementsData.widget_settings_nonce |
| 308 |
}); |
| 309 |
} |
| 310 |
}); |
| 311 |
}, |
| 312 |
|
| 313 |
easyEltab: function() { |
| 314 |
$('#toplevel_page_easy-elements-dashboard ul.wp-submenu a').on('click', function (e) { |
| 315 |
const href = $(this).attr('href'); |
| 316 |
const isDashboardPage = window.location.href.includes('page=easy-elements-dashboard'); |
| 317 |
|
| 318 |
if (href.includes('page=easy-elements-license')) { |
| 319 |
return; |
| 320 |
} |
| 321 |
|
| 322 |
if (isDashboardPage && href.includes('#')) { |
| 323 |
e.preventDefault(); |
| 324 |
|
| 325 |
let tab = 'overview'; |
| 326 |
if (href.includes('#widget')) tab = 'widget'; |
| 327 |
if (href.includes('#extensions')) tab = 'extensions'; |
| 328 |
|
| 329 |
activateTab(tab); |
| 330 |
history.replaceState(null, null, '#' + tab); |
| 331 |
} |
| 332 |
}); |
| 333 |
|
| 334 |
let hash = window.location.hash.substring(1); |
| 335 |
if (hash) activateTab(hash); |
| 336 |
else activateTab('overview'); |
| 337 |
|
| 338 |
$('.easyel-nav-tab').click(function (e) { |
| 339 |
const tab = $(this).data('tab'); |
| 340 |
|
| 341 |
if (tab === 'activate_license') { |
| 342 |
const url = $(this).attr('href'); |
| 343 |
if (url) { |
| 344 |
window.location.href = url; |
| 345 |
} |
| 346 |
return; |
| 347 |
} |
| 348 |
|
| 349 |
e.preventDefault(); |
| 350 |
activateTab(tab); |
| 351 |
history.replaceState(null, null, '#' + tab); |
| 352 |
}); |
| 353 |
|
| 354 |
function activateTab(tab) { |
| 355 |
$('.easyel-nav-tab').removeClass('easyel-nav-tab-active'); |
| 356 |
$('.easyel-nav-tab[data-tab="' + tab + '"]').addClass('easyel-nav-tab-active'); |
| 357 |
$('.easyel-tab-panel').hide(); |
| 358 |
$('#tab-' + tab).show(); |
| 359 |
$('#toplevel_page_easy-elements-dashboard ul.wp-submenu li').removeClass('current'); |
| 360 |
$('#toplevel_page_easy-elements-dashboard ul.wp-submenu a[href*="#' + tab + '"]').parent().addClass('current'); |
| 361 |
} |
| 362 |
}, |
| 363 |
easyElFilter: function() { |
| 364 |
$(".easyel-action-btn").on("click", function() { |
| 365 |
var filter = $(this).data("filter"); |
| 366 |
$(".easyel-action-btn").removeClass("active"); |
| 367 |
$(this).addClass("active"); |
| 368 |
|
| 369 |
$(".easy-widget-item,.easyel-extension-item").each(function() { |
| 370 |
var $widget = $(this); |
| 371 |
|
| 372 |
if (filter === "easyel_all") $widget.show(); |
| 373 |
else if (filter === "easyel_free") { |
| 374 |
if ($widget.hasClass("easyel-pro-widget")) $widget.hide(); |
| 375 |
else $widget.show(); |
| 376 |
} else if (filter === "easyel_pro") { |
| 377 |
if ($widget.hasClass("easyel-pro-widget")) $widget.show(); |
| 378 |
else $widget.hide(); |
| 379 |
} |
| 380 |
}); |
| 381 |
}); |
| 382 |
}, |
| 383 |
|
| 384 |
easyelVideoPopuo: function() { |
| 385 |
if ($(".easyel-video-popup").length ) { |
| 386 |
var $popup = $('#easyel-popup-video-area'), |
| 387 |
$videoContainer = $popup.find('.easyel-popup-video'); |
| 388 |
|
| 389 |
$('.easyel-video-popup').on('click', function(e){ |
| 390 |
e.preventDefault(); |
| 391 |
var videoId = $(this).attr('href').split('v=')[1].split('&')[0]; |
| 392 |
$videoContainer.html('<iframe src="https://www.youtube.com/embed/' + videoId + '?autoplay=1" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>'); |
| 393 |
$popup.fadeIn(); |
| 394 |
}); |
| 395 |
|
| 396 |
$popup.on('click', '.easyel-popup-close, #easyel-popup-video-area', function(e){ |
| 397 |
if($(e.target).is('.easyel-popup-close') || $(e.target).is('#easyel-popup-video-area')){ |
| 398 |
$popup.fadeOut(); |
| 399 |
$videoContainer.html(''); |
| 400 |
} |
| 401 |
}); |
| 402 |
}; |
| 403 |
}, |
| 404 |
|
| 405 |
easyelFaq: function() { |
| 406 |
if ($(".easyel-faq-item").length ) { |
| 407 |
$(".easyel-faq-item.active").find(".easyel-faq-item-content").show(); |
| 408 |
$(".easyel-faq-item-heading").click(function(){ |
| 409 |
var faqItem = $(this).closest(".easyel-faq-item"); |
| 410 |
var content = faqItem.children(".easyel-faq-item-content"); |
| 411 |
|
| 412 |
if(faqItem.hasClass("active")){ |
| 413 |
faqItem.removeClass("active"); |
| 414 |
content.slideUp(300); |
| 415 |
} else { |
| 416 |
$(".easyel-faq-item.active").removeClass("active").children(".easyel-faq-item-content").slideUp(300); |
| 417 |
faqItem.addClass("active"); |
| 418 |
content.slideDown(300); |
| 419 |
} |
| 420 |
}); |
| 421 |
}; |
| 422 |
}, |
| 423 |
|
| 424 |
easyel_notify: function(message, type = 'success', duration = 3000) { |
| 425 |
const toast = document.createElement('div'); |
| 426 |
toast.className = `easyel-toast ${type}`; |
| 427 |
toast.innerText = message; |
| 428 |
|
| 429 |
document.body.appendChild(toast); |
| 430 |
|
| 431 |
// Show animation |
| 432 |
setTimeout(() => toast.classList.add('show'), 50); |
| 433 |
|
| 434 |
// Auto remove after duration |
| 435 |
setTimeout(() => { |
| 436 |
toast.classList.remove('show'); |
| 437 |
setTimeout(() => toast.remove(), 300); |
| 438 |
}, duration); |
| 439 |
}, |
| 440 |
|
| 441 |
initSettings: function() { |
| 442 |
$('#easyel-settings-save').click(function (e) { |
| 443 |
e.preventDefault(); |
| 444 |
|
| 445 |
let dataArr = $('#easyel-settings-form').serializeArray(); |
| 446 |
let settings = {}; |
| 447 |
|
| 448 |
dataArr.forEach(field => { |
| 449 |
let name = field.name; |
| 450 |
let value = field.value; |
| 451 |
|
| 452 |
// Detect nested name e.g. fb_config[page_id] |
| 453 |
if (name.includes('[')) { |
| 454 |
let mainKey = name.split('[')[0]; // fb_config |
| 455 |
let subKey = name.match(/\[(.*?)\]/)[1]; // page_id |
| 456 |
|
| 457 |
if (!settings[mainKey]) settings[mainKey] = {}; // init object |
| 458 |
settings[mainKey][subKey] = value; // assign value |
| 459 |
} else { |
| 460 |
// simple field (no nested) |
| 461 |
settings[name] = value; |
| 462 |
} |
| 463 |
}); |
| 464 |
|
| 465 |
$.ajax({ |
| 466 |
url: ajaxurl, |
| 467 |
type: "POST", |
| 468 |
data: { |
| 469 |
action: "easyel_save_user_data", |
| 470 |
security: easyElementsData.nonce, |
| 471 |
settings: settings |
| 472 |
}, |
| 473 |
beforeSend: function () { |
| 474 |
$('#easyel-settings-save') |
| 475 |
.text("Saving...") |
| 476 |
.prop("disabled", true); |
| 477 |
}, |
| 478 |
success: function(res){ |
| 479 |
$('#easyel-settings-save') |
| 480 |
.text('Save Settings') |
| 481 |
.prop('disabled', false); |
| 482 |
|
| 483 |
if(res.success){ |
| 484 |
EasyElementsAdmin.easyel_notify(res.data.message, 'success'); |
| 485 |
} else { |
| 486 |
EasyElementsAdmin.easyel_notify('Error saving settings.', 'error'); |
| 487 |
} |
| 488 |
}, |
| 489 |
error: function(){ |
| 490 |
EasyElementsAdmin.easyel_notify('AJAX error!', 'error'); |
| 491 |
$('#easyel-settings-save').text('Save Settings').prop('disabled', false); |
| 492 |
} |
| 493 |
}); |
| 494 |
|
| 495 |
}); |
| 496 |
}, |
| 497 |
}; |
| 498 |
|
| 499 |
$(document).ready(function() { |
| 500 |
EasyElementsAdmin.init(); |
| 501 |
}); |
| 502 |
|
| 503 |
window.EasyElementsAdmin = EasyElementsAdmin; |
| 504 |
|
| 505 |
$(document).ready(function ($) { |
| 506 |
|
| 507 |
function hideEmptyGroups() { |
| 508 |
|
| 509 |
$('.easyel-widgets-grid').each(function () { |
| 510 |
var wrapper = $(this); |
| 511 |
|
| 512 |
var items = wrapper.find('.easy-widget-item'); |
| 513 |
|
| 514 |
var visibleItems = items.filter(function () { |
| 515 |
return $(this).css('display') !== 'none'; |
| 516 |
}).length; |
| 517 |
|
| 518 |
var headingGroup = wrapper.prev('.easyel-widget-heading-group'); |
| 519 |
|
| 520 |
if (visibleItems === 0) { |
| 521 |
headingGroup.hide(); |
| 522 |
} else { |
| 523 |
headingGroup.show(); |
| 524 |
} |
| 525 |
}); |
| 526 |
} |
| 527 |
|
| 528 |
hideEmptyGroups(); |
| 529 |
|
| 530 |
$(document).on('click', '.easyel-action-btn', function () { |
| 531 |
setTimeout(hideEmptyGroups, 50); |
| 532 |
}); |
| 533 |
|
| 534 |
}); |
| 535 |
|
| 536 |
|
| 537 |
$(document).ready(function() { |
| 538 |
|
| 539 |
$('.easyel-scroll-smoother-popup-setting').on('click', function(e) { |
| 540 |
e.preventDefault(); |
| 541 |
|
| 542 |
$('.easyel-smooth-scroll-popup').addClass('active'); |
| 543 |
$('html').addClass('popup-opened'); |
| 544 |
}); |
| 545 |
|
| 546 |
$('.easyel-smooth-scroll-popup-close-icon').on('click', function(e) { |
| 547 |
e.preventDefault(); |
| 548 |
$('.easyel-smooth-scroll-popup').removeClass('active'); |
| 549 |
$('html').removeClass('popup-opened'); |
| 550 |
}); |
| 551 |
}); |
| 552 |
|
| 553 |
function easyelDisplayMessage(message, type = 'success') { |
| 554 |
let messageBox = $('#easyel-message-box'); |
| 555 |
|
| 556 |
if (type === 'success') { |
| 557 |
messageBox.html('<p class="easyel-saved-success-message">' + message + '</p>').fadeIn().delay(1500).fadeOut(); |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
$(document).ready(function($){ |
| 562 |
|
| 563 |
var $form = $('.easyel-smooth-scroll-settings-main-wrapper'); |
| 564 |
var $saveButton = $('.smooth_scroll_popup_item_save'); |
| 565 |
|
| 566 |
$saveButton.prop('disabled', true); |
| 567 |
|
| 568 |
$form.on('input change', 'input, select', function() { |
| 569 |
$saveButton.prop('disabled', false).val('Save Changes'); |
| 570 |
}); |
| 571 |
|
| 572 |
$(document).on('click', '.smooth_scroll_popup_item_save', function(event){ |
| 573 |
event.preventDefault(); |
| 574 |
|
| 575 |
var saveButton = $(this); |
| 576 |
|
| 577 |
saveButton.prop('disabled', true).val('Saving...'); |
| 578 |
|
| 579 |
var settings = { |
| 580 |
smooth_scroll_speed: $('input[name="smooth_scroll_speed"]').val(), |
| 581 |
smooth_scroll_normalize: $('input[name="smooth_scroll_normalize"]').is(':checked') ? 1 : 0, |
| 582 |
smooth_scroll_enable_mobile: $('input[name="smooth_scroll_enable_mobile"]').is(':checked') ? 1 : 0, |
| 583 |
smooth_scroll_disable_editor_mode: $('input[name="smooth_scroll_disable_editor_mode"]').is(':checked') ? 1 : 0, |
| 584 |
enable_smooth_scroller: $('input[data-key="enable_smooth_scroller"]').is(':checked') ? 1 : 0 |
| 585 |
}; |
| 586 |
|
| 587 |
// AJAX call |
| 588 |
$.ajax({ |
| 589 |
url: ajaxurl, |
| 590 |
type: 'POST', |
| 591 |
dataType: 'json', |
| 592 |
data: { |
| 593 |
action: 'save_smooth_scroll_settings', |
| 594 |
nonce: easyElementsData.nonce, |
| 595 |
settings: settings |
| 596 |
}, |
| 597 |
success: function(response){ |
| 598 |
if(response.success){ |
| 599 |
easyelDisplayMessage('All settings saved', 'success'); |
| 600 |
saveButton.val('Saved All Data').prop('disabled', true); |
| 601 |
} else { |
| 602 |
easyelDisplayMessage('Error saving settings', 'error'); |
| 603 |
saveButton.val('Save Changes').prop('disabled', false); |
| 604 |
} |
| 605 |
}, |
| 606 |
error: function(jqXHR, textStatus, errorThrown){ |
| 607 |
console.log('AJAX error:', textStatus, errorThrown); |
| 608 |
easyelDisplayMessage('AJAX error: ' + textStatus, 'error'); |
| 609 |
saveButton.val('Save Changes').prop('disabled', false); |
| 610 |
} |
| 611 |
}); |
| 612 |
}); |
| 613 |
}); |
| 614 |
|
| 615 |
})(jQuery); |
| 616 |
|