| 1 |
/* global jQuery */ |
| 2 |
import '@wpmudev/shared-ui/dist/js/_src/modal-dialog'; |
| 3 |
import './modules/nav'; |
| 4 |
import './modules/toggle'; |
| 5 |
import './modules/modal'; |
| 6 |
|
| 7 |
(function ($) { |
| 8 |
let zone_index = 0; |
| 9 |
|
| 10 |
$(document).on('click', '.add_cdn_hostname', function (e) { |
| 11 |
e.preventDefault(); |
| 12 |
let ref_el = $('.cdn-zone:first').clone(); |
| 13 |
|
| 14 |
if (zone_index === 0) { |
| 15 |
zone_index = $('.cdn-zone').length; |
| 16 |
} else { |
| 17 |
zone_index++; |
| 18 |
} |
| 19 |
|
| 20 |
ref_el = $(ref_el).attr('id', `cdn-zone-${zone_index}`); |
| 21 |
$(ref_el).find('.cdn_hostname').val(''); |
| 22 |
$(ref_el).find('.cdn_zone').prop('selectedIndex', 0); |
| 23 |
|
| 24 |
$(ref_el).find('button').removeClass('sui-hidden-important'); |
| 25 |
|
| 26 |
$('#cdn-zones').append(ref_el); |
| 27 |
}); |
| 28 |
|
| 29 |
$('#cdn-zones').on('click', '.remove_cdn_hostname', function () { |
| 30 |
const target_node = $(this).parents('.cdn-zone'); |
| 31 |
if (target_node.attr('id') === 'cdn-zone-0') { |
| 32 |
alert('Nice try :) This zone cannot be removed!'); |
| 33 |
return false; |
| 34 |
} |
| 35 |
|
| 36 |
target_node.remove(); |
| 37 |
return true; |
| 38 |
}); |
| 39 |
|
| 40 |
// toggle sitemap options based on cache preloading |
| 41 |
$('#enable_cache_preload').on('change', function () { |
| 42 |
if ($(this).is(':checked')) { |
| 43 |
$('#enable_sitemap_preload_wrapper').show(); |
| 44 |
} else { |
| 45 |
$('#enable_sitemap_preload_wrapper').hide(); |
| 46 |
} |
| 47 |
}); |
| 48 |
|
| 49 |
$('#enable_page_cache').on('change', function () { |
| 50 |
if ($(this).is(':checked')) { |
| 51 |
$('#preload_page_cache_warning_message').hide(); |
| 52 |
} else { |
| 53 |
$('#preload_page_cache_warning_message').show(); |
| 54 |
} |
| 55 |
}); |
| 56 |
|
| 57 |
$('#cloudflare-api-token').on('keyup keypress change', function () { |
| 58 |
if ($(this).val().length > 0) { |
| 59 |
$('#cloudflare-api-details').hide(); |
| 60 |
} else { |
| 61 |
$('#cloudflare-api-details').show(); |
| 62 |
} |
| 63 |
}); |
| 64 |
|
| 65 |
$('.heartbeat_dashboard_status').on('change', function () { |
| 66 |
if ($(this).val() === 'modify') { |
| 67 |
$('#heartbeat-dashboard-interval').show(); |
| 68 |
} else { |
| 69 |
$('#heartbeat-dashboard-interval').hide(); |
| 70 |
} |
| 71 |
}); |
| 72 |
|
| 73 |
$('.heartbeat_radio').on('change', function () { |
| 74 |
const targetInput = $(this).attr('aria-controls'); |
| 75 |
|
| 76 |
if (!targetInput) { |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
if ($(this).val() === 'modify') { |
| 81 |
$(`#${targetInput}`).show(); |
| 82 |
} else { |
| 83 |
$(`#${targetInput}`).hide(); |
| 84 |
} |
| 85 |
}); |
| 86 |
|
| 87 |
$('#powered-cache-import-file-input').on('change', function () { |
| 88 |
const elm = $(this)[0]; |
| 89 |
if (elm.files.length) { |
| 90 |
const file = elm.files[0]; |
| 91 |
$('#powered-cache-import-file-name').text(file.name); |
| 92 |
$('#powered-cache-import-upload-wrap').addClass('sui-has_file'); |
| 93 |
$('#powered-cache-import-btn').removeAttr('disabled'); |
| 94 |
} else { |
| 95 |
$('#powered-cache-import-file-name').text(''); |
| 96 |
$('#powered-cache-import-upload-wrap').removeClass('sui-has_file'); |
| 97 |
$('#powered-cache-import-btn').attr('disabled', 'disabled'); |
| 98 |
} |
| 99 |
}); |
| 100 |
|
| 101 |
$('#powered-cache-import-remove-file').on('click', function () { |
| 102 |
$('#powered-cache-import-file-input').val('').trigger('change'); |
| 103 |
}); |
| 104 |
|
| 105 |
$('#js_execution_method').on('change', function (e) { |
| 106 |
if ('blocking' !== $(this).val()) { |
| 107 |
$('#js_execution_exclusions_field').show(); |
| 108 |
} else { |
| 109 |
$('#js_execution_exclusions_field').hide(); |
| 110 |
} |
| 111 |
}); |
| 112 |
|
| 113 |
$('#js_delay').on('change', function () { |
| 114 |
if ($(this).is(':checked')) { |
| 115 |
$('#combine_js').prop("checked", false).prop("disabled", true); |
| 116 |
}else{ |
| 117 |
if( $('#minify_js').is(':checked') ){ |
| 118 |
$('#combine_js').prop("disabled", false); |
| 119 |
} |
| 120 |
} |
| 121 |
}); |
| 122 |
|
| 123 |
$('#minify_js').on('change', function () { |
| 124 |
if ($(this).is(':checked') && !$('#js_delay').is(':checked')) { |
| 125 |
$('#combine_js').prop("disabled", false); |
| 126 |
}else{ |
| 127 |
$('#combine_js').prop("disabled", true); |
| 128 |
} |
| 129 |
}); |
| 130 |
|
| 131 |
$('#object_cache').on('change', function () { |
| 132 |
// Check if new selection is memcached or memcache |
| 133 |
if ($(this).val() === 'memcached' || $(this).val() === 'memcache') { |
| 134 |
$.ajax({ |
| 135 |
url : ajaxurl, |
| 136 |
method: 'post', |
| 137 |
data : { |
| 138 |
nonce : $('#powered_cache_settings_nonce').val(), |
| 139 |
action: 'powered_cache_check_alloptions', |
| 140 |
}, |
| 141 |
success(response) { |
| 142 |
if (response.success && response.data.status) { |
| 143 |
let $alloptionsContainer = $('#object_cache_alloptions_message'); |
| 144 |
|
| 145 |
if (response.data.status === 'success') { |
| 146 |
return; |
| 147 |
} |
| 148 |
|
| 149 |
let statusClass = 'sui-notice-warning'; // Default to warning |
| 150 |
|
| 151 |
if (response.data.status === 'critical') { |
| 152 |
statusClass = 'sui-notice-error'; // Change to error if critical |
| 153 |
} |
| 154 |
|
| 155 |
$alloptionsContainer.addClass(statusClass); |
| 156 |
|
| 157 |
let message = '<span class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></span>'; |
| 158 |
message += response.data.message; |
| 159 |
|
| 160 |
$alloptionsContainer.find('.sui-notice-message').html(message); |
| 161 |
$alloptionsContainer.removeClass('sui-hidden'); |
| 162 |
$alloptionsContainer.show(); |
| 163 |
} |
| 164 |
}, |
| 165 |
}); |
| 166 |
} else { |
| 167 |
$('#object_cache_alloptions_message').hide(); |
| 168 |
} |
| 169 |
}); |
| 170 |
|
| 171 |
|
| 172 |
})(jQuery); |
| 173 |
|