PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.11.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.11.0
4.0.8 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 All 149 releases
visualizer / js / library.js

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

309 lines 11.4 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() {
37
38 var link = document.createElement('link');
39 link.rel = 'stylesheet';
40 link.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css';
41 document.head.appendChild(link);
42
43 var overlay = document.createElement('div');
44 overlay.classList.add('vizualizer-renew-notice-overlay');
45 overlay.id = 'overlay-visualizer';
46 document.body.appendChild(overlay);
47
48 var popup = document.createElement('div');
49 popup.classList.add('vizualizer-renew-notice-popup');
50
51 var closeIcon = document.createElement('i');
52 closeIcon.classList.add('fas', 'fa-times', 'vizualizer-renew-notice-close-icon');
53 closeIcon.addEventListener('click', function() {
54 document.body.removeChild(overlay);
55 popup.style.display = 'none';
56 });
57 popup.appendChild(closeIcon);
58
59 var heading = document.createElement('h1');
60 heading.textContent = 'Alert!';
61 heading.classList.add('vizualizer-renew-notice-heading');
62 popup.appendChild(heading);
63
64 var message = document.createElement('p');
65 message.textContent = 'In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it.';
66 message.classList.add('vizualizer-renew-notice-message');
67 popup.appendChild(message);
68
69 var buttonsContainer = document.createElement('div');
70 buttonsContainer.classList.add('vizualizer-renew-notice-buttons-container');
71
72 var link1 = document.createElement('a');
73 link1.href = 'https://store.themeisle.com/';
74 link1.target = '_blank';
75 var button1 = document.createElement('button');
76 button1.innerHTML = '<span class="fas fa-shopping-cart"></span> Renew License';
77 button1.classList.add('vizualizer-renew-notice-button', 'vizualizer-renew-notice-renew-button');
78 link1.appendChild(button1);
79 buttonsContainer.appendChild(link1);
80
81 var link2 = document.createElement('a');
82 link2.href = '/wp-admin/options-general.php#visualizer_pro_license';
83 var button2 = document.createElement('button');
84 button2.innerHTML = '<span class="fas fa-key"></span> Activate License';
85 button2.classList.add('vizualizer-renew-notice-button', 'vizualizer-renew-notice-activate-button');
86 link2.appendChild(button2);
87 buttonsContainer.appendChild(link2);
88
89 popup.appendChild(buttonsContainer);
90
91 document.body.appendChild(popup);
92
93 }
94
95 (function ($, vmv, vu) {
96 var resizeTimeout;
97
98 $.fn.adjust = function () {
99 return $(this).each(function () {
100 var width = $('#visualizer-library').width(),
101 margin = width * 0.02;
102
103 width *= 0.305;
104 $(this).prev( '.visualizer-chart-title' ).width(width - 14);
105 var ChartHeight = width * 0.93;
106 if ( $( '.visualizer-nochart-canvas' ).length === 0 ) {
107 ChartHeight = width * 0.78;
108 if ( $( '#visualizer-sidebar' ).hasClass('one-columns') ) {
109 ChartHeight = width * 0.92;
110 }
111 }
112 $(this).width(width).height( ChartHeight );
113 });
114 };
115
116 $('.visualizer-chart-canvas').adjust();
117
118 $(document).ready(function () {
119 // clears the filters in the library form and submits.
120 $('#viz-lib-reset').on('click', function(e){
121 e.preventDefault();
122 $(this).parent('form')[0].reset();
123 $(this).parent('form').find('.viz-filter').each(function(index, el){
124 var tag = $(el).prop('tagName').toLowerCase() + (typeof $(el).attr('type') !== 'undefined' ? $(el).attr('type').toLowerCase() : '');
125 switch(tag){
126 case 'select':
127 $(el).prop('selectedIndex', 0);
128 break;
129 case 'inputtext':
130 $(el).val('');
131 break;
132 }
133
134 });
135 $(this).parent('form').submit();
136 });
137
138 $('.visualizer-chart-shortcode').click(function (e) {
139
140 if ( ! visualizer.is_pro_user && e.target.classList.contains('viz-is-pro-chart') ) {
141 createPopupProBlocker();
142 e.preventDefault();
143 e.stopPropagation();
144 return;
145 }
146
147 var range, selection;
148
149 if (window.getSelection && document.createRange) {
150 selection = window.getSelection();
151 range = document.createRange();
152 range.selectNodeContents(e.target);
153 selection.removeAllRanges();
154 selection.addRange(range);
155 } else if (document.selection && document.body.createTextRange) {
156 range = document.body.createTextRange();
157 range.moveToElementText(e.target);
158 range.select();
159 }
160 });
161
162 $( '.visualizer-languages-list' ).on( 'click', '[data-lang_code]', function() {
163 if ( $(this).find( 'i' ).hasClass( 'otgs-ico-add' ) ) {
164 vu.create = vu.create + '&lang=' + $(this).data('lang_code') + '&parent_chart_id=' + $(this).data('chart');
165 $('.add-new-chart').click();
166 } else {
167 vu.edit = vu.edit + '&lang=' + $(this).data('lang_code') + '&chart=' + $(this).data('chart');
168 $('.visualizer-chart-edit').click();
169 }
170 } );
171
172 $('.add-new-chart').click(function () {
173 var wnd = window,
174 view = new vmv.Chart({action: vu.create});
175 vu.create = vu.create.replace(/[\?&]lang=[^&]+/, '').replace(/[\?&]parent_chart_id=[^&]+/, '');
176
177 window.parent.addEventListener('message', function(event){
178 switch(event.data) {
179 case 'visualizer:mediaframe:close':
180 view.close();
181 break;
182 }
183 }, false);
184
185 // remove the 'type' while refreshing the library page on creation of a new chart.
186 // this is to avoid cases where users have filtered for chart type A and end up creating chart type B
187 // remove 'vaction' as well so that additional actions are removed
188 wnd.send_to_editor = function () {
189 wnd.location.href = vu.base.replace(/type=[a-zA-Z]*/, '').replace(/vaction/, '');
190 };
191 view.open();
192
193 return false;
194 });
195
196 $('.visualizer-chart-edit').click(function (event) {
197
198 if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) {
199 createPopupProBlocker();
200 return;
201 }
202
203 var wnd = window;
204 var view = new vmv.Chart( {
205 action: vu.edit.indexOf('&chart') != -1 ? vu.edit : vu.edit + '&chart=' + $(this).attr('data-chart')
206 } );
207 vu.edit = vu.edit.replace(/[\?&]lang=[^&]+/, '');
208
209 wnd.send_to_editor = function () {
210 wnd.location.href = wnd.location.href.replace(/vaction/, '');
211 };
212
213 view.open();
214
215 return false;
216 });
217 $(".visualizer-chart-clone").on("click", function ( event ) {
218 if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) {
219 createPopupProBlocker();
220 event.preventDefault();
221 }
222 });
223
224 $(".visualizer-chart-export").on("click", function (event) {
225
226 if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) {
227 createPopupProBlocker();
228 return;
229 }
230
231 $.ajax({
232 url: $(this).attr("data-chart"),
233 method: "get",
234 success: function (data, textStatus, jqXHR) {
235 var a = document.createElement("a");
236 document.body.appendChild(a);
237 a.style = "display: none";
238 var blob = new Blob([data.data.csv], {type: "application/csv"}),
239 url = window.URL.createObjectURL(blob);
240 a.href = url;
241 a.download = data.data.name;
242 a.click();
243 setTimeout(function () {
244 window.URL.revokeObjectURL(url);
245 }, 100);
246 }
247 });
248 return false;
249 });
250
251 $(".visualizer-chart-image").on("click", function (event) {
252 if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) {
253 createPopupProBlocker();
254 return;
255 }
256 $('body').trigger('visualizer:action:specificchart', {action: 'image', id: $(this).attr("data-chart"), data: null, dataObj: {name: $(this).attr("data-chart-title")}});
257 return false;
258 });
259
260 // if vaction=addnew is found as a GET request parameter, show the modal.
261 if(location.href.indexOf('vaction=addnew') !== -1){
262 $('.add-new-chart').first().trigger('click');
263 }
264
265 //if vaction=edit is found as a GET request parameter, show the modal.
266 if(location.href.indexOf('vaction=edit') !== -1 && location.href.indexOf('chart=') !== -1){
267 const chartId = location.href.split('chart=')[1].split('&')[0];
268 $('.visualizer-chart-edit').attr('data-chart', chartId).trigger('click');
269 }
270
271 $(window).resize(function () {
272 clearTimeout(resizeTimeout);
273 resizeTimeout = setTimeout(function () {
274 $('.visualizer-chart-canvas').adjust();
275 }, 100);
276 });
277
278 $('.visualizer-error i.error').on('click', function(){
279 alert( $(this).attr('data-viz-error') );
280 });
281 $('.visualizer-chart:not(.visualizer-chart-display), .visualizer-library-pagination').fadeIn(500);
282 });
283 })(jQuery, visualizer.media.view, visualizer.urls);
284
285
286 document.querySelectorAll('.visualizer-chart').forEach(function (chart) {
287 const translatable = chart.querySelector('.visualizer-languages-list');
288 if ( ! translatable ) {
289 return;
290 }
291
292 const chartId = chart.querySelector('.visualizer-chart-canvas')?.id?.replace('visualizer-', '');
293
294 if ( ! chartId ) {
295 return;
296 }
297
298 const translatableActions = translatable.querySelectorAll('[data-lang_code]');
299 translatableActions.forEach(function (action) {
300 action.addEventListener('click', function () {
301 window?.tiTrk?.with('visualizer')?.add({
302 feature: 'chart-library',
303 featureComponent: 'chart-language-translations-used',
304 groupId: chartId,
305 });
306 });
307 });
308 });
309