| 1 |
|
| 2 |
/* eslint complexity: ["error", 100] */ |
| 3 |
|
| 4 |
window.wp = window.wp || {}; |
| 5 |
window.mainwpVars = window.mainwpVars || {}; |
| 6 |
|
| 7 |
let executingUpdateCategories = false; |
| 8 |
let queueUpdateCategories = 0; |
| 9 |
|
| 10 |
function reload_init() { |
| 11 |
read_current_url(); |
| 12 |
if (typeof wpOnload == 'function') |
| 13 |
wpOnload(); |
| 14 |
managebackups_init(); |
| 15 |
managesites_init(); |
| 16 |
// Update form action URL, workaround for browser without History API |
| 17 |
jQuery('#wpbody-content form').each(function () { |
| 18 |
if (jQuery(this).attr('action') == '') |
| 19 |
jQuery(this).attr('action', mainwp_current_url); |
| 20 |
}); |
| 21 |
stick_element_init(); |
| 22 |
} |
| 23 |
|
| 24 |
/** AJAX page load **/ |
| 25 |
let mainwp_current_url = ''; |
| 26 |
function read_current_url() { |
| 27 |
mainwp_current_url = document.location.href.replace(/^.*?\/([^/]*?)\/?$/i, '$1'); |
| 28 |
return mainwp_current_url; |
| 29 |
} |
| 30 |
function load_url(href, obj, e) { // NOSONAR - complex. |
| 31 |
let page = href.match(/page=/i) ? href.replace(/^.*\?page=([^&]+).*?$/i, '$1') : ''; // NOSONAR - safe with run time error. |
| 32 |
if (page || href == 'index.php') { |
| 33 |
if (!jQuery('body').hasClass('mainwp-ui-page')) { |
| 34 |
return; |
| 35 |
} |
| 36 |
if (typeof e !== 'undefined') |
| 37 |
e.preventDefault(); |
| 38 |
jQuery('#wpbody-content').html('<div class="mainwp-loading"><img src="images/loading.gif" /> ' + __('Please wait...') + '</div>'); |
| 39 |
if (jQuery(obj).hasClass('menu-top')) { |
| 40 |
let top = jQuery(obj).closest('li.menu-top'); |
| 41 |
jQuery('#adminmenu .current').removeClass('current').addClass('wp-not-current-submenu'); |
| 42 |
jQuery('.wp-has-current-submenu').removeClass('wp-has-current-submenu').addClass('wp-not-current-submenu'); |
| 43 |
if (top.hasClass('wp-has-submenu')) { |
| 44 |
top.removeClass('wp-not-current-submenu').addClass('wp-has-current-submenu'); |
| 45 |
jQuery(obj).removeClass('wp-not-current-submenu').addClass('wp-has-current-submenu'); |
| 46 |
} else { |
| 47 |
top.removeClass('wp-not-current-submenu').addClass('current'); |
| 48 |
jQuery(obj).removeClass('wp-not-current-submenu').addClass('current'); |
| 49 |
} |
| 50 |
top.find('li.wp-first-item').addClass('current'); |
| 51 |
} else { |
| 52 |
jQuery('#adminmenu .current').removeClass('current'); |
| 53 |
jQuery(obj).closest('li').addClass('current'); |
| 54 |
let top = jQuery(obj).closest('li.menu-top'); |
| 55 |
if (top.hasClass('wp-not-current-submenu')) { |
| 56 |
jQuery('.wp-has-current-submenu').removeClass('wp-has-current-submenu').addClass('wp-not-current-submenu'); |
| 57 |
top.removeClass('wp-not-current-submenu').addClass('wp-has-current-submenu'); |
| 58 |
} |
| 59 |
top.find('a.menu-top').removeClass('wp-not-current-submenu').addClass('wp-has-current-submenu'); |
| 60 |
} |
| 61 |
if (page) { |
| 62 |
jQuery.get(ajaxurl, { |
| 63 |
action: 'mainwp_load_title', |
| 64 |
page: page, |
| 65 |
nonce: mainwp_ajax_nonce |
| 66 |
}, function (data) { |
| 67 |
document.title = data; |
| 68 |
}); |
| 69 |
jQuery.get(ajaxurl, { |
| 70 |
action: 'mainwp_load', |
| 71 |
page: page, |
| 72 |
nonce: mainwp_ajax_nonce |
| 73 |
}, function (data) { |
| 74 |
pagenow = page; // NOSONAR - wp variable. |
| 75 |
data += '<div class="clear"></div>'; |
| 76 |
jQuery('#wpbody-content').html(data); |
| 77 |
reload_init(); |
| 78 |
}); |
| 79 |
} else { |
| 80 |
jQuery.get(ajaxurl, { |
| 81 |
action: 'mainwp_load_dashboard_title', |
| 82 |
nonce: mainwp_ajax_nonce |
| 83 |
}, function (data) { |
| 84 |
document.title = data; |
| 85 |
}); |
| 86 |
jQuery.get(ajaxurl, { |
| 87 |
action: 'mainwp_load_dashboard', |
| 88 |
nonce: mainwp_ajax_nonce |
| 89 |
}, function (data) { |
| 90 |
pagenow = 'dashboard'; |
| 91 |
data += '<div class="clear"></div>'; |
| 92 |
jQuery('#wpbody-content').html(data); |
| 93 |
reload_init(); |
| 94 |
postboxes.init(pagenow); |
| 95 |
mainwp_ga_getstats(); |
| 96 |
}); |
| 97 |
} |
| 98 |
|
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
window.onpopstate = function (e) { |
| 103 |
read_current_url(); |
| 104 |
if (e.state) |
| 105 |
load_url(mainwp_current_url, e.state.anchor); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
function scroll_element() { |
| 112 |
let top = jQuery(this).scrollTop(); |
| 113 |
let start = 20; |
| 114 |
jQuery('.stick-to-window').each(function () { |
| 115 |
let init = jQuery(this).data('init-position'); |
| 116 |
if (top > init.top) |
| 117 |
jQuery(this).stop().animate({ top: (top - init.top) + init.top + start }, 1000); |
| 118 |
else |
| 119 |
jQuery(this).stop().css({ top: init.top }); |
| 120 |
}); |
| 121 |
} |
| 122 |
function stick_element_init() { |
| 123 |
jQuery('.stick-to-window').each(function () { |
| 124 |
let pos = jQuery(this).position(); |
| 125 |
jQuery(this).css({ |
| 126 |
position: 'absolute', |
| 127 |
top: pos.top, |
| 128 |
left: pos.left |
| 129 |
}); |
| 130 |
jQuery(this).data('init-position', pos); |
| 131 |
}); |
| 132 |
} |
| 133 |
function stick_element_reset() { |
| 134 |
jQuery('.stick-to-window').each(function () { |
| 135 |
jQuery(this).css({ |
| 136 |
position: 'static', |
| 137 |
top: 0, |
| 138 |
left: 0 |
| 139 |
}); |
| 140 |
}); |
| 141 |
stick_element_init(); |
| 142 |
scroll_element(); |
| 143 |
} |
| 144 |
jQuery(function () { |
| 145 |
jQuery(window).trigger('scroll', scroll_element).trigger('resize', stick_element_reset); |
| 146 |
stick_element_init(); |
| 147 |
}); |
| 148 |
|
| 149 |
window.mainwp_confirm = function (msg, confirmed_callback, cancelled_callback, updateType, multiple, extra) { // updateType: 1 single update, 2 multi update |
| 150 |
let confVal; |
| 151 |
if (jQuery('#mainwp-disable-update-confirmations').length > 0) { |
| 152 |
confVal = jQuery('#mainwp-disable-update-confirmations').val(); |
| 153 |
} |
| 154 |
if (jQuery('#mainwp-disable-update-confirmations').length > 0 && typeof updateType !== 'undefined' && updateType !== false && (confVal == 2 || (confVal == 1 && updateType == 1)) && confirmed_callback && typeof confirmed_callback == 'function') { |
| 155 |
confirmed_callback(); |
| 156 |
return; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
jQuery('#mainwp-modal-confirm .content-massage').html(msg); |
| 161 |
|
| 162 |
if (typeof extra !== 'undefined' && extra !== false) { |
| 163 |
jQuery('#mainwp-confirm-form').show(); |
| 164 |
jQuery('#mainwp-confirm-form').find('label').html('Type ' + extra + ' to confirm'); |
| 165 |
} |
| 166 |
|
| 167 |
let opts = { |
| 168 |
onApprove: function () { |
| 169 |
if (typeof extra !== 'undefined' && extra !== false) { |
| 170 |
let extraValue = jQuery('#mainwp-confirm-input').val(); |
| 171 |
if (confirmed_callback && typeof confirmed_callback == 'function') { |
| 172 |
if (extraValue === extra) { |
| 173 |
confirmed_callback(); |
| 174 |
} else { |
| 175 |
jQuery('#mainwp-confirm-input').val('').trigger('focus').transition('shake'); |
| 176 |
return; |
| 177 |
} |
| 178 |
} |
| 179 |
} else if (confirmed_callback && typeof confirmed_callback == 'function') { |
| 180 |
confirmed_callback(); |
| 181 |
} |
| 182 |
}, |
| 183 |
onDeny() { |
| 184 |
if (cancelled_callback && typeof cancelled_callback == 'function') |
| 185 |
cancelled_callback(); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
if (multiple) { |
| 190 |
opts.allowMultiple = true; |
| 191 |
} |
| 192 |
|
| 193 |
jQuery('#mainwp-modal-confirm').modal(opts).modal('show'); |
| 194 |
|
| 195 |
// if it is update confirm and then display the update confirm notice text |
| 196 |
if (typeof updateType !== 'undefined' && updateType !== false && (updateType == 1 || updateType == 2)) { |
| 197 |
jQuery('#mainwp-modal-confirm .update-confirm-notice ').show(); |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
/** |
| 203 |
* Select sites |
| 204 |
*/ |
| 205 |
jQuery(document).on('change', '.mainwp_selected_sites_item input:checkbox', function () { |
| 206 |
if (jQuery(this).is(':checked')) |
| 207 |
jQuery(this).parent().addClass('selected_sites_item_checked'); |
| 208 |
else |
| 209 |
jQuery(this).parent().removeClass('selected_sites_item_checked'); |
| 210 |
mainwp_site_select(); |
| 211 |
}); |
| 212 |
|
| 213 |
jQuery(document).on('change', '.mainwp_selected_groups_item input:checkbox', function () { |
| 214 |
if (jQuery(this).is(':checked')) |
| 215 |
jQuery(this).parent().addClass('selected_groups_item_checked'); |
| 216 |
else |
| 217 |
jQuery(this).parent().removeClass('selected_groups_item_checked'); |
| 218 |
mainwp_group_select(); |
| 219 |
}); |
| 220 |
|
| 221 |
jQuery(document).on('change', '.mainwp_selected_clients_item input:checkbox', function () { |
| 222 |
if (jQuery(this).is(':checked')) |
| 223 |
jQuery(this).parent().addClass('selected_clients_item_checked'); |
| 224 |
else |
| 225 |
jQuery(this).parent().removeClass('selected_clients_item_checked'); |
| 226 |
mainwp_client_select(); |
| 227 |
}); |
| 228 |
|
| 229 |
|
| 230 |
jQuery(function () { |
| 231 |
// seems not used. |
| 232 |
jQuery('.mainwp_selected_sites_item input:radio').on('change', function () { |
| 233 |
if (jQuery(this).is(':checked')) { |
| 234 |
jQuery(this).parent().addClass('selected_sites_item_checked'); |
| 235 |
jQuery(this).parent().parent().find('.mainwp_selected_sites_item input:radio:not(:checked)').parent().removeClass('selected_sites_item_checked'); |
| 236 |
} else |
| 237 |
jQuery(this).parent().removeClass('selected_sites_item_checked'); |
| 238 |
mainwp_site_select(); |
| 239 |
}); |
| 240 |
// seems not used. |
| 241 |
jQuery('.mainwp_selected_groups_item input:radio').on('change', function () { |
| 242 |
if (jQuery(this).is(':checked')) { |
| 243 |
jQuery(this).parent().addClass('selected_groups_item_checked'); |
| 244 |
jQuery(this).parent().parent().find('.mainwp_selected_groups_item input:radio:not(:checked)').parent().removeClass('selected_groups_item_checked'); |
| 245 |
} else |
| 246 |
jQuery(this).parent().removeClass('selected_groups_item_checked'); |
| 247 |
}); |
| 248 |
}); |
| 249 |
|
| 250 |
let mainwp_site_select = function () { |
| 251 |
mainwp_newpost_updateCategories(); |
| 252 |
}; |
| 253 |
let mainwp_group_select = function () { |
| 254 |
mainwp_newpost_updateCategories(); |
| 255 |
}; |
| 256 |
let mainwp_client_select = function () { |
| 257 |
mainwp_newpost_updateCategories(); |
| 258 |
}; |
| 259 |
|
| 260 |
let mainwp_ss_select = function (me, val) { |
| 261 |
let parent = jQuery(me).closest('.mainwp_select_sites_wrapper'); |
| 262 |
let tab = parent.find('#select_sites_tab').val(); |
| 263 |
if (tab == 'site') { |
| 264 |
parent.find('#mainwp-select-sites-list .item:not(.no-select) INPUT:enabled:checkbox').each(function () { |
| 265 |
jQuery(this).attr('checked', val).trigger("change"); |
| 266 |
if (val) { |
| 267 |
jQuery(this).closest('.item.checkbox').checkbox('set checked'); |
| 268 |
} |
| 269 |
else { |
| 270 |
jQuery(this).closest('.item.checkbox').checkbox('set unchecked'); |
| 271 |
} |
| 272 |
}); |
| 273 |
} else if (tab == 'staging') { |
| 274 |
parent.find('#mainwp-select-staging-sites-list .item:not(.no-select) INPUT:enabled:checkbox').each(function () { |
| 275 |
jQuery(this).attr('checked', val).trigger("change"); |
| 276 |
if (val) { |
| 277 |
jQuery(this).closest('.item.checkbox').checkbox('set checked'); |
| 278 |
} |
| 279 |
else { |
| 280 |
jQuery(this).closest('.item.checkbox').checkbox('set unchecked'); |
| 281 |
} |
| 282 |
}); |
| 283 |
} else if (tab == 'client') { |
| 284 |
parent.find('#mainwp-select-clients-list .item:not(.no-select) INPUT:enabled:checkbox').each(function () { |
| 285 |
jQuery(this).attr('checked', val).trigger("change"); |
| 286 |
if (val) { |
| 287 |
jQuery(this).closest('.item.checkbox').checkbox('set checked'); |
| 288 |
} |
| 289 |
else { |
| 290 |
jQuery(this).closest('.item.checkbox').checkbox('set unchecked'); |
| 291 |
} |
| 292 |
}); |
| 293 |
|
| 294 |
} else { //group |
| 295 |
parent.find('#mainwp-select-groups-list .item:not(.no-select) INPUT:enabled:checkbox').each(function () { |
| 296 |
jQuery(this).attr('checked', val).trigger("change"); |
| 297 |
if (val) { |
| 298 |
jQuery(this).closest('.item.checkbox').checkbox('set checked'); |
| 299 |
} |
| 300 |
else { |
| 301 |
jQuery(this).closest('.item.checkbox').checkbox('set unchecked'); |
| 302 |
} |
| 303 |
}); |
| 304 |
} |
| 305 |
if (val) { |
| 306 |
jQuery('.mainwp-ss-select').hide(); |
| 307 |
jQuery('.mainwp-ss-deselect').show(); |
| 308 |
} else { |
| 309 |
jQuery('.mainwp-ss-select').show(); |
| 310 |
jQuery('.mainwp-ss-deselect').hide(); |
| 311 |
} |
| 312 |
mainwp_newpost_updateCategories(); |
| 313 |
return false; |
| 314 |
}; |
| 315 |
|
| 316 |
|
| 317 |
let mainwp_ss_select_disconnected = function (me, val) { |
| 318 |
let parent = jQuery(me).closest('.mainwp_select_sites_wrapper'); |
| 319 |
let tab = parent.find('#select_sites_tab').val(); |
| 320 |
if (tab == 'site') { |
| 321 |
parent.find('#mainwp-select-sites-list .warning.item:not(.no-select) INPUT:enabled:checkbox').each(function () { |
| 322 |
jQuery(this).attr('checked', val).trigger("change"); |
| 323 |
if (val) { |
| 324 |
jQuery(this).closest('.item.warning.checkbox').checkbox('set checked'); |
| 325 |
} |
| 326 |
else { |
| 327 |
jQuery(this).closest('.item.warning.checkbox').checkbox('set unchecked'); |
| 328 |
} |
| 329 |
}); |
| 330 |
} |
| 331 |
if (val) { |
| 332 |
jQuery('.mainwp-ss-select-disconnected').hide(); |
| 333 |
jQuery('.mainwp-ss-deselect-disconnected').show(); |
| 334 |
} else { |
| 335 |
jQuery('.mainwp-ss-select-disconnected').show(); |
| 336 |
jQuery('.mainwp-ss-deselect-disconnected').hide(); |
| 337 |
} |
| 338 |
mainwp_newpost_updateCategories(); |
| 339 |
return false; |
| 340 |
}; |
| 341 |
|
| 342 |
window.mainwp_sites_selection_onvisible_callback = function (me) { |
| 343 |
let selected_tab = jQuery(me).attr('select-by'); |
| 344 |
let select_by = 'site'; |
| 345 |
let parent = jQuery(me).closest('.mainwp_select_sites_wrapper'); |
| 346 |
if (selected_tab == 'staging') { |
| 347 |
// uncheck live sites |
| 348 |
parent.find('#mainwp-select-sites-list INPUT:checkbox').prop('checked', false); |
| 349 |
parent.find('#mainwp-select-groups-list INPUT:checkbox').prop('checked', false); |
| 350 |
parent.find('#mainwp-select-clients-list INPUT:checkbox').prop('checked', false); |
| 351 |
} else if (selected_tab == 'site') { |
| 352 |
// uncheck staging sites |
| 353 |
parent.find('#mainwp-select-staging-sites-list INPUT:checkbox').prop('checked', false); |
| 354 |
parent.find('#mainwp-select-groups-list INPUT:checkbox').prop('checked', false); |
| 355 |
parent.find('#mainwp-select-clients-list INPUT:checkbox').prop('checked', false); |
| 356 |
} else if (selected_tab == 'group') { |
| 357 |
// uncheck sites |
| 358 |
parent.find('#mainwp-select-sites-list INPUT:checkbox').prop('checked', false); |
| 359 |
parent.find('#mainwp-select-staging-sites-list INPUT:checkbox').prop('checked', false); |
| 360 |
parent.find('#mainwp-select-clients-list INPUT:checkbox').prop('checked', false); |
| 361 |
select_by = 'group'; |
| 362 |
} else if (selected_tab == 'client') { |
| 363 |
// uncheck sites |
| 364 |
parent.find('#mainwp-select-sites-list INPUT:checkbox').prop('checked', false); |
| 365 |
parent.find('#mainwp-select-groups-list INPUT:checkbox').prop('checked', false); |
| 366 |
parent.find('#mainwp-select-staging-sites-list INPUT:checkbox').prop('checked', false); |
| 367 |
select_by = 'client'; |
| 368 |
} |
| 369 |
|
| 370 |
jQuery('.mainwp-ss-select').show(); |
| 371 |
jQuery('.mainwp-ss-deselect').hide(); |
| 372 |
|
| 373 |
console.log('select by: ' + select_by); |
| 374 |
|
| 375 |
parent.find('#select_by').val(select_by); |
| 376 |
parent.find('#select_sites_tab').val(selected_tab); |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
let mainwp_newpost_updateCategories = function () { |
| 381 |
if (executingUpdateCategories) { |
| 382 |
queueUpdateCategories++; |
| 383 |
return; |
| 384 |
} |
| 385 |
executingUpdateCategories = true; |
| 386 |
console.log('mainwp_newpost_updateCategories'); |
| 387 |
let catsSelection = jQuery('#categorychecklist'); |
| 388 |
if (catsSelection.length > 0) { |
| 389 |
let tab = jQuery('#select_sites_tab').val(); |
| 390 |
let sites = []; |
| 391 |
let groups = []; |
| 392 |
let clients = []; |
| 393 |
if (tab == 'site') { |
| 394 |
sites = jQuery.map(jQuery('#mainwp-select-sites-list INPUT:checkbox:checked'), function (el) { |
| 395 |
return jQuery(el).val(); |
| 396 |
}); |
| 397 |
} else if (tab == 'staging') { |
| 398 |
sites = jQuery.map(jQuery('#mainwp-select-staging-sites-list INPUT:checkbox:checked'), function (el) { |
| 399 |
return jQuery(el).val(); |
| 400 |
}); |
| 401 |
} else if (tab == 'client') { |
| 402 |
clients = jQuery.map(jQuery('#mainwp-select-clients-list INPUT:checkbox:checked'), function (el) { |
| 403 |
return jQuery(el).val(); |
| 404 |
}); |
| 405 |
} else { //group |
| 406 |
groups = jQuery.map(jQuery('#mainwp-select-groups-list INPUT:checkbox:checked'), function (el) { |
| 407 |
return jQuery(el).val(); |
| 408 |
}); |
| 409 |
} |
| 410 |
|
| 411 |
let selected_categories = catsSelection.dropdown('get value'); |
| 412 |
|
| 413 |
console.log('selected cats:'); |
| 414 |
console.log(selected_categories); |
| 415 |
|
| 416 |
let data = mainwp_secure_data({ |
| 417 |
action: 'mainwp_get_categories', |
| 418 |
sites: encodeURIComponent(sites.join(',')), |
| 419 |
groups: encodeURIComponent(groups.join(',')), |
| 420 |
clients: encodeURIComponent(clients.join(',')), |
| 421 |
selected_categories: selected_categories ? encodeURIComponent(selected_categories) : '', |
| 422 |
post_id: jQuery('#post_ID').val(), |
| 423 |
custom_post_type: jQuery('#mainwp_custom_post_type_edit_post').length ? jQuery('#mainwp_custom_post_type_edit_post').val() : '' // support CPT ext. |
| 424 |
}); |
| 425 |
|
| 426 |
jQuery.post(ajaxurl, data, function (pSelectedCategories) { |
| 427 |
return function (response) { |
| 428 |
if (response?.content) { |
| 429 |
catsSelection.dropdown('remove selected'); |
| 430 |
catsSelection.find('.menu').html(response.content); |
| 431 |
catsSelection.dropdown('refresh'); |
| 432 |
let arrVal = pSelectedCategories.split(","); |
| 433 |
catsSelection.dropdown('set selected', arrVal); |
| 434 |
console.log('re-selected: ' + pSelectedCategories); |
| 435 |
updateCategoriesPostFunc(); |
| 436 |
} |
| 437 |
}; |
| 438 |
}(selected_categories), 'json'); |
| 439 |
} else { |
| 440 |
updateCategoriesPostFunc(); |
| 441 |
} |
| 442 |
}; |
| 443 |
let updateCategoriesPostFunc = function () { |
| 444 |
if (queueUpdateCategories > 0) { |
| 445 |
queueUpdateCategories--; |
| 446 |
executingUpdateCategories = false; |
| 447 |
mainwp_newpost_updateCategories(); |
| 448 |
} else { |
| 449 |
executingUpdateCategories = false; |
| 450 |
} |
| 451 |
}; |
| 452 |
|
| 453 |
jQuery(document).on('keydown', 'form[name="post"]', function (event) { |
| 454 |
if (event.keyCode == 13 && event.srcElement.tagName.toLowerCase() == "input") { |
| 455 |
event.preventDefault(); |
| 456 |
} |
| 457 |
}); |
| 458 |
jQuery(document).on('keyup', '#mainwp-sites-menu-filter', function () { |
| 459 |
let filter = jQuery(this).val().toLowerCase(); |
| 460 |
let parent = jQuery('#mainwp-sites-sidebar-menu'); |
| 461 |
let siteItems = parent.find('.mainwp-site-menu-item'); |
| 462 |
|
| 463 |
for (let ss of siteItems) { |
| 464 |
let currentElement = jQuery(ss); |
| 465 |
let value = currentElement.find('label').text().toLowerCase(); |
| 466 |
if (value.indexOf(filter) > -1) { |
| 467 |
currentElement.show(); |
| 468 |
} else { |
| 469 |
currentElement.hide(); |
| 470 |
} |
| 471 |
} |
| 472 |
}); |
| 473 |
|
| 474 |
// Accordion initialization on pre-existing markup |
| 475 |
jQuery(function () { |
| 476 |
mainwp_sidebar_accordion_init(); |
| 477 |
}); |
| 478 |
|
| 479 |
window.mainwp_sidebar_accordion_init = function(){ |
| 480 |
if (jQuery('.mainwp-sidebar-accordion').length > 0) { |
| 481 |
console.log('sidebar accordion init'); |
| 482 |
jQuery('.mainwp-sidebar-accordion').accordion({ |
| 483 |
"onOpening": function () { |
| 484 |
let parent = jQuery(this).closest('.mainwp-sidebar-accordion'); |
| 485 |
let ident = jQuery('.mainwp-sidebar-accordion').index(parent); |
| 486 |
mainwp_accordion_on_collapse(ident, 1); |
| 487 |
}, |
| 488 |
"onClosing": function () { |
| 489 |
let parent = jQuery(this).closest('.mainwp-sidebar-accordion'); |
| 490 |
let ident = jQuery('.mainwp-sidebar-accordion').index(parent); |
| 491 |
mainwp_accordion_on_collapse(ident, 0); |
| 492 |
} |
| 493 |
}); |
| 494 |
mainwp_accordion_init_collapse(); |
| 495 |
} |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
let mainwp_accordion_on_collapse = function (ident, val) { |
| 500 |
if (typeof (Storage) !== 'undefined') { |
| 501 |
if (typeof (pagenow) !== 'undefined') { |
| 502 |
localStorage.setItem('mainwp-accordion[' + pagenow + '][' + ident + ']', val); |
| 503 |
} |
| 504 |
} |
| 505 |
}; |
| 506 |
let mainwp_accordion_init_collapse = function () { |
| 507 |
jQuery('.mainwp-sidebar-accordion .title').addClass('active'); |
| 508 |
jQuery('.mainwp-sidebar-accordion .content').addClass('active'); |
| 509 |
|
| 510 |
jQuery('.mainwp-sidebar-accordion').each(function () { |
| 511 |
let ident = jQuery('.mainwp-sidebar-accordion').index(this); |
| 512 |
if (typeof (pagenow) !== 'undefined') { |
| 513 |
let val = localStorage.getItem('mainwp-accordion[' + pagenow + '][' + ident + ']'); |
| 514 |
if (val === '0') { |
| 515 |
jQuery(this).find('.title').removeClass('active'); |
| 516 |
jQuery(this).find('.content').removeClass('active'); |
| 517 |
} |
| 518 |
} |
| 519 |
}); |
| 520 |
}; |
| 521 |
|
| 522 |
window.mainwp_ui_state_save = function (ident, val) { |
| 523 |
if (typeof (Storage) !== 'undefined') { |
| 524 |
localStorage.setItem('mainwp-dashboard[' + ident + ']', val); |
| 525 |
} |
| 526 |
}; |
| 527 |
|
| 528 |
window.mainwp_ui_state_load = function (ident) { |
| 529 |
if (typeof (Storage) !== 'undefined') { |
| 530 |
return localStorage.getItem('mainwp-dashboard[' + ident + ']'); |
| 531 |
} |
| 532 |
return '1'; // show if Storage undefined. |
| 533 |
}; |
| 534 |
|
| 535 |
window.mainwp_sites_filter_select = function (objInput) { |
| 536 |
let filter = jQuery(objInput).val().toLowerCase(); |
| 537 |
let parent = jQuery(objInput).closest('.mainwp_select_sites_wrapper'); |
| 538 |
let tab = jQuery('#select_sites_tab').val(); |
| 539 |
let siteItems = []; |
| 540 |
|
| 541 |
if (tab == 'group') { |
| 542 |
siteItems = parent.find('.mainwp_selected_groups_item'); |
| 543 |
} else if (tab == 'site' || tab == 'staging') { |
| 544 |
siteItems = parent.find('.mainwp_selected_sites_item'); |
| 545 |
} |
| 546 |
|
| 547 |
for (let id of siteItems) { |
| 548 |
let currentElement = jQuery(id); |
| 549 |
let value = currentElement.find('label').text().toLowerCase(); |
| 550 |
if (value.indexOf(filter) > -1) { |
| 551 |
currentElement.removeClass('no-select').show(); |
| 552 |
} else { |
| 553 |
currentElement.addClass('no-select').hide(); |
| 554 |
} |
| 555 |
} |
| 556 |
if (tab == 'site' || tab == 'staging') { |
| 557 |
mainwp_newpost_updateCategories(); |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
jQuery(document).on('keyup', '#mainwp-select-sites-filter', function () { |
| 562 |
mainwp_sites_filter_select(this); |
| 563 |
}); |
| 564 |
|
| 565 |
jQuery(document).on('keyup', '#mainwp-screenshots-sites-filter', function () { |
| 566 |
mainwp_sites_filter_select(this); |
| 567 |
}); |
| 568 |
|
| 569 |
jQuery(function(){ |
| 570 |
if(jQuery(document).find('#mainwp-select-sites-header .ui.menu .item').length){ |
| 571 |
jQuery(document).find('#mainwp-select-sites-header .ui.menu .item').tab( {'onVisible': function() { mainwp_sites_selection_onvisible_callback( this ); } } ); |
| 572 |
} |
| 573 |
}); |
| 574 |
|
| 575 |
window.mainwp_get_icon_start = function () { |
| 576 |
jQuery('.cached-icon-expired').attr('queue', 1); |
| 577 |
mainwpVars.bulkInstallTotal = jQuery('.cached-icon-expired[queue="1"]').length; |
| 578 |
console.log(mainwpVars.bulkInstallTotal + ': expired cached icons'); |
| 579 |
if (0 === mainwpVars.bulkInstallTotal) { |
| 580 |
return; |
| 581 |
} |
| 582 |
mainwp_get_icon_start_next(); |
| 583 |
} |
| 584 |
|
| 585 |
let mainwp_get_icon_start_next = function () { |
| 586 |
let itemIconProcess = jQuery('.cached-icon-expired[queue="1"]:first'); |
| 587 |
if (itemIconProcess.length > 0) { |
| 588 |
mainwp_get_icon_start_specific(itemIconProcess); |
| 589 |
} else { |
| 590 |
console.log('Finished update icons.'); |
| 591 |
} |
| 592 |
}; |
| 593 |
|
| 594 |
let mainwp_get_icon_start_specific = function (itemIconProcess) { |
| 595 |
itemIconProcess.attr('queue', '0'); |
| 596 |
let slug; |
| 597 |
let type = itemIconProcess.attr('icon-type'); |
| 598 |
if (type == 'plugin' || type == 'theme') { |
| 599 |
slug = jQuery(itemIconProcess).attr('item-slug'); |
| 600 |
} else { |
| 601 |
return; |
| 602 |
} |
| 603 |
|
| 604 |
if ('' === slug || '.' === slug) { |
| 605 |
mainwp_get_icon_start_next(); |
| 606 |
} |
| 607 |
|
| 608 |
let data = mainwp_secure_data({ |
| 609 |
action: 'mainwp_refresh_icon', |
| 610 |
slug: slug, |
| 611 |
type: type |
| 612 |
}); |
| 613 |
jQuery.post(ajaxurl, data, function (response) { |
| 614 |
console.log(response + ': ' + slug); |
| 615 |
mainwp_get_icon_start_next(); |
| 616 |
}); |
| 617 |
} |
| 618 |
|
| 619 |
jQuery(function () { |
| 620 |
jQuery(document).on('click', '.cached-icon-customable', function () { |
| 621 |
let iconObj = jQuery(this); |
| 622 |
jQuery('#mainwp_delete_image_field').hide(); |
| 623 |
jQuery('#mainwp-upload-custom-icon-modal').modal('setting', 'closable', false).modal('show'); |
| 624 |
if (iconObj[0].hasAttribute('src') && iconObj.attr('src') != '') { |
| 625 |
jQuery('#mainwp_delete_image_field').find('.ui.image').attr('src', iconObj.attr('src')); |
| 626 |
jQuery('#mainwp_delete_image_field').show(); |
| 627 |
} |
| 628 |
jQuery(document).on('click', '#update_custom_icon_btn', function () { |
| 629 |
mainwp_upload_custom_icon(iconObj); |
| 630 |
return false; |
| 631 |
}); |
| 632 |
return false; |
| 633 |
}); |
| 634 |
|
| 635 |
|
| 636 |
jQuery(document).on('click', '.mainwp-selecte-theme-button', function () { |
| 637 |
jQuery('#mainwp-select-mainwp-themes-modal').modal({ |
| 638 |
allowMultiple: false, |
| 639 |
closable: true, |
| 640 |
onHide: function () { |
| 641 |
window.location.href = location.href; |
| 642 |
} |
| 643 |
}).modal('show'); |
| 644 |
|
| 645 |
return false; |
| 646 |
}); |
| 647 |
|
| 648 |
}); |
| 649 |
|
| 650 |
|
| 651 |
let mainwp_upload_custom_icon = function (iconObj) { |
| 652 |
|
| 653 |
let type = iconObj.attr('icon-type'); |
| 654 |
|
| 655 |
if (type !== 'plugin' && type !== 'theme') { |
| 656 |
return false; |
| 657 |
} |
| 658 |
|
| 659 |
let slug = jQuery(iconObj).attr('item-slug'); |
| 660 |
|
| 661 |
let deleteIcon = jQuery('#mainwp_delete_image_chk').is(':checked'); |
| 662 |
|
| 663 |
let msg = __('Updating the icon. Please wait...'); |
| 664 |
mainwp_set_message_zone('#mainwp-message-zone-upload', '<i class="notched circle loading icon"></i> ' + msg, ''); |
| 665 |
jQuery('#update_custom_icon_btn').attr('disabled', 'disabled'); |
| 666 |
|
| 667 |
//Add via ajax!! |
| 668 |
let formdata = new FormData(jQuery('#uploadicon_form')[0]); |
| 669 |
formdata.append("action", 'mainwp_upload_custom_icon'); |
| 670 |
formdata.append("type", type); |
| 671 |
formdata.append("slug", slug); |
| 672 |
formdata.append("delete", deleteIcon ? 1 : 0); |
| 673 |
formdata.append("security", security_nonces['mainwp_upload_custom_icon']); |
| 674 |
|
| 675 |
jQuery.ajax({ |
| 676 |
type: 'POST', |
| 677 |
url: ajaxurl, |
| 678 |
data: formdata, |
| 679 |
success: function (response) { |
| 680 |
if (response && response.result == 'success') { |
| 681 |
let msg = ''; |
| 682 |
|
| 683 |
if (type === 'plugin') { |
| 684 |
if (jQuery('#mainwp-show-plugins').length > 0) { |
| 685 |
msg = __('Loading...'); |
| 686 |
mainwp_fetch_plugins(); |
| 687 |
} |
| 688 |
} else if (jQuery('#mainwp_show_themes').length > 0) { |
| 689 |
msg = __('Loading...'); |
| 690 |
mainwp_fetch_themes(); |
| 691 |
} |
| 692 |
if (msg !== '') { |
| 693 |
mainwp_set_message_zone('#mainwp-message-zone-upload', '<i class="notched circle loading icon"></i> ' + __('Loading...'), ''); |
| 694 |
} else { |
| 695 |
mainwp_set_message_zone('#mainwp-message-zone-upload'); |
| 696 |
} |
| 697 |
setTimeout(function () { |
| 698 |
window.location.href = location.href; |
| 699 |
}, 3000); |
| 700 |
} else { |
| 701 |
feedback('mainwp-message-zone-upload', __('Undefined error. Please try again.'), 'red'); |
| 702 |
} |
| 703 |
}, |
| 704 |
error: function () { |
| 705 |
}, |
| 706 |
contentType: false, |
| 707 |
cache: false, |
| 708 |
processData: false, |
| 709 |
enctype: 'multipart/form-data', |
| 710 |
dataType: 'json' |
| 711 |
}); |
| 712 |
|
| 713 |
}; |
| 714 |
|
| 715 |
let mainwp_upload_custom_types_icon = function (iconObj, uploadAct, iconItemId, iconFileSlug, deleteIcon, callback_uploaded) { |
| 716 |
let msg = __('Updating the icon. Please wait...'); |
| 717 |
mainwp_set_message_zone('#mainwp-message-zone-upload', '<i class="notched circle loading icon"></i> ' + msg, ''); |
| 718 |
jQuery('#update_custom_icon_btn').attr('disabled', 'disabled'); |
| 719 |
|
| 720 |
let upload_act = typeof uploadAct !== "undefined" && '' != uploadAct ? uploadAct : 'mainwp_upload_custom_types_icon'; |
| 721 |
let elemid = undefined !== jQuery(iconObj).attr('data-element-id') ? jQuery(iconObj).attr('data-element-id') : ''; |
| 722 |
//Add via ajax!! |
| 723 |
let formdata = new FormData(jQuery('#uploadicon_form')[0]); |
| 724 |
formdata.append("action", upload_act); |
| 725 |
formdata.append("iconFileSlug", iconFileSlug); |
| 726 |
formdata.append("iconItemId", iconItemId); |
| 727 |
formdata.append("delete", deleteIcon ? 1 : 0); |
| 728 |
formdata.append("security", security_nonces[upload_act]); |
| 729 |
formdata.append("elementid", elemid); |
| 730 |
jQuery.ajax({ |
| 731 |
type: 'POST', |
| 732 |
url: ajaxurl, |
| 733 |
data: formdata, |
| 734 |
success: function (response) { |
| 735 |
jQuery('#update_custom_icon_btn').removeAttr('disabled'); |
| 736 |
if (response && response.result == 'success') { |
| 737 |
mainwp_set_message_zone('#mainwp-message-zone-upload'); |
| 738 |
if (typeof callback_uploaded == 'function') { |
| 739 |
callback_uploaded(response); |
| 740 |
} |
| 741 |
} else { |
| 742 |
feedback('mainwp-message-zone-upload', __('Undefined error. Please try again.'), 'red'); |
| 743 |
} |
| 744 |
}, |
| 745 |
error: function () { |
| 746 |
}, |
| 747 |
contentType: false, |
| 748 |
cache: false, |
| 749 |
processData: false, |
| 750 |
enctype: 'multipart/form-data', |
| 751 |
dataType: 'json' |
| 752 |
}); |
| 753 |
|
| 754 |
}; |
| 755 |
|
| 756 |
let mainwp_guidedtours_onchange = function (me) { |
| 757 |
let data = mainwp_secure_data({ |
| 758 |
action: 'mainwp_guided_tours_option_update', |
| 759 |
enable: jQuery(me).is(":checked") ? 1 : 0, |
| 760 |
}); |
| 761 |
jQuery.post(ajaxurl, data, function () { |
| 762 |
setTimeout(() => { |
| 763 |
window.location.href = location.href; |
| 764 |
}, 1000); |
| 765 |
}); |
| 766 |
} |
| 767 |
|
| 768 |
|