PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.4
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.4
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
← All changes | js/render-facade.js +23 -111 4.0.53.4.4 View file →
@@ -1,26 +1,17 @@
1 1 /* global console */
2 2 /* global visualizer */
3 3 /* global jQuery */
4 -window['vizClipboard1'] = window['vizClipboard1'] || null;
5 -window['vizClipboard2'] = window['vizClipboard2'] || null;
4 +
6 5 (function($, visualizer){
7 -
6 +
8 7 function initActionsButtons(v) {
9 - if($('a.visualizer-chart-shortcode').length > 0 && vizClipboard1 === null) {
10 - vizClipboard1 = new ClipboardJS('a.visualizer-chart-shortcode'); // jshint ignore:line
11 - vizClipboard1.on('success', function(e) {
12 - window.alert(v.i10n['copied']);
13 -
14 - });
15 - }
16 -
17 - if($('a.visualizer-action[data-visualizer-type=copy]').length > 0 && vizClipboard2 === null) {
8 + if($('a.visualizer-action[data-visualizer-type=copy]').length > 0) {
18 9 $('a.visualizer-action[data-visualizer-type=copy]').on('click', function(e) {
19 10 e.preventDefault();
20 11 });
21 - vizClipboard2 = new ClipboardJS('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
22 - vizClipboard2.on('success', function(e) {
12 + var clipboard = new Clipboard('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
13 + clipboard.on('success', function(e) {
23 14 window.alert(v.i10n['copied']);
24 15 });
25 16 }
26 17 $('a.visualizer-action[data-visualizer-type!=copy]').off('click').on('click', function(e) {
@@ -32,11 +23,8 @@
32 23 lock.lock();
33 24 e.preventDefault();
34 25 $.ajax({
35 26 url : v.rest_url.replace('#id#', chart).replace('#type#', type),
36 - beforeSend: function ( xhr ) {
37 - xhr.setRequestHeader( 'X-WP-Nonce', v.wp_nonce );
38 - },
39 27 success: function(data) {
40 28 if (data && data.data) {
41 29 switch(type){
42 30 case 'csv':
@@ -102,105 +90,29 @@
102 90 var event = new CustomEvent('visualizer:render:currentchart:update', {detail: {visualizer: visualizer}});
103 91 document.body.dispatchEvent(event);
104 92 };
105 93
106 - initChartDisplay();
94 + // facade loads N times in the library and front end (where N = the number of different chart libraries supported)
95 + // so all charts are also loaded N times
96 + // this will ensure that no matter how many times facade is loaded, it initializes all charts only once.
97 + // fixed as part of the issue to add annotations.
98 + if(localStorage.getItem( 'viz-facade-loaded' ) === '1'){
99 + // prevent library from hanging.
100 + setTimeout( function(){
101 + localStorage.removeItem( 'viz-facade-loaded' );
102 + }, 2000);
103 + return;
104 + }
105 + localStorage.setItem( 'viz-facade-loaded', '1');
106 + // remove the flag so that repeated loading of the library does not cause problems.
107 + setTimeout( function(){
108 + localStorage.removeItem( 'viz-facade-loaded' );
109 + }, 2000);
110 +
111 + $('body').trigger('visualizer:render:chart:start', visualizer);
107 112 initActionsButtons(visualizer);
108 113 registerDefaultActions();
109 114 });
110 -
111 - function initChartDisplay() {
112 - if(visualizer.is_front == true){ // jshint ignore:line
113 - displayChartsOnFrontEnd();
114 - } else {
115 - showChart();
116 - }
117 - }
118 -
119 - /**
120 - * If an `id` is provided, that particular chart will load.
121 - */
122 - function showChart(id) {
123 - // clone the visualizer object so that the original object is not affected.
124 - var viz = Object.assign(visualizer, window.visualizer || {});
125 - if(id){
126 - viz.id = id;
127 - }
128 - $('body').trigger('visualizer:render:chart:start', viz);
129 - }
130 -
131 - function displayChartsOnFrontEnd() {
132 - function renderVisibleLazyCharts() {
133 - $('div.visualizer-front:not(.viz-facade-loaded):not(.visualizer-lazy):not(.visualizer-cw-error):empty').each(function(index, element){
134 - // Do not render charts that are intentionally hidden.
135 - const style = window.getComputedStyle(element);
136 - if (style.display === 'none' || style.visibility === 'hidden') {
137 - return;
138 - }
139 -
140 - // Only render charts that are currently within the viewport.
141 - const rect = element.getBoundingClientRect();
142 - const inViewport = rect.bottom >= 0 && rect.top <= (window.innerHeight || document.documentElement.clientHeight);
143 - if (!inViewport) {
144 - return;
145 - }
146 -
147 - const id = $(element).addClass('viz-facade-loaded').attr('id');
148 - setTimeout(function(){
149 - // Add a short delay between each chart to avoid overloading the browser event loop.
150 - showChart(id);
151 - }, ( index + 1 ) * 100);
152 - });
153 - }
154 -
155 - $(window).on('scroll', renderVisibleLazyCharts);
156 -
157 - // Run once on page load to render any lazy charts already in the viewport.
158 - renderVisibleLazyCharts();
159 -
160 - $('div.visualizer-front-container:not(.visualizer-lazy-render)').each(function(index, element){
161 - // Do not render charts that are intentionally hidden.
162 - const style = window.getComputedStyle($(element).find('.visualizer-front')[0]);
163 - if (style.display === 'none' || style.visibility === 'hidden') {
164 - return;
165 - }
166 -
167 - const id = $(element).find('.visualizer-front').addClass('viz-facade-loaded').attr('id');
168 - setTimeout(function(){
169 - // Add a short delay between each chart to avoid overloading the browser event loop.
170 - showChart(id);
171 - }, ( index + 1 ) * 100);
172 - });
173 -
174 - // interate through all charts that are to be lazy-loaded and observe each one.
175 - $('div.visualizer-front.visualizer-lazy').each(function(index, element){
176 - var id = $(element).attr('id');
177 - var limit = $(element).attr('data-lazy-limit');
178 - if(!limit){
179 - limit = 300;
180 - }
181 - var target = document.querySelector('#' + id);
182 -
183 - // configure the intersection observer instance
184 - var intersectionObserverOptions = {
185 - root: null,
186 - rootMargin: limit + 'px',
187 - threshold: 0
188 - };
189 -
190 - var observer = new IntersectionObserver(function(entries) {
191 - entries.forEach(function(entry) {
192 - if (entry.isIntersecting) {
193 - observer.unobserve(target);
194 - showChart($(entry.target).attr('id'));
195 - }
196 - });
197 - }, intersectionObserverOptions);
198 -
199 - // start observing.
200 - observer.observe(target);
201 - });
202 - }
203 115
204 116 function registerDefaultActions(){
205 117 $('body').off('visualizer:action:specificchart:defaultprint').on('visualizer:action:specificchart:defaultprint', function(event, v){
206 118 var iframe = $('<iframe>').attr("name", "print-visualization").attr("id", "print-visualization").css("position", "absolute");