codemirror
1 year ago
datatables
1 year ago
admin-menu-organizer.js
1 year ago
admin-page.js
1 year ago
content-order-sort.js
1 year ago
custom-admin-menu.js
1 year ago
external-permalinks.js
1 year ago
gutenberg-content-duplication.js
1 year ago
hide-admin-notices.js
1 year ago
jBox.all.min.js
1 year ago
jquery.jsticky.mod.js
1 year ago
jquery.jsticky.mod.min.js
1 year ago
jquery.mjs.nestedSortable.js
1 year ago
jquery.ui.touch-punch.min.js
1 year ago
js.cookie.min.js
1 year ago
list-tables-content-order.js
1 year ago
media-replace.js
1 year ago
multiple-user-roles.js
1 year ago
select2.full.min.js
1 year ago
toggle-hidden-menu.js
1 year ago
admin-page.js
1137 lines
| 1 | (function( $ ) { |
| 2 | 'use strict'; |
| 3 | |
| 4 | $(document).ready( function() { |
| 5 | |
| 6 | // Make page header sticky on scroll. Using https://github.com/AndrewHenderson/jSticky |
| 7 | $('#asenha-header').sticky({ |
| 8 | topSpacing: 0, // Space between element and top of the viewport (in pixels) |
| 9 | zIndex: 100, // z-index |
| 10 | stopper: '', // Id, class, or number value |
| 11 | stickyClass: 'asenha-sticky' // Class applied to element when it's stuck. Class name or false. |
| 12 | }) |
| 13 | |
| 14 | // Clicking on header save button triggers click of the hidden form submit button |
| 15 | $('.asenha-save-button').click( function(e) { |
| 16 | |
| 17 | e.preventDefault(); |
| 18 | |
| 19 | $('.asenha-saving-changes').fadeIn(); |
| 20 | |
| 21 | // Get current tab's URL hash and save it in cookie |
| 22 | var hash = decodeURI(window.location.hash).substr(1); // get hash without the # character |
| 23 | Cookies.set('asenha_tab', hash, { expires: 1 }); // expires in 1 day |
| 24 | |
| 25 | // Submit the settings form |
| 26 | $('input[type="submit"]#asenha-submit').click(); |
| 27 | |
| 28 | }); |
| 29 | |
| 30 | // Search modules |
| 31 | var searchInput = $('#module-search-input'); |
| 32 | |
| 33 | $(searchInput).keyup(delay(function (e) { |
| 34 | var searchVal = $(this).val(); |
| 35 | var filterItems = $('[data-search-filter]'); |
| 36 | |
| 37 | if ( searchVal != '' ) { |
| 38 | setTimeout(function() { |
| 39 | $(searchInput).addClass('has-text-input'); |
| 40 | $('.modules-tab').hide(); |
| 41 | $('.search-tab').show(); |
| 42 | $('.asenha-fields.section-visible').addClass('originally-visible'); |
| 43 | $('.asenha-fields').removeClass('section-visible'); |
| 44 | $('.asenha-fields').removeClass('section-hidden'); |
| 45 | $('.asenha-fields').addClass('section-visible-for-search'); |
| 46 | filterItems.parents('.asenha-toggle').addClass('result-is-hidden'); |
| 47 | $('[data-search-filter][data-module-info*="' + searchVal.toLowerCase() + '"]').parents('.asenha-toggle').removeClass('result-is-hidden'); |
| 48 | }, 250 ); |
| 49 | refreshCodeMirror(); |
| 50 | } else { |
| 51 | setTimeout(function() { |
| 52 | searchInput.removeClass('has-text-input'); |
| 53 | filterItems.parents('.asenha-toggle').removeClass('result-is-hidden'); |
| 54 | clear_search(); |
| 55 | refreshCodeMirror(); |
| 56 | }, 250 ); |
| 57 | } |
| 58 | }, 200)); |
| 59 | |
| 60 | // Restore all results when the x button on search input field is clicked. |
| 61 | // The click triggers a 'search' event we're listening to below |
| 62 | |
| 63 | if ( searchInput.length > 0 ) { |
| 64 | document.getElementById("module-search-input").addEventListener("search", function(event) { |
| 65 | clear_search(); |
| 66 | refreshCodeMirror(); |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | // Ref: https://stackoverflow.com/a/1909508 |
| 71 | function delay(fn, ms) { |
| 72 | let timer = 0 |
| 73 | return function(...args) { |
| 74 | clearTimeout(timer) |
| 75 | timer = setTimeout(fn.bind(this, ...args), ms || 0) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | function clear_search() { |
| 80 | searchInput.removeClass('has-text-input'); |
| 81 | $('[data-search-filter]').each( function() { |
| 82 | $(this).parents('.asenha-toggle').removeClass('result-is-hidden'); |
| 83 | $('.modules-tab').show(); |
| 84 | $('.search-tab').hide(); |
| 85 | $('.asenha-fields').removeClass('section-visible-for-search'); |
| 86 | $('.asenha-fields').addClass('section-hidden'); |
| 87 | // Has no effect. Compensate with CSS .asenha-fields.section-visible.section-hidden { display: block; } |
| 88 | // $('.asenha-fields.originally-visible').removeClass('section-hidden'); |
| 89 | $('.asenha-fields.originally-visible').addClass('section-visible'); |
| 90 | $('.asenha-fields').removeClass('originally-visible'); |
| 91 | }); |
| 92 | } |
| 93 | |
| 94 | // Show all / less toggler for field options | Modified from https://codepen.io/symonsays/pen/rzgEgY |
| 95 | $('.asenha-field-with-options.field-show-more > .show-more').click(function(e) { |
| 96 | |
| 97 | e.preventDefault(); |
| 98 | |
| 99 | var $this = $(this); |
| 100 | $this.toggleClass('show-more'); |
| 101 | |
| 102 | if ($this.hasClass('show-more')) { |
| 103 | $this.next().removeClass('opened',0); |
| 104 | $this.html(adminPageVars.expandText + ' ▼'); |
| 105 | } else { |
| 106 | $this.next().addClass('opened',0); |
| 107 | $this.html(adminPageVars.collapseText + ' ▲'); |
| 108 | } |
| 109 | |
| 110 | }); |
| 111 | |
| 112 | // Email Delivery >> Send test email |
| 113 | $('#send-test-email').click(function(e) { |
| 114 | e.preventDefault(); |
| 115 | var emailTo = $('#test-email-to').val(); |
| 116 | if ( emailTo ) { |
| 117 | $('#ajax-result').show(); |
| 118 | $('.sending-test-email').show(); |
| 119 | $('.test-email-result').hide(); |
| 120 | $('#test-email-success').hide(); |
| 121 | $('#test-email-failed').hide(); |
| 122 | $.ajax({ |
| 123 | url: ajaxurl, |
| 124 | data: { |
| 125 | 'action':'send_test_email', |
| 126 | 'email_to': emailTo, |
| 127 | 'nonce': adminPageVars.sendTestEmailNonce |
| 128 | }, |
| 129 | success:function(data) { |
| 130 | var data = data.slice(0,-1); // remove strange trailing zero in string returned by AJAX call |
| 131 | var response = JSON.parse(data); |
| 132 | if ( response.status == 'success' ) { |
| 133 | setTimeout( function() { |
| 134 | $('.sending-test-email').hide(); |
| 135 | // $('.test-email-result').show(); |
| 136 | $('#test-email-success').show(); |
| 137 | }, 1500); |
| 138 | } |
| 139 | if ( response.status == 'failed' ) { |
| 140 | setTimeout( function() { |
| 141 | $('.sending-test-email').hide(); |
| 142 | // $('.test-email-result').show(); |
| 143 | $('#test-email-failed').show(); |
| 144 | }, 1500); |
| 145 | } |
| 146 | }, |
| 147 | error:function(errorThrown) { |
| 148 | console.log(errorThrown); |
| 149 | setTimeout( function() { |
| 150 | $('.sending-test-email').hide(); |
| 151 | $('.test-email-result').show(); |
| 152 | $('#test-email-failed').show(); |
| 153 | }, 1500); |
| 154 | } |
| 155 | }); |
| 156 | } else { |
| 157 | alert( 'Please enter destination email address first.' ); |
| 158 | } |
| 159 | }); |
| 160 | |
| 161 | // Form Builder >> Send test email |
| 162 | $('#form-builder-send-test-email').click(function(e) { |
| 163 | e.preventDefault(); |
| 164 | var emailTo = $('#form-builder-test-email-to').val(); |
| 165 | var emailTemplate = $('.form-builder-email-template select').val(); |
| 166 | if ( emailTo ) { |
| 167 | $('#form-builder-ajax-result').show(); |
| 168 | $('.form-builder-sending-test-email').show(); |
| 169 | $('.test-email-result').hide(); |
| 170 | $('#form-builder-test-email-success').hide(); |
| 171 | $('#form-builder-test-email-failed').hide(); |
| 172 | $.ajax({ |
| 173 | type: 'POST', |
| 174 | url: ajaxurl, |
| 175 | data: { |
| 176 | action: 'formbuilder_test_email_template', |
| 177 | email_template: emailTemplate, |
| 178 | test_email: emailTo, |
| 179 | nonce: adminPageVars.formBuilderSendTestEmailNonce |
| 180 | }, |
| 181 | success:function(data) { |
| 182 | var response = JSON.parse(data); |
| 183 | if ( response.success ) { |
| 184 | setTimeout( function() { |
| 185 | $('.form-builder-sending-test-email').hide(); |
| 186 | $('#form-builder-test-email-success').show(); |
| 187 | }, 1500); |
| 188 | } |
| 189 | if ( ! response.success ) { |
| 190 | setTimeout( function() { |
| 191 | $('.form-builder-sending-test-email').hide(); |
| 192 | $('#form-builder-test-email-failed').show(); |
| 193 | }, 1500); |
| 194 | } |
| 195 | }, |
| 196 | error:function(errorThrown) { |
| 197 | console.log(errorThrown); |
| 198 | setTimeout( function() { |
| 199 | $('.sending-test-email').hide(); |
| 200 | $('.test-email-result').show(); |
| 201 | $('#test-email-failed').show(); |
| 202 | }, 1500); |
| 203 | } |
| 204 | }); |
| 205 | } else { |
| 206 | alert( 'Please enter destination email address first.' ); |
| 207 | } |
| 208 | }); |
| 209 | |
| 210 | // Initialize data tables |
| 211 | var table = $("#login-attempts-log").DataTable({ |
| 212 | pageLength: 10, |
| 213 | order: [[2, 'desc']], |
| 214 | language: { |
| 215 | emptyTable: adminPageVars.dataTable.emptyTable, |
| 216 | info: adminPageVars.dataTable.info, |
| 217 | infoEmpty: adminPageVars.dataTable.infoEmpty, |
| 218 | infoFiltered: adminPageVars.dataTable.infoFiltered, |
| 219 | lengthMenu: adminPageVars.dataTable.lengthMenu, |
| 220 | search: adminPageVars.dataTable.search, |
| 221 | zeroRecords: adminPageVars.dataTable.zeroRecords, |
| 222 | paginate: { |
| 223 | first: adminPageVars.dataTable.paginate.first, |
| 224 | last: adminPageVars.dataTable.paginate.last, |
| 225 | next: adminPageVars.dataTable.paginate.next, |
| 226 | previous: adminPageVars.dataTable.paginate.previous |
| 227 | }, |
| 228 | } |
| 229 | }); |
| 230 | |
| 231 | // Place fields into the "Content Management" tab |
| 232 | |
| 233 | $('.enable-duplication').appendTo('.fields-content-management > table > tbody'); |
| 234 | $('.duplication-redirect-destination').appendTo('.fields-content-management .enable-duplication .asenha-subfields'); |
| 235 | |
| 236 | $('.content-order').appendTo('.fields-content-management > table > tbody'); |
| 237 | // $('.content-order-subfields-heading').appendTo('.fields-content-management .content-order .asenha-subfields'); |
| 238 | $('.content-order-for').appendTo('.fields-content-management .content-order .asenha-subfields'); |
| 239 | |
| 240 | |
| 241 | $('.enable-media-replacement').appendTo('.fields-content-management > table > tbody'); |
| 242 | $('.enable-svg-upload').appendTo('.fields-content-management > table > tbody'); |
| 243 | $('.enable-svg-upload-for').appendTo('.fields-content-management .enable-svg-upload .asenha-subfields'); |
| 244 | $('.enable-avif-upload').appendTo('.fields-content-management > table > tbody'); |
| 245 | $('.avif-support-status').appendTo('.fields-content-management .enable-avif-upload .asenha-subfields'); |
| 246 | |
| 247 | $('.enable-external-permalinks').appendTo('.fields-content-management > table > tbody'); |
| 248 | $('.enable-external-permalinks-for').appendTo('.fields-content-management .enable-external-permalinks .asenha-subfields'); |
| 249 | $('.external-links-new-tab').appendTo('.fields-content-management > table > tbody'); |
| 250 | $('.custom-nav-menu-items-new-tab').appendTo('.fields-content-management > table > tbody'); |
| 251 | $('.enable-missed-schedule-posts-auto-publish').appendTo('.fields-content-management > table > tbody'); |
| 252 | |
| 253 | // Place fields into "Admin Interface" tab |
| 254 | $('.hide-modify-elements').appendTo('.fields-admin-interface > table > tbody'); |
| 255 | $('.hide-ab-wp-logo-menu').appendTo('.fields-admin-interface .hide-modify-elements .asenha-subfields'); |
| 256 | $('.hide-ab-site-menu').appendTo('.fields-admin-interface .hide-modify-elements .asenha-subfields'); |
| 257 | $('.hide-ab-customize-menu').appendTo('.fields-admin-interface .hide-modify-elements .asenha-subfields'); |
| 258 | $('.hide-ab-updates-menu').appendTo('.fields-admin-interface .hide-modify-elements .asenha-subfields'); |
| 259 | $('.hide-ab-comments-menu').appendTo('.fields-admin-interface .hide-modify-elements .asenha-subfields'); |
| 260 | $('.hide-ab-new-content-menu').appendTo('.fields-admin-interface .hide-modify-elements .asenha-subfields'); |
| 261 | $('.hide-ab-howdy').appendTo('.fields-admin-interface .hide-modify-elements .asenha-subfields'); |
| 262 | $('.hide-help-drawer').appendTo('.fields-admin-interface .hide-modify-elements .asenha-subfields'); |
| 263 | |
| 264 | $('.hide-admin-notices').appendTo('.fields-admin-interface > table > tbody'); |
| 265 | |
| 266 | $('.disable-dashboard-widgets').appendTo('.fields-admin-interface > table > tbody'); |
| 267 | $('.disable-welcome-panel-in-dashboard').appendTo('.fields-admin-interface .disable-dashboard-widgets .asenha-subfields'); |
| 268 | $('.disabled-dashboard-widgets').appendTo('.fields-admin-interface .disable-dashboard-widgets .asenha-subfields'); |
| 269 | $('.hide-admin-bar').appendTo('.fields-admin-interface > table > tbody'); |
| 270 | |
| 271 | $('.hide-admin-bar-for').appendTo('.fields-admin-interface .hide-admin-bar .asenha-subfields'); |
| 272 | $('.hide-admin-bar-always-show-for-admins').appendTo('.fields-admin-interface .hide-admin-bar .asenha-subfields'); |
| 273 | |
| 274 | $('.hide-admin-bar-description').appendTo('.fields-admin-interface .hide-admin-bar .asenha-subfields'); |
| 275 | |
| 276 | $('.wider-admin-menu').appendTo('.fields-admin-interface > table > tbody'); |
| 277 | $('.admin-menu-width').appendTo('.fields-admin-interface .wider-admin-menu .asenha-subfields'); |
| 278 | $('.customize-admin-menu').appendTo('.fields-admin-interface > table > tbody'); |
| 279 | |
| 280 | $('.show-custom-taxonomy-filters').appendTo('.fields-admin-interface > table > tbody'); |
| 281 | |
| 282 | $('.enhance-list-tables').appendTo('.fields-admin-interface > table > tbody'); |
| 283 | $('.show-featured-image-column').appendTo('.fields-admin-interface .enhance-list-tables .asenha-subfields'); |
| 284 | $('.show-excerpt-column').appendTo('.fields-admin-interface .enhance-list-tables .asenha-subfields'); |
| 285 | $('.show-last-modified-column').appendTo('.fields-admin-interface .enhance-list-tables .asenha-subfields'); |
| 286 | $('.show-id-column').appendTo('.fields-admin-interface .enhance-list-tables .asenha-subfields'); |
| 287 | $('.show-file-size-column').appendTo('.fields-admin-interface .enhance-list-tables .asenha-subfields'); |
| 288 | $('.show-id-in-action_row').appendTo('.fields-admin-interface .enhance-list-tables .asenha-subfields'); |
| 289 | $('.hide-date-column').appendTo('.fields-admin-interface .enhance-list-tables .asenha-subfields'); |
| 290 | $('.hide-comments-column').appendTo('.fields-admin-interface .enhance-list-tables .asenha-subfields'); |
| 291 | $('.hide-post-tags-column').appendTo('.fields-admin-interface .enhance-list-tables .asenha-subfields'); |
| 292 | $('.various-admin-ui-enhancements').appendTo('.fields-admin-interface > table > tbody'); |
| 293 | $('.media-library-infinite-scrolling').appendTo('.fields-admin-interface .various-admin-ui-enhancements .asenha-subfields'); |
| 294 | $('.display-active-plugins-first').appendTo('.fields-admin-interface .various-admin-ui-enhancements .asenha-subfields'); |
| 295 | |
| 296 | $('.custom-admin-footer-text').appendTo('.fields-admin-interface > table > tbody'); |
| 297 | $('.custom-admin-footer-left').appendTo('.fields-admin-interface .custom-admin-footer-text .asenha-subfields'); |
| 298 | reinitWpEditor('admin_site_enhancements--custom_admin_footer_left'); |
| 299 | $('.custom-admin-footer-right').appendTo('.fields-admin-interface .custom-admin-footer-text .asenha-subfields'); |
| 300 | reinitWpEditor('admin_site_enhancements--custom_admin_footer_right'); |
| 301 | |
| 302 | // Place fields into "Log In | Log Out" tab |
| 303 | $('.change-login-url').appendTo('.fields-login-logout > table > tbody'); |
| 304 | $('.custom-login-slug').appendTo('.fields-login-logout .change-login-url .asenha-subfields'); |
| 305 | $('.default-login-redirect-slug').appendTo('.fields-login-logout .change-login-url .asenha-subfields'); |
| 306 | $('.change-login-url-description').appendTo('.fields-login-logout .change-login-url .asenha-subfields'); |
| 307 | $('.login-id-type-restriction').appendTo('.fields-login-logout > table > tbody'); |
| 308 | $('.login-id-type').appendTo('.fields-login-logout .login-id-type-restriction .asenha-subfields'); |
| 309 | |
| 310 | $('.site-identity-on-login').appendTo('.fields-login-logout > table > tbody'); |
| 311 | $('.enable-login-logout-menu').appendTo('.fields-login-logout > table > tbody'); |
| 312 | $('.enable-last-login-column').appendTo('.fields-login-logout > table > tbody'); |
| 313 | $('.registration-date-column').appendTo('.fields-login-logout > table > tbody'); |
| 314 | $('.redirect-after-login').appendTo('.fields-login-logout > table > tbody'); |
| 315 | |
| 316 | $('.redirect-after-login-to-slug').appendTo('.fields-login-logout .redirect-after-login .asenha-subfields'); |
| 317 | $('.redirect-after-login-for').appendTo('.fields-login-logout .redirect-after-login .asenha-subfields'); |
| 318 | |
| 319 | $('.redirect-after-logout').appendTo('.fields-login-logout > table > tbody'); |
| 320 | |
| 321 | $('.redirect-after-logout-to-slug').appendTo('.fields-login-logout .redirect-after-logout .asenha-subfields'); |
| 322 | $('.redirect-after-logout-for').appendTo('.fields-login-logout .redirect-after-logout .asenha-subfields'); |
| 323 | |
| 324 | |
| 325 | // Place fields into "Custom Code" tab |
| 326 | |
| 327 | $('.enable-custom-admin-css').appendTo('.fields-custom-code > table > tbody'); |
| 328 | $('.custom-admin-css').appendTo('.fields-custom-code .enable-custom-admin-css .asenha-subfields'); |
| 329 | $('.enable-custom-frontend-css').appendTo('.fields-custom-code > table > tbody'); |
| 330 | |
| 331 | $('.custom-frontend-css').appendTo('.fields-custom-code .enable-custom-frontend-css .asenha-subfields'); |
| 332 | $('.insert-head-body-footer-code').appendTo('.fields-custom-code > table > tbody'); |
| 333 | $('.head-code-priority').appendTo('.fields-custom-code .insert-head-body-footer-code .asenha-subfields'); |
| 334 | $('.head-code').appendTo('.fields-custom-code .insert-head-body-footer-code .asenha-subfields'); |
| 335 | $('.body-code-priority').appendTo('.fields-custom-code .insert-head-body-footer-code .asenha-subfields'); |
| 336 | $('.body-code').appendTo('.fields-custom-code .insert-head-body-footer-code .asenha-subfields'); |
| 337 | $('.footer-code-priority').appendTo('.fields-custom-code .insert-head-body-footer-code .asenha-subfields'); |
| 338 | $('.footer-code').appendTo('.fields-custom-code .insert-head-body-footer-code .asenha-subfields'); |
| 339 | $('.enable-custom-body-class').appendTo('.fields-custom-code > table > tbody'); |
| 340 | $('.enable-custom-body-class-for').appendTo('.fields-custom-code .enable-custom-body-class .asenha-subfields'); |
| 341 | $('.manage-ads-appads-txt').appendTo('.fields-custom-code > table > tbody'); |
| 342 | $('.ads-txt-content').appendTo('.fields-custom-code .manage-ads-appads-txt .asenha-subfields'); |
| 343 | $('.app-ads-txt-content').appendTo('.fields-custom-code .manage-ads-appads-txt .asenha-subfields'); |
| 344 | $('.manage-robots-txt').appendTo('.fields-custom-code > table > tbody'); |
| 345 | $('.robots-txt-content').appendTo('.fields-custom-code .manage-robots-txt .asenha-subfields'); |
| 346 | |
| 347 | // Place fields into the "Disable Components" tab |
| 348 | $('.disable-gutenberg').appendTo('.fields-disable-components > table > tbody'); |
| 349 | |
| 350 | $('.disable-gutenberg-for').appendTo('.fields-disable-components .disable-gutenberg .asenha-subfields'); |
| 351 | $('.disable-gutenberg-frontend-styles').appendTo('.fields-disable-components .disable-gutenberg .asenha-subfields'); |
| 352 | $('.disable-comments').appendTo('.fields-disable-components > table > tbody'); |
| 353 | |
| 354 | $('.disable-comments-for').appendTo('.fields-disable-components .disable-comments .asenha-subfields'); |
| 355 | $('.disable-rest-api').appendTo('.fields-disable-components > table > tbody'); |
| 356 | |
| 357 | $('.disable-feeds').appendTo('.fields-disable-components > table > tbody'); |
| 358 | $('.disable-all-updates').appendTo('.fields-disable-components > table > tbody'); |
| 359 | $('.disable-smaller-components').appendTo('.fields-disable-components > table > tbody'); |
| 360 | $('.disable-head-generator-tag').appendTo('.fields-disable-components .disable-smaller-components .asenha-subfields'); |
| 361 | $('.disable-feed-generator-tag').appendTo('.fields-disable-components .disable-smaller-components .asenha-subfields'); |
| 362 | $('.disable-resource-version-number').appendTo('.fields-disable-components .disable-smaller-components .asenha-subfields'); |
| 363 | $('.disable-head-wlwmanifest-tag').appendTo('.fields-disable-components .disable-smaller-components .asenha-subfields'); |
| 364 | $('.disable-head-rsd-tag').appendTo('.fields-disable-components .disable-smaller-components .asenha-subfields'); |
| 365 | $('.disable-head-shortlink-tag').appendTo('.fields-disable-components .disable-smaller-components .asenha-subfields'); |
| 366 | $('.disable-frontend-dashicons').appendTo('.fields-disable-components .disable-smaller-components .asenha-subfields'); |
| 367 | $('.disable-emoji-support').appendTo('.fields-disable-components .disable-smaller-components .asenha-subfields'); |
| 368 | $('.disable-jquery-migrate').appendTo('.fields-disable-components .disable-smaller-components .asenha-subfields'); |
| 369 | $('.disable-block-widgets').appendTo('.fields-disable-components .disable-smaller-components .asenha-subfields'); |
| 370 | $('.disable-lazy-load').appendTo('.fields-disable-components .disable-smaller-components .asenha-subfields'); |
| 371 | $('.disable-application-passwords').appendTo('.fields-disable-components .disable-smaller-components .asenha-subfields'); |
| 372 | $('.disable-plugin-theme-editor').appendTo('.fields-disable-components .disable-smaller-components .asenha-subfields'); |
| 373 | |
| 374 | // Place fields into "Security" tab |
| 375 | $('.limit-login-attempts').appendTo('.fields-security > table > tbody'); |
| 376 | $('.login-fails-allowed').appendTo('.fields-security .limit-login-attempts .asenha-subfields'); |
| 377 | $('.login-lockout-maxcount').appendTo('.fields-security .limit-login-attempts .asenha-subfields'); |
| 378 | |
| 379 | $('.limit-login-attempts-header-override').appendTo('.fields-security .limit-login-attempts .asenha-subfields'); |
| 380 | $('.limit-login-attempts-header-override-description').appendTo('.fields-security .limit-login-attempts .asenha-subfields'); |
| 381 | $('.login-attempts-log-table').appendTo('.fields-security .limit-login-attempts .asenha-subfields'); |
| 382 | |
| 383 | $('.obfuscate-author-slugs').appendTo('.fields-security > table > tbody'); |
| 384 | $('.obfuscate-email-address').appendTo('.fields-security > table > tbody'); |
| 385 | $('.obfuscate-email-address-description').appendTo('.fields-security .obfuscate-email-address .asenha-subfields'); |
| 386 | |
| 387 | $('.disable-xmlrpc').appendTo('.fields-security > table > tbody'); |
| 388 | |
| 389 | // Place fields into "Optimizations" tab |
| 390 | $('.image-upload-control').appendTo('.fields-optimizations > table > tbody'); |
| 391 | $('.image-max-width').appendTo('.fields-optimizations .image-upload-control .asenha-subfields'); |
| 392 | $('.image-max-height').appendTo('.fields-optimizations .image-upload-control .asenha-subfields'); |
| 393 | |
| 394 | $('.image-upload-control-description').appendTo('.fields-optimizations .image-upload-control .asenha-subfields'); |
| 395 | |
| 396 | $('.enable-revisions-control').appendTo('.fields-optimizations > table > tbody'); |
| 397 | $('.revisions-max-number').appendTo('.fields-optimizations .enable-revisions-control .asenha-subfields'); |
| 398 | $('.enable-revisions-control-for').appendTo('.fields-optimizations .enable-revisions-control .asenha-subfields'); |
| 399 | $('.enable-heartbeat-control').appendTo('.fields-optimizations > table > tbody'); |
| 400 | $('.heartbeat-control-for-admin-pages').appendTo('.fields-optimizations .enable-heartbeat-control .asenha-subfields'); |
| 401 | $('.heartbeat-interval-for-admin-pages').appendTo('.fields-optimizations .enable-heartbeat-control .asenha-subfields'); |
| 402 | $('.heartbeat-control-for-post-edit').appendTo('.fields-optimizations .enable-heartbeat-control .asenha-subfields'); |
| 403 | $('.heartbeat-interval-for-post-edit').appendTo('.fields-optimizations .enable-heartbeat-control .asenha-subfields'); |
| 404 | $('.heartbeat-control-for-frontend').appendTo('.fields-optimizations .enable-heartbeat-control .asenha-subfields'); |
| 405 | $('.heartbeat-interval-for-frontend').appendTo('.fields-optimizations .enable-heartbeat-control .asenha-subfields'); |
| 406 | |
| 407 | // Place fields into "Utilities" tab |
| 408 | $('.smtp-email-delivery').appendTo('.fields-utilities > table > tbody'); |
| 409 | $('.smtp-default-from-description').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 410 | $('.smtp-default-from-name').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 411 | $('.smtp-default-from-email').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 412 | $('.smtp-force-from').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 413 | |
| 414 | $('.smtp--description').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 415 | $('.smtp-host').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 416 | $('.smtp-port').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 417 | $('.smtp-security').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 418 | |
| 419 | $('.smtp-username').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 420 | $('.smtp-password').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 421 | $('.smtp-bypass-ssl-verification').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 422 | $('.smtp-debug').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 423 | |
| 424 | $('.smtp-send-test-email-description').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 425 | $('.smtp-send-test-email-to').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 426 | $('.smtp-send-test-email-result').appendTo('.fields-utilities .smtp-email-delivery .asenha-subfields'); |
| 427 | |
| 428 | $('.multiple-user-roles').appendTo('.fields-utilities > table > tbody'); |
| 429 | $('.image-sizes-panel').appendTo('.fields-utilities > table > tbody'); |
| 430 | $('.view-admin-as-role').appendTo('.fields-utilities > table > tbody'); |
| 431 | $('.view-admin-as-role-description').appendTo('.fields-utilities .view-admin-as-role .asenha-subfields'); |
| 432 | $('.enable-password-protection').appendTo('.fields-utilities > table > tbody'); |
| 433 | $('.password-protection-password').appendTo('.fields-utilities .enable-password-protection .asenha-subfields'); |
| 434 | |
| 435 | $('.maintenance-mode').appendTo('.fields-utilities > table > tbody'); |
| 436 | |
| 437 | $('.maintenance-page-type-custom').appendTo('.fields-utilities .maintenance-mode .asenha-subfields'); |
| 438 | |
| 439 | $('.maintenance-page-heading').appendTo('.maintenance-page-type-custom'); |
| 440 | $('.maintenance-page-description').appendTo('.maintenance-page-type-custom'); |
| 441 | |
| 442 | $('.maintenance-page-background').appendTo('.maintenance-page-type-custom'); |
| 443 | |
| 444 | $('.maintenance-mode-description').appendTo('.fields-utilities .maintenance-mode .asenha-subfields'); |
| 445 | $('.redirect-404-to-homepage').appendTo('.fields-utilities > table > tbody'); |
| 446 | |
| 447 | $('.display-system-summary').appendTo('.fields-utilities > table > tbody'); |
| 448 | $('.search-engine-visibility-status').appendTo('.fields-utilities > table > tbody'); |
| 449 | |
| 450 | |
| 451 | // Remove empty .form-table that originally holds the fields |
| 452 | const formTableCount = $('.form-table').length; |
| 453 | // $('.form-table')[formTableCount-1].remove(); |
| 454 | |
| 455 | // Enable Custom Admin CSS => Initialize CodeMirror |
| 456 | var adminCssTextarea = document.getElementById("admin_site_enhancements[custom_admin_css]"); |
| 457 | // if ( typeof CodeMirror != "undefined" ) { |
| 458 | // alert('CodeMirror is available'); |
| 459 | // } |
| 460 | var adminCssEditor = CodeMirror.fromTextArea(adminCssTextarea, { |
| 461 | mode: "css", |
| 462 | lineNumbers: true, |
| 463 | lineWrapping: true |
| 464 | }); |
| 465 | |
| 466 | adminCssEditor.setSize("100%",600); |
| 467 | |
| 468 | // Enable Custom Frontend CSS => Initialize CodeMirror |
| 469 | var frontendCssTextarea = document.getElementById("admin_site_enhancements[custom_frontend_css]"); |
| 470 | var frontendCssEditor = CodeMirror.fromTextArea(frontendCssTextarea, { |
| 471 | mode: "css", |
| 472 | lineNumbers: true, |
| 473 | lineWrapping: true |
| 474 | }); |
| 475 | |
| 476 | frontendCssEditor.setSize("100%",600); |
| 477 | |
| 478 | // Manage ads.txt and app-ads.txt=> Initialize CodeMirror |
| 479 | var adsTxtTextarea = document.getElementById("admin_site_enhancements[ads_txt_content]"); |
| 480 | var adsTxtEditor = CodeMirror.fromTextArea(adsTxtTextarea, { |
| 481 | mode: "markdown", |
| 482 | lineNumbers: true, |
| 483 | lineWrapping: true |
| 484 | }); |
| 485 | |
| 486 | adsTxtEditor.setSize("100%",300); |
| 487 | |
| 488 | var appAdsTxtTextarea = document.getElementById("admin_site_enhancements[app_ads_txt_content]"); |
| 489 | var appAdsTxtEditor = CodeMirror.fromTextArea(appAdsTxtTextarea, { |
| 490 | mode: "markdown", |
| 491 | lineNumbers: true, |
| 492 | lineWrapping: true |
| 493 | }); |
| 494 | |
| 495 | appAdsTxtEditor.setSize("100%",300); |
| 496 | |
| 497 | // Manage robots.txt => Initialize CodeMirror |
| 498 | var robotsTxtTextarea = document.getElementById("admin_site_enhancements[robots_txt_content]"); |
| 499 | var robotsTxtEditor = CodeMirror.fromTextArea(robotsTxtTextarea, { |
| 500 | mode: "markdown", |
| 501 | lineNumbers: true, |
| 502 | lineWrapping: true |
| 503 | }); |
| 504 | |
| 505 | robotsTxtEditor.setSize("100%",400); |
| 506 | |
| 507 | // Insert <head>, <body> and <footer> code => Initialize CodeMirror |
| 508 | var headCodeTextarea = document.getElementById("admin_site_enhancements[head_code]"); |
| 509 | var headCodeEditor = CodeMirror.fromTextArea(headCodeTextarea, { |
| 510 | mode: "htmlmixed", |
| 511 | lineNumbers: true, |
| 512 | lineWrapping: true |
| 513 | }); |
| 514 | headCodeEditor.setSize("100%",300); |
| 515 | |
| 516 | var bodyCodeTextarea = document.getElementById("admin_site_enhancements[body_code]"); |
| 517 | var bodyCodeEditor = CodeMirror.fromTextArea(bodyCodeTextarea, { |
| 518 | mode: "htmlmixed", |
| 519 | lineNumbers: true, |
| 520 | lineWrapping: true |
| 521 | }); |
| 522 | bodyCodeEditor.setSize("100%",300); |
| 523 | |
| 524 | var footerCodeTextarea = document.getElementById("admin_site_enhancements[footer_code]"); |
| 525 | var footerCodeEditor = CodeMirror.fromTextArea(footerCodeTextarea, { |
| 526 | mode: "htmlmixed", |
| 527 | lineNumbers: true, |
| 528 | lineWrapping: true |
| 529 | }); |
| 530 | footerCodeEditor.setSize("100%",300); |
| 531 | |
| 532 | |
| 533 | |
| 534 | function refreshCodeMirror() { |
| 535 | |
| 536 | adminCssEditor.refresh(); // Custom Admin CSS >> CodeMirror |
| 537 | frontendCssEditor.refresh(); // Custom Fronend CSS >> CodeMirror |
| 538 | adsTxtEditor.refresh(); // Manage ads.txt >> CodeMirror |
| 539 | appAdsTxtEditor.refresh(); // Manage app-ads.txt >> CodeMirror |
| 540 | headCodeEditor.refresh(); // Insert <head>, <body> and <footer> code >> CodeMirror |
| 541 | bodyCodeEditor.refresh(); // Insert <head>, <body> and <footer> code >> CodeMirror |
| 542 | footerCodeEditor.refresh(); // Insert <head>, <body> and <footer> code >> CodeMirror |
| 543 | robotsTxtEditor.refresh(); // Manage robots.txt >> CodeMirror |
| 544 | |
| 545 | } |
| 546 | |
| 547 | // Show and hide corresponding fields on tab clicks |
| 548 | |
| 549 | function tabSwitcher( tabSlug ) { |
| 550 | $('.asenha-fields.fields-'+tabSlug).addClass('section-visible'); |
| 551 | $('.asenha-fields.fields-'+tabSlug).removeClass('section-hidden'); |
| 552 | $('.asenha-fields:not(.fields-'+tabSlug+')').removeClass('section-visible'); |
| 553 | $('.asenha-fields:not(.fields-'+tabSlug+')').addClass('section-hidden'); |
| 554 | window.location.hash = tabSlug; |
| 555 | Cookies.set('asenha_tab', tabSlug, { expires: 1 }); // expires in 1 day |
| 556 | } |
| 557 | |
| 558 | $('#tab-content-management + label').click( function() { |
| 559 | tabSwitcher('content-management'); |
| 560 | }); |
| 561 | |
| 562 | $('#tab-admin-interface + label').click( function() { |
| 563 | tabSwitcher('admin-interface'); |
| 564 | }); |
| 565 | |
| 566 | $('#tab-login-logout + label').click( function() { |
| 567 | tabSwitcher('login-logout'); |
| 568 | refreshCodeMirror(); |
| 569 | }); |
| 570 | |
| 571 | $('#tab-custom-code + label').click( function() { |
| 572 | tabSwitcher('custom-code'); |
| 573 | refreshCodeMirror(); |
| 574 | }); |
| 575 | |
| 576 | $('#tab-disable-components + label').click( function() { |
| 577 | tabSwitcher('disable-components'); |
| 578 | }); |
| 579 | |
| 580 | $('#tab-security + label').click( function() { |
| 581 | tabSwitcher('security'); |
| 582 | }); |
| 583 | |
| 584 | $('#tab-optimizations + label').click( function() { |
| 585 | tabSwitcher('optimizations'); |
| 586 | }); |
| 587 | |
| 588 | $('#tab-utilities + label').click( function() { |
| 589 | tabSwitcher('utilities'); |
| 590 | refreshCodeMirror(); |
| 591 | }); |
| 592 | |
| 593 | // Open tab set in 'asenha_tab' cookie set on saving changes. Defaults to content-management tab when cookie is empty |
| 594 | var asenhaTabHash = Cookies.get('asenha_tab'); |
| 595 | |
| 596 | if (typeof asenhaTabHash === 'undefined') { |
| 597 | $('#tab-content-management + label').trigger('click'); |
| 598 | } else { |
| 599 | $('#tab-' + asenhaTabHash + ' + label').trigger('click'); |
| 600 | } |
| 601 | |
| 602 | // Show or hide subfields on document ready and on toggle click |
| 603 | |
| 604 | function subfieldsToggler( fieldId, fieldClass, sortableId, codeMirrorInstances ) { |
| 605 | |
| 606 | if (document.getElementById('admin_site_enhancements['+fieldId+']')) { |
| 607 | |
| 608 | // Show/hide subfields on document ready, depending on if module is enabled or not |
| 609 | if ( document.getElementById('admin_site_enhancements['+fieldId+']').checked ) { |
| 610 | |
| 611 | $('.'+fieldClass+' .asenha-subfields').show(); |
| 612 | if (document.querySelector('.'+fieldClass+' .asenha-subfield-select-inner')) { |
| 613 | $('.'+fieldClass+' .asenha-subfield-select-inner').show(); |
| 614 | } |
| 615 | $('.asenha-toggle.'+fieldClass+' td .asenha-field-with-options').addClass('is-enabled'); |
| 616 | if ( codeMirrorInstances ) { |
| 617 | Object.keys(codeMirrorInstances).forEach(function(key) { |
| 618 | if ( codeMirrorInstances[key] ) { |
| 619 | codeMirrorInstances[key].refresh(); |
| 620 | } |
| 621 | }); |
| 622 | } |
| 623 | |
| 624 | } else { |
| 625 | |
| 626 | $('.'+fieldClass+' .asenha-subfields').hide(); |
| 627 | if (document.querySelector('.'+fieldClass+' .asenha-subfield-select-inner')) { |
| 628 | $('.'+fieldClass+' .asenha-subfield-select-inner').hide(); |
| 629 | } |
| 630 | |
| 631 | } |
| 632 | |
| 633 | // Show/hide subfields on toggle click |
| 634 | document.getElementById('admin_site_enhancements['+fieldId+']').addEventListener('click', event => { |
| 635 | if (event.target.checked) { |
| 636 | |
| 637 | $('.'+fieldClass+' .asenha-subfields').fadeIn(); |
| 638 | if (document.querySelector('.'+fieldClass+' .asenha-subfield-select-inner')) { |
| 639 | $('.'+fieldClass+' .asenha-subfield-select-inner').show(); |
| 640 | } |
| 641 | $('.'+fieldClass+' .asenha-field-with-options').toggleClass('is-enabled'); |
| 642 | if (document.getElementById(sortableId)) { |
| 643 | // Initialize sortable elements: https://api.jqueryui.com/sortable/ |
| 644 | $('#' + sortableId ).sortable(); |
| 645 | } |
| 646 | if ( codeMirrorInstances ) { |
| 647 | Object.keys(codeMirrorInstances).forEach(function(key) { |
| 648 | if ( codeMirrorInstances[key] ) { |
| 649 | codeMirrorInstances[key].refresh(); |
| 650 | } |
| 651 | }); |
| 652 | } |
| 653 | |
| 654 | } else { |
| 655 | |
| 656 | $('.'+fieldClass+' .asenha-subfields').hide(); |
| 657 | if (document.querySelector('.'+fieldClass+' .asenha-subfield-select-inner')) { |
| 658 | $('.'+fieldClass+' .asenha-subfield-select-inner').hide(); |
| 659 | } |
| 660 | $('.'+fieldClass+' .asenha-field-with-options').toggleClass('is-enabled'); |
| 661 | |
| 662 | } |
| 663 | }); |
| 664 | |
| 665 | } |
| 666 | |
| 667 | } |
| 668 | |
| 669 | // Re-init wp_editor for snippet description. Required because the wp_editor was moved in the DOM after document ready. |
| 670 | // Ref: https://stackoverflow.com/a/21519323 |
| 671 | // Ref: https://core.trac.wordpress.org/ticket/19173 |
| 672 | function reinitWpEditor(id) { |
| 673 | tinymce.execCommand('mceRemoveEditor', true, id); |
| 674 | var init = tinymce.extend( {}, tinyMCEPreInit.mceInit[ id ] ); |
| 675 | try { tinymce.init( init ); } catch(e){} |
| 676 | $('textarea[id="' + id + '"]').closest('form').find('input[type="submit"]').click(function(){ |
| 677 | if( getUserSetting( 'editor' ) == 'tmce' ){ |
| 678 | var id = mce.find( 'textarea' ).attr( 'id' ); |
| 679 | tinymce.execCommand( 'mceRemoveEditor', false, id ); |
| 680 | tinymce.execCommand( 'mceAddEditor', false, id ); |
| 681 | } |
| 682 | return true; |
| 683 | }); |
| 684 | } |
| 685 | |
| 686 | |
| 687 | subfieldsToggler( 'enable_duplication', 'enable-duplication' ); |
| 688 | subfieldsToggler( 'content_order', 'content-order' ); |
| 689 | |
| 690 | subfieldsToggler( 'enable_svg_upload', 'enable-svg-upload' ); |
| 691 | subfieldsToggler( 'enable_avif_upload', 'enable-avif-upload' ); |
| 692 | |
| 693 | subfieldsToggler( 'enable_external_permalinks', 'enable-external-permalinks' ); |
| 694 | |
| 695 | subfieldsToggler( 'enhance_list_tables', 'enhance-list-tables' ); |
| 696 | subfieldsToggler( 'custom_admin_footer_text', 'custom-admin-footer-text' ); |
| 697 | subfieldsToggler( 'wider_admin_menu', 'wider-admin-menu' ); |
| 698 | subfieldsToggler( 'customize_admin_menu', 'customize-admin-menu', 'custom-admin-menu' ); |
| 699 | subfieldsToggler( 'disable_dashboard_widgets', 'disable-dashboard-widgets' ); |
| 700 | subfieldsToggler( 'various_admin_ui_enhancements', 'various-admin-ui-enhancements' ); |
| 701 | |
| 702 | // Clean Up Admin Bar |
| 703 | subfieldsToggler( 'hide_modify_elements', 'hide-modify-elements' ); |
| 704 | |
| 705 | subfieldsToggler( 'hide_admin_bar', 'hide-admin-bar' ); |
| 706 | subfieldsToggler( 'change_login_url', 'change-login-url' ); |
| 707 | subfieldsToggler( 'login_id_type_restriction', 'login-id-type-restriction' ); |
| 708 | |
| 709 | subfieldsToggler( 'redirect_after_login', 'redirect-after-login' ); |
| 710 | subfieldsToggler( 'redirect_after_logout', 'redirect-after-logout' ); |
| 711 | subfieldsToggler( 'enable_custom_admin_css', 'enable-custom-admin-css', '', {adminCssEditor} ); |
| 712 | subfieldsToggler( 'enable_custom_frontend_css', 'enable-custom-frontend-css', '', {frontendCssEditor} ); |
| 713 | subfieldsToggler( 'insert_head_body_footer_code', 'insert-head-body-footer-code', '', {headCodeEditor,bodyCodeEditor,footerCodeEditor} ); |
| 714 | subfieldsToggler( 'enable_custom_body_class', 'enable-custom-body-class' ); |
| 715 | subfieldsToggler( 'manage_ads_appads_txt', 'manage-ads-appads-txt', '', {adsTxtEditor,appAdsTxtEditor} ); |
| 716 | subfieldsToggler( 'manage_robots_txt', 'manage-robots-txt', '', {robotsTxtEditor} ); |
| 717 | |
| 718 | subfieldsToggler( 'disable_gutenberg', 'disable-gutenberg' ); |
| 719 | subfieldsToggler( 'disable_comments', 'disable-comments' ); |
| 720 | |
| 721 | subfieldsToggler( 'disable_smaller_components', 'disable-smaller-components' ); |
| 722 | subfieldsToggler( 'limit_login_attempts', 'limit-login-attempts' ); |
| 723 | |
| 724 | subfieldsToggler( 'obfuscate_email_address', 'obfuscate-email-address' ); |
| 725 | subfieldsToggler( 'image_upload_control', 'image-upload-control' ); |
| 726 | subfieldsToggler( 'enable_revisions_control', 'enable-revisions-control' ); |
| 727 | subfieldsToggler( 'enable_heartbeat_control', 'enable-heartbeat-control' ); |
| 728 | |
| 729 | |
| 730 | // Enable Heartbeat Control => Check if "Modify interval" is chosen/clicked and show/hide the corresponding select field |
| 731 | if ( $('input[name="admin_site_enhancements[heartbeat_control_for_admin_pages]"]:checked').val() == 'modify' ) { |
| 732 | $('.heartbeat-interval-for-admin-pages .asenha-subfield-select-inner').show(); |
| 733 | } |
| 734 | |
| 735 | $('input[name="admin_site_enhancements[heartbeat_control_for_admin_pages]"]').click(function() { |
| 736 | var radioValue = $(this).attr('value'); |
| 737 | if ( radioValue == 'modify' ) { |
| 738 | $('.heartbeat-interval-for-admin-pages .asenha-subfield-select-inner').show(); |
| 739 | } else { |
| 740 | $('.heartbeat-interval-for-admin-pages .asenha-subfield-select-inner').hide(); |
| 741 | } |
| 742 | }); |
| 743 | |
| 744 | if ( $('input[name="admin_site_enhancements[heartbeat_control_for_post_edit]"]:checked').val() == 'modify' ) { |
| 745 | $('.heartbeat-interval-for-post-edit .asenha-subfield-select-inner').show(); |
| 746 | } |
| 747 | |
| 748 | $('input[name="admin_site_enhancements[heartbeat_control_for_post_edit]"]').click(function() { |
| 749 | var radioValue = $(this).attr('value'); |
| 750 | if ( radioValue == 'modify' ) { |
| 751 | $('.heartbeat-interval-for-post-edit .asenha-subfield-select-inner').show(); |
| 752 | } else { |
| 753 | $('.heartbeat-interval-for-post-edit .asenha-subfield-select-inner').hide(); |
| 754 | } |
| 755 | }); |
| 756 | |
| 757 | if ( $('input[name="admin_site_enhancements[heartbeat_control_for_frontend]"]:checked').val() == 'modify' ) { |
| 758 | $('.heartbeat-interval-for-frontend .asenha-subfield-select-inner').show(); |
| 759 | } |
| 760 | |
| 761 | $('input[name="admin_site_enhancements[heartbeat_control_for_frontend]"]').click(function() { |
| 762 | var radioValue = $(this).attr('value'); |
| 763 | if ( radioValue == 'modify' ) { |
| 764 | $('.heartbeat-interval-for-frontend .asenha-subfield-select-inner').show(); |
| 765 | } else { |
| 766 | $('.heartbeat-interval-for-frontend .asenha-subfield-select-inner').hide(); |
| 767 | } |
| 768 | }); |
| 769 | |
| 770 | subfieldsToggler( 'smtp_email_delivery', 'smtp-email-delivery' ); |
| 771 | |
| 772 | |
| 773 | |
| 774 | // SMTP Email Delivery => Empty field value on click, so new password can be easily entered |
| 775 | var oldSmtpPassValue = ''; |
| 776 | |
| 777 | $('input[name="admin_site_enhancements[smtp_password]"]').focusin(function() { |
| 778 | oldSmtpPassValue = $(this).val(); |
| 779 | $(this).val(''); |
| 780 | }); |
| 781 | |
| 782 | $('input[name="admin_site_enhancements[smtp_password]"]').focusout(function() { |
| 783 | if ( $(this).val() == '' ) { |
| 784 | $(this).val(oldSmtpPassValue); |
| 785 | } |
| 786 | }); |
| 787 | |
| 788 | subfieldsToggler( 'view_admin_as_role', 'view-admin-as-role' ); |
| 789 | subfieldsToggler( 'enable_password_protection', 'enable-password-protection' ); |
| 790 | |
| 791 | // Enable Password protection => Empty field value on click, so new password can be easily entered |
| 792 | var oldValue = ''; |
| 793 | $('input[name="admin_site_enhancements[password_protection_password]"]').focusin(function() { |
| 794 | oldValue = $(this).val(); |
| 795 | $(this).val(''); |
| 796 | }); |
| 797 | |
| 798 | $('input[name="admin_site_enhancements[password_protection_password]"]').focusout(function() { |
| 799 | if ( $(this).val() == '' ) { |
| 800 | $(this).val(oldValue); |
| 801 | } |
| 802 | }); |
| 803 | |
| 804 | |
| 805 | subfieldsToggler( 'maintenance_mode', 'maintenance-mode' ); |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | // Content Toggler |
| 811 | $('.asenha-body').on('click', '.asenha-content-toggler', function(e) { |
| 812 | e.preventDefault(); |
| 813 | var targetSelector = $(this).data('target-selector'); |
| 814 | var showText = $(this).data('show-text'); |
| 815 | var hideText = $(this).data('hide-text'); |
| 816 | var expanded = $(this).attr('data-expanded'); |
| 817 | // $(targetSelector).toggle(); |
| 818 | if (expanded == 'no') { |
| 819 | $(targetSelector).slideDown(200); |
| 820 | $(this).html(hideText + ' <span>▲</span>'); |
| 821 | $(this).attr('data-expanded','yes'); |
| 822 | } else { |
| 823 | $(targetSelector).slideUp(200); |
| 824 | $(this).html(showText + ' <span>▼</span>'); |
| 825 | $(this).attr('data-expanded','no'); |
| 826 | } |
| 827 | }); |
| 828 | |
| 829 | // Media frame handler for image selection / upload fields |
| 830 | // Reference: https://plugins.trac.wordpress.org/browser/bm-custom-login/trunk/bm-custom-login.php |
| 831 | function media_frame_init( selector, button_selector ) { |
| 832 | // media_frame_init( '#login-page-logo-image', '#login-page-logo-image-button' ); |
| 833 | var theSelector = $(selector); |
| 834 | var button = $(button_selector); |
| 835 | |
| 836 | button.click(function (event) { |
| 837 | event.preventDefault(); |
| 838 | |
| 839 | // Configuration of the media frame new instance |
| 840 | wp.media.frames.frame = wp.media({ |
| 841 | title: adminPageVars.mediaFrameTitle, |
| 842 | multiple: false, |
| 843 | library: { |
| 844 | type: 'image' |
| 845 | }, |
| 846 | button: { |
| 847 | text: adminPageVars.mediaFrameButtonText |
| 848 | } |
| 849 | }); |
| 850 | |
| 851 | // Function used for the image selection and media manager closing |
| 852 | var media_set_image = function() { |
| 853 | var selection = wp.media.frames.frame.state().get('selection'); |
| 854 | |
| 855 | // Nothing is selected |
| 856 | if (!selection) { |
| 857 | return; |
| 858 | } |
| 859 | |
| 860 | // Iterate through selected elements |
| 861 | selection.each(function(attachment) { |
| 862 | // console.log(attachment); |
| 863 | var url = attachment.attributes.url; |
| 864 | url = url.replace( adminPageVars.wpcontentUrl, '' ); |
| 865 | theSelector.val(url); |
| 866 | |
| 867 | if ( '#login-page-logo-image' == selector ) { |
| 868 | var attachmentId = $('.login-page-logo-image-attachment-id input'); |
| 869 | var originalWidthInput = $('.login-page-logo-image-width-original input'); |
| 870 | var originalHeightInput = $('.login-page-logo-image-height-original input'); |
| 871 | var widthInput = $('.login-page-logo-image-width input'); |
| 872 | var heightInput = $('.login-page-logo-image-height input'); |
| 873 | attachmentId.val(attachment.attributes.id); |
| 874 | originalWidthInput.val(attachment.attributes.width); |
| 875 | originalHeightInput.val(attachment.attributes.height); |
| 876 | widthInput.val(attachment.attributes.width); |
| 877 | heightInput.val(attachment.attributes.height); |
| 878 | } |
| 879 | |
| 880 | if ( '#form-builder-email-header-image' == selector ) { |
| 881 | var attachmentId = $('.form-builder-email-header-image-attachment-id input'); |
| 882 | attachmentId.val(attachment.attributes.id); |
| 883 | } |
| 884 | }); |
| 885 | }; |
| 886 | |
| 887 | wp.media.frames.frame.on('close', media_set_image); |
| 888 | wp.media.frames.frame.on('select', media_set_image); |
| 889 | wp.media.frames.frame.open(); |
| 890 | }); |
| 891 | } |
| 892 | |
| 893 | // Form Builder - Empty out stored/hidden attachment ID when "Email header image" field is emptied |
| 894 | var emailHeaderImage = $('#form-builder-email-header-image'); |
| 895 | var emailHeaderImageAttachmentId = $('.form-builder-email-header-image-attachment-id input'); |
| 896 | |
| 897 | $(emailHeaderImage).keyup(delay(function (e) { |
| 898 | if ($(this).val().length === 0) { |
| 899 | emailHeaderImageAttachmentId.val(""); |
| 900 | } |
| 901 | }, 200)); |
| 902 | |
| 903 | // =============== Image Ratio Calculator / Preservation for Login Page Customizer >> Logo Image ================= |
| 904 | |
| 905 | // Code modified from: https://codepen.io/tobiasdev/pen/XNjxdZ by Tobias Bogliolo |
| 906 | |
| 907 | var initialWidth, initialHeight, newWidth, newHeight, aspectRatio; |
| 908 | |
| 909 | //Get new values: |
| 910 | function getValues(){ |
| 911 | initialWidth = $(".login-page-logo-image-width-original input").val(); |
| 912 | initialHeight = $(".login-page-logo-image-height-original input").val(); |
| 913 | newWidth = $(".login-page-logo-image-width input").val(); |
| 914 | newHeight = $(".login-page-logo-image-height input").val(); |
| 915 | }; |
| 916 | |
| 917 | //Aspect ratio: |
| 918 | function getAspectRatio(){ |
| 919 | // Formula: "Aspect Ratio = Width / Height". |
| 920 | return aspectRatio = initialWidth/initialHeight; |
| 921 | }; |
| 922 | |
| 923 | //Get new height: |
| 924 | $(".login-page-logo-image-width input").on("change keyup", function(){ |
| 925 | // Refresh data. |
| 926 | getValues(); |
| 927 | getAspectRatio(); |
| 928 | // New height = new width / (original width / original height). |
| 929 | newHeight = Math.round(newWidth/aspectRatio); |
| 930 | // Output: |
| 931 | $(".login-page-logo-image-height input").val(newHeight); |
| 932 | }); |
| 933 | |
| 934 | //Get new width: |
| 935 | $(".login-page-logo-image-height input").on("change keyup", function(){ |
| 936 | // Refresh data. |
| 937 | getValues(); |
| 938 | getAspectRatio(); |
| 939 | // New width = (original width / original height) * new height. |
| 940 | newWidth = Math.round(newHeight*aspectRatio); |
| 941 | // Output: |
| 942 | $(".login-page-logo-image-width input").val(newWidth); |
| 943 | }); |
| 944 | |
| 945 | //Reset: |
| 946 | $(".login-page-logo-image-width-original input, .login-page-logo-image-height-original input").on("change keyup", function(){ |
| 947 | // Output: |
| 948 | $(".login-page-logo-image-width input").val(""); |
| 949 | $(".login-page-logo-image-height input").val(""); |
| 950 | }); |
| 951 | |
| 952 | // =============== ASE PRO ================= |
| 953 | |
| 954 | if ( asenhaStats.isYearEndPromoPeriod ) { |
| 955 | |
| 956 | // Promo nudge |
| 957 | if ( asenhaStats.hidePromoNudge ) { |
| 958 | $('.asenha-promo-nudge').hide(); |
| 959 | $('#bottom-upgrade-nudge').show(); |
| 960 | } else { |
| 961 | $('.asenha-promo-nudge').show(); |
| 962 | $('#bottom-upgrade-nudge').hide(); |
| 963 | } |
| 964 | |
| 965 | $('#dismiss-promo-nudge').click(function(e) { |
| 966 | e.preventDefault(); |
| 967 | $.ajax({ |
| 968 | url: ajaxurl, |
| 969 | data: { |
| 970 | 'action':'dismiss_promo_nudge', |
| 971 | 'nonce': adminPageVars.nonce |
| 972 | }, |
| 973 | success:function(data) { |
| 974 | $('.asenha-promo-nudge').hide(); |
| 975 | }, |
| 976 | error:function(errorThrown) { |
| 977 | console.log(errorThrown); |
| 978 | } |
| 979 | }); |
| 980 | }); |
| 981 | |
| 982 | } else { |
| 983 | |
| 984 | // Upgrade nudge to Pro |
| 985 | if ( asenhaStats.hideUpgradeNudge ) { |
| 986 | $('.asenha-upgrade-nudge').hide(); |
| 987 | $('#bottom-upgrade-nudge').show(); |
| 988 | } else { |
| 989 | $('.asenha-upgrade-nudge').show(); |
| 990 | $('#bottom-upgrade-nudge').hide(); |
| 991 | } |
| 992 | |
| 993 | $('#dismiss-upgrade-nudge').click(function(e) { |
| 994 | e.preventDefault(); |
| 995 | $.ajax({ |
| 996 | url: ajaxurl, |
| 997 | data: { |
| 998 | 'action':'dismiss_upgrade_nudge', |
| 999 | 'nonce': adminPageVars.nonce |
| 1000 | }, |
| 1001 | success:function(data) { |
| 1002 | $('.asenha-upgrade-nudge').hide(); |
| 1003 | // $('#bottom-upgrade-nudge').show(); |
| 1004 | }, |
| 1005 | error:function(errorThrown) { |
| 1006 | console.log(errorThrown); |
| 1007 | } |
| 1008 | }); |
| 1009 | }); |
| 1010 | |
| 1011 | } |
| 1012 | |
| 1013 | // =============== SPONSORSHIP ================= |
| 1014 | |
| 1015 | // Stats on saving changes from asenha_admin_scripts() wp_localize_script() is availble in the 'asenhaStats' object----- |
| 1016 | // console.log( asenhaStats ); |
| 1017 | // alert(JSON.stringify(asenhaStats)); |
| 1018 | if ( asenhaStats.showSupportNudge ) { |
| 1019 | $('.asenha-support-nudge').show(); |
| 1020 | } else { |
| 1021 | $('.asenha-support-nudge').hide(); |
| 1022 | } |
| 1023 | |
| 1024 | $('#have-shared,#have-reviewed').click(function(e) { |
| 1025 | e.preventDefault(); |
| 1026 | // $.ajax({ |
| 1027 | // url: 'https://bowo.io/asenha-sp-ndg', |
| 1028 | // method: 'GET', |
| 1029 | // dataType: 'jsonp', |
| 1030 | // crossDomain: true |
| 1031 | // }); |
| 1032 | $.ajax({ |
| 1033 | url: ajaxurl, |
| 1034 | data: { |
| 1035 | 'action':'have_supported', |
| 1036 | 'nonce': adminPageVars.nonce |
| 1037 | }, |
| 1038 | success:function(data) { |
| 1039 | $('.asenha-support-nudge').hide(); |
| 1040 | }, |
| 1041 | error:function(errorThrown) { |
| 1042 | console.log(errorThrown); |
| 1043 | } |
| 1044 | }); |
| 1045 | }); |
| 1046 | |
| 1047 | $('#support-nudge-dismiss').click(function(e) { |
| 1048 | e.preventDefault(); |
| 1049 | // $.ajax({ |
| 1050 | // url: 'https://bowo.io/asenha-sp-ndg', |
| 1051 | // method: 'GET', |
| 1052 | // dataType: 'jsonp', |
| 1053 | // crossDomain: true |
| 1054 | // }); |
| 1055 | $.ajax({ |
| 1056 | url: ajaxurl, |
| 1057 | data: { |
| 1058 | 'action':'dismiss_support_nudge', |
| 1059 | 'nonce': adminPageVars.nonce |
| 1060 | }, |
| 1061 | success:function(data) { |
| 1062 | $('.asenha-support-nudge').hide(); |
| 1063 | }, |
| 1064 | error:function(errorThrown) { |
| 1065 | console.log(errorThrown); |
| 1066 | } |
| 1067 | }); |
| 1068 | }); |
| 1069 | |
| 1070 | // Expand support notice | Modified from https://codepen.io/symonsays/pen/rzgEgY |
| 1071 | $('.asenha-support-nudge.nudge-show-more > .show-more').click(function(e) { |
| 1072 | |
| 1073 | e.preventDefault(); |
| 1074 | |
| 1075 | var $this = $(this); |
| 1076 | $this.toggleClass('show-more'); |
| 1077 | $this.hide(); |
| 1078 | |
| 1079 | if ($this.hasClass('show-more')) { |
| 1080 | $this.next().removeClass('opened',0); |
| 1081 | } else { |
| 1082 | $this.next().addClass('opened',0); |
| 1083 | } |
| 1084 | |
| 1085 | }); |
| 1086 | |
| 1087 | // Collapse support notice | Modified from https://codepen.io/symonsays/pen/rzgEgY |
| 1088 | $('#support-nudge-show-less').click(function(e) { |
| 1089 | |
| 1090 | e.preventDefault(); |
| 1091 | |
| 1092 | $('.nudge-wrapper-show-more').removeClass('opened',0); |
| 1093 | $('#support-nudge-show-moreless').addClass('show-more'); |
| 1094 | $('#support-nudge-show-moreless').show(); |
| 1095 | |
| 1096 | }); |
| 1097 | |
| 1098 | |
| 1099 | |
| 1100 | // Modal for sponsoring plugin dev and maintenance: https://stephanwagner.me/jBox |
| 1101 | |
| 1102 | // var sponsorModal = new jBox('Modal', { |
| 1103 | // attach: '#plugin-sponsor', |
| 1104 | // trigger: 'click', // or 'mouseenter' |
| 1105 | // // content: 'Test' |
| 1106 | // content: $('#asenha-sponsor'), |
| 1107 | // width: 740, // pixels |
| 1108 | // closeButton: 'box', |
| 1109 | // addClass: 'plugin-sponsor-modal', |
| 1110 | // overlayClass: 'plugin-sponsor-modal-overlay', |
| 1111 | // target: '#wpwrap', // where to anchor the modal |
| 1112 | // position: { |
| 1113 | // x: 'center', |
| 1114 | // y: 'top' |
| 1115 | // }, |
| 1116 | // // fade: 1000, |
| 1117 | // animation: { |
| 1118 | // open: 'slide:top', |
| 1119 | // close: 'slide:top' |
| 1120 | // } |
| 1121 | // }); |
| 1122 | |
| 1123 | // $('#plugin-sponsor').click( function() { |
| 1124 | // $.ajax({ |
| 1125 | // url: 'https://bowo.io/asenha-sp-btn', |
| 1126 | // method: 'GET', |
| 1127 | // dataType: 'jsonp', |
| 1128 | // crossDomain: true |
| 1129 | // // success: function(response) { |
| 1130 | // // console.log(response); |
| 1131 | // // } |
| 1132 | // }); |
| 1133 | // }); |
| 1134 | |
| 1135 | }); // END OF $(document).ready() |
| 1136 | |
| 1137 | })( jQuery ); |