| 1 |
jQuery(function($) { |
| 2 |
|
| 3 |
function runAjaxAction(button, action) { |
| 4 |
button = $(button); |
| 5 |
var panel = button.closest('.puc-debug-bar-panel-v5'); |
| 6 |
var responseBox = button.closest('td').find('.puc-ajax-response'); |
| 7 |
|
| 8 |
responseBox.text('Processing...').show(); |
| 9 |
$.post( |
| 10 |
ajaxurl, |
| 11 |
{ |
| 12 |
action : action, |
| 13 |
uid : panel.data('uid'), |
| 14 |
_wpnonce: panel.data('nonce') |
| 15 |
}, |
| 16 |
function(data) { |
| 17 |
//The response contains HTML that should already be escaped in server-side code. |
| 18 |
//phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html |
| 19 |
responseBox.html(data); |
| 20 |
}, |
| 21 |
'html' |
| 22 |
); |
| 23 |
} |
| 24 |
|
| 25 |
$('.puc-debug-bar-panel-v5 input[name="puc-check-now-button"]').on('click', function() { |
| 26 |
runAjaxAction(this, 'puc_v5_debug_check_now'); |
| 27 |
return false; |
| 28 |
}); |
| 29 |
|
| 30 |
$('.puc-debug-bar-panel-v5 input[name="puc-request-info-button"]').on('click', function() { |
| 31 |
runAjaxAction(this, 'puc_v5_debug_request_info'); |
| 32 |
return false; |
| 33 |
}); |
| 34 |
|
| 35 |
|
| 36 |
// Debug Bar uses the panel class name as part of its link and container IDs. This means we can |
| 37 |
// end up with multiple identical IDs if more than one plugin uses the update checker library. |
| 38 |
// Fix it by replacing the class name with the plugin slug. |
| 39 |
var panels = $('#debug-menu-targets').find('.puc-debug-bar-panel-v5'); |
| 40 |
panels.each(function() { |
| 41 |
var panel = $(this); |
| 42 |
var uid = panel.data('uid'); |
| 43 |
var target = panel.closest('.debug-menu-target'); |
| 44 |
|
| 45 |
//Change the panel wrapper ID. |
| 46 |
target.attr('id', 'debug-menu-target-puc-' + uid); |
| 47 |
|
| 48 |
//Change the menu link ID as well and point it at the new target ID. |
| 49 |
$('#debug-bar-menu').find('.puc-debug-menu-link-' + uid) |
| 50 |
.closest('.debug-menu-link') |
| 51 |
.attr('id', 'debug-menu-link-puc-' + uid) |
| 52 |
.attr('href', '#' + target.attr('id')); |
| 53 |
}); |
| 54 |
}); |