| 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 |
}, |
| 16 |
|
| 17 |
initWidgetToggles: function() { |
| 18 |
|
| 19 |
$('.easy-widget-item.easyel-pro-enable .widget-toggle-checkbox').each(function() { |
| 20 |
$(this).prop('checked', false).prop('disabled', true); |
| 21 |
}); |
| 22 |
|
| 23 |
$('.widget-toggle-checkbox').on('change', function() { |
| 24 |
var checkbox = $(this); |
| 25 |
var widgetItem = checkbox.closest('.easy-widget-item'); |
| 26 |
|
| 27 |
if (widgetItem.hasClass('easyel-pro-enable')) { |
| 28 |
|
| 29 |
checkbox.prop('checked', false).prop('disabled', true); |
| 30 |
return false; |
| 31 |
} |
| 32 |
|
| 33 |
var widgetKey = checkbox.data('widget-key'); |
| 34 |
var status = checkbox.is(':checked') ? '1' : '0'; |
| 35 |
|
| 36 |
if (!widgetKey) return; |
| 37 |
|
| 38 |
$.post(ajaxurl, { |
| 39 |
action: 'easy_elements_save_widget_setting', |
| 40 |
widget_key: widgetKey, |
| 41 |
status: status, |
| 42 |
nonce: easyElementsData.widget_settings_nonce |
| 43 |
}) |
| 44 |
.done(function(response) { |
| 45 |
if (!response.success) { |
| 46 |
checkbox.prop('checked', !checkbox.is(':checked')); |
| 47 |
} |
| 48 |
}) |
| 49 |
.fail(function() { |
| 50 |
checkbox.prop('checked', !checkbox.is(':checked')); |
| 51 |
}); |
| 52 |
}); |
| 53 |
}, |
| 54 |
|
| 55 |
initSearchFunctionality: function() { |
| 56 |
$('#element-search').on('input', function() { |
| 57 |
var searchTerm = $(this).val().toLowerCase(); |
| 58 |
$('.easy-widget-item').each(function() { |
| 59 |
var widgetTitle = $(this).find('.widget-header strong').text().toLowerCase(); |
| 60 |
var widgetDesc = $(this).find('.widget-description').text().toLowerCase(); |
| 61 |
|
| 62 |
if (widgetTitle.includes(searchTerm) || widgetDesc.includes(searchTerm)) { |
| 63 |
$(this).show(); |
| 64 |
} else { |
| 65 |
$(this).hide(); |
| 66 |
} |
| 67 |
}); |
| 68 |
}); |
| 69 |
}, |
| 70 |
|
| 71 |
initBulkActions: function() { |
| 72 |
$('#activate-all-btn').on('click', function() { |
| 73 |
var currentTab = $('.easyel-nav-tab-active').data('tab'); |
| 74 |
EasyElementsAdmin.performBulkAction('activate_all', currentTab); |
| 75 |
}); |
| 76 |
|
| 77 |
$('#deactivate-all-btn').on('click', function() { |
| 78 |
EasyElementsAdmin.performBulkAction('deactivate_all'); |
| 79 |
}); |
| 80 |
}, |
| 81 |
|
| 82 |
performBulkAction: function(action) { |
| 83 |
var currentTab = $('.easyel-nav-tab-active').data('tab'); |
| 84 |
var btn = action === 'activate_all' ? $('#activate-all-btn') : $('#deactivate-all-btn'); |
| 85 |
var originalText = btn.text(); |
| 86 |
|
| 87 |
btn.prop('disabled', true).text(easyElementsData.strings.processing); |
| 88 |
|
| 89 |
$.post(ajaxurl, { |
| 90 |
action: 'easy_elements_bulk_action', |
| 91 |
bulk_action: action, |
| 92 |
tab: currentTab, |
| 93 |
nonce: easyElementsData.bulk_action_nonce |
| 94 |
}) |
| 95 |
.done(function(response) { |
| 96 |
if (response.success) { |
| 97 |
$('.widget-toggle-checkbox').each(function() { |
| 98 |
var $checkbox = $(this); |
| 99 |
|
| 100 |
if ($checkbox.data('tab') === currentTab) { |
| 101 |
var isPro = $checkbox.closest('.easy-widget-item').hasClass('easyel-pro-enable'); |
| 102 |
if (isPro && !response.data.is_pro_active) { |
| 103 |
$checkbox.prop('checked', false).prop('disabled', true); |
| 104 |
} else { |
| 105 |
$checkbox.prop('checked', action === 'activate_all'); |
| 106 |
$checkbox.prop('disabled', false); |
| 107 |
} |
| 108 |
} |
| 109 |
}); |
| 110 |
} |
| 111 |
}) |
| 112 |
.always(function() { |
| 113 |
btn.prop('disabled', false).text(originalText); |
| 114 |
}); |
| 115 |
}, |
| 116 |
|
| 117 |
initAllExtensions: function() { |
| 118 |
let $extensionsTab = $('.easyel-tab-panel.extensions'); |
| 119 |
|
| 120 |
$('.easyel-extension-toggle').on('change', function () { |
| 121 |
let checkbox = $(this); |
| 122 |
let key = checkbox.data('key'); |
| 123 |
let tab = checkbox.data('tab'); |
| 124 |
let status = checkbox.is(':checked') ? 1 : 0; |
| 125 |
|
| 126 |
$.post(ajaxurl, { |
| 127 |
action: 'easy_elements_save_global_extensions', |
| 128 |
tab: tab, |
| 129 |
key: key, |
| 130 |
status: status, |
| 131 |
nonce: easyElementsData.widget_settings_nonce |
| 132 |
}) |
| 133 |
.fail(function () { |
| 134 |
checkbox.prop('checked', !checkbox.is(':checked')); |
| 135 |
}); |
| 136 |
}); |
| 137 |
|
| 138 |
$extensionsTab.on('change', '.easyel-group-toggle', function () { |
| 139 |
let groupCheckbox = $(this); |
| 140 |
let groupSlug = groupCheckbox.data('group'); |
| 141 |
let groupWrapper = $('.easyel-extension-wrapper[data-group="' + groupSlug + '"]'); |
| 142 |
let hiddenField = $('input.easyel-group-hidden[name="easy_element_group_' + groupSlug + '"]'); |
| 143 |
|
| 144 |
let status = groupCheckbox.is(':checked') ? 1 : 0; |
| 145 |
groupWrapper.find('.easyel-extension-toggle').each(function () { |
| 146 |
let checkbox = $(this); |
| 147 |
if (checkbox.closest('.easyel-extension-item').hasClass('easyel-pro-enable')) return; |
| 148 |
checkbox.prop('checked', status === 1); |
| 149 |
}); |
| 150 |
|
| 151 |
hiddenField.val(status); |
| 152 |
|
| 153 |
let keys = []; |
| 154 |
groupWrapper.find('.easyel-extension-toggle').each(function() { keys.push($(this).data('key')); }); |
| 155 |
if (keys.length) { |
| 156 |
$.post(ajaxurl, { |
| 157 |
action: 'easy_elements_save_global_extensions_bulk', |
| 158 |
tab: 'extensions', |
| 159 |
keys: keys, |
| 160 |
status: status, |
| 161 |
group: groupSlug, |
| 162 |
nonce: easyElementsData.widget_settings_nonce |
| 163 |
}); |
| 164 |
} |
| 165 |
}); |
| 166 |
}, |
| 167 |
|
| 168 |
easyEltab: function() { |
| 169 |
$('#toplevel_page_easy-elements-dashboard ul.wp-submenu a').on('click', function (e) { |
| 170 |
const href = $(this).attr('href'); |
| 171 |
const isDashboardPage = window.location.href.includes('page=easy-elements-dashboard'); |
| 172 |
|
| 173 |
if (href.includes('page=easy-elements-license')) { |
| 174 |
return; |
| 175 |
} |
| 176 |
|
| 177 |
if (isDashboardPage && href.includes('#')) { |
| 178 |
e.preventDefault(); |
| 179 |
|
| 180 |
let tab = 'overview'; |
| 181 |
if (href.includes('#widget')) tab = 'widget'; |
| 182 |
if (href.includes('#extensions')) tab = 'extensions'; |
| 183 |
|
| 184 |
activateTab(tab); |
| 185 |
history.replaceState(null, null, '#' + tab); |
| 186 |
} |
| 187 |
}); |
| 188 |
|
| 189 |
let hash = window.location.hash.substring(1); |
| 190 |
if (hash) activateTab(hash); |
| 191 |
else activateTab('overview'); |
| 192 |
|
| 193 |
$('.easyel-nav-tab').click(function (e) { |
| 194 |
const tab = $(this).data('tab'); |
| 195 |
|
| 196 |
if (tab === 'activate_license') { |
| 197 |
const url = $(this).attr('href'); |
| 198 |
if (url) { |
| 199 |
window.location.href = url; |
| 200 |
} |
| 201 |
return; |
| 202 |
} |
| 203 |
|
| 204 |
e.preventDefault(); |
| 205 |
activateTab(tab); |
| 206 |
history.replaceState(null, null, '#' + tab); |
| 207 |
}); |
| 208 |
|
| 209 |
function activateTab(tab) { |
| 210 |
$('.easyel-nav-tab').removeClass('easyel-nav-tab-active'); |
| 211 |
$('.easyel-nav-tab[data-tab="' + tab + '"]').addClass('easyel-nav-tab-active'); |
| 212 |
$('.easyel-tab-panel').hide(); |
| 213 |
$('#tab-' + tab).show(); |
| 214 |
$('#toplevel_page_easy-elements-dashboard ul.wp-submenu li').removeClass('current'); |
| 215 |
$('#toplevel_page_easy-elements-dashboard ul.wp-submenu a[href*="#' + tab + '"]').parent().addClass('current'); |
| 216 |
} |
| 217 |
}, |
| 218 |
easyElFilter: function() { |
| 219 |
$(".easyel-action-btn").on("click", function() { |
| 220 |
var filter = $(this).data("filter"); |
| 221 |
$(".easyel-action-btn").removeClass("active"); |
| 222 |
$(this).addClass("active"); |
| 223 |
|
| 224 |
$(".easy-widget-item,.easyel-extension-item").each(function() { |
| 225 |
var $widget = $(this); |
| 226 |
|
| 227 |
if (filter === "easyel_all") $widget.show(); |
| 228 |
else if (filter === "easyel_free") { |
| 229 |
if ($widget.hasClass("easyel-pro-widget")) $widget.hide(); |
| 230 |
else $widget.show(); |
| 231 |
} else if (filter === "easyel_pro") { |
| 232 |
if ($widget.hasClass("easyel-pro-widget")) $widget.show(); |
| 233 |
else $widget.hide(); |
| 234 |
} |
| 235 |
}); |
| 236 |
}); |
| 237 |
}, |
| 238 |
|
| 239 |
easyelVideoPopuo: function() { |
| 240 |
if ($(".easyel-video-popup").length ) { |
| 241 |
var $popup = $('#easyel-popup-video-area'), |
| 242 |
$videoContainer = $popup.find('.easyel-popup-video'); |
| 243 |
|
| 244 |
$('.easyel-video-popup').on('click', function(e){ |
| 245 |
e.preventDefault(); |
| 246 |
var videoId = $(this).attr('href').split('v=')[1].split('&')[0]; |
| 247 |
$videoContainer.html('<iframe src="https://www.youtube.com/embed/' + videoId + '?autoplay=1" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>'); |
| 248 |
$popup.fadeIn(); |
| 249 |
}); |
| 250 |
|
| 251 |
$popup.on('click', '.easyel-popup-close, #easyel-popup-video-area', function(e){ |
| 252 |
if($(e.target).is('.easyel-popup-close') || $(e.target).is('#easyel-popup-video-area')){ |
| 253 |
$popup.fadeOut(); |
| 254 |
$videoContainer.html(''); |
| 255 |
} |
| 256 |
}); |
| 257 |
}; |
| 258 |
}, |
| 259 |
|
| 260 |
easyelFaq: function() { |
| 261 |
if ($(".easyel-faq-item").length ) { |
| 262 |
$(".easyel-faq-item.active").find(".easyel-faq-item-content").show(); |
| 263 |
$(".easyel-faq-item-heading").click(function(){ |
| 264 |
var faqItem = $(this).closest(".easyel-faq-item"); |
| 265 |
var content = faqItem.children(".easyel-faq-item-content"); |
| 266 |
|
| 267 |
if(faqItem.hasClass("active")){ |
| 268 |
faqItem.removeClass("active"); |
| 269 |
content.slideUp(300); |
| 270 |
} else { |
| 271 |
$(".easyel-faq-item.active").removeClass("active").children(".easyel-faq-item-content").slideUp(300); |
| 272 |
faqItem.addClass("active"); |
| 273 |
content.slideDown(300); |
| 274 |
} |
| 275 |
}); |
| 276 |
}; |
| 277 |
}, |
| 278 |
}; |
| 279 |
|
| 280 |
$(document).ready(function() { |
| 281 |
EasyElementsAdmin.init(); |
| 282 |
}); |
| 283 |
|
| 284 |
window.EasyElementsAdmin = EasyElementsAdmin; |
| 285 |
|
| 286 |
})(jQuery); |
| 287 |
|