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 +150 -31 3.1.23.4.5 View file →
@@ -4,18 +4,30 @@
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 });
13 23 }
14 - $('a.visualizer-action[data-visualizer-type!=copy]').on('click', function(e) {
24 + $('a.visualizer-action[data-visualizer-type!=copy]').off('click').on('click', function(e) {
15 25 var type = $(this).attr( 'data-visualizer-type' );
16 26 var chart = $(this).attr( 'data-visualizer-chart-id' );
27 + var container = $(this).attr( 'data-visualizer-container-id' );
17 28 var lock = $('.visualizer-front.visualizer-front-' + chart);
29 + var mime = $(this).attr( 'data-visualizer-mime' );
18 30 lock.lock();
19 31 e.preventDefault();
20 32 $.ajax({
21 33 url : v.rest_url.replace('#id#', chart).replace('#type#', type),
@@ -22,40 +34,40 @@
22 34 success: function(data) {
23 35 if (data && data.data) {
24 36 switch(type){
25 37 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);
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 + }
37 53 break;
38 54 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();
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 + }
45 66 break;
46 67 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);
68 + case 'image':
69 + $('body').trigger('visualizer:action:specificchart', {action: type, id: container, data: data.data.csv, dataObj: data.data});
58 70 break;
59 71 default:
60 72 if(window.visualizer_perform_action) {
61 73 window.visualizer_perform_action(type, chart, data.data);
@@ -68,12 +80,119 @@
68 80 });
69 81 });
70 82 }
71 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 +
72 93 $(document).ready(function(){
73 - $('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();
74 119 initActionsButtons(visualizer);
120 + registerDefaultActions();
75 121 });
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 +
180 + function registerDefaultActions(){
181 + $('body').off('visualizer:action:specificchart:defaultprint').on('visualizer:action:specificchart:defaultprint', function(event, v){
182 + var iframe = $('<iframe>').attr("name", "print-visualization").attr("id", "print-visualization").css("position", "absolute");
183 + iframe.appendTo($('body'));
184 + var iframe_doc = iframe.get(0).contentWindow || iframe.get(0).contentDocument.document || iframe.get(0).contentDocument;
185 + iframe_doc.document.open();
186 + iframe_doc.document.write(v.data);
187 + iframe_doc.document.close();
188 + setTimeout(function(){
189 + window.frames['print-visualization'].focus();
190 + window.frames['print-visualization'].print();
191 + iframe.remove();
192 + }, 500);
193 + });
194 + }
76 195 })(jQuery, visualizer);
77 196
78 197 (function ($) {
79 198 $.fn.lock = function () {
@@ -121,5 +240,5 @@
121 240 });
122 241
123 242 return $(this);
124 243 };
125 -})(jQuery);
244 +})(jQuery);