PluginProbe
Chartify – WordPress Chart Plugin / 3.7.8
Chartify – WordPress Chart Plugin v3.7.8
3.8.0 3.7.9 3.7.8 3.7.7 3.7.6 3.7.5 trunk 1.0.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 All 83 releases
chart-builder / admin / js / chart-builder-admin-general.js

chart-builder-admin-general.js in Chartify – WordPress Chart Plugin 3.7.8, at admin/js/chart-builder-admin-general.js

868 lines 34.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 // Replace image to YouTube embed video
47 $(document).on('click', '.ays-chart-youtube-placeholder', function() {
48 var videoId = $(this).data('video-id');
49 var iframe = $('<iframe>', {
50 src: 'https://www.youtube.com/embed/' + videoId + '?autoplay=1',
51 class: '',
52 width: 560,
53 height: 315,
54 frameborder: 0,
55 allow: 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture',
56 allowfullscreen: true,
57 });
58 $(this).replaceWith(iframe);
59 });
60
61 $(document).find('#ays-title').on('input', function () {
62 $(document).find('.ays_chart_title_in_top').text($(this).val());
63 });
64
65 $(document).find('.form-check-input.select-all').on('click', function() {
66 var checkboxes = $(document).find('.check-current-row');
67 if ($(this).prop('checked') == true && checkboxes.length !== 0) {
68 $(this).parents('thead').next('tbody').find('tr').addClass("ays-chart-tr-selected");
69 checkboxes.prop('checked',true);
70 $(document).find('#ays-chart-bulk-delete').prop('disabled', false);
71 $(document).find('#ays-chart-bulk-delete-bottom').prop('disabled', false);
72 } else {
73 $(this).parents('thead').next('tbody').find('tr').removeClass("ays-chart-tr-selected");
74 checkboxes.prop('checked',false);
75 $(document).find('#ays-chart-bulk-delete').prop('disabled', true);
76 $(document).find('#ays-chart-bulk-delete-bottom').prop('disabled', true);
77 }
78 });
79
80 $(document).find('.check-current-row').on('click', function() {
81 var checkboxesArr = $(document).find('.check-current-row');
82 var selectAllCheckBox = $(document).find('.form-check-input.select-all');
83 var count = 0;
84
85 for (var i = 0; i < checkboxesArr.length; i++) {
86 if (checkboxesArr.eq(i).prop('checked') == true) {
87 count++;
88 }
89 }
90
91 if ((count == 0 && selectAllCheckBox.prop('checked') == true) || (count != 0 && selectAllCheckBox.prop('checked') == true)) {
92 selectAllCheckBox.prop('checked', false);
93 } else if (count == checkboxesArr.length && selectAllCheckBox.prop('checked') == false) {
94 selectAllCheckBox.prop('checked', true);
95 }
96
97 if ( $(this).prop('checked') ) {
98 $(this).parents('tr').addClass("ays-chart-tr-selected");
99 $(document).find('#ays-chart-bulk-delete').prop('disabled', false);
100 $(document).find('#ays-chart-bulk-delete-bottom').prop('disabled', false);
101 } else if ( !$(this).prop('checked') && count > 0) {
102 $(this).parents('tr').removeClass("ays-chart-tr-selected");
103 $(document).find('#ays-chart-bulk-delete').prop('disabled', false);
104 $(document).find('#ays-chart-bulk-delete-bottom').prop('disabled', false);
105 } else {
106 $(this).parents('tr').removeClass("ays-chart-tr-selected");
107 $(document).find('#ays-chart-bulk-delete').prop('disabled', true);
108 $(document).find('#ays-chart-bulk-delete-bottom').prop('disabled', true);
109 }
110 });
111
112 // Bulk delete confirmation
113 $(document).on('click', '#ays-chart-bulk-delete', function(e) {
114 e.preventDefault();
115 var confirm = window.confirm(aysChartBuilderAdmin.confirmDelete);
116 if (confirm) {
117 $(document).find('#ays-chart-bulk-delete-confirm').trigger('click');
118 }
119 });
120 $(document).on('click', '#ays-chart-bulk-delete-bottom', function(e) {
121 e.preventDefault();
122 var confirm = window.confirm(aysChartBuilderAdmin.confirmDelete);
123 if (confirm) {
124 $(document).find('#ays-chart-bulk-delete-confirm-bottom').trigger('click');
125 }
126 });
127
128 // Delete confirmation
129 $(document).on('click', '.ays_chart_delete_confirm', function(e){
130 e.preventDefault();
131 var confirm = window.confirm(aysChartBuilderAdmin.confirmDelete);
132 if (confirm){
133 window.location.replace($(this).attr('href'));
134 }
135 });
136
137 function performSearch() {
138 var _this = $(this);
139 var parent = _this.parents('form');
140
141 var search_input = parent.find('input#ays-chart-search-input');
142 var input_value = search_input.val();
143
144 var field = 's';
145 var flag = false;
146 var url = window.location.href;
147 if (url.indexOf('?' + field + '=') != -1) {
148 flag = true;
149 } else if (url.indexOf('&' + field + '=') != -1) {
150 flag = true;
151 }
152
153 if (flag) {
154 if (typeof input_value != 'undefined' && input_value != "") {
155 url = location.href.replace(/&s=([^&]$|[^&]*)/i, "&s=" + input_value);
156 } else if (input_value == "") {
157 url = location.href.replace(/&s=([^&]$|[^&]*)/i, "");
158 }
159 } else {
160 if (typeof input_value != 'undefined' && input_value != "") {
161 url = location.href + "&s=" + input_value;
162 }
163 }
164
165 location.href = url.replace(/&paged=([^&]$|[^&]*)/i, "&paged=1");
166 }
167
168 $(document).find("input#ays-chart-search-input + button#ays-chart-search").on("click", function (e) {
169 e.preventDefault();
170 performSearch.call(this);
171 });
172
173 $(document).on("keypress", '#ays-chart-search-input', function (e) {
174 if (e.which === 13) {
175 e.preventDefault();
176 performSearch.call(this);
177 }
178 });
179
180 $(document).on("click", "button[id^='ays-chart-filter']", function (e) {
181 e.preventDefault();
182 var _this = $(this);
183 var parent = _this.parents('form');
184
185 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'];
186 var inputValues = inputSelectors.map(selector => parent.find(selector).val());
187
188 var filterFields = ['filterbytype', 'filterbyauthor', 'filterbysource', 'filterbychartsource', 'filterbydate', 'orderby', 'order'];
189
190 addFiltersUrl(inputValues, filterFields);
191 });
192
193 $(document).on("click", "button[id^='ays-chart-filter-clear']", function (e) {
194 e.preventDefault();
195 clearFiltersUrl();
196 });
197
198 function addFiltersUrl(inputValues, filterFields) {
199 var url = window.location.href;
200 for (var i = 0; i < inputValues.length; i++) {
201 var flag = url.includes('?' + filterFields[i] + '=') || url.includes('&' + filterFields[i] + '=');
202 if (flag) {
203 url = url.replace(new RegExp('&?' + filterFields[i] + '=([^&]*)'), '');
204 }
205 if (inputValues[i]) {
206 url += '&' + filterFields[i] + '=' + inputValues[i];
207 }
208 }
209
210 location.href = url.replace(/&paged=([^&]$|[^&]*)/i, "&paged=1");
211 }
212
213 function clearFiltersUrl() {
214 var url = window.location.href;
215 var filterFields = ['filterbytype', 'filterbyauthor', 'filterbysource', 'filterbychartsource', 'filterbydate', 'orderby', 'order'];
216
217 for (var i = 0; i < filterFields.length; i++) {
218 url = url.replace(new RegExp('&?' + filterFields[i] + '=([^&]*)'), '');
219 }
220
221 location.href = url.replace(/&paged=([^&]$|[^&]*)/i, "&paged=1");
222 }
223
224 $(document).find('#ays-chart-filter-author').select2({
225 placeholder: aysChartBuilderAdmin.selectUser,
226 dropdownAutoWidth: true,
227 minimumInputLength: 1,
228 allowClear: true,
229 language: {
230 searching: function() {
231 return aysChartBuilderAdmin.searching;
232 },
233 inputTooShort: function () {
234 return aysChartBuilderAdmin.pleaseEnterMore;
235 }
236 },
237 ajax: {
238 url: ajaxurl,
239 dataType: 'json',
240 data: function (response) {
241 var checkedUsers = $(document).find('#ays-chart-filter-author').val();
242 return {
243 action: 'ays_chart_admin_ajax',
244 function: window.aysChartBuilderChartSettings.ajax['actions']['author_user_search'],
245 security: window.aysChartBuilderChartSettings.ajax['nonces']['author_user_search'],
246 params: {
247 search: response.term,
248 val: checkedUsers
249 }
250 };
251 }
252 }
253 });
254 $(document).find('#ays-chart-filter-author-bottom').select2({
255 placeholder: aysChartBuilderAdmin.selectUser,
256 dropdownAutoWidth: true,
257 minimumInputLength: 1,
258 allowClear: true,
259 language: {
260 searching: function() {
261 return aysChartBuilderAdmin.searching;
262 },
263 inputTooShort: function () {
264 return aysChartBuilderAdmin.pleaseEnterMore;
265 }
266 },
267 ajax: {
268 url: ajaxurl,
269 dataType: 'json',
270 data: function (response) {
271 var checkedUsers = $(document).find('#ays-chart-filter-author-bottom').val();
272 return {
273 action: 'ays_chart_admin_ajax',
274 function: window.aysChartBuilderChartSettings.ajax['actions']['author_user_search'],
275 security: window.aysChartBuilderChartSettings.ajax['nonces']['author_user_search'],
276 params: {
277 search: response.term,
278 val: checkedUsers
279 }
280 };
281 }
282 }
283 });
284
285 $(document).on('mouseenter', 'td.column-title', function() {
286 // $(this).find('.chart-list-table-actions-row').css('visibility', 'visible');
287 $(this).find('.chart-list-table-actions-row').css('display', 'flex');
288 // $(this).css('padding', '8px 8px');
289 });
290 $(document).on('mouseleave', 'td.column-title', function() {
291 // $(this).find('.chart-list-table-actions-row').css('visibility', 'hidden');
292 $(this).find('.chart-list-table-actions-row').hide();
293 // $(this).css('padding', '23px 8px');
294 });
295
296 $(document).find('.ays-chart-copy-image').on('click', function(){
297 var _this = this;
298 var input = $(_this).parent().find('input.ays-chart-shortcode-input');
299 var length = input.val().length;
300
301 input[0].focus();
302 input[0].setSelectionRange(0, length);
303 document.execCommand('copy');
304 // document.getSelection().removeAllRanges();
305
306 $(_this).attr('data-original-title', aysChartBuilderAdmin.copied);
307 $(_this).attr("data-bs-original-title", aysChartBuilderAdmin.copied);
308 $(_this).attr("title", aysChartBuilderAdmin.copied);
309 $(_this).tooltip('show');
310 });
311
312 $(document).find('.ays-chart-shortcode-input').on('focus', function(){
313 this.setSelectionRange(0, $(this).val().length);
314 });
315
316 $(document).find('.ays-chart-copy-image').on('mouseleave', function(){
317 var _this = this;
318
319 $(_this).attr('data-original-title', aysChartBuilderAdmin.clickForCopy);
320 $(_this).attr("data-bs-original-title", aysChartBuilderAdmin.clickForCopy);
321 $(_this).attr("title", aysChartBuilderAdmin.clickForCopy);
322 });
323
324 $(document).on('click', '.notice-dismiss', function (e) {
325 changeCurrentUrl('status');
326 });
327
328 var toggle_ddmenu = $(document).find('.toggle_ddmenu');
329 toggle_ddmenu.on('click', function () {
330 var ddmenu = $(this).next();
331 var state = ddmenu.attr('data-expanded');
332 switch (state) {
333 case 'true':
334 $(this).find('.ays_fa').css({
335 transform: 'rotate(0deg)'
336 });
337 ddmenu.attr('data-expanded', 'false');
338 break;
339 case 'false':
340 $(this).find('.ays_fa').css({
341 transform: 'rotate(90deg)'
342 });
343 ddmenu.attr('data-expanded', 'true');
344 break;
345 }
346 });
347
348 function changeCurrentUrl(key){
349 var linkModified = location.href.split('?')[1].split('&');
350 for(var i = 0; i < linkModified.length; i++){
351 if(linkModified[i].split("=")[0] == key){
352 linkModified.splice(i, 1);
353 }
354 }
355 linkModified = linkModified.join('&');
356 window.history.replaceState({}, document.title, '?'+linkModified);
357 }
358
359 // Select message vars charts page
360 $(document).find('.ays-chart-message-vars-icon').on('click', function(e){
361 $(this).parents(".ays-chart-message-vars-box").find(".ays-chart-message-vars-data").toggle('fast');
362 });
363
364 $(document).find('.ays-chart-open-charts-list').on('click', function(e){
365 $(this).parents(".ays-chart-subtitle-main-box").find(".ays-chart-charts-data").toggle('fast');
366 });
367
368 $(document).on( "click" , function(e){
369 if($(e.target).closest('.ays-chart-message-vars-box,.ays-chart-subtitle-main-box').length != 0){
370
371 }
372 else{
373 $(document).find(".ays-chart-message-vars-box .ays-chart-message-vars-data,.ays-chart-subtitle-main-box .ays-chart-charts-data").hide('fast');
374 }
375 });
376
377 $(document).find(".ays-chart-go-to-charts").on("click" , function(e){
378 e.preventDefault();
379 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.');
380 if(confirmRedirect){
381 window.location = $(this).attr("href");
382 }
383 });
384
385 $(document).find('.ays-chart-message-vars-each-data').on('click', function(e){
386 var messageVar = $(this).find(".ays-chart-message-vars-each-var").val();
387 var mainParent = $(this).parents('.ays-chart-box-for-mv');
388 var dataTMCE = mainParent.find('.ays-chart-message-vars-data').attr('data-tmce');
389
390 if ( mainParent.find("#wp-"+dataTMCE+"-wrap").hasClass("tmce-active") ){
391 window.tinyMCE.get(dataTMCE).setContent( window.tinyMCE.get(dataTMCE).getContent() + messageVar + " " );
392 }else{
393 mainParent.find('#'+dataTMCE).append( " " + messageVar + " ");
394 }
395 });
396
397 $(document).on("click", ".ays-chart-cards-block .ays-chart-card__footer button.status-missing", function(e){
398 var $this = $(this);
399 var thisParent = $this.parents(".ays-chart-cards-block");
400
401 $this.prop('disabled', true);
402 $this.addClass('disabled');
403
404 var loader_html = '<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>';
405
406 $this.html(loader_html);
407
408 var attr_plugin = $this.attr('data-plugin');
409 var wp_nonce = thisParent.find('#ays_chart_ajax_install_plugin_nonce').val();
410
411 var data = {
412 action: 'ays_chart_install_plugin',
413 _ajax_nonce: wp_nonce,
414 plugin: attr_plugin,
415 type: 'plugin'
416 };
417
418 $.ajax({
419 url: aysChartBuilderAdmin.ajaxUrl,
420 method: 'post',
421 dataType: 'json',
422 data: data,
423 success: function (response) {
424 if (response.success) {
425 swal.fire({
426 type: 'success',
427 html: "<h4>"+ response['data']['msg'] +"</h4>"
428 }).then( function(res) {
429 if ( $this.hasClass('status-missing') ) {
430 $this.removeClass('status-missing');
431 }
432 $this.text(aysChartBuilderAdmin.activated);
433 $this.addClass('status-active');
434 });
435 }
436 else {
437 swal.fire({
438 type: 'info',
439 html: "<h4>"+ response['data'][0]['message'] +"</h4>"
440 }).then( function(res) {
441 $this.text(aysChartBuilderAdmin.errorMsg);
442 });
443 }
444 },
445 error: function(){
446 swal.fire({
447 type: 'info',
448 html: "<h2>"+ aysChartBuilderAdmin.loadResource +"</h2><br><h6>"+ aysChartBuilderAdmin.somethingWentWrong +"</h6>"
449 }).then( function(res) {
450 $this.text(aysChartBuilderAdmin.errorMsg);
451 });
452 // $this.prop('disabled', false);
453 // if ( $this.hasClass('disabled') ) {
454 // $this.removeClass('disabled');
455 // }
456 }
457 });
458 });
459
460 $(document).on("click", ".ays-chart-cards-block .ays-chart-card__footer button.status-installed", function(e){
461 var $this = $(this);
462 var thisParent = $this.parents(".ays-chart-cards-block");
463
464 $this.prop('disabled', true);
465 $this.addClass('disabled');
466
467 var loader_html = '<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>';
468
469 $this.html(loader_html);
470
471 var attr_plugin = $this.attr('data-plugin');
472 var wp_nonce = thisParent.find('#ays_chart_ajax_install_plugin_nonce').val();
473
474 var data = {
475 action: 'ays_chart_activate_plugin',
476 _ajax_nonce: wp_nonce,
477 plugin: attr_plugin,
478 type: 'plugin'
479 };
480
481 $.ajax({
482 url: aysChartBuilderAdmin.ajaxUrl,
483 method: 'post',
484 dataType: 'json',
485 data: data,
486 success: function (response) {
487 if( response.success ){
488 swal.fire({
489 type: 'success',
490 html: "<h4>"+ response['data'] +"</h4>"
491 }).then( function(res) {
492 if ( $this.hasClass('status-installed') ) {
493 $this.removeClass('status-installed');
494 }
495 $this.text(aysChartBuilderAdmin.activated);
496 $this.addClass('status-active disabled');
497 });
498 } else {
499 swal.fire({
500 type: 'info',
501 html: "<h4>"+ response['data'][0]['message'] +"</h4>"
502 });
503 }
504 },
505 error: function(){
506 swal.fire({
507 type: 'info',
508 html: "<h2>"+ aysChartBuilderAdmin.loadResource +"</h2><br><h6>"+ aysChartBuilderAdmin.somethingWentWrong +"</h6>"
509 }).then( function(res) {
510 $this.text(aysChartBuilderAdmin.errorMsg);
511 });;
512 // $this.prop('disabled', false);
513 // if ( $this.hasClass('disabled') ) {
514 // $this.removeClass('disabled');
515 // }
516 }
517 });
518 });
519
520 $(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){
521 e.preventDefault();
522
523 var $this = $(this);
524 var thisParent = $this.parents("#ays-chart-dismiss-buttons-content");
525 // var thisParent = $this.parents("#ays-chart-dismiss-buttons-content-helloween");
526 // var thisParent = $this.parents("#ays-chart-dismiss-buttons-content-black-friday");
527 var mainParent = $this.parents("div.ays_chart_dicount_info");
528 var closeButton = mainParent.find("button.notice-dismiss");
529
530 var attr_plugin = $this.attr('data-plugin');
531 var wp_nonce = thisParent.find('#chart-builder-sale-banner').val();
532 if(typeof wp_nonce == 'undefined'){
533 wp_nonce = $(document).find('#chart-builder-sale-banner').val();
534 }
535
536 var data = {
537 action: 'ays_chart_dismiss_button',
538 _ajax_nonce: wp_nonce,
539 };
540
541 $.ajax({
542 url: aysChartBuilderAdmin.ajaxUrl,
543 method: 'post',
544 dataType: 'json',
545 data: data,
546 success: function (response) {
547 if( response.status ){
548 closeButton.trigger('click');
549 } else {
550 swal.fire({
551 type: 'info',
552 html: "<h2>"+ aysChartBuilderAdmin.errorMsg +"</h2><br><h6>"+ aysChartBuilderAdmin.somethingWentWrong +"</h6>"
553 }).then(function(res) {
554 closeButton.trigger('click');
555 });
556 }
557 },
558 error: function(){
559 swal.fire({
560 type: 'info',
561 html: "<h2>"+ aysChartBuilderAdmin.errorMsg +"</h2><br><h6>"+ aysChartBuilderAdmin.somethingWentWrong +"</h6>"
562 }).then(function(res) {
563 closeButton.trigger('click');
564 });
565 }
566 });
567 });
568
569 /* */
570
571 // Pro features start
572 $(document).find(".ays-pro-features-v2-upgrade-button").hover(function() {
573 // Code to execute when the mouse enters the element
574 var unlockedImg = "Unlocked_24_24.svg";
575 var imgBox = $(this).find(".ays-pro-features-v2-upgrade-icon");
576 var imgUrl = imgBox.attr("data-img-src");
577 var newString = imgUrl.replace("Locked_24x24.svg", unlockedImg);
578
579 imgBox.css("background-image", 'url(' + newString + ')');
580 imgBox.attr("data-img-src", newString);
581 }, function() {
582
583 var lockedImg = "Locked_24x24.svg";
584 var imgBox = $(this).find(".ays-pro-features-v2-upgrade-icon");
585 var imgUrl = imgBox.attr("data-img-src");
586 var newString = imgUrl.replace("Unlocked_24_24.svg", lockedImg);
587
588 imgBox.css("background-image", 'url(' + newString + ')');
589 imgBox.attr("data-img-src", newString);
590 });
591 // Pro features end
592
593 var checkCountdownIsExists = $(document).find('#ays-chart-new-silver-bundle-dicount-month-main');
594
595 if ( checkCountdownIsExists.length > 0 ) {
596 var second = 1000,
597 minute = second * 60,
598 hour = minute * 60,
599 day = hour * 24;
600
601 var chartCountdownEndTime = aysChartBuilderAdmin.chartBannerDate;
602 // var chartCountdownEndTime = "NOV 28, 2025 23:59:59";
603 var countDown_new = new Date(chartCountdownEndTime).getTime();
604
605 if ( isNaN(countDown_new) || isFinite(countDown_new) == false ) {
606 var AYS_QUIZ_MILLISECONDS = 3 * day;
607 var countdownStartDate = new Date(Date.now() + AYS_QUIZ_MILLISECONDS);
608 var quizCountdownEndTime = countdownStartDate.aysQuizCustomFormat( "#YYYY#-#MM#-#DD# #hhhh#:#mm#:#ss#" );
609 var countDown_new = new Date(quizCountdownEndTime).getTime();
610 }
611
612 aysChartBannerCountdown();
613
614 var y = setInterval(function() {
615
616 var now = new Date().getTime();
617 var distance_new = countDown_new - now;
618
619 aysChartBannerCountdown();
620
621 if (distance_new < 0) {
622 var headline = document.getElementById("ays-chart-countdown-headline"),
623 countdown = document.getElementById("ays-chart-countdown"),
624 content = document.getElementById("ays-chart-countdown-content");
625
626 // headline.innerText = "Sale is over!";
627 countdown.style.display = "none";
628 content.style.display = "block";
629
630 clearInterval(y);
631 }
632 }, 1000);
633 }
634
635 function aysChartBannerCountdown(){
636 var now = new Date().getTime();
637 var distance_new = countDown_new - now;
638
639 var countDownDays = document.getElementById("ays-chart-countdown-days");
640 var countDownHours = document.getElementById("ays-chart-countdown-hours");
641 var countDownMinutes = document.getElementById("ays-chart-countdown-minutes");
642 var countDownSeconds = document.getElementById("ays-chart-countdown-seconds");
643
644 if((countDownDays !== null || countDownHours !== null || countDownMinutes !== null || countDownSeconds !== null) && distance_new > 0){
645
646 var countDownDays_innerText = Math.floor(distance_new / (day));
647 var countDownHours_innerText = Math.floor((distance_new % (day)) / (hour));
648 var countDownMinutes_innerText = Math.floor((distance_new % (hour)) / (minute));
649 var countDownSeconds_innerText = Math.floor((distance_new % (minute)) / second);
650
651 if( isNaN(countDownDays_innerText) || isNaN(countDownHours_innerText) || isNaN(countDownMinutes_innerText) || isNaN(countDownSeconds_innerText) ){
652 var headline = document.getElementById("ays-chart-countdown-headline"),
653 countdown = document.getElementById("ays-chart-countdown"),
654 content = document.getElementById("ays-chart-countdown-content");
655
656 // headline.innerText = "Sale is over!";
657 countdown.style.display = "none";
658 content.style.display = "block";
659
660 clearInterval(y);
661 } else {
662 countDownDays.innerText = countDownDays_innerText;
663 countDownHours.innerText = countDownHours_innerText;
664 countDownMinutes.innerText = countDownMinutes_innerText;
665 countDownSeconds.innerText = countDownSeconds_innerText;
666 }
667 }
668 }
669
670 Date.prototype.aysChartCustomFormat = function( formatString){
671 var YYYY,YY,MMMM,MMM,MM,M,DDDD,DDD,DD,D,hhhh,hhh,hh,h,mm,m,ss,s,ampm,AMPM,dMod,th;
672 YY = ((YYYY=this.getFullYear())+"").slice(-2);
673 MM = (M=this.getMonth()+1)<10?('0'+M):M;
674 MMM = (MMMM=["January","February","March","April","May","June","July","August","September","October","November","December"][M-1]).substring(0,3);
675 DD = (D=this.getDate())<10?('0'+D):D;
676 DDD = (DDDD=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][this.getDay()]).substring(0,3);
677 th=(D>=10&&D<=20)?'th':((dMod=D%10)==1)?'st':(dMod==2)?'nd':(dMod==3)?'rd':'th';
678 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);
679 h=(hhh=this.getHours());
680 if (h==0) h=24;
681 if (h>12) h-=12;
682 hh = h<10?('0'+h):h;
683 hhhh = hhh<10?('0'+hhh):hhh;
684 AMPM=(ampm=hhh<12?'am':'pm').toUpperCase();
685 mm=(m=this.getMinutes())<10?('0'+m):m;
686 ss=(s=this.getSeconds())<10?('0'+s):s;
687
688 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);
689 // token: description: example:
690 // #YYYY# 4-digit year 1999
691 // #YY# 2-digit year 99
692 // #MMMM# full month name February
693 // #MMM# 3-letter month name Feb
694 // #MM# 2-digit month number 02
695 // #M# month number 2
696 // #DDDD# full weekday name Wednesday
697 // #DDD# 3-letter weekday name Wed
698 // #DD# 2-digit day number 09
699 // #D# day number 9
700 // #th# day ordinal suffix nd
701 // #hhhh# 2-digit 24-based hour 17
702 // #hhh# military/24-based hour 17
703 // #hh# 2-digit hour 05
704 // #h# hour 5
705 // #mm# 2-digit minute 07
706 // #m# minute 7
707 // #ss# 2-digit second 09
708 // #s# second 9
709 // #ampm# "am" or "pm" pm
710 // #AMPM# "AM" or "PM" PM
711 };
712
713 var createdNewChart = getCookie('ays_chart_created_new');
714 if (createdNewChart && createdNewChart > 1) {
715 var url = new URL(window.location.href);
716 var getCustomPostId = getCookie('ays_chart_created_new_'+createdNewChart+'_post_id');
717 var link = "#";
718 if(getCustomPostId){
719 link = getCustomPostId;
720 }
721
722 var parameterValue = url.searchParams.get("action");
723 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>';
724
725 var htmlContent = parameterValue && parameterValue == 'edit' ? '' : htmlDefaultText;
726 var previewButtonSvgIcon = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M11.9999 7.21325C11.8231 7.21325 11.6535 7.28349 11.5285 7.40851C11.4035 7.53354 11.3333 7.70311 11.3333 7.87992V12.6666C11.3333 12.8434 11.263 13.013 11.138 13.138C11.013 13.263 10.8434 13.3333 10.6666 13.3333H3.33325C3.15644 13.3333 2.98687 13.263 2.86185 13.138C2.73682 13.013 2.66659 12.8434 2.66659 12.6666V5.33325C2.66659 5.15644 2.73682 4.98687 2.86185 4.86185C2.98687 4.73682 3.15644 4.66658 3.33325 4.66658H8.11992C8.29673 4.66658 8.4663 4.59635 8.59132 4.47132C8.71635 4.3463 8.78658 4.17673 8.78658 3.99992C8.78658 3.82311 8.71635 3.65354 8.59132 3.52851C8.4663 3.40349 8.29673 3.33325 8.11992 3.33325H3.33325C2.80282 3.33325 2.29411 3.54397 1.91904 3.91904C1.54397 4.29411 1.33325 4.80282 1.33325 5.33325V12.6666C1.33325 13.197 1.54397 13.7057 1.91904 14.0808C2.29411 14.4559 2.80282 14.6666 3.33325 14.6666H10.6666C11.197 14.6666 11.7057 14.4559 12.0808 14.0808C12.4559 13.7057 12.6666 13.197 12.6666 12.6666V7.87992C12.6666 7.70311 12.5963 7.53354 12.4713 7.40851C12.3463 7.28349 12.1767 7.21325 11.9999 7.21325ZM14.6133 1.74659C14.5456 1.58369 14.4162 1.45424 14.2533 1.38659C14.1731 1.35242 14.087 1.33431 13.9999 1.33325H9.99992C9.82311 1.33325 9.65354 1.40349 9.52851 1.52851C9.40349 1.65354 9.33325 1.82311 9.33325 1.99992C9.33325 2.17673 9.40349 2.3463 9.52851 2.47132C9.65354 2.59635 9.82311 2.66659 9.99992 2.66659H12.3933L5.52659 9.52658C5.4641 9.58856 5.4145 9.66229 5.38066 9.74353C5.34681 9.82477 5.32939 9.91191 5.32939 9.99992C5.32939 10.0879 5.34681 10.1751 5.38066 10.2563C5.4145 10.3375 5.4641 10.4113 5.52659 10.4733C5.58856 10.5357 5.66229 10.5853 5.74353 10.6192C5.82477 10.653 5.91191 10.6705 5.99992 10.6705C6.08793 10.6705 6.17506 10.653 6.2563 10.6192C6.33754 10.5853 6.41128 10.5357 6.47325 10.4733L13.3333 3.60659V5.99992C13.3333 6.17673 13.4035 6.3463 13.5285 6.47132C13.6535 6.59635 13.8231 6.66658 13.9999 6.66658C14.1767 6.66658 14.3463 6.59635 14.4713 6.47132C14.5963 6.3463 14.6666 6.17673 14.6666 5.99992V1.99992C14.6655 1.9128 14.6474 1.82673 14.6133 1.74659Z" fill="#007DCB"/></svg>';
727
728 swal({
729 title: '<strong>Great job</strong>',
730 type: 'success',
731 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,
732 confirmButtonText: '<a href="'+ link +'" target="_blank">'+ 'Preview Chart' + ' ' + previewButtonSvgIcon +'</a>',
733 confirmButtonAriaLabel: 'Preview this chart',
734 showCloseButton: true,
735 focusConfirm: false,
736 cancelButtonText: '<i class="ays_fa ays_fa_thumbs_up"></i> Done',
737 cancelButtonAriaLabel: 'Thumbs up, done!',
738 });
739 deleteCookie('ays_chart_created_new');
740 deleteCookie('ays_chart_created_new'+createdNewChart+'_post_id');
741 }
742
743 function getCookie (cname) {
744 let name = cname + "=";
745 let decodedCookie = decodeURIComponent(document.cookie);
746 let ca = decodedCookie.split(';');
747 for(let i = 0; i <ca.length; i++) {
748 let c = ca[i];
749 while (c.charAt(0) == ' ') {
750 c = c.substring(1);
751 }
752 if (c.indexOf(name) == 0) {
753 return c.substring(name.length, c.length);
754 }
755 }
756 return "";
757 }
758
759 function deleteCookie (name) {
760 document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
761 }
762
763 });
764
765 })(jQuery);
766
767 function selectAndCopyElementContents(el) {
768 if (window.getSelection && document.createRange) {
769 var _this = jQuery(document).find('.ays-chart-copy-element-box');
770
771 var text = el.textContent;
772 var textField = document.createElement('textarea');
773
774 textField.innerText = text;
775 document.body.appendChild(textField);
776 textField.select();
777 document.execCommand('copy');
778 textField.remove();
779
780 var selection = window.getSelection();
781 selection.setBaseAndExtent(el,0,el,1);
782
783 _this.attr( "data-original-title", 'Copied!' );
784 _this.attr( "title", 'Copied!' );
785
786 _this.tooltip("show");
787
788 } else if (document.selection && document.body.createTextRange) {
789 var textRange = document.body.createTextRange();
790 textRange.moveToElementText(el);
791 textRange.select();
792 }
793 }
794
795 document.addEventListener("DOMContentLoaded", function() {
796 var startDate = new Date("2025-09-24");
797 var endDate = new Date("2025-10-25");
798 var totalLicenses = 50;
799 var progressionPattern = new Array(3, 2, 1, 4, 2, 3, 1, 2, 4, 3, 2, 1, 3, 2, 4, 1, 3, 2, 2, 3, 1, 2);
800 function getCurrentProgress() {
801 var today = new Date();
802 var daysPassed = Math.floor((today - startDate) / (1000 * 60 * 60 * 24));
803 var usedLicenses = 0;
804 for (var i = 0; i < Math.min(daysPassed, progressionPattern.length); i++) {
805 usedLicenses += progressionPattern[i];
806 }
807 return Math.min(usedLicenses, totalLicenses);
808 }
809 function updateProgress() {
810 var usedLicenses = getCurrentProgress();
811 var remainingLicenses = totalLicenses - usedLicenses;
812 var progressPercentage = (usedLicenses / totalLicenses) * 100;
813 var remainingElement = document.getElementById("remaining-licenses");
814 var progressElement = document.getElementById("progress-fill");
815 if (remainingElement) remainingElement.textContent = remainingLicenses;
816 if (progressElement) progressElement.style.width = progressPercentage + "%";
817 }
818 updateProgress();
819 });
820
821 // Copy to clipboard function
822 function chartCopyToClipboard(text) {
823 if (navigator.clipboard && window.isSecureContext) {
824 navigator.clipboard.writeText(text).then(function() {
825 chartShowCopyNotification(aysChartBuilderAdmin.successCopyCoupon);
826 }).catch(function() {
827 fallbackCopyTextToClipboard(text);
828 });
829 } else {
830 fallbackCopyTextToClipboard(text);
831 }
832 }
833
834 function fallbackCopyTextToClipboard(text) {
835 var textArea = document.createElement("textarea");
836 textArea.value = text;
837 textArea.style.position = "fixed";
838 textArea.style.top = "-9999px";
839 textArea.style.left = "-9999px";
840 document.body.appendChild(textArea);
841 textArea.focus();
842 textArea.select();
843 try {
844 var successful = document.execCommand("copy");
845 if (successful) {
846 chartShowCopyNotification(aysChartBuilderAdmin.successCopyCoupon);
847 } else {
848 chartShowCopyNotification(aysChartBuilderAdmin.failedCopyCoupon);
849 }
850 } catch (err) {
851 chartShowCopyNotification(aysChartBuilderAdmin.failedCopyCoupon);
852 }
853 document.body.removeChild(textArea);
854 }
855
856 function chartShowCopyNotification(message) {
857 var notification = document.createElement("div");
858 notification.className = "ays-chart-copy-notification show";
859 console.log(notification);
860 notification.textContent = message;
861 document.body.appendChild(notification);
862 setTimeout(function() {
863 notification.classList.remove("show");
864 setTimeout(function() {
865 document.body.removeChild(notification);
866 }, 300);
867 }, 2000);
868 }