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