PluginProbe
Chartify – WordPress Chart Plugin / 3.3.9
Chartify – WordPress Chart Plugin v3.3.9
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-chartjs.js

chart-builder-admin-chartjs.js in Chartify – WordPress Chart Plugin 3.3.9, at admin/js/chart-builder-admin-chartjs.js

1,142 lines 44.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($) {
2 'use strict';
3 function ChartBuilderChartsJs(element, options){
4 this.el = element;
5 this.$el = $(element);
6 this.ajaxAction = 'ays_chart_admin_ajax';
7 this.htmlClassPrefix = 'ays-chart-';
8 this.htmlNamePrefix = 'ays_';
9 this.dbOptions = undefined;
10 this.chartSourceData = undefined;
11 this.chartObj = undefined;
12 this.chartOptions = null;
13 this.chartData = null;
14 this.chartTempData = null;
15 this.chartType = 'pie_chart';
16 this.chartSourceType = 'chart-js';
17 this.chartObject = null;
18
19 this.chartSources = {
20 'pie_chart' : 'Pie Chart',
21 'bar_chart' : 'Bar Chart',
22 'line_chart' : 'Line Chart',
23 }
24
25 this.init();
26
27 return this;
28 }
29
30 ChartBuilderChartsJs.prototype.init = function() {
31 var _this = this;
32 _this.chartSourceData = window.ChartBuilderSourceData;
33 _this.setEvents();
34 _this.initLibraries();
35 _this.setAccordionEvents();
36 };
37
38 // Set events
39 ChartBuilderChartsJs.prototype.setEvents = function(e){
40 var _this = this;
41
42 _this.chartType = _this.chartSourceData.chartType;
43 _this.chartSourceType = _this.chartSourceData.chartSourceType;
44 _this.chartData = _this.chartSourceData.source;
45 _this.loadChartBySource();
46 _this.configureOptions();
47 _this.resizeChart();
48
49 /* == Tabulation == */
50 _this.$el.on('click', '.nav-tab-wrapper a.nav-tab' , _this.changeTabs);
51 /* */
52
53 /* == Notifications dismiss button == */
54 _this.$el.on('click', '.notice-dismiss', function (e) {
55 _this.changeCurrentUrl('status');
56 });
57
58 _this.$el.on('click', '.toggle_ddmenu' , _this.toggleDDmenu);
59 /* */
60
61 /* Add Manual data */
62 _this.$el.on("click" , '.'+_this.htmlClassPrefix+'add-new-row-box', function(){
63 _this.addChartDataRow();
64 });
65
66 _this.$el.on("click" , '.'+_this.htmlClassPrefix+'add-new-column-box', function(){
67 _this.addChartDataColumn();
68 });
69
70 _this.$el.on('click', '.'+_this.htmlClassPrefix+'show-on-chart-bttn', function(e){
71 e.preventDefault();
72 _this.showOnChart();
73 });
74
75 /* */
76
77 /* Delete data */
78 _this.$el.on("click" , '.'+_this.htmlClassPrefix+'chart-source-data-remove-row', function(){
79 _this.deleteChartDataRow($(this));
80 _this.detectManualChange();
81 });
82 _this.$el.on("click" , '.'+_this.htmlClassPrefix+'chart-source-data-remove-col', function(){
83 _this.deleteChartDataColumn($(this));
84 _this.detectManualChange();
85 });
86 _this.$el.on('mouseenter', '.'+_this.htmlClassPrefix+'chart-source-data-remove-block', function() {
87 $(this).find('path').css('fill', '#ff0000');
88 });
89 _this.$el.on('mouseleave', '.'+_this.htmlClassPrefix+'chart-source-data-remove-block', function() {
90 $(this).find('path').css('fill', '#b8b8b8');
91 });
92 /* */
93
94 /* Save with Ctrl + S */
95 _this.$el.on('keydown', $(document), _this.quickSaveHotKeys);
96 /* */
97
98 // Submit buttons disabling
99 _this.$el.on('click', '.'+_this.htmlClassPrefix+'loader-banner', _this.submitOnce);
100 /* */
101
102 // Disabling submit when press enter button on inputing
103 $(document).on("keypress", '.ays-text-input', _this.keyBoardConfig.bind(_this));
104 /* */
105
106 // Modal close
107 $(document).on('click', '.ays-close', function () {
108 $(this).parents('.ays-modal').aysModal('hide');
109 });
110
111 // Changing source type to manual
112 _this.$el.on('input', '.'+_this.htmlClassPrefix+'chart-source-data-content input', function () {
113 _this.detectManualChange();
114 });
115
116 // Shortcode text for editor tooltip
117 $(document).find('strong.ays-chart-shortcode-box').on('mouseleave', function(){
118 var _this = $(this);
119
120 _this.attr('data-original-title', aysChartBuilderAdmin.clickForCopy);
121 _this.attr("data-bs-original-title", aysChartBuilderAdmin.clickForCopy);
122 _this.attr("title", aysChartBuilderAdmin.clickForCopy);
123 });
124
125 _this.$el.find('.'+_this.htmlClassPrefix+'toggle-hidden-option').on('change', function () {
126 // var animationOptions = _this.$el.find('.'+_this.htmlClassPrefix+'hidden-options-section');
127 var currentSettings = $(this).parents('.' + _this.htmlClassPrefix + 'settings-data-main-wrap')
128 var hiddenSection = currentSettings.find('.' + _this.htmlClassPrefix + 'hidden-options-section');
129 var notHiddenSection = currentSettings.find('.' + _this.htmlClassPrefix + 'not-hidden-options-section');
130
131 if ($(this).is(':checked')) {
132 hiddenSection.removeClass('display_none');
133 notHiddenSection.addClass('display_none');
134 } else {
135 hiddenSection.addClass('display_none');
136 notHiddenSection.removeClass('display_none');
137 }
138 });
139
140 _this.$el.on("click", '.'+_this.htmlClassPrefix+'chart-source-data-sort', function(){
141 _this.sortDataByColumn($(this));
142 _this.detectManualChange();
143 });
144
145 // Live preview
146 _this.liveSettingsPreview();
147 }
148
149 ChartBuilderChartsJs.prototype.liveSettingsPreview = function () {
150 var _this = this;
151
152 // title
153 _this.$el.find('#ays-title').on('input', function () {
154 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').text($(this).val());
155 });
156
157 // description
158 _this.$el.find('#'+_this.htmlClassPrefix+'description').on('input', function () {
159 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').text($(this).val());
160 });
161
162 // chart styles
163 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-width').on('input', function () {
164 _this.chartSourceData.settings.border_width = $(this).val();
165 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('border-width', $(this).val() + 'px');
166 _this.chartObject.update();
167 });
168
169 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-radius').on('input', function () {
170 _this.chartSourceData.settings.border_radius = $(this).val();
171 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('border-radius', $(this).val() + 'px');
172 _this.chartObject.update();
173 });
174
175 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-color').on('input', function () {
176 _this.chartSourceData.settings.border_color = $(this).val();
177 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('border-color', $(this).val());
178 _this.chartObject.update();
179 });
180
181 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-style').on('change', function () {
182 _this.chartSourceData.settings.border_style = $(this).val();
183 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('border-style', $(this).val());
184 _this.chartObject.update();
185 });
186
187 _this.$el.find('#'+_this.htmlClassPrefix+'option-background-color').on('input', function () {
188 _this.chartSourceData.settings.background_color = $(this).val();
189 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('background-color', $(this).val());
190 _this.chartObject.update();
191 });
192
193 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-width-with-title').on('input', function () {
194 _this.chartSourceData.settings.border_width_with_title = $(this).val();
195 _this.$el.find('.'+_this.htmlClassPrefix+'container').css('border-width', $(this).val() + 'px');
196 _this.chartObject.update();
197 });
198
199 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-radius-with-title').on('input', function () {
200 _this.chartSourceData.settings.border_radius_with_title = $(this).val();
201 _this.$el.find('.'+_this.htmlClassPrefix+'container').css('border-radius', $(this).val() + 'px');
202 _this.chartObject.update();
203 });
204
205 _this.$el.find('#'+_this.htmlClassPrefix+'option-box-shadow').on('change', function () {
206 console.log($(this).is(':checked'));
207 if ($(this).is(':checked')) {
208 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('box-shadow', '2px 2px 10px 2px ' + _this.chartSourceData.settings.box_shadow_color);
209 } else {
210 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('box-shadow', 'unset');
211 }
212 _this.chartObject.update();
213 });
214
215 _this.$el.find('#'+_this.htmlClassPrefix+'option-box-shadow-color').on('input', function () {
216 if (_this.$el.find('#'+_this.htmlClassPrefix+'option-box-shadow').is(':checked')) {
217 _this.chartSourceData.settings.box_shadow_color = $(this).val();
218 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('box-shadow', '2px 2px 10px 2px ' + _this.chartSourceData.settings.box_shadow_color);
219 _this.chartObject.update();
220 }
221 });
222
223 //title
224 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-gap').on('input', function () {
225 _this.chartSourceData.settings.title_gap = $(this).val();
226 _this.$el.find('.'+_this.htmlClassPrefix+'header-container').attr('style', 'margin-bottom: ' + $(this).val() + 'px' + ' !important;');
227 _this.chartObject.update();
228 });
229
230 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-color').on('input', function () {
231 _this.chartSourceData.settings.title_color = $(this).val();
232 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('color', $(this).val());
233 _this.chartObject.update();
234 });
235
236 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-font-size').on('input', function () {
237 _this.chartSourceData.settings.title_font_size = $(this).val();
238 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('font-size', $(this).val() + 'px');
239 _this.chartObject.update();
240 });
241
242 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-bold').on('change', function () {
243 _this.chartSourceData.settings.title_bold = $(this).is(':checked') ? 'checked' : '';
244 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('font-weight', $(this).is(':checked') ? 'bold' : 'normal');
245 _this.chartObject.update();
246 });
247
248 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-italic').on('change', function () {
249 _this.chartSourceData.settings.title_italic = $(this).is(':checked') ? 'checked' : '';
250 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('font-style', $(this).is(':checked') ? 'italic' : 'normal');
251 _this.chartObject.update();
252 });
253
254 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-text-shadow').on('change', function () {
255 if ($(this).is(':checked')) {
256 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('text-shadow', '2px 2px 5px ' + _this.chartSourceData.settings.title_shadow_color);
257 } else {
258 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('text-shadow', 'unset');
259 }
260 _this.chartObject.update();
261 });
262
263 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-shadow-color').on('input', function () {
264 if (_this.$el.find('#'+_this.htmlClassPrefix+'option-title-text-shadow').is(':checked')) {
265 _this.chartSourceData.settings.title_shadow_color = $(this).val();
266 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('text-shadow', '2px 2px 5px ' + $(this).val());
267 _this.chartObject.update();
268 }
269 });
270
271 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-position').on('change', function () {
272 _this.chartSourceData.settings.title_position = $(this).val();
273 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('text-align', $(this).val());
274 _this.chartObject.update();
275 });
276
277 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-text-transform').on('change', function () {
278 _this.chartSourceData.settings.title_transform = $(this).val();
279 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('text-transform', $(this).val());
280 _this.chartObject.update();
281 });
282
283 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-text-decoration').on('change', function () {
284 _this.chartSourceData.settings.title_decoration = $(this).val();
285 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('text-decoration', $(this).val());
286 _this.chartObject.update();
287 });
288
289 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-letter-spacing').on('input', function () {
290 _this.chartSourceData.settings.title_letter_spacing = $(this).val();
291 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('letter-spacing', $(this).val() + 'px');
292 _this.chartObject.update();
293 });
294
295 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-gap-description').on('input', function () {
296 _this.chartSourceData.settings.title_gap_description = $(this).val();
297 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('margin-bottom', $(this).val() + 'px');
298 _this.chartObject.update();
299 });
300
301 // description
302 _this.$el.find('#'+_this.htmlClassPrefix+'description').on('input', function () {
303 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').text($(this).val());
304 });
305
306 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-color').on('input', function () {
307 _this.chartSourceData.settings.description_color = $(this).val();
308 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('color', $(this).val());
309 _this.chartObject.update();
310 });
311
312 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-font-size').on('input', function () {
313 _this.chartSourceData.settings.description_font_size = $(this).val();
314 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('font-size', $(this).val() + 'px');
315 _this.chartObject.update();
316 });
317
318 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-bold').on('change', function () {
319 _this.chartSourceData.settings.description_bold = $(this).is(':checked') ? 'checked' : '';
320 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('font-weight', $(this).is(':checked') ? 'bold' : 'normal');
321 _this.chartObject.update();
322 });
323
324 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-italic').on('change', function () {
325 _this.chartSourceData.settings.description_italic = $(this).is(':checked') ? 'checked' : '';
326 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('font-style', $(this).is(':checked') ? 'italic' : 'normal');
327 _this.chartObject.update();
328 });
329
330 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-text-shadow').on('change', function () {
331 if ($(this).is(':checked')) {
332 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('text-shadow', '2px 2px 5px ' + _this.chartSourceData.settings.description_shadow_color);
333 } else {
334 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('text-shadow', 'unset');
335 }
336 _this.chartObject.update();
337 });
338
339 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-shadow-color').on('input', function () {
340 if (_this.$el.find('#'+_this.htmlClassPrefix+'option-description-text-shadow').is(':checked')) {
341 _this.chartSourceData.settings.description_shadow_color = $(this).val();
342 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('text-shadow', '2px 2px 5px ' + $(this).val());
343 _this.chartObject.update();
344 }
345 });
346
347 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-position').on('change', function () {
348 _this.chartSourceData.settings.description_position = $(this).val();
349 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('text-align', $(this).val());
350 _this.chartObject.update();
351 });
352
353 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-text-transform').on('change', function () {
354 _this.chartSourceData.settings.description_transform = $(this).val();
355 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('text-transform', $(this).val());
356 _this.chartObject.update();
357 });
358
359 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-text-decoration').on('change', function () {
360 _this.chartSourceData.settings.description_decoration = $(this).val();
361 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('text-decoration', $(this).val());
362 _this.chartObject.update();
363 });
364
365 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-letter-spacing').on('input', function () {
366 _this.chartSourceData.settings.description_letter_spacing = $(this).val();
367 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('letter-spacing', $(this).val() + 'px');
368 _this.chartObject.update();
369 });
370
371 // advanced options
372 _this.$el.find('#'+_this.htmlClassPrefix+'option-outer-radius').on('input', function () {
373 _this.chartSourceData.settings.outer_radius = $(this).val();
374 _this.chartObject.options.radius = _this.chartSourceData.settings.outer_radius;
375 _this.chartObject.update();
376 });
377
378 _this.$el.find('#'+_this.htmlClassPrefix+'option-slice-spacing').on('input', function () {
379 _this.chartSourceData.settings.slice_spacing = $(this).val();
380 _this.chartObject.options.spacing = _this.chartSourceData.settings.slice_spacing;
381 _this.chartObject.update();
382 });
383
384 _this.$el.find('#'+_this.htmlClassPrefix+'option-circumference').on('input', function () {
385 _this.chartSourceData.settings.circumference = $(this).val();
386 _this.chartObject.options.circumference = _this.chartSourceData.settings.circumference;
387 _this.chartObject.update();
388 });
389
390 _this.$el.find('#'+_this.htmlClassPrefix+'option-start-angle').on('input', function () {
391 _this.chartSourceData.settings.start_angle = $(this).val();
392 _this.chartObject.options.rotation = _this.chartSourceData.settings.start_angle;
393 _this.chartObject.update();
394 });
395 }
396
397 ChartBuilderChartsJs.prototype.detectManualChange = function (e) {
398 var input = $(document).find('input[name="ays_source_type"]');
399 if (input.val() !== 'manual') input.val('manual');
400 }
401
402 ChartBuilderChartsJs.prototype.keyBoardConfig = function(e) {
403 if (e.which == 13) {
404 if ($(document).find("#ays-charts-form-chart-js").length !== 0 || $(document).find("#ays-settings-form").length !== 0) {
405 var parent = $(e.target).parents('.ays-chart-chart-source-data-edit-block');
406 var index = $(e.target).parents('.ays-chart-chart-source-data-input-box').index();
407 index = parent.index() == 0 ? index - 1 : index - 2;
408
409 if (e.shiftKey) {
410 var prevRow;
411 if (parent.prev('.ays-chart-chart-source-data-edit-block').length === 0) {
412 return false;
413 }
414 prevRow = parent.prev('.ays-chart-chart-source-data-edit-block');
415
416 prevRow.children('.ays-chart-chart-source-data-input-box').eq(index).find('.ays-text-input').focus();
417 } else {
418 var nextRow;
419 if (parent.next('.ays-chart-chart-source-data-edit-block').length === 0) {
420 this.addChartDataRow();
421 }
422 nextRow = parent.next('.ays-chart-chart-source-data-edit-block');
423
424 nextRow.children('.ays-chart-chart-source-data-input-box').eq(index).find('.ays-text-input').focus();
425 }
426
427 return false;
428 }
429 }
430 }
431
432 // Change tabs (tabulation)
433 ChartBuilderChartsJs.prototype.changeTabs = function(e){
434 if(! $(this).hasClass('no-js')){
435 var elemenetID = $(this).attr('href');
436 var active_tab = $(this).attr('data-tab');
437 $(document).find('.nav-tab-wrapper a.nav-tab').each(function () {
438 if ($(this).hasClass('nav-tab-active')) {
439 $(this).removeClass('nav-tab-active');
440 }
441 });
442 $(this).addClass('nav-tab-active');
443 $(document).find('.ays-tab-content').each(function () {
444 $(this).removeClass('ays-tab-content-active');
445 });
446 $(document).find("[name='ays_chart_tab']").val(active_tab);
447 $('.ays-tab-content' + elemenetID).addClass('ays-tab-content-active');
448 e.preventDefault();
449 }
450 }
451
452 ChartBuilderChartsJs.prototype.changeCurrentUrl = function(key){
453 var linkModified = location.href.split('?')[1].split('&');
454 for(var i = 0; i < linkModified.length; i++){
455 if(linkModified[i].split("=")[0] == key){
456 linkModified.splice(i, 1);
457 }
458 }
459 linkModified = linkModified.join('&');
460 window.history.replaceState({}, document.title, '?'+linkModified);
461 }
462
463 ChartBuilderChartsJs.prototype.toggleDDmenu = function(e){
464 var ddmenu = $(this).next();
465 var state = ddmenu.attr('data-expanded');
466 switch (state) {
467 case 'true':
468 $(this).find('.ays_fa').css({
469 transform: 'rotate(0deg)'
470 });
471 ddmenu.attr('data-expanded', 'false');
472 break;
473 case 'false':
474 $(this).find('.ays_fa').css({
475 transform: 'rotate(90deg)'
476 });
477 ddmenu.attr('data-expanded', 'true');
478 break;
479 }
480 }
481
482 ChartBuilderChartsJs.prototype.submitOnce = function(el) {
483 setTimeout(function() {
484 $(document).find('.ays-chart-loader-banner').attr('disabled', true);
485 }, 50);
486
487 setTimeout(function() {
488 $(document).find('.ays-chart-loader-banner').attr('disabled', false);
489 }, 5000);
490 }
491
492 // Load charts by given type main function
493 ChartBuilderChartsJs.prototype.initLibraries = function (){
494 var _this = this;
495
496 _this.$el.find('#ays-chart-option-create-author').select2({
497 placeholder: aysChartBuilderAdmin.selectUser,
498 minimumInputLength: 1,
499 allowClear: true,
500 language: {
501 searching: function() {
502 return aysChartBuilderAdmin.searching;
503 },
504 inputTooShort: function () {
505 return aysChartBuilderAdmin.pleaseEnterMore;
506 }
507 },
508 ajax: {
509 url: ajaxurl,
510 dataType: 'json',
511 data: function (response) {
512 var checkedUsers = _this.$el.find('#ays-chart-option-create-author').val();
513 return {
514 action: _this.ajaxAction,
515 function: window.aysChartBuilderChartSettings.ajax['actions']['author_user_search'],
516 security: window.aysChartBuilderChartSettings.ajax['nonces']['author_user_search'],
517 params: {
518 search: response.term,
519 val: checkedUsers
520 }
521 };
522 }
523 }
524 });
525
526 _this.$el.find('.' + _this.htmlClassPrefix + 'chart-source-data-content').sortable({
527 items: "> div." + _this.htmlClassPrefix + "chart-source-data-edit-block:not(:first)",
528 handle: "." + _this.htmlClassPrefix + "chart-source-data-move-row",
529 update: function (event, ui) {
530 _this.$el.find('div.' + _this.htmlClassPrefix + 'chart-source-data-edit-block:not(:first)').each(function (index) {
531 $(this).attr('data-source-id', index + 1);
532 $(this).find("input.ays-text-input").attr('name', 'ays_chart_source_data[' + (index + 1) + '][]')
533 });
534 }
535 });
536 }
537
538 // Load charts by given type main function
539 ChartBuilderChartsJs.prototype.loadChartBySource = function(isChangedType = false){
540 var _this = this;
541
542 if( ! _this.chartType ){
543 _this.chartType = _this.chartSourceData.chartType;
544 }
545
546 if(typeof _this.chartType !== undefined && _this.chartType){
547 switch (_this.chartType) {
548 case 'pie_chart':
549 _this.pieChartView(isChangedType);
550 break;
551 case 'bar_chart':
552 _this.barChartView(isChangedType);
553 break;
554 case 'line_chart':
555 _this.lineChartView(isChangedType);
556 break;
557 default:
558 _this.pieChartView(isChangedType);
559 break;
560 }
561 }
562 }
563
564 // Load chart by pie chart
565 ChartBuilderChartsJs.prototype.pieChartView = function(isChangedType){
566 var _this = this;
567 var getChartSource = _this.chartSourceData.source;
568
569 var dataTypes = _this.chartConvertData( getChartSource );
570
571 var settings = _this.chartSourceData.settings;
572 var nSettings = _this.configOptionsForCharts(settings);
573
574 var ctx = document.getElementById(_this.htmlClassPrefix + '-canvas');
575
576 _this.chartObject = new Chart(ctx, {
577 type: 'pie',
578 data: {
579 labels: dataTypes?.labels,
580 datasets: dataTypes?.dataSets,
581 },
582 options: {
583 radius: nSettings.outerRadius,
584 spacing: nSettings.sliceSpacing,
585 circumference: nSettings.circumference,
586 rotation: nSettings.startAngle,
587 }
588 });
589
590 _this.resizeChart();
591 }
592
593 // Load chart by bar chart
594 ChartBuilderChartsJs.prototype.barChartView = function(isChangedType){
595 var _this = this;
596 var getChartSource = _this.chartSourceData.source;
597
598 var dataTypes = _this.chartConvertData( getChartSource );
599
600 var settings = _this.chartSourceData.settings;
601 var nSettings = _this.configOptionsForCharts(settings);
602
603 var ctx = document.getElementById(_this.htmlClassPrefix + '-canvas');
604
605 _this.chartObject = new Chart(ctx, {
606 type: 'bar',
607 data: {
608 labels: dataTypes?.labels,
609 datasets: dataTypes?.dataSets,
610 },
611 options: {
612 // indexAxis: nSettings.indexAxis,
613 }
614 });
615
616 _this.resizeChart();
617 }
618
619 // Load chart by line chart
620 ChartBuilderChartsJs.prototype.lineChartView = function(isChangedType){
621 var _this = this;
622 var getChartSource = _this.chartSourceData.source;
623
624 var dataTypes = _this.chartConvertData( getChartSource );
625
626 var settings = _this.chartSourceData.settings;
627 var nSettings = _this.configOptionsForCharts(settings);
628
629 var ctx = document.getElementById(_this.htmlClassPrefix + '-canvas');
630
631 _this.chartObject = new Chart(ctx, {
632 type: 'line',
633 data: {
634 labels: dataTypes?.labels,
635 datasets: dataTypes?.dataSets,
636 },
637 options: {
638 // indexAxis: nSettings.indexAxis,
639 }
640 });
641
642 _this.resizeChart();
643 }
644
645 /*
646 Configure all settings for all chart types
647 Getting settings for each chart type in respective function
648 */
649 ChartBuilderChartsJs.prototype.configOptionsForCharts = function (settings) {
650 var newSettings = {};
651
652 // newSettings.indexAxis = (settings['index_axis'] == 'checked') ? 'y' : 'x';
653 newSettings.outerRadius = settings['outer_radius'];
654 newSettings.sliceSpacing = settings['slice_spacing'];
655 newSettings.circumference = settings['circumference'];
656 newSettings.startAngle = settings['start_angle'];
657
658 return newSettings;
659 }
660
661 // Detect window resize moment to draw charts responsively
662 ChartBuilderChartsJs.prototype.resizeChart = function(){
663 var _this = this;
664
665 //create trigger to resizeEnd event
666 $(window).resize(function() {
667 if(this.resizeTO) clearTimeout(this.resizeTO);
668 this.resizeTO = setTimeout(function() {
669 $(this).trigger('resizeEnd');
670 }, 100);
671 });
672
673 //redraw graph when window resize is completed
674 $(window).on('resizeEnd', function() {
675 _this.chartObject.resize();
676 });
677
678 }
679
680 ChartBuilderChartsJs.prototype.chartConvertData = function( data ){
681 var _this = this;
682 var dataTypes = [];
683
684 var dataTypes = Array.from({ length: data[0].length }, () => []);
685 for (var i = 0; i < data.length; i++) {
686 for (var j = 0; j < data[i].length; j++) {
687 if (i === 0) {
688 dataTypes[j].push(data[i][j]);
689 } else {
690 dataTypes[j].push(i === 0 || j === 0 ? data[i][j] : +data[i][j]);
691 }
692 }
693 }
694
695 var labels = dataTypes.shift();
696 labels.shift();
697 var dataSets = dataTypes.map(item => ({
698 label: item[0],
699 data: item.slice(1).map(Number),
700 }));
701
702 return {labels, dataSets};
703 }
704
705 // Update chart data and display immediately
706 ChartBuilderChartsJs.prototype.updateChartData = function(){
707 var _this = this;
708 var newData = _this.chartConvertData( _this.chartData );
709
710 _this.chartObject.data = {
711 ..._this.chartObject.data,
712 labels: newData?.labels,
713 datasets: newData?.dataSets,
714 },
715 _this.chartObject.update();
716 }
717
718 ChartBuilderChartsJs.prototype.addChartDataRow = function (element){
719 var _this = this;
720 var content = '';
721
722 var addedTermsandConds = this.$el.find("."+this.htmlClassPrefix+"chart-source-data-edit-block");
723 var addedTermsandCondsId = this.$el.find("."+this.htmlClassPrefix+"chart-source-data-edit-block:last-child");
724 var dataId = addedTermsandConds.length >= 1 ? addedTermsandCondsId.data("sourceId") + 1 : 1;
725 var colCount = addedTermsandConds.first().children().length - 1;
726
727 var termsCondsMessageAttrName = this.newTermsCondsMessageAttrName( this.htmlNamePrefix + 'chart_source_data' , dataId );
728
729 content += '<div class = "'+this.htmlClassPrefix+'chart-source-data-edit-block" data-source-id="' + dataId + '" >';
730 content += '<div class="'+this.htmlClassPrefix+'chart-source-data-move-block '+this.htmlClassPrefix+'chart-source-data-move-row">';
731 content += '<svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><path d="M278.6 9.4c-12.5-12.5-32.8-12.5-45.3 0l-64 64c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l9.4-9.4V224H109.3l9.4-9.4c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-64 64c-12.5 12.5-12.5 32.8 0 45.3l64 64c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3l-9.4-9.4H224V402.7l-9.4-9.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l64 64c12.5 12.5 32.8 12.5 45.3 0l64-64c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-9.4 9.4V288H402.7l-9.4 9.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l64-64c12.5-12.5 12.5-32.8 0-45.3l-64-64c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l9.4 9.4H288V109.3l9.4 9.4c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3l-64-64z" style="fill: #b8b8b8;" /></svg>';
732 content += '</div>';
733 content += '<div class="'+this.htmlClassPrefix+'icons-box '+this.htmlClassPrefix+'icons-remove-box">';
734 content += '<svg class="'+this.htmlClassPrefix+'chart-source-data-remove-block '+this.htmlClassPrefix+'chart-source-data-remove-row" data-trigger="hover" data-bs-toggle="tooltip" title="Delete row" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M310.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L160 210.7 54.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L114.7 256 9.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L160 301.3 265.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L205.3 256 310.6 150.6z" style="fill: #b8b8b8;" /></svg>';
735 content += '</div>';
736 for (var i = 0; i < colCount; i++) {
737 if (i == 0) {
738 content += '<div class="'+this.htmlClassPrefix+'chart-source-data-input-box '+this.htmlClassPrefix+'chart-source-data-name-input-box" data-cell-id="'+i+'">';
739 content += '<input type="text" class="ays-text-input form-control" name="' + termsCondsMessageAttrName + '">';
740 content += '</div>';
741 } else {
742 content += '<div class="'+this.htmlClassPrefix+'chart-source-data-input-box '+this.htmlClassPrefix+'chart-source-data-input-number" data-cell-id="'+i+'">';
743 content += '<input type="number" class="ays-text-input form-control" name="' + termsCondsMessageAttrName + '" step="any">';
744 content += '</div>';
745 }
746 }
747 content += '</div>';
748
749 this.$el.find('.'+this.htmlClassPrefix+'chart-source-data-content').append(content);
750 $('[data-bs-toggle="tooltip"]').tooltip();
751 }
752
753 ChartBuilderChartsJs.prototype.addChartDataColumn = function (e){
754 var _this = this;
755
756 var rows = _this.$el.find("."+_this.htmlClassPrefix+"chart-source-data-content").children();
757 var lastColId = +$(rows[0]).find('.'+_this.htmlClassPrefix+'chart-source-data-input-box:last-child').attr('data-cell-id');
758 rows.each(function(key, row){
759 var dataIDEach = row.getAttribute('data-source-id');
760 var content = '';
761
762 if (key === 0) {
763 content += '<div class="'+_this.htmlClassPrefix+'chart-source-data-input-box ' +_this.htmlClassPrefix+'chart-source-title-box" data-cell-id="'+(lastColId+1)+'">';
764 content += '<svg class="'+_this.htmlClassPrefix+'chart-source-data-remove-block '+_this.htmlClassPrefix+'chart-source-data-remove-col" data-trigger="hover" data-bs-toggle="tooltip" title="Delete column" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" width="10px">';
765 content += '<path d="M310.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L160 210.7 54.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L114.7 256 9.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L160 301.3 265.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L205.3 256 310.6 150.6z" style="fill: #b8b8b8;" />';
766 content += '</svg>';
767
768 content += '<div class="' + _this.htmlClassPrefix + 'chart-source-data-titles-box-item">';
769 content += '<input type="text" class="ays-text-input form-control ' + _this.htmlClassPrefix+'chart-source-title-input" name="' + _this.newTermsCondsMessageAttrName( _this.htmlNamePrefix + 'chart_source_data' , dataIDEach ) + '">';
770 content += '<svg class="' + _this.htmlClassPrefix + 'chart-source-data-sort" data-sort-order="asc" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 320 512">';
771 content += '<path d="M137.4 41.4c12.5-12.5 32.8-12.5 45.3 0l128 128c9.2 9.2 11.9 22.9 6.9 34.9s-16.6 19.8-29.6 19.8H32c-12.9 0-24.6-7.8-29.6-19.8s-2.2-25.7 6.9-34.9l128-128zm0 429.3l-128-128c-9.2-9.2-11.9-22.9-6.9-34.9s16.6-19.8 29.6-19.8H288c12.9 0 24.6 7.8 29.6 19.8s2.2 25.7-6.9 34.9l-128 128c-12.5 12.5-32.8 12.5-45.3 0z" style="fill: #b8b8b8;" />';
772 content += '</svg>';
773 content += '</div>'
774 content += '</div>';
775 } else {
776 content += '<div class="'+_this.htmlClassPrefix+'chart-source-data-input-box ' +_this.htmlClassPrefix+'chart-source-data-input-number" data-cell-id="'+(lastColId+1)+'">';
777 content += '<input type="number" class="ays-text-input form-control" name="' + _this.newTermsCondsMessageAttrName( _this.htmlNamePrefix + 'chart_source_data' , dataIDEach ) + '" step="any">';
778 content += '</div>';
779 }
780
781 $(row).append(content);
782 $('[data-bs-toggle="tooltip"]').tooltip();
783 });
784 }
785
786 ChartBuilderChartsJs.prototype.deleteChartDataRow = function (element){
787 var _this = this;
788
789 var rows = _this.$el.find("."+_this.htmlClassPrefix+"chart-source-data-content").children();
790 if ((rows.length - 1) >= 2) {
791 var confirm = window.confirm(aysChartBuilderAdmin.confirmRowDelete);
792 if (confirm) {
793 var thisMainParent = element.parent().parent();
794 thisMainParent.remove();
795 }
796 } else {
797 alert(aysChartBuilderAdmin.minRowNotice);
798 }
799
800 element.blur();
801 element.tooltip('hide');
802 }
803
804 ChartBuilderChartsJs.prototype.deleteChartDataColumn = function (element){
805 var _this = this;
806
807 var rows = _this.$el.find("."+_this.htmlClassPrefix+"chart-source-data-content").children();
808 if (rows.eq(1).children('.ays-chart-chart-source-data-input-number').length >= 2) {
809 var confirm = window.confirm(aysChartBuilderAdmin.confirmColDelete);
810 if (confirm) {
811 var parent = element.parents('.ays-chart-chart-source-title-box');
812 var index = _this.returnIndexOfEl(parent);
813 rows.each(function(key, row){
814 var dataRow = $(row).find('.ays-chart-chart-source-data-input-box:not("ays-chart-chart-source-data-name-input-box")');
815 $(dataRow).each(function(ind, cell){
816 if (ind == index) {
817 $(cell).remove();
818 }
819 });
820 });
821 }
822 } else {
823 alert(aysChartBuilderAdmin.minColNotice);
824 }
825
826 element.blur();
827 element.tooltip('hide');
828 }
829
830 ChartBuilderChartsJs.prototype.sortDataByColumn = function (el) {
831 var _this = this;
832
833 var sortingOrder = el.attr('data-sort-order');
834 var colFirst = el.parents('.'+_this.htmlClassPrefix+'chart-source-data-input-box');
835 var colIndex = colFirst.attr('data-cell-id');
836 var colList = colFirst.parents('.'+_this.htmlClassPrefix+'chart-source-data-content').find('.'+_this.htmlClassPrefix+'chart-source-data-input-box[data-cell-id="'+colIndex+'"] input.ays-text-input');
837
838 var sorted = {};
839 colList.each(function(key, input){
840 if (key !== 0) {
841 var rowIndex = $(input).parents('.'+_this.htmlClassPrefix+'chart-source-data-edit-block').attr('data-source-id');
842 sorted[rowIndex] = +input.value
843 }
844 });
845
846 if (sortingOrder === 'asc') {
847 sorted = _this.sortDataAsc(sorted);
848 el.attr('data-sort-order', 'desc');
849 } else if (sortingOrder === 'desc') {
850 sorted = _this.sortDataDesc(sorted);
851 el.attr('data-sort-order', 'asc');
852 } else {
853 sorted = _this.sortDataAsc(sorted);
854 el.attr('data-sort-order', 'desc');
855 }
856
857 var container = _this.$el.find('.'+_this.htmlClassPrefix+'chart-source-data-content');
858 var newContainer = [];
859 sorted.forEach((index, newIndex) => {
860 var row = container.find("."+_this.htmlClassPrefix+"chart-source-data-edit-block[data-source-id='"+index+"']");
861 var inputs = row.find('input.ays-text-input');
862 var inputName = _this.newTermsCondsMessageAttrName(_this.htmlNamePrefix + 'chart_source_data', newIndex + 1);
863
864 $(inputs).each(function (inputIndex, input) {
865 input.setAttribute('name', inputName);
866 });
867
868 newContainer.push(row);
869 });
870 sorted.forEach((index, newIndex) => {
871 var row = container.find("."+_this.htmlClassPrefix+"chart-source-data-edit-block[data-source-id='"+index+"']");
872 newContainer.push(row);
873 });
874
875 container.innerHTML = '';
876 newContainer.forEach(row => {
877 container.append(row);
878 });
879
880 var rows = container.find("."+_this.htmlClassPrefix+"chart-source-data-edit-block");
881 for (var i = 0; i < rows.length; i++) {
882 $(rows[i]).attr('data-source-id', i);
883 }
884 }
885
886 ChartBuilderChartsJs.prototype.sortDataAsc = function (data) {
887 return Object.keys(data).sort(function (a, b) {return data[a] - data[b]});
888 }
889
890 ChartBuilderChartsJs.prototype.sortDataDesc = function (data) {
891 return Object.keys(data).sort(function (a, b) {return data[b] - data[a]});
892 }
893
894 ChartBuilderChartsJs.prototype.returnIndexOfEl = function (element){
895 var i = 0;
896 var elements = element.parent().find('.ays-chart-chart-source-title-box');
897 elements.each(function(key, cell){
898 if ($(cell).is(element)) {
899 i = key;
900 }
901 });
902 return i;
903 }
904
905 ChartBuilderChartsJs.prototype.configureOptions = function() {
906 var _this = this;
907
908 _this.$el.find('.ays-chart-chart-source-title-box').eq(0).find('.ays-chart-chart-source-data-remove-block').css('visibility', 'hidden');
909
910 var removeCols = _this.$el.find('.ays-chart-chart-source-title-box').find('.ays-chart-chart-source-data-remove-block');
911 if (_this.chartType === 'pie_chart') {
912 removeCols.css('visibility', 'hidden');
913 }
914
915 var options = _this.$el.find('.cb-changable-opt');
916 var typeOptions = _this.$el.find('.cb-'+_this.chartType+'-opt');
917 options.addClass('display_none');
918 typeOptions.removeClass('display_none');
919
920 var manualTabs = _this.$el.find('.cb-changable-manual:not(.cb-'+_this.chartType+'-manual)');
921 var typeManualTab = _this.$el.find('.cb-'+_this.chartType+'-manual');
922 manualTabs.remove();
923 typeManualTab.removeClass('display_none');
924
925 var tabs = _this.$el.find('.cb-changable-tab:not(.cb-'+_this.chartType+'-tab)').parents('fieldset.ays-accordion-options-container');
926 var currentTabs = _this.$el.find('.cb-'+_this.chartType+'-tab').parents('fieldset.ays-accordion-options-container');
927 tabs.addClass('display_none');
928 currentTabs.removeClass('display_none');
929 }
930
931 ChartBuilderChartsJs.prototype.newTermsCondsMessageAttrName = function (termCondName, termCondId){
932 var _this = this;
933 return termCondName + '['+ termCondId +'][]';
934 }
935
936 ChartBuilderChartsJs.prototype.setAccordionEvents = function(e){
937 var _this = this;
938
939 _this.$el.on('click', '.ays-accordion-options-header', function(e){
940 _this.openCloseAccordion(e, _this);
941 });
942
943 _this.$el.on('click', '.ays-slices-accordion-options-header', function(e){
944 _this.openCloseAccordion(e, _this, '-slices');
945 });
946
947 _this.$el.on('click', '.ays-series-accordion-options-header', function(e){
948 _this.openCloseAccordion(e, _this, '-series');
949 });
950
951 _this.$el.on('click', '.ays-rows-accordion-options-header', function(e){
952 _this.openCloseAccordion(e, _this, '-rows');
953 });
954 }
955
956 ChartBuilderChartsJs.prototype.openCloseAccordion = function(e, _this, contType = ""){
957 var container = $(e.target).parents('.ays' + contType + '-accordion-options-container');
958 var parent = (contType != "") ? container.parents('.ays-chart' + contType + '-settings') : _this.$el.find('#' + container.parents('.ays-tab-content').attr('id') + ' .ays-accordions-container').eq(0);
959 var index = (contType != "") ? container.index() : -1;
960
961 if( container.attr('data-collapsed') === 'true' ){
962 _this.closeAllAccordions( parent, contType, index );
963 setTimeout(() => {
964 container.find('.ays' + contType + '-accordion-options-content').slideDown();
965 container.attr('data-collapsed', 'false');
966 container.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').find('path').css('fill', '#008cff');
967 container.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').removeClass('ays' + contType + '-accordion-arrow-right').addClass('ays' + contType + '-accordion-arrow-down');
968 }, 150);
969 }else{
970 setTimeout(() => {
971 container.find('.ays' + contType + '-accordion-options-content').slideUp();
972 container.attr('data-collapsed', 'true');
973 container.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').find('path').css('fill', '#c4c4c4');
974 container.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').removeClass('ays' + contType + '-accordion-arrow-down').addClass('ays' + contType + '-accordion-arrow-right');
975 }, 150);
976 }
977 }
978
979 ChartBuilderChartsJs.prototype.closeAllAccordions = function( container, contType, index ){
980 var _this = this;
981
982 container.find('.ays' + contType + '-accordion-options-container').each(function (i){
983 var $this = $(this);
984 if (i != index) {
985 setTimeout(() => {
986 $this.find('.ays' + contType + '-accordion-options-content').slideUp();
987 $this.attr('data-collapsed', 'true');
988 $this.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').find('path').css('fill', '#c4c4c4');
989 $this.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').removeClass('ays' + contType + '-accordion-arrow-down').addClass('ays' + contType + '-accordion-arrow-right');
990 }, 150);
991 }
992 });
993 }
994
995 ChartBuilderChartsJs.prototype.quickSaveHotKeys = function() {
996 $(document).on('keydown', function(e){
997 var saveButton = $(document).find('input#ays-button-apply');
998 if ( saveButton.length > 0 ) {
999 if (!(e.which == 83 && e.ctrlKey) && !(e.which == 19)){
1000 return true;
1001 }
1002 saveButton.trigger("click");
1003 e.preventDefault();
1004 return false;
1005 }
1006 });
1007 }
1008
1009 // Manual data preview button
1010 ChartBuilderChartsJs.prototype.showOnChart = function () { // TODO
1011 var _this = this;
1012
1013 var lastId = $(document).find(".ays-chart-chart-source-data-edit-block:last-child").attr('data-source-id');
1014 var chartData = [];
1015
1016 var rowTitles = $(document).find('.ays-chart-chart-source-data-name-input-box');
1017 rowTitles.each(function(key, el) {
1018 var value = $(el).find('input').val();
1019 if ( value == '' ) {
1020 $(el).find('input').val('Option');
1021 }
1022 });
1023
1024 var form = $(document).find("#ays-charts-form-chart-js");
1025 var data = form.serializeFormJSON();
1026
1027 for (var i = 0; i <= lastId; i++) {
1028 if (data['ays_chart_source_data['+i+'][]'] !== undefined) {
1029 var dataRow = data['ays_chart_source_data['+i+'][]'];
1030 var filteredRow = [];
1031 for (var key = 0; key < dataRow.length; key++) {
1032 var value = dataRow[key];
1033 if (value != '') {
1034 filteredRow.push(value);
1035 } else {
1036 if (i == 0) {
1037 filteredRow.push('Title'+key);
1038 } else {
1039 filteredRow.push('0');
1040 }
1041 }
1042 }
1043 if (filteredRow.length != 0) {
1044 chartData.push(filteredRow);
1045 }
1046 }
1047 }
1048
1049 _this.chartData = chartData;
1050 _this.updateChartData();
1051 }
1052
1053 ChartBuilderChartsJs.prototype.htmlDecode = function (input) {
1054 if (!input) return input;
1055
1056 var e = document.createElement('div');
1057 e.innerHTML = input;
1058 return e.childNodes[0].nodeValue;
1059 }
1060
1061 $.fn.ChartBuilderChartsJsMain = function(options) {
1062 return this.each(function() {
1063 if (!$.data(this, 'ChartBuilderChartsJsMain')) {
1064 $.data(this, 'ChartBuilderChartsJsMain', new ChartBuilderChartsJs(this, options));
1065 } else {
1066 try {
1067 $(this).data('ChartBuilderChartsJsMain').init();
1068 } catch (err) {
1069 console.error('ChartBuilderChartsJsMain has not initiated properly');
1070 }
1071 }
1072 });
1073 };
1074 $(document).find('#ays-charts-form-chart-js').ChartBuilderChartsJsMain();
1075
1076 })(jQuery);
1077
1078 (function ($) {
1079
1080 $.fn.serializeFormJSON = function () {
1081 let o = {},
1082 a = this.serializeArray();
1083 $.each(a, function () {
1084 if (o[this.name]) {
1085 if (!o[this.name].push) {
1086 o[this.name] = [o[this.name]];
1087 }
1088 o[this.name].push(this.value || '');
1089 } else {
1090 o[this.name] = this.value || '';
1091 }
1092 });
1093 return o;
1094 };
1095
1096 $.fn.lock = function () {
1097 $(this).each(function () {
1098 var $this = $(this);
1099 var position = $this.css('position');
1100
1101 if (!position) {
1102 position = 'static';
1103 }
1104
1105 switch (position) {
1106 case 'absolute':
1107 case 'relative':
1108 break;
1109 default:
1110 $this.css('position', 'relative');
1111 break;
1112 }
1113 $this.data('position', position);
1114
1115 var width = $this.width(),
1116 height = $this.height();
1117
1118 var locker = $('<div class="locker"></div>');
1119 locker.width(width).height(height);
1120
1121 var loader = $('<div class="locker-loader"></div>');
1122 loader.width(width).height(height);
1123
1124 locker.append(loader);
1125 $this.append(locker);
1126 $(window).resize(function () {
1127 $this.find('.locker,.locker-loader').width($this.width()).height($this.height());
1128 });
1129 });
1130
1131 return $(this);
1132 };
1133
1134 $.fn.unlock = function () {
1135 $(this).each(function () {
1136 $(this).find('.locker').remove();
1137 $(this).css('position', $(this).data('position'));
1138 });
1139
1140 return $(this);
1141 };
1142 })(jQuery);