PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.11.9
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.11.9
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 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.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
visualizer / js / library.js

library.js in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.11.9, at js/library.js

254 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global visualizer */
2 /* global alert */
3
4 (function (wpmv) {
5 var vm, vmv;
6
7 vm = visualizer.media = {};
8 vmv = vm.view = {};
9
10 vmv.Chart = wpmv.MediaFrame.extend({
11 initialize: function () {
12 var self = this;
13
14 _.defaults(self.options, {
15 action: '',
16 state: 'iframe:visualizer'
17 });
18
19 wpmv.MediaFrame.prototype.initialize.apply(self, arguments);
20
21 wpmv.settings.tabUrl = self.options.action;
22 self.createIframeStates();
23 },
24
25 open: function () {
26 try{
27 wpmv.MediaFrame.prototype.open.apply(this, arguments);
28 }catch(error){
29 alert(visualizer.i10n.conflict);
30 }
31 this.$el.addClass('hide-menu');
32 }
33 });
34 })(wp.media.view);
35
36 function createPopupProBlocker( $ , e ) {
37 if ( ! visualizer.is_pro_user && e.target.classList.contains('viz-is-pro-chart') ) {
38 $("#overlay-visualizer").css("display", "block");
39 $(".vizualizer-renew-notice-popup").css("display", "block");
40 return true;
41 }
42 return false;
43 }
44
45 (function ($, vmv, vu) {
46 var resizeTimeout;
47
48 $.fn.adjust = function () {
49 return $(this).each(function () {
50 var width = $('#visualizer-library').width(),
51 margin = width * 0.02;
52
53 width *= 0.305;
54 $(this).prev( '.visualizer-chart-title' ).width(width - 14);
55 var ChartHeight = width * 0.93;
56 if ( $( '.visualizer-nochart-canvas' ).length === 0 ) {
57 ChartHeight = width * 0.78;
58 if ( $( '#visualizer-sidebar' ).hasClass('one-columns') ) {
59 ChartHeight = width * 0.92;
60 }
61 }
62 $(this).width(width).height( ChartHeight );
63 });
64 };
65
66 $('.visualizer-chart-canvas').adjust();
67
68 $(document).ready(function () {
69 // clears the filters in the library form and submits.
70 $('#viz-lib-reset').on('click', function(e){
71 e.preventDefault();
72 $(this).parent('form')[0].reset();
73 $(this).parent('form').find('.viz-filter').each(function(index, el){
74 var tag = $(el).prop('tagName').toLowerCase() + (typeof $(el).attr('type') !== 'undefined' ? $(el).attr('type').toLowerCase() : '');
75 switch(tag){
76 case 'select':
77 $(el).prop('selectedIndex', 0);
78 break;
79 case 'inputtext':
80 $(el).val('');
81 break;
82 }
83
84 });
85 $(this).parent('form').submit();
86 });
87
88 $('.visualizer-chart-shortcode').click(function (event) {
89
90 if ( createPopupProBlocker( $, event ) ) {
91 event.preventDefault();
92 event.stopPropagation();
93 return;
94 }
95
96 var range, selection;
97
98 if (window.getSelection && document.createRange) {
99 selection = window.getSelection();
100 range = document.createRange();
101 range.selectNodeContents(event.target);
102 selection.removeAllRanges();
103 selection.addRange(range);
104 } else if (document.selection && document.body.createTextRange) {
105 range = document.body.createTextRange();
106 range.moveToElementText(event.target);
107 range.select();
108 }
109 });
110
111 $( '.visualizer-languages-list' ).on( 'click', '[data-lang_code]', function() {
112 if ( $(this).find( 'i' ).hasClass( 'otgs-ico-add' ) ) {
113 vu.create = vu.create + '&lang=' + $(this).data('lang_code') + '&parent_chart_id=' + $(this).data('chart');
114 $('.add-new-chart').click();
115 } else {
116 vu.edit = vu.edit + '&lang=' + $(this).data('lang_code') + '&chart=' + $(this).data('chart');
117 $('.visualizer-chart-edit').click();
118 }
119 } );
120
121 $('.add-new-chart').click(function () {
122 var wnd = window,
123 view = new vmv.Chart({action: vu.create});
124 vu.create = vu.create.replace(/[\?&]lang=[^&]+/, '').replace(/[\?&]parent_chart_id=[^&]+/, '');
125
126 window.parent.addEventListener('message', function(event){
127 switch(event.data) {
128 case 'visualizer:mediaframe:close':
129 view.close();
130 break;
131 }
132 }, false);
133
134 // remove the 'type' while refreshing the library page on creation of a new chart.
135 // this is to avoid cases where users have filtered for chart type A and end up creating chart type B
136 // remove 'vaction' as well so that additional actions are removed
137 wnd.send_to_editor = function () {
138 wnd.location.href = vu.base.replace(/type=[a-zA-Z]*/, '').replace(/vaction/, '');
139 };
140 view.open();
141
142 return false;
143 });
144
145 $('.visualizer-chart-edit').click(function (event) {
146
147 if ( createPopupProBlocker( $, event ) ) {
148 return;
149 }
150
151 var wnd = window;
152 var view = new vmv.Chart( {
153 action: vu.edit.indexOf('&chart') != -1 ? vu.edit : vu.edit + '&chart=' + $(this).attr('data-chart')
154 } );
155 vu.edit = vu.edit.replace(/[\?&]lang=[^&]+/, '');
156
157 wnd.send_to_editor = function () {
158 wnd.location.href = wnd.location.href.replace(/vaction/, '');
159 };
160
161 view.open();
162
163 return false;
164 });
165 $(".visualizer-chart-clone").on("click", function ( event ) {
166 if ( createPopupProBlocker( $, event ) ) {
167 event.preventDefault();
168 }
169 });
170
171 $(".visualizer-chart-export").on("click", function (event) {
172
173 if ( createPopupProBlocker( $, event ) ) {
174 return;
175 }
176
177 $.ajax({
178 url: $(this).attr("data-chart"),
179 method: "get",
180 success: function (data, textStatus, jqXHR) {
181 var a = document.createElement("a");
182 document.body.appendChild(a);
183 a.style = "display: none";
184 var blob = new Blob([data.data.csv], {type: "application/csv"}),
185 url = window.URL.createObjectURL(blob);
186 a.href = url;
187 a.download = data.data.name;
188 a.click();
189 setTimeout(function () {
190 window.URL.revokeObjectURL(url);
191 }, 100);
192 }
193 });
194 return false;
195 });
196
197 $(".visualizer-chart-image").on("click", function (event) {
198 if ( createPopupProBlocker( $, event ) ) {
199 return;
200 }
201 $('body').trigger('visualizer:action:specificchart', {action: 'image', id: $(this).attr("data-chart"), data: null, dataObj: {name: $(this).attr("data-chart-title")}});
202 return false;
203 });
204
205 // if vaction=addnew is found as a GET request parameter, show the modal.
206 if(location.href.indexOf('vaction=addnew') !== -1){
207 $('.add-new-chart').first().trigger('click');
208 }
209
210 //if vaction=edit is found as a GET request parameter, show the modal.
211 if(location.href.indexOf('vaction=edit') !== -1 && location.href.indexOf('chart=') !== -1){
212 const chartId = location.href.split('chart=')[1].split('&')[0];
213 $('.visualizer-chart-edit').attr('data-chart', chartId).trigger('click');
214 }
215
216 $(window).resize(function () {
217 clearTimeout(resizeTimeout);
218 resizeTimeout = setTimeout(function () {
219 $('.visualizer-chart-canvas').adjust();
220 }, 100);
221 });
222
223 $('.visualizer-error i.error').on('click', function(){
224 alert( $(this).attr('data-viz-error') );
225 });
226 $('.visualizer-chart:not(.visualizer-chart-display), .visualizer-library-pagination').fadeIn(500);
227 });
228 })(jQuery, visualizer.media.view, visualizer.urls);
229
230
231 document.querySelectorAll('.visualizer-chart').forEach(function (chart) {
232 const translatable = chart.querySelector('.visualizer-languages-list');
233 if ( ! translatable ) {
234 return;
235 }
236
237 const chartId = chart.querySelector('.visualizer-chart-canvas')?.id?.replace('visualizer-', '');
238
239 if ( ! chartId ) {
240 return;
241 }
242
243 const translatableActions = translatable.querySelectorAll('[data-lang_code]');
244 translatableActions.forEach(function (action) {
245 action.addEventListener('click', function () {
246 window?.tiTrk?.with('visualizer')?.add({
247 feature: 'chart-library',
248 featureComponent: 'chart-language-translations-used',
249 groupId: chartId,
250 });
251 });
252 });
253 });
254