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 +20 -82 3.10.43.4.4 View file →
@@ -1,24 +1,16 @@
1 1 /* global console */
2 2 /* global visualizer */
3 3 /* global jQuery */
4 -var vizClipboard1=null;
4 +
5 5 (function($, visualizer){
6 6
7 7 function initActionsButtons(v) {
8 - if($('a.visualizer-chart-shortcode').length > 0 && vizClipboard1 === null) {
9 - vizClipboard1 = new ClipboardJS('a.visualizer-chart-shortcode'); // jshint ignore:line
10 - vizClipboard1.on('success', function(e) {
11 - window.alert(v.i10n['copied']);
12 -
13 - });
14 - }
15 -
16 8 if($('a.visualizer-action[data-visualizer-type=copy]').length > 0) {
17 9 $('a.visualizer-action[data-visualizer-type=copy]').on('click', function(e) {
18 10 e.preventDefault();
19 11 });
20 - var clipboard = new ClipboardJS('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
12 + var clipboard = new Clipboard('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
21 13 clipboard.on('success', function(e) {
22 14 window.alert(v.i10n['copied']);
23 15 });
24 16 }
@@ -31,11 +23,8 @@
31 23 lock.lock();
32 24 e.preventDefault();
33 25 $.ajax({
34 26 url : v.rest_url.replace('#id#', chart).replace('#type#', type),
35 - beforeSend: function ( xhr ) {
36 - xhr.setRequestHeader( 'X-WP-Nonce', v.wp_nonce );
37 - },
38 27 success: function(data) {
39 28 if (data && data.data) {
40 29 switch(type){
41 30 case 'csv':
@@ -101,80 +90,29 @@
101 90 var event = new CustomEvent('visualizer:render:currentchart:update', {detail: {visualizer: visualizer}});
102 91 document.body.dispatchEvent(event);
103 92 };
104 93
105 - 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);
106 112 initActionsButtons(visualizer);
107 113 registerDefaultActions();
108 114 });
109 -
110 - // Refresh charts if chart not generated.
111 - function refreshEachCharts() {
112 - setTimeout( function() {
113 - displayChartsOnFrontEnd();
114 - }, 100 );
115 - }
116 -
117 - function initChartDisplay() {
118 - if(visualizer.is_front == true){ // jshint ignore:line
119 - displayChartsOnFrontEnd();
120 - }else{
121 - showChart();
122 - }
123 - }
124 -
125 - /**
126 - * If an `id` is provided, that particular chart will load.
127 - */
128 - function showChart(id) {
129 - // clone the visualizer object so that the original object is not affected.
130 - var viz = Object.assign(visualizer, window.visualizer || {});
131 - if(id){
132 - viz.id = id;
133 - }
134 - $('body').trigger('visualizer:render:chart:start', viz);
135 - }
136 -
137 - function displayChartsOnFrontEnd() {
138 - // display all charts that are NOT to be lazy-loaded.
139 - $( 'div.viz-facade-loaded:not(.visualizer-lazy):not(.visualizer-cw-error):empty' ).removeClass( 'viz-facade-loaded' );
140 - $('div.visualizer-front:not(.visualizer-lazy):not(.viz-facade-loaded)').each(function(index, element){
141 - if ( $(element).is(':visible') ) {
142 - var id = $(element).addClass('viz-facade-loaded').attr('id');
143 - showChart(id);
144 - }
145 - refreshEachCharts();
146 - });
147 -
148 - // interate through all charts that are to be lazy-loaded and observe each one.
149 - $('div.visualizer-front.visualizer-lazy').each(function(index, element){
150 - var id = $(element).attr('id');
151 - var limit = $(element).attr('data-lazy-limit');
152 - if(!limit){
153 - limit = 300;
154 - }
155 - var target = document.querySelector('#' + id);
156 -
157 - // configure the intersection observer instance
158 - var intersectionObserverOptions = {
159 - root: null,
160 - rootMargin: limit + 'px',
161 - threshold: 0
162 - };
163 -
164 - var observer = new IntersectionObserver(function(entries) {
165 - entries.forEach(function(entry) {
166 - if (entry.isIntersecting) {
167 - observer.unobserve(target);
168 - showChart($(entry.target).attr('id'));
169 - }
170 - });
171 - }, intersectionObserverOptions);
172 -
173 - // start observing.
174 - observer.observe(target);
175 - });
176 - }
177 115
178 116 function registerDefaultActions(){
179 117 $('body').off('visualizer:action:specificchart:defaultprint').on('visualizer:action:specificchart:defaultprint', function(event, v){
180 118 var iframe = $('<iframe>').attr("name", "print-visualization").attr("id", "print-visualization").css("position", "absolute");