| 1 |
jQuery(document).ready(function ($) { |
| 2 |
jQuery('.nav-tab-wrapper a').on('click', function (e) { |
| 3 |
e.preventDefault() |
| 4 |
|
| 5 |
var tab = jQuery(this).attr('href') |
| 6 |
|
| 7 |
if ( tab.indexOf('#') === 0 ) { |
| 8 |
jQuery(this).addClass('nav-tab-active').siblings().removeClass('nav-tab-active') |
| 9 |
jQuery(`.stless_settings ${tab}`).addClass('active').siblings().removeClass('active') |
| 10 |
|
| 11 |
var url = new URL(window.location.href) |
| 12 |
url.searchParams.set('tab', tab.replace('#', '')) |
| 13 |
|
| 14 |
window.history.replaceState(null, '', url.toString()) |
| 15 |
} |
| 16 |
}) |
| 17 |
|
| 18 |
$(document).on('click', '.pointer', function (e) { |
| 19 |
e.stopPropagation() |
| 20 |
var pointer = $(this) |
| 21 |
pointer |
| 22 |
.pointer({ |
| 23 |
content: |
| 24 |
'<h3>' + |
| 25 |
pointer.data('title') + |
| 26 |
'</h3><p>' + |
| 27 |
pointer.data('text') + |
| 28 |
'</p>', |
| 29 |
position: pointer.data('position'), |
| 30 |
}) |
| 31 |
.pointer('open') |
| 32 |
}) |
| 33 |
|
| 34 |
$(document).on('click', function () { |
| 35 |
$('.wp-pointer').hide() |
| 36 |
}) |
| 37 |
|
| 38 |
$(document).on('click', '.wp-pointer', function (e) { |
| 39 |
e.stopPropagation() |
| 40 |
}) |
| 41 |
|
| 42 |
$(document).on('click', '.stateless-info-button', function (e) { |
| 43 |
e.stopPropagation() |
| 44 |
e.preventDefault() |
| 45 |
|
| 46 |
var opened = $(this).closest('.stateless-info-heading').hasClass('open') |
| 47 |
var id = $(this).data('section') |
| 48 |
|
| 49 |
if (opened) { |
| 50 |
$(this).closest('.stateless-info-heading').removeClass('open') |
| 51 |
$('#' + id).addClass('hidden') |
| 52 |
} else { |
| 53 |
$(this).closest('.stateless-info-heading').addClass('open') |
| 54 |
$('#' + id).removeClass('hidden') |
| 55 |
} |
| 56 |
}) |
| 57 |
|
| 58 |
// Copy Status Info to clipboard |
| 59 |
var clipboard = new ClipboardJS('.stateless-info-heading .copy-button') |
| 60 |
|
| 61 |
clipboard.on('success', function(e) { |
| 62 |
$('.stateless-info-copy-success').show(); |
| 63 |
|
| 64 |
setTimeout(function() { |
| 65 |
$('.stateless-info-copy-success').fadeOut(500); |
| 66 |
}, 5000); |
| 67 |
}) |
| 68 |
|
| 69 |
// Check if API and AJAX is available |
| 70 |
function setServiceStatus(id, status) { |
| 71 |
var data = $('.stateless-info-heading .button.copy-button').attr('data-clipboard-text'); |
| 72 |
$('.stateless-info-heading .button.copy-button').attr( 'data-clipboard-text', data.replace('%' + id + '%', status)); |
| 73 |
|
| 74 |
$(`#stateless-info-block-stateless .${id} .value`).text(status); |
| 75 |
} |
| 76 |
|
| 77 |
$.ajax({ |
| 78 |
method: 'GET', |
| 79 |
url: window.wp_stateless_configs.api_root + 'status', |
| 80 |
}) |
| 81 |
.then(function() { |
| 82 |
setServiceStatus( 'api_status', window.wp_stateless_configs.text_ok ); |
| 83 |
}) |
| 84 |
.fail(function() { |
| 85 |
setServiceStatus( 'api_status', window.wp_stateless_configs.text_fail ); |
| 86 |
}) |
| 87 |
|
| 88 |
$.ajax({ |
| 89 |
method: 'POST', |
| 90 |
url: window.wp_stateless_configs.ajaxurl, |
| 91 |
data: { |
| 92 |
action: 'stateless_check_ajax', |
| 93 |
_ajax_nonce: window.wp_stateless_configs.stateless_check_ajax_nonce, |
| 94 |
} |
| 95 |
}) |
| 96 |
.then(function() { |
| 97 |
setServiceStatus( 'ajax_status', window.wp_stateless_configs.text_ok ); |
| 98 |
}) |
| 99 |
.fail(function() { |
| 100 |
setServiceStatus( 'ajax_status', window.wp_stateless_configs.text_fail ); |
| 101 |
}) |
| 102 |
|
| 103 |
}) |
| 104 |
|