| @@ -1,1280 +1,615 @@ | ||
| 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 | - $('.widget-toggle-checkbox').on('change', function () { | |
| 22 | - | |
| 23 | - var checkbox = $(this); | |
| 24 | - var mainWrap = $('.easyel-plugin-main-settings-page'); | |
| 25 | - var indicator = mainWrap.find('.easyel-saving-indicator'); | |
| 26 | - | |
| 27 | - var widgetKey = checkbox.data('widget-key'); | |
| 28 | - var status = checkbox.is(':checked') ? '1' : '0'; | |
| 29 | - | |
| 30 | - if (!widgetKey) return; | |
| 31 | - | |
| 32 | - indicator.text('Saving...'); | |
| 33 | - mainWrap.addClass('is-saving'); | |
| 34 | - | |
| 35 | - $.ajax({ | |
| 36 | - url: ajaxurl, | |
| 37 | - type: 'POST', | |
| 38 | - data: { | |
| 39 | - action: 'easy_elements_save_widget_setting', | |
| 40 | - widget_key: widgetKey, | |
| 41 | - status: status, | |
| 42 | - nonce: easyElementsData.widget_settings_nonce | |
| 43 | - }, | |
| 44 | - | |
| 45 | - success: function (response) { | |
| 46 | - | |
| 47 | - if (response.success) { | |
| 48 | - | |
| 49 | - indicator.text('Saved'); | |
| 50 | - | |
| 51 | - setTimeout(function () { | |
| 52 | - mainWrap.removeClass('is-saving'); | |
| 53 | - indicator.text('Saving...'); | |
| 54 | - }, 500 ); | |
| 55 | - | |
| 56 | - } else { | |
| 57 | - // Pro-locked items never reach this branch in | |
| 58 | - // normal use (click is intercepted at the | |
| 59 | - // upgrade-modal handler). On any other save | |
| 60 | - // failure just revert silently. | |
| 61 | - checkbox.prop('checked', !checkbox.is(':checked')); | |
| 62 | - mainWrap.removeClass('is-saving'); | |
| 63 | - } | |
| 64 | - }, | |
| 65 | - | |
| 66 | - error: function () { | |
| 67 | - mainWrap.removeClass('is-saving'); | |
| 68 | - checkbox.prop('checked', !checkbox.is(':checked')); | |
| 69 | - } | |
| 70 | - }); | |
| 71 | - }); | |
| 72 | - | |
| 73 | - | |
| 74 | - | |
| 75 | - | |
| 76 | - }, | |
| 77 | - | |
| 78 | - initSearchFunctionality: function() { | |
| 79 | - | |
| 80 | - function hideEmptyGroups() { | |
| 81 | - $('.easyel-widgets-grid').each(function () { | |
| 82 | - var wrapper = $(this); | |
| 83 | - var items = wrapper.find('.easy-widget-item'); | |
| 84 | - | |
| 85 | - var visibleItems = items.filter(function () { | |
| 86 | - return $(this).css('display') !== 'none'; | |
| 87 | - }).length; | |
| 88 | - | |
| 89 | - var headingGroup = wrapper.prev('.easyel-widget-heading-group'); | |
| 90 | - | |
| 91 | - if (visibleItems === 0) { | |
| 92 | - headingGroup.hide(); | |
| 93 | - wrapper.hide(); | |
| 94 | - } else { | |
| 95 | - headingGroup.show(); | |
| 96 | - wrapper.show(); | |
| 97 | - } | |
| 98 | - }); | |
| 99 | - } | |
| 100 | - | |
| 101 | - $('#element-search').on('input', function() { | |
| 102 | - var searchTerm = $(this).val().toLowerCase(); | |
| 103 | - | |
| 104 | - $('.easy-widget-item').each(function() { | |
| 105 | - var widgetTitle = $(this).find('.widget-header strong').text().toLowerCase(); | |
| 106 | - var widgetDesc = $(this).find('.widget-description').text().toLowerCase(); | |
| 107 | - | |
| 108 | - if (widgetTitle.includes(searchTerm) || widgetDesc.includes(searchTerm)) { | |
| 109 | - $(this).show(); | |
| 110 | - } else { | |
| 111 | - $(this).hide(); | |
| 112 | - } | |
| 113 | - }); | |
| 114 | - | |
| 115 | - hideEmptyGroups(); | |
| 116 | - }); | |
| 117 | - | |
| 118 | - hideEmptyGroups(); | |
| 119 | - }, | |
| 120 | - | |
| 121 | - | |
| 122 | - initBulkActions: function() { | |
| 123 | - $('#activate-all-btn').on('click', function() { | |
| 124 | - var currentTab = $('.easyel-nav-tab-active').data('tab'); | |
| 125 | - EasyElementsAdmin.performBulkAction('activate_all', currentTab); | |
| 126 | - }); | |
| 127 | - | |
| 128 | - $('#deactivate-all-btn').on('click', function() { | |
| 129 | - EasyElementsAdmin.performBulkAction('deactivate_all'); | |
| 130 | - }); | |
| 131 | - }, | |
| 132 | - | |
| 133 | - performBulkAction: function(action) { | |
| 134 | - | |
| 135 | - var currentTab = $('.easyel-nav-tab-active').data('tab'); | |
| 136 | - var currentFilter = $('.easyel-action-btn.active').data('filter'); | |
| 137 | - var btn = action === 'activate_all' ? $('#activate-all-btn') : $('#deactivate-all-btn'); | |
| 138 | - var originalText = btn.text(); | |
| 139 | - | |
| 140 | - let mainWrap = $('.easyel-plugin-main-settings-page'); | |
| 141 | - let indicator = mainWrap.find('.easyel-saving-indicator'); | |
| 142 | - | |
| 143 | - btn.prop('disabled', true).text(easyElementsData.strings.processing); | |
| 144 | - | |
| 145 | - indicator.text('Saving...'); | |
| 146 | - mainWrap.addClass('is-saving'); | |
| 147 | - | |
| 148 | - $.post(ajaxurl, { | |
| 149 | - action: 'easy_elements_bulk_action', | |
| 150 | - bulk_action: action, | |
| 151 | - tab: currentTab, | |
| 152 | - filter: currentFilter, | |
| 153 | - nonce: easyElementsData.bulk_action_nonce | |
| 154 | - }) | |
| 155 | - .done(function(response) { | |
| 156 | - | |
| 157 | - if (response.success) { | |
| 158 | - | |
| 159 | - $('.widget-toggle-checkbox').each(function() { | |
| 160 | - var $checkbox = $(this); | |
| 161 | - let item = $checkbox.closest('.easy-widget-item'); | |
| 162 | - | |
| 163 | - if ($checkbox.data('tab') !== currentTab) { | |
| 164 | - return; | |
| 165 | - } | |
| 166 | - | |
| 167 | - let isProWidget = item.hasClass('easyel-pro-widget'); | |
| 168 | - | |
| 169 | - if (currentFilter === 'easyel_free' && isProWidget) { | |
| 170 | - return; | |
| 171 | - } | |
| 172 | - | |
| 173 | - if (currentFilter === 'easyel_pro' && !isProWidget) { | |
| 174 | - return; | |
| 175 | - } | |
| 176 | - | |
| 177 | - // Pro-only widgets aren't registered when the | |
| 178 | - // premium add-on is inactive, so a bulk "activate" | |
| 179 | - // request to the server is rejected for them. Mirror | |
| 180 | - // that here: leave them unchecked rather than | |
| 181 | - // pretending the bulk action affected them. | |
| 182 | - if (isProWidget && !response.data.is_pro_active) { | |
| 183 | - $checkbox.prop('checked', false); | |
| 184 | - } else { | |
| 185 | - $checkbox.prop('checked', action === 'activate_all'); | |
| 186 | - } | |
| 187 | - | |
| 188 | - }); | |
| 189 | - | |
| 190 | - $('.easyel-group-toggle-widget').each(function() { | |
| 191 | - let groupCheckbox = $(this); | |
| 192 | - let groupSlug = groupCheckbox.data('group'); | |
| 193 | - let groupWrapper = $('.easyel-widgets-grid[data-group="' + groupSlug + '"]'); | |
| 194 | - | |
| 195 | - let allChecked = true; | |
| 196 | - groupWrapper.find('.widget-toggle-checkbox').each(function() { | |
| 197 | - if (!$(this).prop('checked') && !$(this).closest('.easyel-widget-item').hasClass('easyel-pro-enable')) { | |
| 198 | - allChecked = false; | |
| 199 | - return false; | |
| 200 | - } | |
| 201 | - }); | |
| 202 | - | |
| 203 | - groupCheckbox.prop('checked', allChecked); | |
| 204 | - groupCheckbox.closest('.easyel-toggle-switch-widget').find('.easyel-enable-all-widget').text(allChecked ? 'Disable All' : 'Enable All'); | |
| 205 | - }); | |
| 206 | - | |
| 207 | - indicator.text('Saved'); | |
| 208 | - | |
| 209 | - setTimeout(function() { | |
| 210 | - mainWrap.removeClass('is-saving'); | |
| 211 | - indicator.text('Saving...'); | |
| 212 | - }, 700); | |
| 213 | - } | |
| 214 | - }) | |
| 215 | - .fail(function() { | |
| 216 | - // Error fallback | |
| 217 | - mainWrap.removeClass('is-saving'); | |
| 218 | - }) | |
| 219 | - .always(function() { | |
| 220 | - btn.prop('disabled', false).text(originalText); | |
| 221 | - }); | |
| 222 | - }, | |
| 223 | - | |
| 224 | - EasyelWidgetGroupEnable: function() { | |
| 225 | - | |
| 226 | - function EasyupdateEnableAllText2(groupCheckbox, groupWrapper) { | |
| 227 | - let allChecked = true; | |
| 228 | - let availableWidgets = groupWrapper.find('.widget-toggle-checkbox').not(':disabled').closest('.easy-widget-item').not('.easyel-pro-enable'); | |
| 229 | - | |
| 230 | - if (availableWidgets.length === 0) { | |
| 231 | - allChecked = false; | |
| 232 | - } else { | |
| 233 | - availableWidgets.each(function() { | |
| 234 | - let checkbox = $(this).find('.widget-toggle-checkbox'); | |
| 235 | - if (!checkbox.prop('checked')) { | |
| 236 | - allChecked = false; | |
| 237 | - return false; | |
| 238 | - } | |
| 239 | - }); | |
| 240 | - } | |
| 241 | - | |
| 242 | - let textSpan = groupCheckbox.closest('.easyel-toggle-switch-widget').find('.easyel-enable-all-widget'); | |
| 243 | - | |
| 244 | - textSpan.text(allChecked ? 'Disable All' : 'Enable All'); | |
| 245 | - groupCheckbox.prop('checked', allChecked); | |
| 246 | - } | |
| 247 | - | |
| 248 | - let groupTabEnable = $(".easyel-tab-panel.widget"); | |
| 249 | - | |
| 250 | - groupTabEnable.find('.easyel-group-toggle-widget').each(function() { | |
| 251 | - let groupCheckbox = $(this); | |
| 252 | - let groupSlug = groupCheckbox.data('group'); | |
| 253 | - let groupWrapper = $('.easyel-widgets-grid[data-group="' + groupSlug + '"]'); | |
| 254 | - | |
| 255 | - EasyupdateEnableAllText2(groupCheckbox, groupWrapper); | |
| 256 | - }); | |
| 257 | - | |
| 258 | - groupTabEnable.on('change', '.easyel-group-toggle-widget', function () { | |
| 259 | - | |
| 260 | - let groupCheckbox = $(this); | |
| 261 | - let groupSlug = groupCheckbox.data('group'); | |
| 262 | - let groupWrapper = $('.easyel-widgets-grid[data-group="' + groupSlug + '"]'); | |
| 263 | - let hiddenField = $('input.easyel-group-hidden[name="easy_element_group_' + groupSlug + '"]'); | |
| 264 | - | |
| 265 | - let status = groupCheckbox.is(':checked') ? 1 : 0; | |
| 266 | - | |
| 267 | - groupWrapper.find('.widget-toggle-checkbox').each(function () { | |
| 268 | - | |
| 269 | - let checkbox = $(this); | |
| 270 | - let widgetItem = checkbox.closest('.easy-widget-item'); | |
| 271 | - | |
| 272 | - if (widgetItem.hasClass('easyel-pro-enable')) return; | |
| 273 | - checkbox.prop('checked', status === 1); | |
| 274 | - }); | |
| 275 | - | |
| 276 | - | |
| 277 | - hiddenField.val(status); | |
| 278 | - | |
| 279 | - EasyupdateEnableAllText2( groupCheckbox, groupWrapper ); | |
| 280 | - | |
| 281 | - let keys = []; | |
| 282 | - groupWrapper.find('.widget-toggle-checkbox').each(function() { keys.push($(this).data('key')); }); | |
| 283 | - if (keys.length) { | |
| 284 | - $.post(ajaxurl, { | |
| 285 | - action: 'easy_elements_bulk_group_action', | |
| 286 | - group: groupSlug, | |
| 287 | - status: status, | |
| 288 | - nonce: easyElementsData.bulk_action_nonce | |
| 289 | - }); | |
| 290 | - } | |
| 291 | - }); | |
| 292 | - }, | |
| 293 | - | |
| 294 | - initAllExtensions: function() { | |
| 295 | - let $extensionsTab = $('.easyel-tab-panel.extensions'); | |
| 296 | - | |
| 297 | - // On page load: hide settings icon for unchecked extensions | |
| 298 | - $('.easyel-extension-toggle').each(function () { | |
| 299 | - var $item = $(this).closest('.easyel-extension-item'); | |
| 300 | - var $gear = $item.find('.dashicons-admin-generic'); | |
| 301 | - if ($gear.length) { | |
| 302 | - if (!$(this).is(':checked')) { | |
| 303 | - $gear.hide(); | |
| 304 | - } | |
| 305 | - } | |
| 306 | - }); | |
| 307 | - | |
| 308 | - $('.easyel-extension-toggle').on('change', function () { | |
| 309 | - let checkbox = $(this); | |
| 310 | - let key = checkbox.data('key'); | |
| 311 | - let tab = checkbox.data('tab'); | |
| 312 | - let status = checkbox.is(':checked') ? 1 : 0; | |
| 313 | - | |
| 314 | - // Show/hide settings icon based on toggle | |
| 315 | - let $item = checkbox.closest('.easyel-extension-item'); | |
| 316 | - let $gear = $item.find('.dashicons-admin-generic'); | |
| 317 | - if ($gear.length) { | |
| 318 | - status ? $gear.show() : $gear.hide(); | |
| 319 | - } | |
| 320 | - | |
| 321 | - let mainWrap = $('.easyel-plugin-main-settings-page'); | |
| 322 | - let indicator = mainWrap.find('.easyel-saving-indicator'); | |
| 323 | - | |
| 324 | - indicator.text('Saving...'); | |
| 325 | - mainWrap.addClass('is-saving'); | |
| 326 | - | |
| 327 | - const featureWidgetMap = { | |
| 328 | - enable_megamenu_builder: 'mega_menu_widget' | |
| 329 | - }; | |
| 330 | - | |
| 331 | - | |
| 332 | - $.post(ajaxurl, { | |
| 333 | - action: 'easy_elements_save_global_extensions', | |
| 334 | - tab: tab, | |
| 335 | - key: key, | |
| 336 | - status: status, | |
| 337 | - nonce: easyElementsData.widget_settings_nonce | |
| 338 | - }) | |
| 339 | - .done(function(response) { | |
| 340 | - if (response.success) { | |
| 341 | - indicator.text('Saved'); | |
| 342 | - | |
| 343 | - if (featureWidgetMap[key]) { | |
| 344 | - const widgetKey = featureWidgetMap[key]; | |
| 345 | - const widgetEl = $('.easy-widget-item[data-widget-key="' + widgetKey + '"]'); | |
| 346 | - | |
| 347 | - if (status === 0) { | |
| 348 | - | |
| 349 | - widgetEl.slideUp(200, function () { | |
| 350 | - $(this).remove(); | |
| 351 | - }); | |
| 352 | - } else { | |
| 353 | - indicator.text('Reloading…'); | |
| 354 | - | |
| 355 | - setTimeout(function () { | |
| 356 | - location.reload(); | |
| 357 | - }, 300); | |
| 358 | - } | |
| 359 | - } | |
| 360 | - | |
| 361 | - | |
| 362 | - } else { | |
| 363 | - // Pro-locked items never reach this branch in | |
| 364 | - // normal use (click is intercepted at the | |
| 365 | - // upgrade-modal handler). On any other save | |
| 366 | - // failure just revert silently. | |
| 367 | - checkbox.prop('checked', !checkbox.is(':checked')); | |
| 368 | - mainWrap.removeClass('is-saving'); | |
| 369 | - return; | |
| 370 | - } | |
| 371 | - | |
| 372 | - setTimeout(function() { | |
| 373 | - mainWrap.removeClass('is-saving'); | |
| 374 | - indicator.text('Saving...'); | |
| 375 | - }, 500); | |
| 376 | - }) | |
| 377 | - .fail(function () { | |
| 378 | - mainWrap.removeClass('is-saving'); | |
| 379 | - checkbox.prop('checked', !checkbox.is(':checked')); | |
| 380 | - }); | |
| 381 | - }); | |
| 382 | - | |
| 383 | - function EasyupdateEnableAllText(groupCheckbox) { | |
| 384 | - let status = groupCheckbox.is(':checked') ? 1 : 0; | |
| 385 | - let label = groupCheckbox.closest('.easyel-toggle-switch-extension'); | |
| 386 | - let textSpan = label.find('.easyel-enable-all'); | |
| 387 | - let groupSlug = groupCheckbox.data('group'); | |
| 388 | - let groupWrapper = $('.easyel-extension-wrapper[data-group="' + groupSlug + '"]'); | |
| 389 | - | |
| 390 | - let totalItems = groupWrapper.find('.easyel-extension-item').length; | |
| 391 | - let proItems = groupWrapper.find('.easyel-extension-item.easyel-pro-enable').length; | |
| 392 | - | |
| 393 | - if (totalItems > 0 && totalItems === proItems) { | |
| 394 | - groupCheckbox.prop('disabled', true); | |
| 395 | - label.css({'opacity': '1','border':'none', 'cursor': 'not-allowed'}); | |
| 396 | - | |
| 397 | - return; | |
| 398 | - } | |
| 399 | - | |
| 400 | - if (status === 1) { | |
| 401 | - textSpan.text('Disable All'); | |
| 402 | - } else { | |
| 403 | - textSpan.text('Enable All'); | |
| 404 | - } | |
| 405 | - } | |
| 406 | - | |
| 407 | - // Extension tab initialize hobar shomoy run hobe | |
| 408 | - $extensionsTab.find('.easyel-group-toggle').each(function() { | |
| 409 | - EasyupdateEnableAllText($(this)); | |
| 410 | - }); | |
| 411 | - | |
| 412 | - $extensionsTab.on('change', '.easyel-group-toggle', function () { | |
| 413 | - let groupCheckbox = $(this); | |
| 414 | - let groupSlug = groupCheckbox.data('group'); | |
| 415 | - let groupWrapper = $('.easyel-extension-wrapper[data-group="' + groupSlug + '"]'); | |
| 416 | - let hiddenField = $('input.easyel-group-hidden[name="easy_element_group_' + groupSlug + '"]'); | |
| 417 | - | |
| 418 | - let status = groupCheckbox.is(':checked') ? 1 : 0; | |
| 419 | - | |
| 420 | - EasyupdateEnableAllText(groupCheckbox); | |
| 421 | - | |
| 422 | - | |
| 423 | - groupWrapper.find('.easyel-extension-toggle').each(function () { | |
| 424 | - let checkbox = $(this); | |
| 425 | - if (checkbox.closest('.easyel-extension-item').hasClass('easyel-pro-enable')) return; | |
| 426 | - checkbox.prop('checked', status === 1); | |
| 427 | - | |
| 428 | - // Show/hide settings icon | |
| 429 | - let $gear = checkbox.closest('.easyel-extension-item').find('.dashicons-admin-generic'); | |
| 430 | - if ($gear.length) { | |
| 431 | - status ? $gear.show() : $gear.hide(); | |
| 432 | - } | |
| 433 | - }); | |
| 434 | - | |
| 435 | - hiddenField.val(status); | |
| 436 | - | |
| 437 | - let mainWrap = $('.easyel-plugin-main-settings-page'); | |
| 438 | - let indicator = mainWrap.find('.easyel-saving-indicator'); | |
| 439 | - | |
| 440 | - indicator.text('Saving...'); | |
| 441 | - mainWrap.addClass('is-saving'); | |
| 442 | - | |
| 443 | - let keys = []; | |
| 444 | - groupWrapper.find('.easyel-extension-toggle').each(function() { keys.push($(this).data('key')); }); | |
| 445 | - if (keys.length) { | |
| 446 | - $.post(ajaxurl, { | |
| 447 | - action: 'easy_elements_save_global_extensions_bulk', | |
| 448 | - tab: 'extensions', | |
| 449 | - keys: keys, | |
| 450 | - status: status, | |
| 451 | - group: groupSlug, | |
| 452 | - nonce: easyElementsData.widget_settings_nonce | |
| 453 | - }).done(function(response) { | |
| 454 | - if (response.success) { | |
| 455 | - indicator.text('Saved'); | |
| 456 | - } else { | |
| 457 | - indicator.text('Failed'); | |
| 458 | - } | |
| 459 | - | |
| 460 | - setTimeout(function() { | |
| 461 | - mainWrap.removeClass('is-saving'); | |
| 462 | - indicator.text('Saving...'); | |
| 463 | - }, 500 ); | |
| 464 | - }) | |
| 465 | - .fail(function() { | |
| 466 | - indicator.text('Failed'); | |
| 467 | - setTimeout(function() { | |
| 468 | - mainWrap.removeClass('is-saving'); | |
| 469 | - indicator.text('Saving...'); | |
| 470 | - }, 700); | |
| 471 | - }); | |
| 472 | - } | |
| 473 | - else { | |
| 474 | - setTimeout(function() { | |
| 475 | - mainWrap.removeClass('is-saving'); | |
| 476 | - indicator.text('Saving...'); | |
| 477 | - }, 500); | |
| 478 | - } | |
| 479 | - }); | |
| 480 | - }, | |
| 481 | - | |
| 482 | - easyEltab: function() { | |
| 483 | - $('#toplevel_page_easy-elements-dashboard ul.wp-submenu a').on('click', function (e) { | |
| 484 | - const href = $(this).attr('href'); | |
| 485 | - const isDashboardPage = window.location.href.includes('page=easy-elements-dashboard'); | |
| 486 | - | |
| 487 | - if (isDashboardPage && href.includes('#')) { | |
| 488 | - e.preventDefault(); | |
| 489 | - | |
| 490 | - let tab = 'overview'; | |
| 491 | - if (href.includes('#widget')) tab = 'widget'; | |
| 492 | - if (href.includes('#extensions')) tab = 'extensions'; | |
| 493 | - if (href.includes('#activate_license')) tab = 'activate_license'; | |
| 494 | - | |
| 495 | - activateTab(tab); | |
| 496 | - history.replaceState(null, null, '#' + tab); | |
| 497 | - } | |
| 498 | - }); | |
| 499 | - | |
| 500 | - let hash = window.location.hash.substring(1); | |
| 501 | - if (hash) activateTab(hash); | |
| 502 | - else activateTab('overview'); | |
| 503 | - | |
| 504 | - $('.easyel-nav-tab').click(function (e) { | |
| 505 | - const tab = $(this).data('tab'); | |
| 506 | - | |
| 507 | - // No data-tab → treat as a real link (e.g. Starter Templates page). | |
| 508 | - if (!tab) return; | |
| 509 | - | |
| 510 | - e.preventDefault(); | |
| 511 | - activateTab(tab); | |
| 512 | - history.replaceState(null, null, '#' + tab); | |
| 513 | - }); | |
| 514 | - | |
| 515 | - function activateTab(tab) { | |
| 516 | - $('.easyel-nav-tab').removeClass('easyel-nav-tab-active'); | |
| 517 | - $('.easyel-nav-tab[data-tab="' + tab + '"]').addClass('easyel-nav-tab-active'); | |
| 518 | - $('.easyel-tab-panel').hide(); | |
| 519 | - $('#tab-' + tab).show(); | |
| 520 | - $('#toplevel_page_easy-elements-dashboard ul.wp-submenu li').removeClass('current'); | |
| 521 | - $('#toplevel_page_easy-elements-dashboard ul.wp-submenu a[href*="#' + tab + '"]').parent().addClass('current'); | |
| 522 | - } | |
| 523 | - }, | |
| 524 | - | |
| 525 | - easyElFilter: function() { | |
| 526 | - $(".easyel-action-btn").on("click", function() { | |
| 527 | - var filter = $(this).data("filter"); | |
| 528 | - $(".easyel-action-btn").removeClass("active"); | |
| 529 | - $(this).addClass("active"); | |
| 530 | - | |
| 531 | - $(".easy-widget-item,.easyel-extension-item").each(function() { | |
| 532 | - var $widget = $(this); | |
| 533 | - | |
| 534 | - if (filter === "easyel_all") $widget.show(); | |
| 535 | - else if (filter === "easyel_free") { | |
| 536 | - if ($widget.hasClass("easyel-pro-widget")) $widget.hide(); | |
| 537 | - else $widget.show(); | |
| 538 | - } else if (filter === "easyel_pro") { | |
| 539 | - if ($widget.hasClass("easyel-pro-widget")) $widget.show(); | |
| 540 | - else $widget.hide(); | |
| 541 | - } | |
| 542 | - }); | |
| 543 | - }); | |
| 544 | - }, | |
| 545 | - | |
| 546 | - easyelVideoPopuo: function() { | |
| 547 | - if ($(".easyel-video-popup").length ) { | |
| 548 | - var $popup = $('#easyel-popup-video-area'), | |
| 549 | - $videoContainer = $popup.find('.easyel-popup-video'); | |
| 550 | - | |
| 551 | - $('.easyel-video-popup').on('click', function(e){ | |
| 552 | - e.preventDefault(); | |
| 553 | - var videoId = $(this).attr('href').split('v=')[1].split('&')[0]; | |
| 554 | - $videoContainer.html('<iframe src="https://www.youtube.com/embed/' + videoId + '?autoplay=1" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>'); | |
| 555 | - $popup.fadeIn(); | |
| 556 | - }); | |
| 557 | - | |
| 558 | - $popup.on('click', '.easyel-popup-close, #easyel-popup-video-area', function(e){ | |
| 559 | - if($(e.target).is('.easyel-popup-close') || $(e.target).is('#easyel-popup-video-area')){ | |
| 560 | - $popup.fadeOut(); | |
| 561 | - $videoContainer.html(''); | |
| 562 | - } | |
| 563 | - }); | |
| 564 | - }; | |
| 565 | - }, | |
| 566 | - | |
| 567 | - easyelFaq: function() { | |
| 568 | - if ($(".easyel-faq-item").length ) { | |
| 569 | - $(".easyel-faq-item.active").find(".easyel-faq-item-content").show(); | |
| 570 | - $(".easyel-faq-item-heading").click(function(){ | |
| 571 | - var faqItem = $(this).closest(".easyel-faq-item"); | |
| 572 | - var content = faqItem.children(".easyel-faq-item-content"); | |
| 573 | - | |
| 574 | - if(faqItem.hasClass("active")){ | |
| 575 | - faqItem.removeClass("active"); | |
| 576 | - content.slideUp(300); | |
| 577 | - } else { | |
| 578 | - $(".easyel-faq-item.active").removeClass("active").children(".easyel-faq-item-content").slideUp(300); | |
| 579 | - faqItem.addClass("active"); | |
| 580 | - content.slideDown(300); | |
| 581 | - } | |
| 582 | - }); | |
| 583 | - }; | |
| 584 | - }, | |
| 585 | - | |
| 586 | - easyel_notify: function(message, type = 'success', duration = 3000) { | |
| 587 | - const toast = document.createElement('div'); | |
| 588 | - toast.className = `easyel-toast ${type}`; | |
| 589 | - toast.innerText = message; | |
| 590 | - | |
| 591 | - document.body.appendChild(toast); | |
| 592 | - | |
| 593 | - // Show animation | |
| 594 | - setTimeout(() => toast.classList.add('show'), 50); | |
| 595 | - | |
| 596 | - // Auto remove after duration | |
| 597 | - setTimeout(() => { | |
| 598 | - toast.classList.remove('show'); | |
| 599 | - setTimeout(() => toast.remove(), 300); | |
| 600 | - }, duration); | |
| 601 | - }, | |
| 602 | - | |
| 603 | - initSettings: function() { | |
| 604 | - $('#easyel-settings-save').click(function (e) { | |
| 605 | - e.preventDefault(); | |
| 606 | - | |
| 607 | - let dataArr = $('#easyel-settings-form').serializeArray(); | |
| 608 | - let settings = {}; | |
| 609 | - | |
| 610 | - dataArr.forEach(field => { | |
| 611 | - let name = field.name; | |
| 612 | - let value = field.value; | |
| 613 | - | |
| 614 | - // Detect nested name e.g. fb_config[page_id] | |
| 615 | - if (name.includes('[')) { | |
| 616 | - let mainKey = name.split('[')[0]; // fb_config | |
| 617 | - let subKey = name.match(/\[(.*?)\]/)[1]; // page_id | |
| 618 | - | |
| 619 | - if (!settings[mainKey]) settings[mainKey] = {}; // init object | |
| 620 | - settings[mainKey][subKey] = value; // assign value | |
| 621 | - } else { | |
| 622 | - // simple field (no nested) | |
| 623 | - settings[name] = value; | |
| 624 | - } | |
| 625 | - }); | |
| 626 | - | |
| 627 | - $.ajax({ | |
| 628 | - url: ajaxurl, | |
| 629 | - type: "POST", | |
| 630 | - data: { | |
| 631 | - action: "easyel_save_user_data", | |
| 632 | - security: easyElementsData.nonce, | |
| 633 | - settings: settings | |
| 634 | - }, | |
| 635 | - beforeSend: function () { | |
| 636 | - $('#easyel-settings-save') | |
| 637 | - .text("Saving...") | |
| 638 | - .prop("disabled", true); | |
| 639 | - }, | |
| 640 | - success: function(res){ | |
| 641 | - $('#easyel-settings-save') | |
| 642 | - .text('Save Settings') | |
| 643 | - .prop('disabled', false); | |
| 644 | - | |
| 645 | - if(res.success){ | |
| 646 | - EasyElementsAdmin.easyel_notify(res.data.message, 'success'); | |
| 647 | - } else { | |
| 648 | - EasyElementsAdmin.easyel_notify('Error saving settings.', 'error'); | |
| 649 | - } | |
| 650 | - }, | |
| 651 | - error: function(){ | |
| 652 | - EasyElementsAdmin.easyel_notify('AJAX error!', 'error'); | |
| 653 | - $('#easyel-settings-save').text('Save Settings').prop('disabled', false); | |
| 654 | - } | |
| 655 | - }); | |
| 656 | - | |
| 657 | - }); | |
| 658 | - }, | |
| 659 | - }; | |
| 660 | - | |
| 661 | - $(document).ready(function() { | |
| 662 | - EasyElementsAdmin.init(); | |
| 663 | - }); | |
| 664 | - | |
| 665 | - window.EasyElementsAdmin = EasyElementsAdmin; | |
| 666 | - | |
| 667 | - $(document).ready(function ($) { | |
| 668 | - | |
| 669 | - function hideEmptyGroups() { | |
| 670 | - | |
| 671 | - $('.easyel-widgets-grid').each(function () { | |
| 672 | - var wrapper = $(this); | |
| 673 | - | |
| 674 | - var items = wrapper.find('.easy-widget-item'); | |
| 675 | - | |
| 676 | - var visibleItems = items.filter(function () { | |
| 677 | - return $(this).css('display') !== 'none'; | |
| 678 | - }).length; | |
| 679 | - | |
| 680 | - var headingGroup = wrapper.prev('.easyel-widget-heading-group'); | |
| 681 | - | |
| 682 | - if (visibleItems === 0) { | |
| 683 | - headingGroup.hide(); | |
| 684 | - } else { | |
| 685 | - headingGroup.show(); | |
| 686 | - } | |
| 687 | - }); | |
| 688 | - } | |
| 689 | - | |
| 690 | - hideEmptyGroups(); | |
| 691 | - | |
| 692 | - $(document).on('click', '.easyel-action-btn', function () { | |
| 693 | - setTimeout(hideEmptyGroups, 50); | |
| 694 | - }); | |
| 695 | - | |
| 696 | - }); | |
| 697 | - | |
| 698 | - | |
| 699 | - $(document).ready(function() { | |
| 700 | - | |
| 701 | - $('.easyel-scroll-smoother-popup-setting').on('click', function(e) { | |
| 702 | - e.preventDefault(); | |
| 703 | - | |
| 704 | - $('.easyel-smooth-scroll-popup').addClass('active'); | |
| 705 | - $('html').addClass('popup-opened'); | |
| 706 | - }); | |
| 707 | - | |
| 708 | - $('.easyel-smooth-scroll-popup-close-icon').on('click', function(e) { | |
| 709 | - e.preventDefault(); | |
| 710 | - $('.easyel-smooth-scroll-popup').removeClass('active'); | |
| 711 | - $('html').removeClass('popup-opened'); | |
| 712 | - }); | |
| 713 | - | |
| 714 | - if ( $('.easyel-smooth-scroll-color').length > 0 ) { | |
| 715 | - $('.easyel-smooth-scroll-color').wpColorPicker(); | |
| 716 | - } | |
| 717 | - | |
| 718 | - }); | |
| 719 | - | |
| 720 | - $(document).ready(function() { | |
| 721 | - | |
| 722 | - $('.easyel-readingprogress-bar-popup-setting').on('click', function(e) { | |
| 723 | - e.preventDefault(); | |
| 724 | - | |
| 725 | - $('.easyel-reading-progressbar-popup').addClass('active'); | |
| 726 | - $('html').addClass('popup-opened'); | |
| 727 | - }); | |
| 728 | - | |
| 729 | - $('.easyel-reading-progressbar-popup-close-icon').on('click', function(e) { | |
| 730 | - e.preventDefault(); | |
| 731 | - $('.easyel-reading-progressbar-popup').removeClass('active'); | |
| 732 | - $('html').removeClass('popup-opened'); | |
| 733 | - }); | |
| 734 | - }); | |
| 735 | - | |
| 736 | - $(document).ready(function() { | |
| 737 | - var scrollTopColorInitialized = false; | |
| 738 | - | |
| 739 | - $('.easyel-scroll-top-popup-setting').on('click', function(e) { | |
| 740 | - e.preventDefault(); | |
| 741 | - $('.easyel-scroll-top-popup').addClass('active'); | |
| 742 | - $('html').addClass('popup-opened'); | |
| 743 | - | |
| 744 | - // Init color pickers inside popup on first open | |
| 745 | - if (!scrollTopColorInitialized) { | |
| 746 | - scrollTopColorInitialized = true; | |
| 747 | - $('.easyel-scroll-top-popup .easyel-color-picker').each(function() { | |
| 748 | - var $input = $(this); | |
| 749 | - // Destroy existing wpColorPicker if any | |
| 750 | - if ($input.closest('.wp-picker-container').length) { | |
| 751 | - $input.closest('.wp-picker-container').replaceWith($input); | |
| 752 | - } | |
| 753 | - $input.wpColorPicker({ | |
| 754 | - change: function(event, ui) { | |
| 755 | - $(event.target).val(ui.color.toString()); | |
| 756 | - $('.scroll_top_popup_item_save').prop('disabled', false).val('Save Changes'); | |
| 757 | - }, | |
| 758 | - clear: function() { | |
| 759 | - $('.scroll_top_popup_item_save').prop('disabled', false).val('Save Changes'); | |
| 760 | - } | |
| 761 | - }); | |
| 762 | - }); | |
| 763 | - } | |
| 764 | - }); | |
| 765 | - | |
| 766 | - $('.easyel-scroll-top-popup-close-icon').on('click', function(e) { | |
| 767 | - e.preventDefault(); | |
| 768 | - $('.easyel-scroll-top-popup').removeClass('active'); | |
| 769 | - $('html').removeClass('popup-opened'); | |
| 770 | - }); | |
| 771 | - | |
| 772 | - // Icon type toggle — show/hide custom icon / image fields | |
| 773 | - $(document).on('change', '#scroll_top_icon_select', function() { | |
| 774 | - var val = $(this).val(); | |
| 775 | - $('.easyel-scroll-top-custom-icon-row').toggle(val === 'custom_icon'); | |
| 776 | - $('.easyel-scroll-top-custom-image-row').toggle(val === 'custom_image'); | |
| 777 | - }); | |
| 778 | - | |
| 779 | - // Image upload via WP media | |
| 780 | - $(document).on('click', '.easyel-scroll-top-upload-btn', function(e) { | |
| 781 | - e.preventDefault(); | |
| 782 | - var frame = wp.media({ | |
| 783 | - title: 'Select Scroll Top Image', | |
| 784 | - multiple: false, | |
| 785 | - library: { type: 'image' } | |
| 786 | - }); | |
| 787 | - frame.on('select', function() { | |
| 788 | - var attachment = frame.state().get('selection').first().toJSON(); | |
| 789 | - $('#scroll_top_custom_image').val(attachment.url); | |
| 790 | - $('.easyel-scroll-top-image-preview').attr('src', attachment.url).show(); | |
| 791 | - $('.easyel-scroll-top-remove-btn').show(); | |
| 792 | - $('.scroll_top_popup_item_save').prop('disabled', false).val('Save Changes'); | |
| 793 | - }); | |
| 794 | - frame.open(); | |
| 795 | - }); | |
| 796 | - | |
| 797 | - // Remove image | |
| 798 | - $(document).on('click', '.easyel-scroll-top-remove-btn', function(e) { | |
| 799 | - e.preventDefault(); | |
| 800 | - $('#scroll_top_custom_image').val(''); | |
| 801 | - $('.easyel-scroll-top-image-preview').attr('src', '').hide(); | |
| 802 | - $(this).hide(); | |
| 803 | - $('.scroll_top_popup_item_save').prop('disabled', false).val('Save Changes'); | |
| 804 | - }); | |
| 805 | - }); | |
| 806 | - | |
| 807 | - function easyelDisplayMessage(message, type = 'success') { | |
| 808 | - let messageBox = $('#easyel-message-box'); | |
| 809 | - | |
| 810 | - if (type === 'success') { | |
| 811 | - messageBox.html('<p class="easyel-saved-success-message">' + message + '</p>').fadeIn().delay(1500).fadeOut(); | |
| 812 | - } | |
| 813 | - } | |
| 814 | - | |
| 815 | - $(document).ready(function($){ | |
| 816 | - | |
| 817 | - var $form = $('.easyel-smooth-scroll-settings-main-wrapper'); | |
| 818 | - var $saveButton = $('.smooth_scroll_popup_item_save'); | |
| 819 | - | |
| 820 | - $saveButton.prop('disabled', true); | |
| 821 | - | |
| 822 | - $form.on('input change', 'input, select', function() { | |
| 823 | - $saveButton.prop('disabled', false).val('Save Changes'); | |
| 824 | - }); | |
| 825 | - | |
| 826 | - if ( $('.easyel-smooth-scroll-color').length > 0 ) { | |
| 827 | - | |
| 828 | - $('.easyel-smooth-scroll-color').wpColorPicker({ | |
| 829 | - change: function(event, ui) { | |
| 830 | - $saveButton.prop('disabled', false).val('Save Changes'); | |
| 831 | - }, | |
| 832 | - clear: function() { | |
| 833 | - $saveButton.prop('disabled', false).val('Save Changes'); | |
| 834 | - } | |
| 835 | - }); | |
| 836 | - } | |
| 837 | - | |
| 838 | - $(document).on('click', '.smooth_scroll_popup_item_save', function(event){ | |
| 839 | - event.preventDefault(); | |
| 840 | - | |
| 841 | - var saveButton = $(this); | |
| 842 | - | |
| 843 | - saveButton.prop('disabled', true).val('Saving...'); | |
| 844 | - | |
| 845 | - var settings = { | |
| 846 | - smooth_scroll_speed: $('input[name="smooth_scroll_speed"]').val(), | |
| 847 | - smooth_scroll_normalize: $('input[name="smooth_scroll_normalize"]').is(':checked') ? 1 : 0, | |
| 848 | - smooth_scroll_enable_mobile: $('input[name="smooth_scroll_enable_mobile"]').is(':checked') ? 1 : 0, | |
| 849 | - smooth_scroll_disable_editor_mode: $('input[name="smooth_scroll_disable_editor_mode"]').is(':checked') ? 1 : 0, | |
| 850 | - enable_smooth_scroller: $('input[data-key="enable_smooth_scroller"]').is(':checked') ? 1 : 0, | |
| 851 | - smooth_scroll_width: $('input[name="smooth_scroll_width"]').val(), | |
| 852 | - smooth_scroll_normal_color: $('input[name="smooth_scroll_normal_color"]').val(), | |
| 853 | - smooth_scroll_highlight_color: $('input[name="smooth_scroll_highlight_color"]').val(), | |
| 854 | - }; | |
| 855 | - | |
| 856 | - // AJAX call | |
| 857 | - $.ajax({ | |
| 858 | - url: ajaxurl, | |
| 859 | - type: 'POST', | |
| 860 | - dataType: 'json', | |
| 861 | - data: { | |
| 862 | - action: 'save_smooth_scroll_settings', | |
| 863 | - nonce: easyElementsData.nonce, | |
| 864 | - settings: settings | |
| 865 | - }, | |
| 866 | - success: function(response){ | |
| 867 | - if(response.success){ | |
| 868 | - easyelDisplayMessage('All settings saved', 'success'); | |
| 869 | - saveButton.val('Saved All Data').prop('disabled', true); | |
| 870 | - } else { | |
| 871 | - easyelDisplayMessage('Error saving settings', 'error'); | |
| 872 | - saveButton.val('Save Changes').prop('disabled', false); | |
| 873 | - } | |
| 874 | - }, | |
| 875 | - error: function(jqXHR, textStatus, errorThrown){ | |
| 876 | - console.log('AJAX error:', textStatus, errorThrown); | |
| 877 | - easyelDisplayMessage('AJAX error: ' + textStatus, 'error'); | |
| 878 | - saveButton.val('Save Changes').prop('disabled', false); | |
| 879 | - } | |
| 880 | - }); | |
| 881 | - }); | |
| 882 | - }); | |
| 883 | - | |
| 884 | - $(document).ready(function($){ | |
| 885 | - | |
| 886 | - var $form = $('.easyel-reading-progressbar-settings-main-wrapper'); | |
| 887 | - var $saveButton = $('.reading_progressbar_popup_item_save'); | |
| 888 | - | |
| 889 | - $saveButton.prop('disabled', true); | |
| 890 | - | |
| 891 | - // Enable save button on input/change | |
| 892 | - $form.on('input change', 'input, select', function() { | |
| 893 | - $saveButton.prop('disabled', false).val('Save Changes'); | |
| 894 | - }); | |
| 895 | - | |
| 896 | - // Initialize color picker safely | |
| 897 | - if ( typeof wp !== 'undefined' && wp.colorPicker ) { | |
| 898 | - if ( $('.easyel-color-picker').length ) { | |
| 899 | - $('.easyel-color-picker').wpColorPicker(); | |
| 900 | - } | |
| 901 | - } | |
| 902 | - | |
| 903 | - // Save via AJAX | |
| 904 | - $(document).on('click', '.reading_progressbar_popup_item_save', function(event){ | |
| 905 | - event.preventDefault(); | |
| 906 | - | |
| 907 | - var saveButton = $(this); | |
| 908 | - saveButton.prop('disabled', true).val('Saving...'); | |
| 909 | - | |
| 910 | - var settings = { | |
| 911 | - reading_progressbar_position: $('select[name="reading_progressbar_position"]').val(), | |
| 912 | - reading_progressbar_display: $('input[name="reading_progressbar_display[]"]:checked').map(function(){ return this.value; }).get(), | |
| 913 | - reading_progressbar_color: $('input[name="reading_progressbar_color"]').val(), | |
| 914 | - reading_progressbar_height: $('input[name="reading_progressbar_height"]').val(), | |
| 915 | - reading_progressbar_specific_page: $('select[name="reading_progressbar_specific_page[]"]').map(function(){ return $(this).val(); }).get(), | |
| 916 | - }; | |
| 917 | - | |
| 918 | - $.ajax({ | |
| 919 | - url: ajaxurl, | |
| 920 | - type: 'POST', | |
| 921 | - dataType: 'json', | |
| 922 | - data: { | |
| 923 | - action: 'save_reading_progressbar_settings', | |
| 924 | - nonce: easyElementsData.nonce, | |
| 925 | - settings: settings | |
| 926 | - }, | |
| 927 | - success: function(response){ | |
| 928 | - if(response.success){ | |
| 929 | - easyelDisplayMessage('Settings Saved', 'success'); | |
| 930 | - saveButton.val('Saved All Data').prop('disabled', true); | |
| 931 | - } else { | |
| 932 | - easyelDisplayMessage('Error saving settings', 'error'); | |
| 933 | - saveButton.val('Save Changes').prop('disabled', false); | |
| 934 | - } | |
| 935 | - }, | |
| 936 | - error: function(jqXHR, textStatus, errorThrown){ | |
| 937 | - console.log('AJAX error:', textStatus, errorThrown); | |
| 938 | - easyelDisplayMessage('AJAX error: ' + textStatus, 'error'); | |
| 939 | - saveButton.val('Save Changes').prop('disabled', false); | |
| 940 | - } | |
| 941 | - }); | |
| 942 | - }); | |
| 943 | - }); | |
| 944 | - | |
| 945 | - // open close popup modal | |
| 946 | - | |
| 947 | - function easyelAdminToggleOpenProModal() { | |
| 948 | - $('#easyel-admin-toggle-pro-upgrade-modal').addClass('active'); | |
| 949 | - $('body').addClass('easyel-admin-toggle-modal-open'); | |
| 950 | - } | |
| 951 | - | |
| 952 | - function easyelAdminToggleCloseProModal() { | |
| 953 | - $('#easyel-admin-toggle-pro-upgrade-modal').removeClass('active'); | |
| 954 | - $('body').removeClass('easyel-admin-toggle-modal-open'); | |
| 955 | - } | |
| 956 | - | |
| 957 | - /** | |
| 958 | - * Pro-locked items (widgets and extensions) — clicking the toggle | |
| 959 | - * area opens the upgrade modal instead of flipping the checkbox. | |
| 960 | - * Capture-phase + stopImmediatePropagation so the click never | |
| 961 | - * reaches the input's native toggle or the regular change handler | |
| 962 | - * that would otherwise fire an AJAX save. | |
| 963 | - */ | |
| 964 | - document.addEventListener( | |
| 965 | - 'click', | |
| 966 | - function (e) { | |
| 967 | - var trigger = e.target && e.target.closest | |
| 968 | - ? e.target.closest('.easyel-pro-enable .easyel-widget-card-switcher') | |
| 969 | - : null; | |
| 970 | - if ( ! trigger ) { | |
| 971 | - return; | |
| 972 | - } | |
| 973 | - e.preventDefault(); | |
| 974 | - e.stopImmediatePropagation(); | |
| 975 | - easyelAdminToggleOpenProModal(); | |
| 976 | - }, | |
| 977 | - true | |
| 978 | - ); | |
| 979 | - | |
| 980 | - // Close modal | |
| 981 | - $(document).on( | |
| 982 | - 'click', | |
| 983 | - '.easyel-admin-toggle-pro-modal-close, \ | |
| 984 | - .easyel-admin-toggle-pro-modal-cancel, \ | |
| 985 | - .easyel-admin-toggle-pro-modal-overlay', | |
| 986 | - function () { | |
| 987 | - easyelAdminToggleCloseProModal(); | |
| 988 | - } | |
| 989 | - ); | |
| 990 | - | |
| 991 | - // reading progressbar popup color js (exclude scroll-top + preloader popups — initialized separately) | |
| 992 | - if ( $('.easyel-color-picker').not('.easyel-scroll-top-popup .easyel-color-picker').not('.easyel-preloader-popup .easyel-color-picker').length ) { | |
| 993 | - $('.easyel-color-picker').not('.easyel-scroll-top-popup .easyel-color-picker').not('.easyel-preloader-popup .easyel-color-picker').wpColorPicker(); | |
| 994 | - } | |
| 995 | - | |
| 996 | - if( $('.easyel-readingprogress-barselect2').length ) { | |
| 997 | - $('.easyel-readingprogress-barselect2').select2({ | |
| 998 | - width: '100%', | |
| 999 | - placeholder: 'Select a page', | |
| 1000 | - multiple: true, | |
| 1001 | - }); | |
| 1002 | - } | |
| 1003 | - | |
| 1004 | - if ( $('.easyel-color-picker').not('.easyel-scroll-top-popup .easyel-color-picker').not('.easyel-preloader-popup .easyel-color-picker').length ) { | |
| 1005 | - $('.easyel-color-picker').not('.easyel-scroll-top-popup .easyel-color-picker').not('.easyel-preloader-popup .easyel-color-picker').wpColorPicker({ | |
| 1006 | - change: function (event, ui) { | |
| 1007 | - var color = ui.color.toString(); | |
| 1008 | - | |
| 1009 | - $(event.target).val(color); | |
| 1010 | - | |
| 1011 | - $('.reading_progressbar_popup_item_save') | |
| 1012 | - .prop('disabled', false) | |
| 1013 | - .val('Save Changes'); | |
| 1014 | - }, | |
| 1015 | - clear: function () { | |
| 1016 | - $('.reading_progressbar_popup_item_save') | |
| 1017 | - .prop('disabled', false) | |
| 1018 | - .val('Save Changes'); | |
| 1019 | - } | |
| 1020 | - }); | |
| 1021 | - } | |
| 1022 | - | |
| 1023 | - // Scroll Top settings save | |
| 1024 | - $(document).ready(function($){ | |
| 1025 | - | |
| 1026 | - var $popup = $('.easyel-scroll-top-popup'); | |
| 1027 | - var $scrollTopSave = $('.scroll_top_popup_item_save'); | |
| 1028 | - | |
| 1029 | - $scrollTopSave.prop('disabled', true); | |
| 1030 | - | |
| 1031 | - $popup.on('input change', 'input, select', function() { | |
| 1032 | - $scrollTopSave.prop('disabled', false).val('Save Changes'); | |
| 1033 | - }); | |
| 1034 | - | |
| 1035 | - $(document).on('click', '.scroll_top_popup_item_save', function(event){ | |
| 1036 | - event.preventDefault(); | |
| 1037 | - | |
| 1038 | - var saveButton = $(this); | |
| 1039 | - saveButton.prop('disabled', true).val('Saving...'); | |
| 1040 | - | |
| 1041 | - // Get color values from wpColorPicker hidden inputs | |
| 1042 | - var bgColor = $popup.find('input[name="scroll_top_bg_color"]').val(); | |
| 1043 | - var iconColor = $popup.find('input[name="scroll_top_icon_color"]').val(); | |
| 1044 | - | |
| 1045 | - var settings = { | |
| 1046 | - scroll_top_icon: $popup.find('select[name="scroll_top_icon"]').val(), | |
| 1047 | - scroll_top_position: $popup.find('select[name="scroll_top_position"]').val(), | |
| 1048 | - scroll_top_bg_color: bgColor || '#333333', | |
| 1049 | - scroll_top_icon_color: iconColor || '#ffffff', | |
| 1050 | - scroll_top_size: $popup.find('input[name="scroll_top_size"]').val() || '45', | |
| 1051 | - scroll_top_radius: $popup.find('input[name="scroll_top_radius"]').val() || '50', | |
| 1052 | - scroll_top_offset: $popup.find('input[name="scroll_top_offset"]').val() || '300', | |
| 1053 | - scroll_top_border_width: $popup.find('input[name="scroll_top_border_width"]').val() || '0', | |
| 1054 | - scroll_top_border_color: $popup.find('input[name="scroll_top_border_color"]').val() || '#cccccc', | |
| 1055 | - scroll_top_hover_bg_color: $popup.find('input[name="scroll_top_hover_bg_color"]').val() || '#000000', | |
| 1056 | - scroll_top_hover_icon_color: $popup.find('input[name="scroll_top_hover_icon_color"]').val() || '#ffffff', | |
| 1057 | - scroll_top_hover_border_color: $popup.find('input[name="scroll_top_hover_border_color"]').val() || '#cccccc', | |
| 1058 | - scroll_top_custom_icon: $popup.find('input[name="scroll_top_custom_icon"]').val() || '', | |
| 1059 | - scroll_top_custom_image: $popup.find('input[name="scroll_top_custom_image"]').val() || '', | |
| 1060 | - }; | |
| 1061 | - | |
| 1062 | - $.ajax({ | |
| 1063 | - url: ajaxurl, | |
| 1064 | - type: 'POST', | |
| 1065 | - dataType: 'json', | |
| 1066 | - data: { | |
| 1067 | - action: 'save_scroll_top_settings', | |
| 1068 | - nonce: easyElementsData.nonce, | |
| 1069 | - settings: settings | |
| 1070 | - }, | |
| 1071 | - success: function(response){ | |
| 1072 | - if(response.success){ | |
| 1073 | - easyelDisplayMessage('Settings Saved', 'success'); | |
| 1074 | - saveButton.val('Saved All Data').prop('disabled', true); | |
| 1075 | - } else { | |
| 1076 | - easyelDisplayMessage('Error saving settings', 'error'); | |
| 1077 | - saveButton.val('Save Changes').prop('disabled', false); | |
| 1078 | - } | |
| 1079 | - }, | |
| 1080 | - error: function(jqXHR, textStatus, errorThrown){ | |
| 1081 | - console.log('AJAX error:', textStatus, errorThrown); | |
| 1082 | - easyelDisplayMessage('AJAX error: ' + textStatus, 'error'); | |
| 1083 | - saveButton.val('Save Changes').prop('disabled', false); | |
| 1084 | - } | |
| 1085 | - }); | |
| 1086 | - }); | |
| 1087 | - }); | |
| 1088 | - | |
| 1089 | - // Preloader: open popup + init color pickers + media uploader (mirrors Scroll Top extension pattern) | |
| 1090 | - $(document).ready(function() { | |
| 1091 | - var preloaderColorInitialized = false; | |
| 1092 | - | |
| 1093 | - // Force the popup hidden on initial load so it never flashes before a click. | |
| 1094 | - $('.easyel-preloader-popup').removeClass('active').hide(); | |
| 1095 | - | |
| 1096 | - function easyelPreloaderToggleFields() { | |
| 1097 | - var $popup = $('.easyel-preloader-popup'); | |
| 1098 | - var style = $popup.find('select[name="preloader_style"]').val(); | |
| 1099 | - | |
| 1100 | - var hasSecondary = (style === 'circle' || style === 'custom_logo'); | |
| 1101 | - var isCustomLogo = (style === 'custom_logo'); | |
| 1102 | - | |
| 1103 | - $popup.find('.easyel-preloader-field-logo-only').toggle(isCustomLogo); | |
| 1104 | - $popup.find('.easyel-preloader-field-secondary-only').toggle(hasSecondary); | |
| 1105 | - } | |
| 1106 | - | |
| 1107 | - $(document).on('click', '.easyel-preloader-popup-setting', function(e) { | |
| 1108 | - e.preventDefault(); | |
| 1109 | - e.stopPropagation(); | |
| 1110 | - $('.easyel-preloader-popup').show().addClass('active'); | |
| 1111 | - $('html').addClass('popup-opened'); | |
| 1112 | - | |
| 1113 | - easyelPreloaderToggleFields(); | |
| 1114 | - | |
| 1115 | - if (!preloaderColorInitialized && typeof $.fn.wpColorPicker === 'function') { | |
| 1116 | - preloaderColorInitialized = true; | |
| 1117 | - $('.easyel-preloader-popup .easyel-color-picker').each(function() { | |
| 1118 | - var $input = $(this); | |
| 1119 | - if ($input.closest('.wp-picker-container').length) { | |
| 1120 | - return; | |
| 1121 | - } | |
| 1122 | - $input.wpColorPicker({ | |
| 1123 | - change: function(event, ui) { | |
| 1124 | - $(event.target).val(ui.color.toString()); | |
| 1125 | - $('.easyel_preloader_popup_item_save').prop('disabled', false).val('Save Changes'); | |
| 1126 | - }, | |
| 1127 | - clear: function() { | |
| 1128 | - $('.easyel_preloader_popup_item_save').prop('disabled', false).val('Save Changes'); | |
| 1129 | - } | |
| 1130 | - }); | |
| 1131 | - }); | |
| 1132 | - } | |
| 1133 | - }); | |
| 1134 | - | |
| 1135 | - $(document).on('click', '.easyel-preloader-popup-close-icon', function(e) { | |
| 1136 | - e.preventDefault(); | |
| 1137 | - var $popup = $('.easyel-preloader-popup'); | |
| 1138 | - $popup.removeClass('active'); | |
| 1139 | - $('html').removeClass('popup-opened'); | |
| 1140 | - setTimeout(function() { | |
| 1141 | - if ( ! $popup.hasClass('active') ) { | |
| 1142 | - $popup.hide(); | |
| 1143 | - } | |
| 1144 | - }, 300); | |
| 1145 | - }); | |
| 1146 | - | |
| 1147 | - // Style change toggles fields | |
| 1148 | - $(document).on('change', '.easyel-preloader-popup select[name="preloader_style"]', function() { | |
| 1149 | - easyelPreloaderToggleFields(); | |
| 1150 | - }); | |
| 1151 | - | |
| 1152 | - // Logo upload via WP media | |
| 1153 | - $(document).on('click', '.easyel-preloader-upload-btn', function(e) { | |
| 1154 | - e.preventDefault(); | |
| 1155 | - var frame = wp.media({ | |
| 1156 | - title: 'Select Preloader Logo', | |
| 1157 | - multiple: false, | |
| 1158 | - library: { type: 'image' } | |
| 1159 | - }); | |
| 1160 | - frame.on('select', function() { | |
| 1161 | - var attachment = frame.state().get('selection').first().toJSON(); | |
| 1162 | - $('.easyel-preloader-logo-input').val(attachment.url); | |
| 1163 | - $('.easyel-preloader-remove-btn').show(); | |
| 1164 | - $('.easyel_preloader_popup_item_save').prop('disabled', false).val('Save Changes'); | |
| 1165 | - }); | |
| 1166 | - frame.open(); | |
| 1167 | - }); | |
| 1168 | - | |
| 1169 | - // Remove logo | |
| 1170 | - $(document).on('click', '.easyel-preloader-remove-btn', function(e) { | |
| 1171 | - e.preventDefault(); | |
| 1172 | - $('.easyel-preloader-logo-input').val(''); | |
| 1173 | - $(this).hide(); | |
| 1174 | - $('.easyel_preloader_popup_item_save').prop('disabled', false).val('Save Changes'); | |
| 1175 | - }); | |
| 1176 | - }); | |
| 1177 | - | |
| 1178 | - // Preloader: AJAX save | |
| 1179 | - $(document).ready(function($){ | |
| 1180 | - | |
| 1181 | - var $popup = $('.easyel-preloader-popup'); | |
| 1182 | - | |
| 1183 | - function easyelPreloaderEnableSaveBtn() { | |
| 1184 | - $('.easyel_preloader_popup_item_save') | |
| 1185 | - .prop('disabled', false) | |
| 1186 | - .removeAttr('disabled') | |
| 1187 | - .val('Save Changes'); | |
| 1188 | - } | |
| 1189 | - | |
| 1190 | - function easyelPreloaderDisableSaveBtn() { | |
| 1191 | - $('.easyel_preloader_popup_item_save') | |
| 1192 | - .prop('disabled', true); | |
| 1193 | - } | |
| 1194 | - | |
| 1195 | - // Initial state — disabled | |
| 1196 | - easyelPreloaderDisableSaveBtn(); | |
| 1197 | - | |
| 1198 | - // Native delegate for text/number/select/checkbox | |
| 1199 | - $popup.on('input change', 'input, select', easyelPreloaderEnableSaveBtn); | |
| 1200 | - | |
| 1201 | - // Snapshot baseline color values; poll for color changes (wpColorPicker doesn't fire native events reliably). | |
| 1202 | - var preloaderColorBaseline = {}; | |
| 1203 | - function easyelPreloaderCaptureColors() { | |
| 1204 | - $popup.find('.easyel-color-picker').each(function() { | |
| 1205 | - var $i = $(this); | |
| 1206 | - preloaderColorBaseline[ $i.attr('name') ] = $i.val(); | |
| 1207 | - }); | |
| 1208 | - } | |
| 1209 | - | |
| 1210 | - // Capture baseline once popup opens (after wpColorPicker init has set initial values) | |
| 1211 | - $(document).on('click', '.easyel-preloader-popup-setting', function() { | |
| 1212 | - setTimeout(easyelPreloaderCaptureColors, 200); | |
| 1213 | - }); | |
| 1214 | - | |
| 1215 | - // Poll every 250ms while popup is open | |
| 1216 | - setInterval(function() { | |
| 1217 | - if ( ! $popup.hasClass('active') ) { | |
| 1218 | - return; | |
| 1219 | - } | |
| 1220 | - $popup.find('.easyel-color-picker').each(function() { | |
| 1221 | - var $i = $(this); | |
| 1222 | - var name = $i.attr('name'); | |
| 1223 | - var current = $i.val(); | |
| 1224 | - if ( preloaderColorBaseline[ name ] !== undefined && preloaderColorBaseline[ name ] !== current ) { | |
| 1225 | - preloaderColorBaseline[ name ] = current; | |
| 1226 | - easyelPreloaderEnableSaveBtn(); | |
| 1227 | - } | |
| 1228 | - }); | |
| 1229 | - }, 250); | |
| 1230 | - | |
| 1231 | - $(document).on('click', '.easyel_preloader_popup_item_save', function(event){ | |
| 1232 | - event.preventDefault(); | |
| 1233 | - | |
| 1234 | - var saveButton = $(this); | |
| 1235 | - saveButton.prop('disabled', true).val('Saving...'); | |
| 1236 | - | |
| 1237 | - var settings = { | |
| 1238 | - preloader_style: $popup.find('select[name="preloader_style"]').val() || 'circle', | |
| 1239 | - preloader_bg_color: $popup.find('input[name="preloader_bg_color"]').val() || '#ffffff', | |
| 1240 | - preloader_color: $popup.find('input[name="preloader_color"]').val() || '#5933ff', | |
| 1241 | - preloader_secondary_color: $popup.find('input[name="preloader_secondary_color"]').val() || '#e0e0e0', | |
| 1242 | - preloader_size: $popup.find('input[name="preloader_size"]').val() || '60', | |
| 1243 | - preloader_speed: $popup.find('input[name="preloader_speed"]').val() || '1', | |
| 1244 | - preloader_min_time: $popup.find('input[name="preloader_min_time"]').val() || '500', | |
| 1245 | - preloader_fadeout_time: $popup.find('input[name="preloader_fadeout_time"]').val() || '600', | |
| 1246 | - preloader_logo: $popup.find('input[name="preloader_logo"]').val() || '', | |
| 1247 | - preloader_logo_width: $popup.find('input[name="preloader_logo_width"]').val() || '36', | |
| 1248 | - preloader_logo_height: $popup.find('input[name="preloader_logo_height"]').val() || '36', | |
| 1249 | - preloader_disable_mobile: $popup.find('input[name="preloader_disable_mobile"]').is(':checked') ? 1 : 0 | |
| 1250 | - }; | |
| 1251 | - | |
| 1252 | - $.ajax({ | |
| 1253 | - url: ajaxurl, | |
| 1254 | - type: 'POST', | |
| 1255 | - dataType: 'json', | |
| 1256 | - data: { | |
| 1257 | - action: 'easyel_save_preloader_settings', | |
| 1258 | - nonce: easyElementsData.nonce, | |
| 1259 | - settings: settings | |
| 1260 | - }, | |
| 1261 | - success: function(response){ | |
| 1262 | - if (response.success) { | |
| 1263 | - easyelDisplayMessage('Settings Saved', 'success'); | |
| 1264 | - saveButton.val('Saved All Data').prop('disabled', true); | |
| 1265 | - } else { | |
| 1266 | - easyelDisplayMessage('Error saving settings', 'error'); | |
| 1267 | - saveButton.val('Save Changes').prop('disabled', false); | |
| 1268 | - } | |
| 1269 | - }, | |
| 1270 | - error: function(jqXHR, textStatus, errorThrown){ | |
| 1271 | - console.log('AJAX error:', textStatus, errorThrown); | |
| 1272 | - easyelDisplayMessage('AJAX error: ' + textStatus, 'error'); | |
| 1273 | - saveButton.val('Save Changes').prop('disabled', false); | |
| 1274 | - } | |
| 1275 | - }); | |
| 1276 | - }); | |
| 1277 | - }); | |
| 1278 | - | |
| 1279 | - | |
| 1280 | -})(jQuery); | |
| 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); | |