| 1 |
(function($) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
$(document).ready(function () { |
| 5 |
var sourceType = 'google-charts'; |
| 6 |
var chartType = 'pie_chart'; |
| 7 |
|
| 8 |
$('[data-toggle="popover"]').popover(); |
| 9 |
$('[data-bs-toggle="tooltip"]').tooltip(); |
| 10 |
|
| 11 |
/* == Add new modal configuration == */ |
| 12 |
$(document).on('dblclick', '.ays-chart-layer_box_blocks label.ays-chart-dblclick-layer:not(.ays-chart-type-pro-feature)', function(){ |
| 13 |
$(document).find('.ays-chart-select_button_layer input.ays-chart-layer_button').trigger('click'); |
| 14 |
}); |
| 15 |
|
| 16 |
$(document).on('change', '.ays-chart-choose-source', function(){ |
| 17 |
$(document).find('.ays-chart-select_button_layer input.ays-chart-layer_button').prop('disabled',false).attr("data-type" , $(this).val()); |
| 18 |
}); |
| 19 |
|
| 20 |
$(document).on('change', '.ays-chart-layer_box_source_type_select' ,function(){ |
| 21 |
var type = $(this).find('option:selected').val(); |
| 22 |
|
| 23 |
sourceType = type ?? 'google-charts'; |
| 24 |
$(document).find('.ays-chart-layer_box_blocks').hide(); |
| 25 |
$(document).find('.ays-chart-layer_box_blocks[source-type="' + sourceType + '"]').show(); |
| 26 |
|
| 27 |
if (sourceType === 'chart-js') { |
| 28 |
$(document).find('.ays-chart-layer_box_link').hide(); |
| 29 |
} else { |
| 30 |
$(document).find('.ays-chart-layer_box_link').show(); |
| 31 |
} |
| 32 |
}); |
| 33 |
|
| 34 |
$(document).on('click', '.ays-chart-layer_button' ,function(){ |
| 35 |
chartType = $(document).find('.ays-chart-choose-source:checked').val(); |
| 36 |
|
| 37 |
var currentUrl = new URL(window.location.href); |
| 38 |
|
| 39 |
currentUrl.searchParams.set('source', sourceType); |
| 40 |
currentUrl.searchParams.set('type', chartType); |
| 41 |
|
| 42 |
window.location.href = currentUrl.toString(); |
| 43 |
}); |
| 44 |
/* */ |
| 45 |
|
| 46 |
$(document).find('#ays-title').on('input', function () { |
| 47 |
$(document).find('.ays_chart_title_in_top').text($(this).val()); |
| 48 |
}); |
| 49 |
|
| 50 |
$(document).find('.form-check-input.select-all').on('click', function() { |
| 51 |
var checkboxes = $(document).find('.check-current-row'); |
| 52 |
if ($(this).prop('checked') == true && checkboxes.length !== 0) { |
| 53 |
$(this).parents('thead').next('tbody').find('tr').addClass("ays-chart-tr-selected"); |
| 54 |
checkboxes.prop('checked',true); |
| 55 |
$(document).find('#ays-chart-bulk-delete').prop('disabled', false); |
| 56 |
$(document).find('#ays-chart-bulk-delete-bottom').prop('disabled', false); |
| 57 |
} else { |
| 58 |
$(this).parents('thead').next('tbody').find('tr').removeClass("ays-chart-tr-selected"); |
| 59 |
checkboxes.prop('checked',false); |
| 60 |
$(document).find('#ays-chart-bulk-delete').prop('disabled', true); |
| 61 |
$(document).find('#ays-chart-bulk-delete-bottom').prop('disabled', true); |
| 62 |
} |
| 63 |
}); |
| 64 |
|
| 65 |
$(document).find('.check-current-row').on('click', function() { |
| 66 |
var checkboxesArr = $(document).find('.check-current-row'); |
| 67 |
var selectAllCheckBox = $(document).find('.form-check-input.select-all'); |
| 68 |
var count = 0; |
| 69 |
|
| 70 |
for (var i = 0; i < checkboxesArr.length; i++) { |
| 71 |
if (checkboxesArr.eq(i).prop('checked') == true) { |
| 72 |
count++; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
if ((count == 0 && selectAllCheckBox.prop('checked') == true) || (count != 0 && selectAllCheckBox.prop('checked') == true)) { |
| 77 |
selectAllCheckBox.prop('checked', false); |
| 78 |
} else if (count == checkboxesArr.length && selectAllCheckBox.prop('checked') == false) { |
| 79 |
selectAllCheckBox.prop('checked', true); |
| 80 |
} |
| 81 |
|
| 82 |
if ( $(this).prop('checked') ) { |
| 83 |
$(this).parents('tr').addClass("ays-chart-tr-selected"); |
| 84 |
$(document).find('#ays-chart-bulk-delete').prop('disabled', false); |
| 85 |
$(document).find('#ays-chart-bulk-delete-bottom').prop('disabled', false); |
| 86 |
} else if ( !$(this).prop('checked') && count > 0) { |
| 87 |
$(this).parents('tr').removeClass("ays-chart-tr-selected"); |
| 88 |
$(document).find('#ays-chart-bulk-delete').prop('disabled', false); |
| 89 |
$(document).find('#ays-chart-bulk-delete-bottom').prop('disabled', false); |
| 90 |
} else { |
| 91 |
$(this).parents('tr').removeClass("ays-chart-tr-selected"); |
| 92 |
$(document).find('#ays-chart-bulk-delete').prop('disabled', true); |
| 93 |
$(document).find('#ays-chart-bulk-delete-bottom').prop('disabled', true); |
| 94 |
} |
| 95 |
}); |
| 96 |
|
| 97 |
// Bulk delete confirmation |
| 98 |
$(document).on('click', '#ays-chart-bulk-delete', function(e) { |
| 99 |
e.preventDefault(); |
| 100 |
var confirm = window.confirm(aysChartBuilderAdmin.confirmDelete); |
| 101 |
if (confirm) { |
| 102 |
$(document).find('#ays-chart-bulk-delete-confirm').trigger('click'); |
| 103 |
} |
| 104 |
}); |
| 105 |
$(document).on('click', '#ays-chart-bulk-delete-bottom', function(e) { |
| 106 |
e.preventDefault(); |
| 107 |
var confirm = window.confirm(aysChartBuilderAdmin.confirmDelete); |
| 108 |
if (confirm) { |
| 109 |
$(document).find('#ays-chart-bulk-delete-confirm-bottom').trigger('click'); |
| 110 |
} |
| 111 |
}); |
| 112 |
|
| 113 |
// Delete confirmation |
| 114 |
$(document).on('click', '.ays_chart_delete_confirm', function(e){ |
| 115 |
e.preventDefault(); |
| 116 |
var confirm = window.confirm(aysChartBuilderAdmin.confirmDelete); |
| 117 |
if (confirm){ |
| 118 |
window.location.replace($(this).attr('href')); |
| 119 |
} |
| 120 |
}); |
| 121 |
|
| 122 |
function performSearch() { |
| 123 |
var _this = $(this); |
| 124 |
var parent = _this.parents('form'); |
| 125 |
|
| 126 |
var search_input = parent.find('input#ays-chart-search-input'); |
| 127 |
var input_value = search_input.val(); |
| 128 |
|
| 129 |
var field = 's'; |
| 130 |
var flag = false; |
| 131 |
var url = window.location.href; |
| 132 |
if (url.indexOf('?' + field + '=') != -1) { |
| 133 |
flag = true; |
| 134 |
} else if (url.indexOf('&' + field + '=') != -1) { |
| 135 |
flag = true; |
| 136 |
} |
| 137 |
|
| 138 |
if (flag) { |
| 139 |
if (typeof input_value != 'undefined' && input_value != "") { |
| 140 |
url = location.href.replace(/&s=([^&]$|[^&]*)/i, "&s=" + input_value); |
| 141 |
} else if (input_value == "") { |
| 142 |
url = location.href.replace(/&s=([^&]$|[^&]*)/i, ""); |
| 143 |
} |
| 144 |
} else { |
| 145 |
if (typeof input_value != 'undefined' && input_value != "") { |
| 146 |
url = location.href + "&s=" + input_value; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
location.href = url.replace(/&paged=([^&]$|[^&]*)/i, "&paged=1"); |
| 151 |
} |
| 152 |
|
| 153 |
$(document).find("input#ays-chart-search-input + button#ays-chart-search").on("click", function (e) { |
| 154 |
e.preventDefault(); |
| 155 |
performSearch.call(this); |
| 156 |
}); |
| 157 |
|
| 158 |
$(document).on("keypress", '#ays-chart-search-input', function (e) { |
| 159 |
if (e.which === 13) { |
| 160 |
e.preventDefault(); |
| 161 |
performSearch.call(this); |
| 162 |
} |
| 163 |
}); |
| 164 |
|
| 165 |
$(document).on("click", "button[id^='ays-chart-filter']", function (e) { |
| 166 |
e.preventDefault(); |
| 167 |
var _this = $(this); |
| 168 |
var parent = _this.parents('form'); |
| 169 |
|
| 170 |
var inputSelectors = ['#ays-chart-filter-select', '#ays-chart-filter-author', '#ays-chart-filter-source', '#ays-chart-filter-chart-source', '#ays-chart-filter-date', '#ays-chart-order-by', '#ays-chart-order']; |
| 171 |
var inputValues = inputSelectors.map(selector => parent.find(selector).val()); |
| 172 |
|
| 173 |
var filterFields = ['filterbytype', 'filterbyauthor', 'filterbysource', 'filterbychartsource', 'filterbydate', 'orderby', 'order']; |
| 174 |
|
| 175 |
addFiltersUrl(inputValues, filterFields); |
| 176 |
}); |
| 177 |
|
| 178 |
$(document).on("click", "button[id^='ays-chart-filter-clear']", function (e) { |
| 179 |
e.preventDefault(); |
| 180 |
clearFiltersUrl(); |
| 181 |
}); |
| 182 |
|
| 183 |
function addFiltersUrl(inputValues, filterFields) { |
| 184 |
var url = window.location.href; |
| 185 |
for (var i = 0; i < inputValues.length; i++) { |
| 186 |
var flag = url.includes('?' + filterFields[i] + '=') || url.includes('&' + filterFields[i] + '='); |
| 187 |
if (flag) { |
| 188 |
url = url.replace(new RegExp('&?' + filterFields[i] + '=([^&]*)'), ''); |
| 189 |
} |
| 190 |
if (inputValues[i]) { |
| 191 |
url += '&' + filterFields[i] + '=' + inputValues[i]; |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
location.href = url.replace(/&paged=([^&]$|[^&]*)/i, "&paged=1"); |
| 196 |
} |
| 197 |
|
| 198 |
function clearFiltersUrl() { |
| 199 |
var url = window.location.href; |
| 200 |
var filterFields = ['filterbytype', 'filterbyauthor', 'filterbysource', 'filterbychartsource', 'filterbydate', 'orderby', 'order']; |
| 201 |
|
| 202 |
for (var i = 0; i < filterFields.length; i++) { |
| 203 |
url = url.replace(new RegExp('&?' + filterFields[i] + '=([^&]*)'), ''); |
| 204 |
} |
| 205 |
|
| 206 |
location.href = url.replace(/&paged=([^&]$|[^&]*)/i, "&paged=1"); |
| 207 |
} |
| 208 |
|
| 209 |
$(document).find('#ays-chart-filter-author').select2({ |
| 210 |
placeholder: aysChartBuilderAdmin.selectUser, |
| 211 |
dropdownAutoWidth: true, |
| 212 |
minimumInputLength: 1, |
| 213 |
allowClear: true, |
| 214 |
language: { |
| 215 |
searching: function() { |
| 216 |
return aysChartBuilderAdmin.searching; |
| 217 |
}, |
| 218 |
inputTooShort: function () { |
| 219 |
return aysChartBuilderAdmin.pleaseEnterMore; |
| 220 |
} |
| 221 |
}, |
| 222 |
ajax: { |
| 223 |
url: ajaxurl, |
| 224 |
dataType: 'json', |
| 225 |
data: function (response) { |
| 226 |
var checkedUsers = $(document).find('#ays-chart-filter-author').val(); |
| 227 |
return { |
| 228 |
action: 'ays_chart_admin_ajax', |
| 229 |
function: window.aysChartBuilderChartSettings.ajax['actions']['author_user_search'], |
| 230 |
security: window.aysChartBuilderChartSettings.ajax['nonces']['author_user_search'], |
| 231 |
params: { |
| 232 |
search: response.term, |
| 233 |
val: checkedUsers |
| 234 |
} |
| 235 |
}; |
| 236 |
} |
| 237 |
} |
| 238 |
}); |
| 239 |
$(document).find('#ays-chart-filter-author-bottom').select2({ |
| 240 |
placeholder: aysChartBuilderAdmin.selectUser, |
| 241 |
dropdownAutoWidth: true, |
| 242 |
minimumInputLength: 1, |
| 243 |
allowClear: true, |
| 244 |
language: { |
| 245 |
searching: function() { |
| 246 |
return aysChartBuilderAdmin.searching; |
| 247 |
}, |
| 248 |
inputTooShort: function () { |
| 249 |
return aysChartBuilderAdmin.pleaseEnterMore; |
| 250 |
} |
| 251 |
}, |
| 252 |
ajax: { |
| 253 |
url: ajaxurl, |
| 254 |
dataType: 'json', |
| 255 |
data: function (response) { |
| 256 |
var checkedUsers = $(document).find('#ays-chart-filter-author-bottom').val(); |
| 257 |
return { |
| 258 |
action: 'ays_chart_admin_ajax', |
| 259 |
function: window.aysChartBuilderChartSettings.ajax['actions']['author_user_search'], |
| 260 |
security: window.aysChartBuilderChartSettings.ajax['nonces']['author_user_search'], |
| 261 |
params: { |
| 262 |
search: response.term, |
| 263 |
val: checkedUsers |
| 264 |
} |
| 265 |
}; |
| 266 |
} |
| 267 |
} |
| 268 |
}); |
| 269 |
|
| 270 |
$(document).on('mouseenter', 'td.column-title', function() { |
| 271 |
// $(this).find('.chart-list-table-actions-row').css('visibility', 'visible'); |
| 272 |
$(this).find('.chart-list-table-actions-row').css('display', 'flex'); |
| 273 |
// $(this).css('padding', '8px 8px'); |
| 274 |
}); |
| 275 |
$(document).on('mouseleave', 'td.column-title', function() { |
| 276 |
// $(this).find('.chart-list-table-actions-row').css('visibility', 'hidden'); |
| 277 |
$(this).find('.chart-list-table-actions-row').hide(); |
| 278 |
// $(this).css('padding', '23px 8px'); |
| 279 |
}); |
| 280 |
|
| 281 |
$(document).find('.ays-chart-copy-image').on('click', function(){ |
| 282 |
var _this = this; |
| 283 |
var input = $(_this).parent().find('input.ays-chart-shortcode-input'); |
| 284 |
var length = input.val().length; |
| 285 |
|
| 286 |
input[0].focus(); |
| 287 |
input[0].setSelectionRange(0, length); |
| 288 |
document.execCommand('copy'); |
| 289 |
// document.getSelection().removeAllRanges(); |
| 290 |
|
| 291 |
$(_this).attr('data-original-title', aysChartBuilderAdmin.copied); |
| 292 |
$(_this).attr("data-bs-original-title", aysChartBuilderAdmin.copied); |
| 293 |
$(_this).attr("title", aysChartBuilderAdmin.copied); |
| 294 |
$(_this).tooltip('show'); |
| 295 |
}); |
| 296 |
|
| 297 |
$(document).find('.ays-chart-shortcode-input').on('focus', function(){ |
| 298 |
this.setSelectionRange(0, $(this).val().length); |
| 299 |
}); |
| 300 |
|
| 301 |
$(document).find('.ays-chart-copy-image').on('mouseleave', function(){ |
| 302 |
var _this = this; |
| 303 |
|
| 304 |
$(_this).attr('data-original-title', aysChartBuilderAdmin.clickForCopy); |
| 305 |
$(_this).attr("data-bs-original-title", aysChartBuilderAdmin.clickForCopy); |
| 306 |
$(_this).attr("title", aysChartBuilderAdmin.clickForCopy); |
| 307 |
}); |
| 308 |
|
| 309 |
$(document).on('click', '.notice-dismiss', function (e) { |
| 310 |
changeCurrentUrl('status'); |
| 311 |
}); |
| 312 |
|
| 313 |
var toggle_ddmenu = $(document).find('.toggle_ddmenu'); |
| 314 |
toggle_ddmenu.on('click', function () { |
| 315 |
var ddmenu = $(this).next(); |
| 316 |
var state = ddmenu.attr('data-expanded'); |
| 317 |
switch (state) { |
| 318 |
case 'true': |
| 319 |
$(this).find('.ays_fa').css({ |
| 320 |
transform: 'rotate(0deg)' |
| 321 |
}); |
| 322 |
ddmenu.attr('data-expanded', 'false'); |
| 323 |
break; |
| 324 |
case 'false': |
| 325 |
$(this).find('.ays_fa').css({ |
| 326 |
transform: 'rotate(90deg)' |
| 327 |
}); |
| 328 |
ddmenu.attr('data-expanded', 'true'); |
| 329 |
break; |
| 330 |
} |
| 331 |
}); |
| 332 |
|
| 333 |
function changeCurrentUrl(key){ |
| 334 |
var linkModified = location.href.split('?')[1].split('&'); |
| 335 |
for(var i = 0; i < linkModified.length; i++){ |
| 336 |
if(linkModified[i].split("=")[0] == key){ |
| 337 |
linkModified.splice(i, 1); |
| 338 |
} |
| 339 |
} |
| 340 |
linkModified = linkModified.join('&'); |
| 341 |
window.history.replaceState({}, document.title, '?'+linkModified); |
| 342 |
} |
| 343 |
|
| 344 |
// Select message vars charts page |
| 345 |
$(document).find('.ays-chart-message-vars-icon').on('click', function(e){ |
| 346 |
$(this).parents(".ays-chart-message-vars-box").find(".ays-chart-message-vars-data").toggle('fast'); |
| 347 |
}); |
| 348 |
|
| 349 |
$(document).find('.ays-chart-open-charts-list').on('click', function(e){ |
| 350 |
$(this).parents(".ays-chart-subtitle-main-box").find(".ays-chart-charts-data").toggle('fast'); |
| 351 |
}); |
| 352 |
|
| 353 |
$(document).on( "click" , function(e){ |
| 354 |
if($(e.target).closest('.ays-chart-message-vars-box,.ays-chart-subtitle-main-box').length != 0){ |
| 355 |
|
| 356 |
} |
| 357 |
else{ |
| 358 |
$(document).find(".ays-chart-message-vars-box .ays-chart-message-vars-data,.ays-chart-subtitle-main-box .ays-chart-charts-data").hide('fast'); |
| 359 |
} |
| 360 |
}); |
| 361 |
|
| 362 |
$(document).find(".ays-chart-go-to-charts").on("click" , function(e){ |
| 363 |
e.preventDefault(); |
| 364 |
var confirmRedirect = window.confirm('Are you sure you want to redirect to another chart? Note that the changes made in this chart will not be saved.'); |
| 365 |
if(confirmRedirect){ |
| 366 |
window.location = $(this).attr("href"); |
| 367 |
} |
| 368 |
}); |
| 369 |
|
| 370 |
$(document).find('.ays-chart-message-vars-each-data').on('click', function(e){ |
| 371 |
var messageVar = $(this).find(".ays-chart-message-vars-each-var").val(); |
| 372 |
var mainParent = $(this).parents('.ays-chart-box-for-mv'); |
| 373 |
var dataTMCE = mainParent.find('.ays-chart-message-vars-data').attr('data-tmce'); |
| 374 |
|
| 375 |
if ( mainParent.find("#wp-"+dataTMCE+"-wrap").hasClass("tmce-active") ){ |
| 376 |
window.tinyMCE.get(dataTMCE).setContent( window.tinyMCE.get(dataTMCE).getContent() + messageVar + " " ); |
| 377 |
}else{ |
| 378 |
mainParent.find('#'+dataTMCE).append( " " + messageVar + " "); |
| 379 |
} |
| 380 |
}); |
| 381 |
|
| 382 |
$(document).on("click", ".ays-chart-cards-block .ays-chart-card__footer button.status-missing", function(e){ |
| 383 |
var $this = $(this); |
| 384 |
var thisParent = $this.parents(".ays-chart-cards-block"); |
| 385 |
|
| 386 |
$this.prop('disabled', true); |
| 387 |
$this.addClass('disabled'); |
| 388 |
|
| 389 |
var loader_html = '<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>'; |
| 390 |
|
| 391 |
$this.html(loader_html); |
| 392 |
|
| 393 |
var attr_plugin = $this.attr('data-plugin'); |
| 394 |
var wp_nonce = thisParent.find('#ays_chart_ajax_install_plugin_nonce').val(); |
| 395 |
|
| 396 |
var data = { |
| 397 |
action: 'ays_chart_install_plugin', |
| 398 |
_ajax_nonce: wp_nonce, |
| 399 |
plugin: attr_plugin, |
| 400 |
type: 'plugin' |
| 401 |
}; |
| 402 |
|
| 403 |
$.ajax({ |
| 404 |
url: aysChartBuilderAdmin.ajaxUrl, |
| 405 |
method: 'post', |
| 406 |
dataType: 'json', |
| 407 |
data: data, |
| 408 |
success: function (response) { |
| 409 |
if (response.success) { |
| 410 |
swal.fire({ |
| 411 |
type: 'success', |
| 412 |
html: "<h4>"+ response['data']['msg'] +"</h4>" |
| 413 |
}).then( function(res) { |
| 414 |
if ( $this.hasClass('status-missing') ) { |
| 415 |
$this.removeClass('status-missing'); |
| 416 |
} |
| 417 |
$this.text(aysChartBuilderAdmin.activated); |
| 418 |
$this.addClass('status-active'); |
| 419 |
}); |
| 420 |
} |
| 421 |
else { |
| 422 |
swal.fire({ |
| 423 |
type: 'info', |
| 424 |
html: "<h4>"+ response['data'][0]['message'] +"</h4>" |
| 425 |
}).then( function(res) { |
| 426 |
$this.text(aysChartBuilderAdmin.errorMsg); |
| 427 |
}); |
| 428 |
} |
| 429 |
}, |
| 430 |
error: function(){ |
| 431 |
swal.fire({ |
| 432 |
type: 'info', |
| 433 |
html: "<h2>"+ aysChartBuilderAdmin.loadResource +"</h2><br><h6>"+ aysChartBuilderAdmin.somethingWentWrong +"</h6>" |
| 434 |
}).then( function(res) { |
| 435 |
$this.text(aysChartBuilderAdmin.errorMsg); |
| 436 |
}); |
| 437 |
// $this.prop('disabled', false); |
| 438 |
// if ( $this.hasClass('disabled') ) { |
| 439 |
// $this.removeClass('disabled'); |
| 440 |
// } |
| 441 |
} |
| 442 |
}); |
| 443 |
}); |
| 444 |
|
| 445 |
$(document).on("click", ".ays-chart-cards-block .ays-chart-card__footer button.status-installed", function(e){ |
| 446 |
var $this = $(this); |
| 447 |
var thisParent = $this.parents(".ays-chart-cards-block"); |
| 448 |
|
| 449 |
$this.prop('disabled', true); |
| 450 |
$this.addClass('disabled'); |
| 451 |
|
| 452 |
var loader_html = '<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>'; |
| 453 |
|
| 454 |
$this.html(loader_html); |
| 455 |
|
| 456 |
var attr_plugin = $this.attr('data-plugin'); |
| 457 |
var wp_nonce = thisParent.find('#ays_chart_ajax_install_plugin_nonce').val(); |
| 458 |
|
| 459 |
var data = { |
| 460 |
action: 'ays_chart_activate_plugin', |
| 461 |
_ajax_nonce: wp_nonce, |
| 462 |
plugin: attr_plugin, |
| 463 |
type: 'plugin' |
| 464 |
}; |
| 465 |
|
| 466 |
$.ajax({ |
| 467 |
url: aysChartBuilderAdmin.ajaxUrl, |
| 468 |
method: 'post', |
| 469 |
dataType: 'json', |
| 470 |
data: data, |
| 471 |
success: function (response) { |
| 472 |
if( response.success ){ |
| 473 |
swal.fire({ |
| 474 |
type: 'success', |
| 475 |
html: "<h4>"+ response['data'] +"</h4>" |
| 476 |
}).then( function(res) { |
| 477 |
if ( $this.hasClass('status-installed') ) { |
| 478 |
$this.removeClass('status-installed'); |
| 479 |
} |
| 480 |
$this.text(aysChartBuilderAdmin.activated); |
| 481 |
$this.addClass('status-active disabled'); |
| 482 |
}); |
| 483 |
} else { |
| 484 |
swal.fire({ |
| 485 |
type: 'info', |
| 486 |
html: "<h4>"+ response['data'][0]['message'] +"</h4>" |
| 487 |
}); |
| 488 |
} |
| 489 |
}, |
| 490 |
error: function(){ |
| 491 |
swal.fire({ |
| 492 |
type: 'info', |
| 493 |
html: "<h2>"+ aysChartBuilderAdmin.loadResource +"</h2><br><h6>"+ aysChartBuilderAdmin.somethingWentWrong +"</h6>" |
| 494 |
}).then( function(res) { |
| 495 |
$this.text(aysChartBuilderAdmin.errorMsg); |
| 496 |
});; |
| 497 |
// $this.prop('disabled', false); |
| 498 |
// if ( $this.hasClass('disabled') ) { |
| 499 |
// $this.removeClass('disabled'); |
| 500 |
// } |
| 501 |
} |
| 502 |
}); |
| 503 |
}); |
| 504 |
|
| 505 |
$(document).on("click", "#ays-chart-dismiss-buttons-content .ays-button, #ays-chart-dismiss-buttons-content-helloween .ays-button-helloween, #ays-chart-dismiss-buttons-content-black-friday .ays-button-black-friday", function(e){ |
| 506 |
e.preventDefault(); |
| 507 |
|
| 508 |
var $this = $(this); |
| 509 |
var thisParent = $this.parents("#ays-chart-dismiss-buttons-content"); |
| 510 |
// var thisParent = $this.parents("#ays-chart-dismiss-buttons-content-helloween"); |
| 511 |
// var thisParent = $this.parents("#ays-chart-dismiss-buttons-content-black-friday"); |
| 512 |
var mainParent = $this.parents("div.ays_chart_dicount_info"); |
| 513 |
var closeButton = mainParent.find("button.notice-dismiss"); |
| 514 |
|
| 515 |
var attr_plugin = $this.attr('data-plugin'); |
| 516 |
var wp_nonce = thisParent.find('#chart-builder-sale-banner').val(); |
| 517 |
|
| 518 |
var data = { |
| 519 |
action: 'ays_chart_dismiss_button', |
| 520 |
_ajax_nonce: wp_nonce, |
| 521 |
}; |
| 522 |
|
| 523 |
$.ajax({ |
| 524 |
url: aysChartBuilderAdmin.ajaxUrl, |
| 525 |
method: 'post', |
| 526 |
dataType: 'json', |
| 527 |
data: data, |
| 528 |
success: function (response) { |
| 529 |
if( response.status ){ |
| 530 |
closeButton.trigger('click'); |
| 531 |
} else { |
| 532 |
swal.fire({ |
| 533 |
type: 'info', |
| 534 |
html: "<h2>"+ aysChartBuilderAdmin.errorMsg +"</h2><br><h6>"+ aysChartBuilderAdmin.somethingWentWrong +"</h6>" |
| 535 |
}).then(function(res) { |
| 536 |
closeButton.trigger('click'); |
| 537 |
}); |
| 538 |
} |
| 539 |
}, |
| 540 |
error: function(){ |
| 541 |
swal.fire({ |
| 542 |
type: 'info', |
| 543 |
html: "<h2>"+ aysChartBuilderAdmin.errorMsg +"</h2><br><h6>"+ aysChartBuilderAdmin.somethingWentWrong +"</h6>" |
| 544 |
}).then(function(res) { |
| 545 |
closeButton.trigger('click'); |
| 546 |
}); |
| 547 |
} |
| 548 |
}); |
| 549 |
}); |
| 550 |
|
| 551 |
/* */ |
| 552 |
|
| 553 |
// Pro features start |
| 554 |
$(document).find(".ays-pro-features-v2-upgrade-button").hover(function() { |
| 555 |
// Code to execute when the mouse enters the element |
| 556 |
var unlockedImg = "Unlocked_24_24.svg"; |
| 557 |
var imgBox = $(this).find(".ays-pro-features-v2-upgrade-icon"); |
| 558 |
var imgUrl = imgBox.attr("data-img-src"); |
| 559 |
var newString = imgUrl.replace("Locked_24x24.svg", unlockedImg); |
| 560 |
|
| 561 |
imgBox.css("background-image", 'url(' + newString + ')'); |
| 562 |
imgBox.attr("data-img-src", newString); |
| 563 |
}, function() { |
| 564 |
|
| 565 |
var lockedImg = "Locked_24x24.svg"; |
| 566 |
var imgBox = $(this).find(".ays-pro-features-v2-upgrade-icon"); |
| 567 |
var imgUrl = imgBox.attr("data-img-src"); |
| 568 |
var newString = imgUrl.replace("Unlocked_24_24.svg", lockedImg); |
| 569 |
|
| 570 |
imgBox.css("background-image", 'url(' + newString + ')'); |
| 571 |
imgBox.attr("data-img-src", newString); |
| 572 |
}); |
| 573 |
// Pro features end |
| 574 |
|
| 575 |
var checkCountdownIsExists = $(document).find('#ays-chart-countdown-main-container'); |
| 576 |
|
| 577 |
if ( checkCountdownIsExists.length > 0 ) { |
| 578 |
var second = 1000, |
| 579 |
minute = second * 60, |
| 580 |
hour = minute * 60, |
| 581 |
day = hour * 24; |
| 582 |
|
| 583 |
var chartCountdownEndTime = aysChartBuilderAdmin.chartBannerDate; |
| 584 |
// var chartCountdownEndTime = "JAN 15, 2025 23:59:59"; |
| 585 |
var countDown_new = new Date(chartCountdownEndTime).getTime(); |
| 586 |
|
| 587 |
if ( isNaN(countDown_new) || isFinite(countDown_new) == false ) { |
| 588 |
var AYS_QUIZ_MILLISECONDS = 3 * day; |
| 589 |
var countdownStartDate = new Date(Date.now() + AYS_QUIZ_MILLISECONDS); |
| 590 |
var quizCountdownEndTime = countdownStartDate.aysQuizCustomFormat( "#YYYY#-#MM#-#DD# #hhhh#:#mm#:#ss#" ); |
| 591 |
var countDown_new = new Date(quizCountdownEndTime).getTime(); |
| 592 |
} |
| 593 |
|
| 594 |
aysChartBannerCountdown(); |
| 595 |
|
| 596 |
var y = setInterval(function() { |
| 597 |
|
| 598 |
var now = new Date().getTime(); |
| 599 |
var distance_new = countDown_new - now; |
| 600 |
|
| 601 |
aysChartBannerCountdown(); |
| 602 |
|
| 603 |
if (distance_new < 0) { |
| 604 |
var headline = document.getElementById("ays-chart-countdown-headline"), |
| 605 |
countdown = document.getElementById("ays-chart-countdown"), |
| 606 |
content = document.getElementById("ays-chart-countdown-content"); |
| 607 |
|
| 608 |
// headline.innerText = "Sale is over!"; |
| 609 |
countdown.style.display = "none"; |
| 610 |
content.style.display = "block"; |
| 611 |
|
| 612 |
clearInterval(y); |
| 613 |
} |
| 614 |
}, 1000); |
| 615 |
} |
| 616 |
|
| 617 |
function aysChartBannerCountdown(){ |
| 618 |
var now = new Date().getTime(); |
| 619 |
var distance_new = countDown_new - now; |
| 620 |
|
| 621 |
var countDownDays = document.getElementById("ays-chart-countdown-days"); |
| 622 |
var countDownHours = document.getElementById("ays-chart-countdown-hours"); |
| 623 |
var countDownMinutes = document.getElementById("ays-chart-countdown-minutes"); |
| 624 |
var countDownSeconds = document.getElementById("ays-chart-countdown-seconds"); |
| 625 |
|
| 626 |
if((countDownDays !== null || countDownHours !== null || countDownMinutes !== null || countDownSeconds !== null) && distance_new > 0){ |
| 627 |
|
| 628 |
var countDownDays_innerText = Math.floor(distance_new / (day)); |
| 629 |
var countDownHours_innerText = Math.floor((distance_new % (day)) / (hour)); |
| 630 |
var countDownMinutes_innerText = Math.floor((distance_new % (hour)) / (minute)); |
| 631 |
var countDownSeconds_innerText = Math.floor((distance_new % (minute)) / second); |
| 632 |
|
| 633 |
if( isNaN(countDownDays_innerText) || isNaN(countDownHours_innerText) || isNaN(countDownMinutes_innerText) || isNaN(countDownSeconds_innerText) ){ |
| 634 |
var headline = document.getElementById("ays-chart-countdown-headline"), |
| 635 |
countdown = document.getElementById("ays-chart-countdown"), |
| 636 |
content = document.getElementById("ays-chart-countdown-content"); |
| 637 |
|
| 638 |
// headline.innerText = "Sale is over!"; |
| 639 |
countdown.style.display = "none"; |
| 640 |
content.style.display = "block"; |
| 641 |
|
| 642 |
clearInterval(y); |
| 643 |
} else { |
| 644 |
countDownDays.innerText = countDownDays_innerText; |
| 645 |
countDownHours.innerText = countDownHours_innerText; |
| 646 |
countDownMinutes.innerText = countDownMinutes_innerText; |
| 647 |
countDownSeconds.innerText = countDownSeconds_innerText; |
| 648 |
} |
| 649 |
} |
| 650 |
} |
| 651 |
|
| 652 |
Date.prototype.aysChartCustomFormat = function( formatString){ |
| 653 |
var YYYY,YY,MMMM,MMM,MM,M,DDDD,DDD,DD,D,hhhh,hhh,hh,h,mm,m,ss,s,ampm,AMPM,dMod,th; |
| 654 |
YY = ((YYYY=this.getFullYear())+"").slice(-2); |
| 655 |
MM = (M=this.getMonth()+1)<10?('0'+M):M; |
| 656 |
MMM = (MMMM=["January","February","March","April","May","June","July","August","September","October","November","December"][M-1]).substring(0,3); |
| 657 |
DD = (D=this.getDate())<10?('0'+D):D; |
| 658 |
DDD = (DDDD=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][this.getDay()]).substring(0,3); |
| 659 |
th=(D>=10&&D<=20)?'th':((dMod=D%10)==1)?'st':(dMod==2)?'nd':(dMod==3)?'rd':'th'; |
| 660 |
formatString = formatString.replace("#YYYY#",YYYY).replace("#YY#",YY).replace("#MMMM#",MMMM).replace("#MMM#",MMM).replace("#MM#",MM).replace("#M#",M).replace("#DDDD#",DDDD).replace("#DDD#",DDD).replace("#DD#",DD).replace("#D#",D).replace("#th#",th); |
| 661 |
h=(hhh=this.getHours()); |
| 662 |
if (h==0) h=24; |
| 663 |
if (h>12) h-=12; |
| 664 |
hh = h<10?('0'+h):h; |
| 665 |
hhhh = hhh<10?('0'+hhh):hhh; |
| 666 |
AMPM=(ampm=hhh<12?'am':'pm').toUpperCase(); |
| 667 |
mm=(m=this.getMinutes())<10?('0'+m):m; |
| 668 |
ss=(s=this.getSeconds())<10?('0'+s):s; |
| 669 |
|
| 670 |
return formatString.replace("#hhhh#",hhhh).replace("#hhh#",hhh).replace("#hh#",hh).replace("#h#",h).replace("#mm#",mm).replace("#m#",m).replace("#ss#",ss).replace("#s#",s).replace("#ampm#",ampm).replace("#AMPM#",AMPM); |
| 671 |
// token: description: example: |
| 672 |
// #YYYY# 4-digit year 1999 |
| 673 |
// #YY# 2-digit year 99 |
| 674 |
// #MMMM# full month name February |
| 675 |
// #MMM# 3-letter month name Feb |
| 676 |
// #MM# 2-digit month number 02 |
| 677 |
// #M# month number 2 |
| 678 |
// #DDDD# full weekday name Wednesday |
| 679 |
// #DDD# 3-letter weekday name Wed |
| 680 |
// #DD# 2-digit day number 09 |
| 681 |
// #D# day number 9 |
| 682 |
// #th# day ordinal suffix nd |
| 683 |
// #hhhh# 2-digit 24-based hour 17 |
| 684 |
// #hhh# military/24-based hour 17 |
| 685 |
// #hh# 2-digit hour 05 |
| 686 |
// #h# hour 5 |
| 687 |
// #mm# 2-digit minute 07 |
| 688 |
// #m# minute 7 |
| 689 |
// #ss# 2-digit second 09 |
| 690 |
// #s# second 9 |
| 691 |
// #ampm# "am" or "pm" pm |
| 692 |
// #AMPM# "AM" or "PM" PM |
| 693 |
}; |
| 694 |
|
| 695 |
var createdNewChart = getCookie('ays_chart_created_new'); |
| 696 |
if (createdNewChart && createdNewChart > 1) { |
| 697 |
var url = new URL(window.location.href); |
| 698 |
|
| 699 |
var parameterValue = url.searchParams.get("action"); |
| 700 |
var htmlDefaultText = '<p style="margin-top:1rem;">For more detailed configuration visit <a href="admin.php?page=chart-builder&action=edit&id=' + createdNewChart + '">edit chart page</a>.</p>'; |
| 701 |
|
| 702 |
var htmlContent = parameterValue && parameterValue == 'edit' ? '' : htmlDefaultText; |
| 703 |
|
| 704 |
swal({ |
| 705 |
title: '<strong>Great job</strong>', |
| 706 |
type: 'success', |
| 707 |
html: '<p>Your chart is Created!<br>Copy the generated shortcode and paste it into any post or page to display the chart.</p><input type="text" id="ays-chart-create-new" onClick="this.setSelectionRange(0, this.value.length)" readonly value="[ays_chart id=\'' + createdNewChart + '\']" />' + htmlContent, |
| 708 |
showCloseButton: true, |
| 709 |
focusConfirm: false, |
| 710 |
confirmButtonText: '<i class="ays_fa ays_fa_thumbs_up"></i> Done', |
| 711 |
confirmButtonAriaLabel: 'Thumbs up, done!', |
| 712 |
}); |
| 713 |
deleteCookie('ays_chart_created_new'); |
| 714 |
} |
| 715 |
|
| 716 |
function getCookie (cname) { |
| 717 |
let name = cname + "="; |
| 718 |
let decodedCookie = decodeURIComponent(document.cookie); |
| 719 |
let ca = decodedCookie.split(';'); |
| 720 |
for(let i = 0; i <ca.length; i++) { |
| 721 |
let c = ca[i]; |
| 722 |
while (c.charAt(0) == ' ') { |
| 723 |
c = c.substring(1); |
| 724 |
} |
| 725 |
if (c.indexOf(name) == 0) { |
| 726 |
return c.substring(name.length, c.length); |
| 727 |
} |
| 728 |
} |
| 729 |
return ""; |
| 730 |
} |
| 731 |
|
| 732 |
function deleteCookie (name) { |
| 733 |
document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; |
| 734 |
} |
| 735 |
|
| 736 |
}); |
| 737 |
|
| 738 |
})(jQuery); |