PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.10.8
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.10.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 3.10.4 All 148 releases
← All changes | js/render-facade.js +150 -34 3.1.03.10.8 View file →
@@ -1,61 +1,77 @@
1 1 /* global console */
2 2 /* global visualizer */
3 3 /* global jQuery */
4 +var vizClipboard1=null;
5 +(function($, visualizer){
6 +
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']);
4 12
5 -(function($, visualizer){
13 + });
14 + }
6 15
7 - function initActionsButtons(v) {
8 16 if($('a.visualizer-action[data-visualizer-type=copy]').length > 0) {
9 - var clipboard = new Clipboard('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
17 + $('a.visualizer-action[data-visualizer-type=copy]').on('click', function(e) {
18 + e.preventDefault();
19 + });
20 + var clipboard = new ClipboardJS('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
10 21 clipboard.on('success', function(e) {
11 22 window.alert(v.i10n['copied']);
12 23 });
13 24 }
14 - $('a.visualizer-action[data-visualizer-type!=copy]').on('click', function(e) {
25 + $('a.visualizer-action[data-visualizer-type!=copy]').off('click').on('click', function(e) {
15 26 var type = $(this).attr( 'data-visualizer-type' );
16 27 var chart = $(this).attr( 'data-visualizer-chart-id' );
28 + var container = $(this).attr( 'data-visualizer-container-id' );
17 29 var lock = $('.visualizer-front.visualizer-front-' + chart);
30 + var mime = $(this).attr( 'data-visualizer-mime' );
18 31 lock.lock();
19 32 e.preventDefault();
20 33 $.ajax({
21 34 url : v.rest_url.replace('#id#', chart).replace('#type#', type),
35 + beforeSend: function ( xhr ) {
36 + xhr.setRequestHeader( 'X-WP-Nonce', v.wp_nonce );
37 + },
22 38 success: function(data) {
23 39 if (data && data.data) {
24 40 switch(type){
25 41 case 'csv':
26 - var a = document.createElement("a");
27 - document.body.appendChild(a);
28 - a.style = "display: none";
29 - var blob = new Blob([data.data.csv], {type: $(this).attr( 'data-visualizer-mime' ) }),
30 - url = window.URL.createObjectURL(blob);
31 - a.href = url;
32 - a.download = data.data.name;
33 - a.click();
34 - setTimeout(function () {
35 - window.URL.revokeObjectURL(url);
36 - }, 100);
42 + var blob = new Blob([data.data.csv], {type: mime });
43 + if(window.navigator.msSaveOrOpenBlob){
44 + window.navigator.msSaveOrOpenBlob(blob, data.data.name);
45 + } else {
46 + var url = window.URL.createObjectURL(blob);
47 + var $a = $("<a>");
48 + $a.attr("href", url);
49 + $("body").append($a);
50 + $a.attr("download", data.data.name);
51 + $a[0].click();
52 + setTimeout(function () {
53 + window.URL.revokeObjectURL(url);
54 + $a.remove();
55 + }, 100);
56 + }
37 57 break;
38 58 case 'xls':
39 - var $a = $("<a>");
40 - $a.attr("href",data.data.csv);
41 - $("body").append($a);
42 - $a.attr("download",data.data.name);
43 - $a[0].click();
44 - $a.remove();
59 + if(window.navigator.msSaveOrOpenBlob){
60 + blob = new Blob([s2ab(atob(data.data.raw))], {type: '' });
61 + window.navigator.msSaveOrOpenBlob(blob, data.data.name);
62 + } else {
63 + var $a = $("<a>"); // jshint ignore:line
64 + $a.attr("href", data.data.csv);
65 + $("body").append($a);
66 + $a.attr("download", data.data.name);
67 + $a[0].click();
68 + $a.remove();
69 + }
45 70 break;
46 71 case 'print':
47 - var iframe = $('<iframe>').attr("name", "print-visualization").attr("id", "print-visualization").css("position", "absolute");
48 - iframe.appendTo($('body'));
49 - var iframe_doc = iframe.get(0).contentWindow || iframe.get(0).contentDocument.document || iframe.get(0).contentDocument;
50 - iframe_doc.document.open();
51 - iframe_doc.document.write(data.data.csv);
52 - iframe_doc.document.close();
53 - setTimeout(function(){
54 - window.frames['print-visualization'].focus();
55 - window.frames['print-visualization'].print();
56 - iframe.remove();
57 - }, 500);
72 + case 'image':
73 + $('body').trigger('visualizer:action:specificchart', {action: type, id: container, data: data.data.csv, dataObj: data.data});
58 74 break;
59 75 default:
60 76 if(window.visualizer_perform_action) {
61 77 window.visualizer_perform_action(type, chart, data.data);
@@ -68,12 +84,112 @@
68 84 });
69 85 });
70 86 }
71 87
88 + function s2ab(s) {
89 + var buf = new ArrayBuffer(s.length);
90 + var view = new Uint8Array(buf);
91 + for (var i=0; i !== s.length; ++i) {
92 + view[i] = s.charCodeAt(i) & 0xFF;
93 + }
94 + return buf;
95 + }
96 +
72 97 $(document).ready(function(){
73 - $('body').trigger('visualizer:render:chart:start', visualizer);
98 +
99 + // for updating the currently displayed chart (preview mode)
100 + window.vizUpdateChartPreview = function(){
101 + var event = new CustomEvent('visualizer:render:currentchart:update', {detail: {visualizer: visualizer}});
102 + document.body.dispatchEvent(event);
103 + };
104 +
105 + initChartDisplay();
74 106 initActionsButtons(visualizer);
107 + registerDefaultActions();
75 108 });
109 +
110 + function initChartDisplay() {
111 + if(visualizer.is_front == true){ // jshint ignore:line
112 + displayChartsOnFrontEnd();
113 + } else {
114 + showChart();
115 + }
116 + }
117 +
118 + /**
119 + * If an `id` is provided, that particular chart will load.
120 + */
121 + function showChart(id) {
122 + // clone the visualizer object so that the original object is not affected.
123 + var viz = Object.assign(visualizer, window.visualizer || {});
124 + if(id){
125 + viz.id = id;
126 + }
127 + $('body').trigger('visualizer:render:chart:start', viz);
128 + }
129 +
130 + function displayChartsOnFrontEnd() {
131 +
132 + $('div.visualizer-front:not(.viz-facade-loaded):not(.visualizer-lazy):not(.visualizer-cw-error):empty').each(function(index, element){
133 +
134 + // Do not render charts that are intentionally hidden.
135 + var style = window.getComputedStyle(element);
136 + if (style.display === 'none' || style.visibility === 'hidden') {
137 + return;
138 + }
139 +
140 + var id = $(element).addClass('viz-facade-loaded').attr('id');
141 + setTimeout(function(){
142 + // Add a short delay between each chart to avoid overloading the browser event loop.
143 + showChart(id);
144 + }, ( index + 1 ) * 100);
145 + });
146 +
147 + // interate through all charts that are to be lazy-loaded and observe each one.
148 + $('div.visualizer-front.visualizer-lazy').each(function(index, element){
149 + var id = $(element).attr('id');
150 + var limit = $(element).attr('data-lazy-limit');
151 + if(!limit){
152 + limit = 300;
153 + }
154 + var target = document.querySelector('#' + id);
155 +
156 + // configure the intersection observer instance
157 + var intersectionObserverOptions = {
158 + root: null,
159 + rootMargin: limit + 'px',
160 + threshold: 0
161 + };
162 +
163 + var observer = new IntersectionObserver(function(entries) {
164 + entries.forEach(function(entry) {
165 + if (entry.isIntersecting) {
166 + observer.unobserve(target);
167 + showChart($(entry.target).attr('id'));
168 + }
169 + });
170 + }, intersectionObserverOptions);
171 +
172 + // start observing.
173 + observer.observe(target);
174 + });
175 + }
176 +
177 + function registerDefaultActions(){
178 + $('body').off('visualizer:action:specificchart:defaultprint').on('visualizer:action:specificchart:defaultprint', function(event, v){
179 + var iframe = $('<iframe>').attr("name", "print-visualization").attr("id", "print-visualization").css("position", "absolute");
180 + iframe.appendTo($('body'));
181 + var iframe_doc = iframe.get(0).contentWindow || iframe.get(0).contentDocument.document || iframe.get(0).contentDocument;
182 + iframe_doc.document.open();
183 + iframe_doc.document.write(v.data);
184 + iframe_doc.document.close();
185 + setTimeout(function(){
186 + window.frames['print-visualization'].focus();
187 + window.frames['print-visualization'].print();
188 + iframe.remove();
189 + }, 500);
190 + });
191 + }
76 192 })(jQuery, visualizer);
77 193
78 194 (function ($) {
79 195 $.fn.lock = function () {
@@ -121,5 +237,5 @@
121 237 });
122 238
123 239 return $(this);
124 240 };
125 -})(jQuery);
241 +})(jQuery);