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 +85 -30 3.1.03.4.4 View file →
@@ -5,17 +5,22 @@
5 5 (function($, visualizer){
6 6
7 7 function initActionsButtons(v) {
8 8 if($('a.visualizer-action[data-visualizer-type=copy]').length > 0) {
9 + $('a.visualizer-action[data-visualizer-type=copy]').on('click', function(e) {
10 + e.preventDefault();
11 + });
9 12 var clipboard = new Clipboard('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
10 13 clipboard.on('success', function(e) {
11 14 window.alert(v.i10n['copied']);
12 15 });
13 16 }
14 - $('a.visualizer-action[data-visualizer-type!=copy]').on('click', function(e) {
17 + $('a.visualizer-action[data-visualizer-type!=copy]').off('click').on('click', function(e) {
15 18 var type = $(this).attr( 'data-visualizer-type' );
16 19 var chart = $(this).attr( 'data-visualizer-chart-id' );
20 + var container = $(this).attr( 'data-visualizer-container-id' );
17 21 var lock = $('.visualizer-front.visualizer-front-' + chart);
22 + var mime = $(this).attr( 'data-visualizer-mime' );
18 23 lock.lock();
19 24 e.preventDefault();
20 25 $.ajax({
21 26 url : v.rest_url.replace('#id#', chart).replace('#type#', type),
@@ -22,40 +27,40 @@
22 27 success: function(data) {
23 28 if (data && data.data) {
24 29 switch(type){
25 30 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);
31 + var blob = new Blob([data.data.csv], {type: mime });
32 + if(window.navigator.msSaveOrOpenBlob){
33 + window.navigator.msSaveOrOpenBlob(blob, data.data.name);
34 + } else {
35 + var url = window.URL.createObjectURL(blob);
36 + var $a = $("<a>");
37 + $a.attr("href", url);
38 + $("body").append($a);
39 + $a.attr("download", data.data.name);
40 + $a[0].click();
41 + setTimeout(function () {
42 + window.URL.revokeObjectURL(url);
43 + $a.remove();
44 + }, 100);
45 + }
37 46 break;
38 47 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();
48 + if(window.navigator.msSaveOrOpenBlob){
49 + blob = new Blob([s2ab(atob(data.data.raw))], {type: '' });
50 + window.navigator.msSaveOrOpenBlob(blob, data.data.name);
51 + } else {
52 + var $a = $("<a>"); // jshint ignore:line
53 + $a.attr("href", data.data.csv);
54 + $("body").append($a);
55 + $a.attr("download", data.data.name);
56 + $a[0].click();
57 + $a.remove();
58 + }
45 59 break;
46 60 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);
61 + case 'image':
62 + $('body').trigger('visualizer:action:specificchart', {action: type, id: container, data: data.data.csv, dataObj: data.data});
58 63 break;
59 64 default:
60 65 if(window.visualizer_perform_action) {
61 66 window.visualizer_perform_action(type, chart, data.data);
@@ -68,12 +73,62 @@
68 73 });
69 74 });
70 75 }
71 76
77 + function s2ab(s) {
78 + var buf = new ArrayBuffer(s.length);
79 + var view = new Uint8Array(buf);
80 + for (var i=0; i !== s.length; ++i) {
81 + view[i] = s.charCodeAt(i) & 0xFF;
82 + }
83 + return buf;
84 + }
85 +
72 86 $(document).ready(function(){
87 +
88 + // for updating the currently displayed chart (preview mode)
89 + window.vizUpdateChartPreview = function(){
90 + var event = new CustomEvent('visualizer:render:currentchart:update', {detail: {visualizer: visualizer}});
91 + document.body.dispatchEvent(event);
92 + };
93 +
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 +
73 111 $('body').trigger('visualizer:render:chart:start', visualizer);
74 112 initActionsButtons(visualizer);
113 + registerDefaultActions();
75 114 });
115 +
116 + function registerDefaultActions(){
117 + $('body').off('visualizer:action:specificchart:defaultprint').on('visualizer:action:specificchart:defaultprint', function(event, v){
118 + var iframe = $('<iframe>').attr("name", "print-visualization").attr("id", "print-visualization").css("position", "absolute");
119 + iframe.appendTo($('body'));
120 + var iframe_doc = iframe.get(0).contentWindow || iframe.get(0).contentDocument.document || iframe.get(0).contentDocument;
121 + iframe_doc.document.open();
122 + iframe_doc.document.write(v.data);
123 + iframe_doc.document.close();
124 + setTimeout(function(){
125 + window.frames['print-visualization'].focus();
126 + window.frames['print-visualization'].print();
127 + iframe.remove();
128 + }, 500);
129 + });
130 + }
76 131 })(jQuery, visualizer);
77 132
78 133 (function ($) {
79 134 $.fn.lock = function () {
@@ -121,5 +176,5 @@
121 176 });
122 177
123 178 return $(this);
124 179 };
125 -})(jQuery);
180 +})(jQuery);