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
visualizer / js / render-facade.js

render-facade.js in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.4.4, at js/render-facade.js

181 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global console */
2 /* global visualizer */
3 /* global jQuery */
4
5 (function($, visualizer){
6
7 function initActionsButtons(v) {
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 });
12 var clipboard = new Clipboard('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
13 clipboard.on('success', function(e) {
14 window.alert(v.i10n['copied']);
15 });
16 }
17 $('a.visualizer-action[data-visualizer-type!=copy]').off('click').on('click', function(e) {
18 var type = $(this).attr( 'data-visualizer-type' );
19 var chart = $(this).attr( 'data-visualizer-chart-id' );
20 var container = $(this).attr( 'data-visualizer-container-id' );
21 var lock = $('.visualizer-front.visualizer-front-' + chart);
22 var mime = $(this).attr( 'data-visualizer-mime' );
23 lock.lock();
24 e.preventDefault();
25 $.ajax({
26 url : v.rest_url.replace('#id#', chart).replace('#type#', type),
27 success: function(data) {
28 if (data && data.data) {
29 switch(type){
30 case 'csv':
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 }
46 break;
47 case 'xls':
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 }
59 break;
60 case 'print':
61 case 'image':
62 $('body').trigger('visualizer:action:specificchart', {action: type, id: container, data: data.data.csv, dataObj: data.data});
63 break;
64 default:
65 if(window.visualizer_perform_action) {
66 window.visualizer_perform_action(type, chart, data.data);
67 }
68 break;
69 }
70 }
71 lock.unlock();
72 }
73 });
74 });
75 }
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
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
111 $('body').trigger('visualizer:render:chart:start', visualizer);
112 initActionsButtons(visualizer);
113 registerDefaultActions();
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 }
131 })(jQuery, visualizer);
132
133 (function ($) {
134 $.fn.lock = function () {
135 $(this).each(function () {
136 var $this = $(this);
137 var position = $this.css('position');
138
139 if (!position) {
140 position = 'static';
141 }
142
143 switch (position) {
144 case 'absolute':
145 case 'relative':
146 break;
147 default:
148 $this.css('position', 'relative');
149 break;
150 }
151 $this.data('position', position);
152
153 var width = $this.width(),
154 height = $this.height();
155
156 var locker = $('<div class="locker"></div>');
157 locker.width(width).height(height);
158
159 var loader = $('<div class="locker-loader"></div>');
160 loader.width(width).height(height);
161
162 locker.append(loader);
163 $this.append(locker);
164 $(window).resize(function () {
165 $this.find('.locker,.locker-loader').width($this.width()).height($this.height());
166 });
167 });
168
169 return $(this);
170 };
171
172 $.fn.unlock = function () {
173 $(this).each(function () {
174 $(this).find('.locker').remove();
175 $(this).css('position', $(this).data('position'));
176 });
177
178 return $(this);
179 };
180 })(jQuery);
181