PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.5
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.5
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 +131 -20 3.1.33.4.5 View file →
@@ -4,9 +4,19 @@
4 4
5 5 (function($, visualizer){
6 6
7 7 function initActionsButtons(v) {
8 + if($('a.visualizer-chart-shortcode').length > 0) {
9 + var clipboard1 = new Clipboard('a.visualizer-chart-shortcode'); // jshint ignore:line
10 + clipboard1.on('success', function(e) {
11 + window.alert(v.i10n['copied']);
12 + });
13 + }
14 +
8 15 if($('a.visualizer-action[data-visualizer-type=copy]').length > 0) {
16 + $('a.visualizer-action[data-visualizer-type=copy]').on('click', function(e) {
17 + e.preventDefault();
18 + });
9 19 var clipboard = new Clipboard('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
10 20 clipboard.on('success', function(e) {
11 21 window.alert(v.i10n['copied']);
12 22 });
@@ -15,8 +25,9 @@
15 25 var type = $(this).attr( 'data-visualizer-type' );
16 26 var chart = $(this).attr( 'data-visualizer-chart-id' );
17 27 var container = $(this).attr( 'data-visualizer-container-id' );
18 28 var lock = $('.visualizer-front.visualizer-front-' + chart);
29 + var mime = $(this).attr( 'data-visualizer-mime' );
19 30 lock.lock();
20 31 e.preventDefault();
21 32 $.ajax({
22 33 url : v.rest_url.replace('#id#', chart).replace('#type#', type),
@@ -23,30 +34,40 @@
23 34 success: function(data) {
24 35 if (data && data.data) {
25 36 switch(type){
26 37 case 'csv':
27 - var a = document.createElement("a");
28 - document.body.appendChild(a);
29 - a.style = "display: none";
30 - var blob = new Blob([data.data.csv], {type: $(this).attr( 'data-visualizer-mime' ) }),
31 - url = window.URL.createObjectURL(blob);
32 - a.href = url;
33 - a.download = data.data.name;
34 - a.click();
35 - setTimeout(function () {
36 - window.URL.revokeObjectURL(url);
37 - }, 100);
38 + var blob = new Blob([data.data.csv], {type: mime });
39 + if(window.navigator.msSaveOrOpenBlob){
40 + window.navigator.msSaveOrOpenBlob(blob, data.data.name);
41 + } else {
42 + var url = window.URL.createObjectURL(blob);
43 + var $a = $("<a>");
44 + $a.attr("href", url);
45 + $("body").append($a);
46 + $a.attr("download", data.data.name);
47 + $a[0].click();
48 + setTimeout(function () {
49 + window.URL.revokeObjectURL(url);
50 + $a.remove();
51 + }, 100);
52 + }
38 53 break;
39 54 case 'xls':
40 - var $a = $("<a>");
41 - $a.attr("href",data.data.csv);
42 - $("body").append($a);
43 - $a.attr("download",data.data.name);
44 - $a[0].click();
45 - $a.remove();
55 + if(window.navigator.msSaveOrOpenBlob){
56 + blob = new Blob([s2ab(atob(data.data.raw))], {type: '' });
57 + window.navigator.msSaveOrOpenBlob(blob, data.data.name);
58 + } else {
59 + var $a = $("<a>"); // jshint ignore:line
60 + $a.attr("href", data.data.csv);
61 + $("body").append($a);
62 + $a.attr("download", data.data.name);
63 + $a[0].click();
64 + $a.remove();
65 + }
46 66 break;
47 67 case 'print':
48 - $('body').trigger('visualizer:action:specificchart', {action: 'print', id: container, data: data.data.csv});
68 + case 'image':
69 + $('body').trigger('visualizer:action:specificchart', {action: type, id: container, data: data.data.csv, dataObj: data.data});
49 70 break;
50 71 default:
51 72 if(window.visualizer_perform_action) {
52 73 window.visualizer_perform_action(type, chart, data.data);
@@ -59,14 +80,104 @@
59 80 });
60 81 });
61 82 }
62 83
84 + function s2ab(s) {
85 + var buf = new ArrayBuffer(s.length);
86 + var view = new Uint8Array(buf);
87 + for (var i=0; i !== s.length; ++i) {
88 + view[i] = s.charCodeAt(i) & 0xFF;
89 + }
90 + return buf;
91 + }
92 +
63 93 $(document).ready(function(){
64 - $('body').trigger('visualizer:render:chart:start', visualizer);
94 +
95 + // for updating the currently displayed chart (preview mode)
96 + window.vizUpdateChartPreview = function(){
97 + var event = new CustomEvent('visualizer:render:currentchart:update', {detail: {visualizer: visualizer}});
98 + document.body.dispatchEvent(event);
99 + };
100 +
101 + // facade loads N times in the library and front end (where N = the number of different chart libraries supported)
102 + // so all charts are also loaded N times
103 + // this will ensure that no matter how many times facade is loaded, it initializes all charts only once.
104 + // fixed as part of the issue to add annotations.
105 + if(localStorage.getItem( 'viz-facade-loaded' ) === '1'){
106 + // prevent library from hanging.
107 + setTimeout( function(){
108 + localStorage.removeItem( 'viz-facade-loaded' );
109 + }, 2000);
110 + return;
111 + }
112 + localStorage.setItem( 'viz-facade-loaded', '1');
113 + // remove the flag so that repeated loading of the library does not cause problems.
114 + setTimeout( function(){
115 + localStorage.removeItem( 'viz-facade-loaded' );
116 + }, 2000);
117 +
118 + initChartDisplay();
65 119 initActionsButtons(visualizer);
66 120 registerDefaultActions();
67 121 });
68 122
123 + function initChartDisplay() {
124 + if(visualizer.is_front == true){ // jshint ignore:line
125 + displayChartsOnFrontEnd();
126 + }else{
127 + showChart();
128 + }
129 + }
130 +
131 + /**
132 + * If an `id` is provided, that particular chart will load.
133 + */
134 + function showChart(id) {
135 + // clone the visualizer object so that the original object is not affected.
136 + var viz = Object.assign({}, visualizer);
137 + if(id){
138 + viz.id = id;
139 + }
140 + $('body').trigger('visualizer:render:chart:start', viz);
141 + }
142 +
143 + function displayChartsOnFrontEnd() {
144 + // display all charts that are NOT to be lazy-loaded.
145 + $('div.visualizer-front:not(.visualizer-lazy)').each(function(index, element){
146 + var id = $(element).attr('id');
147 + showChart(id);
148 + });
149 +
150 + // interate through all charts that are to be lazy-loaded and observe each one.
151 + $('div.visualizer-front.visualizer-lazy').each(function(index, element){
152 + var id = $(element).attr('id');
153 + var limit = $(element).attr('data-lazy-limit');
154 + if(!limit){
155 + limit = 300;
156 + }
157 + var target = document.querySelector('#' + id);
158 +
159 + // configure the intersection observer instance
160 + var intersectionObserverOptions = {
161 + root: null,
162 + rootMargin: limit + 'px',
163 + threshold: 0
164 + };
165 +
166 + var observer = new IntersectionObserver(function(entries) {
167 + entries.forEach(function(entry) {
168 + if (entry.isIntersecting) {
169 + observer.unobserve(target);
170 + showChart($(entry.target).attr('id'));
171 + }
172 + });
173 + }, intersectionObserverOptions);
174 +
175 + // start observing.
176 + observer.observe(target);
177 + });
178 + }
179 +
69 180 function registerDefaultActions(){
70 181 $('body').off('visualizer:action:specificchart:defaultprint').on('visualizer:action:specificchart:defaultprint', function(event, v){
71 182 var iframe = $('<iframe>').attr("name", "print-visualization").attr("id", "print-visualization").css("position", "absolute");
72 183 iframe.appendTo($('body'));
@@ -129,5 +240,5 @@
129 240 });
130 241
131 242 return $(this);
132 243 };
133 -})(jQuery);
244 +})(jQuery);