admin-foogallery-attachment-autosave.js
3 days ago
admin-foogallery-divi.js
3 days ago
admin-foogallery-edit.js
3 days ago
admin-foogallery-editor.js
3 days ago
admin-foogallery-elementor.js
3 days ago
admin-page-foogallery-extensions-modal.js
3 days ago
admin-page-foogallery-extensions.js
3 days ago
admin-page-foogallery-settings.js
3 days ago
admin-tinymce.js
3 days ago
admin-uploader.js
3 days ago
foogallery-command-palette.js
3 days ago
foogallery.admin.datasources.js
3 days ago
foogallery.admin.min.js
3 days ago
foogallery.admin.template.js
3 days ago
admin-page-foogallery-settings.js
337 lines
| 1 | jQuery(document).ready(function($) { |
| 2 | $.admin_tabs = { |
| 3 | |
| 4 | init : function() { |
| 5 | $("a.nav-tab").on('click', function(e) { |
| 6 | e.preventDefault(); |
| 7 | |
| 8 | $this = $(this); |
| 9 | |
| 10 | $this.parents(".nav-tab-wrapper:first").find(".nav-tab-active").removeClass("nav-tab-active"); |
| 11 | $this.addClass("nav-tab-active"); |
| 12 | |
| 13 | $(".nav-container:visible").hide(); |
| 14 | |
| 15 | var hash = $this.attr("href"); |
| 16 | |
| 17 | $(hash+'_tab').show(); |
| 18 | |
| 19 | //fix the referer so if changes are saved, we come back to the same tab |
| 20 | var referer = $("input[name=_wp_http_referer]").val(); |
| 21 | if (referer.indexOf("#") >= 0) { |
| 22 | referer = referer.substr(0, referer.indexOf("#")); |
| 23 | } |
| 24 | referer += hash; |
| 25 | |
| 26 | window.location.hash = hash; |
| 27 | |
| 28 | $("input[name=_wp_http_referer]").val(referer); |
| 29 | }); |
| 30 | |
| 31 | if (window.location.hash) { |
| 32 | $('a.nav-tab[href="' + window.location.hash + '"]').click(); |
| 33 | } |
| 34 | |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | }; //End of admin_tabs |
| 39 | |
| 40 | $.admin_tabs.init(); |
| 41 | }); |
| 42 | |
| 43 | // |
| 44 | (function(FOOGALLERY, $, undefined) { |
| 45 | |
| 46 | FOOGALLERY.loadImageOptimizationContent = function() { |
| 47 | var data = 'action=foogallery_get_image_optimization_info' + |
| 48 | '&_wpnonce=' + $('#foogallery_setting_image_optimization-nonce').val() + |
| 49 | '&_wp_http_referer=' + encodeURIComponent($('input[name="_wp_http_referer"]').val()); |
| 50 | |
| 51 | $.ajax({ |
| 52 | type: "POST", |
| 53 | url: ajaxurl, |
| 54 | data: data, |
| 55 | success: function(data) { |
| 56 | $('#foogallery_settings_image_optimization_container').replaceWith(data); |
| 57 | } |
| 58 | }); |
| 59 | }; |
| 60 | |
| 61 | FOOGALLERY.renderSettingsAjaxResponse = function($container, response) { |
| 62 | if (!response || !response.data) { |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | var html = response.data.html || response.data.message; |
| 67 | if (html) { |
| 68 | $container.html(html); |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | FOOGALLERY.bindClearCssOptimizationButton = function() { |
| 73 | $('.foogallery_clear_css_optimizations').on('click', function(e) { |
| 74 | e.preventDefault(); |
| 75 | |
| 76 | var $button = $(this), |
| 77 | $container = $('#foogallery_clear_css_optimizations_container'), |
| 78 | $spinner = $('#foogallery_clear_css_cache_spinner'), |
| 79 | data = 'action=foogallery_clear_css_optimizations' + |
| 80 | '&_wpnonce=' + $button.data('nonce') + |
| 81 | '&_wp_http_referer=' + encodeURIComponent($('input[name="_wp_http_referer"]').val()); |
| 82 | |
| 83 | $spinner.addClass('is-active'); |
| 84 | $button.prop('disabled', true); |
| 85 | |
| 86 | $.ajax({ |
| 87 | type: "POST", |
| 88 | url: ajaxurl, |
| 89 | data: data, |
| 90 | dataType: "json", |
| 91 | success: function(response) { |
| 92 | FOOGALLERY.renderSettingsAjaxResponse($container, response); |
| 93 | }, |
| 94 | error: function(xhr) { |
| 95 | FOOGALLERY.renderSettingsAjaxResponse($container, xhr.responseJSON); |
| 96 | }, |
| 97 | complete: function() { |
| 98 | $spinner.removeClass('is-active'); |
| 99 | $button.prop('disabled', false); |
| 100 | } |
| 101 | }); |
| 102 | }); |
| 103 | }; |
| 104 | |
| 105 | FOOGALLERY.bindClearThumbnailCacheButton = function() { |
| 106 | $('.foogallery_clear_thumbnail_cache').on('click', function(e) { |
| 107 | e.preventDefault(); |
| 108 | |
| 109 | var $button = $(this), |
| 110 | $container = $('#foogallery_clear_thumbnail_cache_container'), |
| 111 | $spinner = $('#foogallery_clear_thumbnail_cache_spinner'), |
| 112 | data = 'action=foogallery_clear_thumbnail_cache' + |
| 113 | '&_wpnonce=' + $button.data('nonce') + |
| 114 | '&_wp_http_referer=' + encodeURIComponent($('input[name="_wp_http_referer"]').val()); |
| 115 | |
| 116 | $spinner.addClass('is-active'); |
| 117 | $button.prop('disabled', true); |
| 118 | |
| 119 | $.ajax({ |
| 120 | type: "POST", |
| 121 | url: ajaxurl, |
| 122 | data: data, |
| 123 | dataType: "json", |
| 124 | success: function(response) { |
| 125 | FOOGALLERY.renderSettingsAjaxResponse($container, response); |
| 126 | }, |
| 127 | error: function(xhr) { |
| 128 | FOOGALLERY.renderSettingsAjaxResponse($container, xhr.responseJSON); |
| 129 | }, |
| 130 | complete: function() { |
| 131 | $spinner.removeClass('is-active'); |
| 132 | $button.prop('disabled', false); |
| 133 | } |
| 134 | }); |
| 135 | }); |
| 136 | }; |
| 137 | |
| 138 | FOOGALLERY.bindTestThumbnailButton = function() { |
| 139 | $('.foogallery_thumb_generation_test').on('click', function(e) { |
| 140 | e.preventDefault(); |
| 141 | |
| 142 | var $button = $(this), |
| 143 | $container = $('#foogallery_thumb_generation_test_container'), |
| 144 | $spinner = $('#foogallery_thumb_generation_test_spinner'), |
| 145 | data = 'action=foogallery_thumb_generation_test' + |
| 146 | '&_wpnonce=' + $button.data('nonce') + |
| 147 | '&_wp_http_referer=' + encodeURIComponent($('input[name="_wp_http_referer"]').val()); |
| 148 | |
| 149 | $spinner.addClass('is-active'); |
| 150 | $button.prop('disabled', true); |
| 151 | |
| 152 | $.ajax({ |
| 153 | type: "POST", |
| 154 | url: ajaxurl, |
| 155 | data: data, |
| 156 | dataType: "json", |
| 157 | success: function(response) { |
| 158 | FOOGALLERY.renderSettingsAjaxResponse($container, response); |
| 159 | }, |
| 160 | error: function(xhr) { |
| 161 | FOOGALLERY.renderSettingsAjaxResponse($container, xhr.responseJSON); |
| 162 | }, |
| 163 | complete: function() { |
| 164 | $spinner.removeClass('is-active'); |
| 165 | $button.prop('disabled', false); |
| 166 | } |
| 167 | }); |
| 168 | }); |
| 169 | }; |
| 170 | |
| 171 | FOOGALLERY.bindApplyRetinaDefaults = function() { |
| 172 | $('.foogallery_apply_retina_support').on('click', function(e) { |
| 173 | e.preventDefault(); |
| 174 | |
| 175 | var $button = $(this), |
| 176 | $container = $('#foogallery_apply_retina_support_container'), |
| 177 | $spinner = $('#foogallery_apply_retina_support_spinner'), |
| 178 | data = 'action=foogallery_apply_retina_defaults' + |
| 179 | '&_wpnonce=' + $button.data('nonce') + |
| 180 | '&_wp_http_referer=' + encodeURIComponent($('input[name="_wp_http_referer"]').val()); |
| 181 | |
| 182 | var selected = []; |
| 183 | $( $button.data('inputs') ).each(function() { |
| 184 | if ($(this).is(":checked")) { |
| 185 | selected.push($(this).attr('name')); |
| 186 | } |
| 187 | }); |
| 188 | |
| 189 | data += '&defaults=' + selected; |
| 190 | |
| 191 | $spinner.addClass('is-active'); |
| 192 | $button.prop('disabled', true); |
| 193 | |
| 194 | $.ajax({ |
| 195 | type: "POST", |
| 196 | url: ajaxurl, |
| 197 | data: data, |
| 198 | dataType: "json", |
| 199 | success: function(response) { |
| 200 | FOOGALLERY.renderSettingsAjaxResponse($container, response); |
| 201 | }, |
| 202 | error: function(xhr) { |
| 203 | FOOGALLERY.renderSettingsAjaxResponse($container, xhr.responseJSON); |
| 204 | }, |
| 205 | complete: function() { |
| 206 | $spinner.removeClass('is-active'); |
| 207 | $button.prop('disabled', false); |
| 208 | } |
| 209 | }); |
| 210 | }); |
| 211 | }; |
| 212 | |
| 213 | FOOGALLERY.bindUninstallButton = function() { |
| 214 | $('#foogallery_uninstall_container').on('click', '.foogallery_uninstall, .foogallery_uninstall_confirm', function(e) { |
| 215 | e.preventDefault(); |
| 216 | |
| 217 | var $button = $(this), |
| 218 | $container = $('#foogallery_uninstall_container'), |
| 219 | $spinner = $('#foogallery_uninstall_spinner'), |
| 220 | data = { |
| 221 | action: 'foogallery_uninstall', |
| 222 | _wpnonce: $button.data('nonce'), |
| 223 | _wp_http_referer: $('input[name="_wp_http_referer"]').val() |
| 224 | }; |
| 225 | |
| 226 | if ($button.hasClass('foogallery_uninstall_confirm')) { |
| 227 | data.confirmation = $('#foogallery_uninstall_confirmation').val(); |
| 228 | } |
| 229 | |
| 230 | $spinner.addClass('is-active'); |
| 231 | $container.find('.foogallery_uninstall, .foogallery_uninstall_confirm, #foogallery_uninstall_confirmation').prop('disabled', true); |
| 232 | |
| 233 | $.ajax({ |
| 234 | type: "POST", |
| 235 | url: ajaxurl, |
| 236 | data: data, |
| 237 | dataType: "json", |
| 238 | success: function(response) { |
| 239 | FOOGALLERY.renderSettingsAjaxResponse($container, response); |
| 240 | }, |
| 241 | error: function(xhr) { |
| 242 | FOOGALLERY.renderSettingsAjaxResponse($container, xhr.responseJSON); |
| 243 | }, |
| 244 | complete: function() { |
| 245 | $('#foogallery_uninstall_spinner').removeClass('is-active'); |
| 246 | $container.find('.foogallery_uninstall, .foogallery_uninstall_confirm, #foogallery_uninstall_confirmation').prop('disabled', false); |
| 247 | } |
| 248 | }); |
| 249 | }); |
| 250 | }; |
| 251 | |
| 252 | FOOGALLERY.bindClearHTMLCacheButton = function() { |
| 253 | $('.foogallery_clear_html_cache').on('click', function(e) { |
| 254 | e.preventDefault(); |
| 255 | |
| 256 | var $button = $(this), |
| 257 | $container = $('#foogallery_clear_html_cache_container'), |
| 258 | $spinner = $('#foogallery_clear_html_cache_spinner'), |
| 259 | data = 'action=foogallery_clear_html_cache' + |
| 260 | '&_wpnonce=' + $button.data('nonce') + |
| 261 | '&_wp_http_referer=' + encodeURIComponent($('input[name="_wp_http_referer"]').val()); |
| 262 | |
| 263 | $spinner.addClass('is-active'); |
| 264 | $button.prop('disabled', true); |
| 265 | |
| 266 | $.ajax({ |
| 267 | type: "POST", |
| 268 | url: ajaxurl, |
| 269 | data: data, |
| 270 | success: function(data) { |
| 271 | $container.html(data); |
| 272 | }, |
| 273 | complete: function() { |
| 274 | $spinner.removeClass('is-active'); |
| 275 | $button.prop('disabled', false); |
| 276 | } |
| 277 | }); |
| 278 | }); |
| 279 | }; |
| 280 | |
| 281 | //find all generic foogallery ajax buttons and bind them |
| 282 | FOOGALLERY.bindSettingsAjaxButtons = function () { |
| 283 | $('.foogallery_settings_ajax').on('click',function(e) { |
| 284 | e.preventDefault(); |
| 285 | |
| 286 | var $button = $(this), |
| 287 | $container = $button.parents('.foogallery_settings_ajax_container:first'), |
| 288 | $spinner = $container.find('.spinner'), |
| 289 | response = $button.data('response'), |
| 290 | confirmMessage = $button.data('confirm'), |
| 291 | confirmResult = true, |
| 292 | data = 'action=' + $button.data('action') + |
| 293 | '&_wpnonce=' + $button.data('nonce') + |
| 294 | '&_wp_http_referer=' + encodeURIComponent($('input[name="_wp_http_referer"]').val()); |
| 295 | |
| 296 | if ( confirmMessage ) { |
| 297 | confirmResult = confirm( confirmMessage ); |
| 298 | }; |
| 299 | |
| 300 | if ( confirmResult ) { |
| 301 | $spinner.addClass('is-active'); |
| 302 | $button.prop('disabled', true); |
| 303 | |
| 304 | $.ajax({ |
| 305 | type : "POST", |
| 306 | url : ajaxurl, |
| 307 | data : data, |
| 308 | success : function (data) { |
| 309 | if (response === 'replace_container') { |
| 310 | $container.html(data); |
| 311 | } else if (response === 'alert') { |
| 312 | alert(data); |
| 313 | } |
| 314 | }, |
| 315 | complete: function () { |
| 316 | $spinner.removeClass('is-active'); |
| 317 | $button.prop('disabled', false); |
| 318 | } |
| 319 | }); |
| 320 | } |
| 321 | }); |
| 322 | }; |
| 323 | |
| 324 | $(function() { //wait for ready |
| 325 | FOOGALLERY.loadImageOptimizationContent(); |
| 326 | FOOGALLERY.bindClearCssOptimizationButton(); |
| 327 | FOOGALLERY.bindClearThumbnailCacheButton(); |
| 328 | FOOGALLERY.bindTestThumbnailButton(); |
| 329 | FOOGALLERY.bindApplyRetinaDefaults(); |
| 330 | FOOGALLERY.bindUninstallButton(); |
| 331 | FOOGALLERY.bindClearHTMLCacheButton(); |
| 332 | |
| 333 | FOOGALLERY.bindSettingsAjaxButtons(); |
| 334 | }); |
| 335 | |
| 336 | }(window.FOOGALLERY = window.FOOGALLERY || {}, jQuery)); |
| 337 |