PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.2
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
visualizer / js / render-facade.js

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

179 lines 7.4 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 var clipboard = new Clipboard('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
10 clipboard.on('success', function(e) {
11 window.alert(v.i10n['copied']);
12 });
13 }
14 $('a.visualizer-action[data-visualizer-type!=copy]').off('click').on('click', function(e) {
15 var type = $(this).attr( 'data-visualizer-type' );
16 var chart = $(this).attr( 'data-visualizer-chart-id' );
17 var container = $(this).attr( 'data-visualizer-container-id' );
18 var lock = $('.visualizer-front.visualizer-front-' + chart);
19 var mime = $(this).attr( 'data-visualizer-mime' );
20 console.log(mime);
21 lock.lock();
22 e.preventDefault();
23 $.ajax({
24 url : v.rest_url.replace('#id#', chart).replace('#type#', type),
25 success: function(data) {
26 if (data && data.data) {
27 switch(type){
28 case 'csv':
29 var blob = new Blob([data.data.csv], {type: mime });
30 if(window.navigator.msSaveOrOpenBlob){
31 window.navigator.msSaveOrOpenBlob(blob, data.data.name);
32 } else {
33 var url = window.URL.createObjectURL(blob);
34 var $a = $("<a>");
35 $a.attr("href", url);
36 $("body").append($a);
37 $a.attr("download", data.data.name);
38 $a[0].click();
39 setTimeout(function () {
40 window.URL.revokeObjectURL(url);
41 $a.remove();
42 }, 100);
43 }
44 break;
45 case 'xls':
46 if(window.navigator.msSaveOrOpenBlob){
47 blob = new Blob([s2ab(atob(data.data.raw))], {type: '' });
48 window.navigator.msSaveOrOpenBlob(blob, data.data.name);
49 } else {
50 var $a = $("<a>"); // jshint ignore:line
51 $a.attr("href", data.data.csv);
52 $("body").append($a);
53 $a.attr("download", data.data.name);
54 $a[0].click();
55 $a.remove();
56 }
57 break;
58 case 'print':
59 $('body').trigger('visualizer:action:specificchart', {action: 'print', id: container, data: data.data.csv});
60 break;
61 default:
62 if(window.visualizer_perform_action) {
63 window.visualizer_perform_action(type, chart, data.data);
64 }
65 break;
66 }
67 }
68 lock.unlock();
69 }
70 });
71 });
72 }
73
74 function s2ab(s) {
75 var buf = new ArrayBuffer(s.length);
76 var view = new Uint8Array(buf);
77 for (var i=0; i !== s.length; ++i) {
78 view[i] = s.charCodeAt(i) & 0xFF;
79 }
80 return buf;
81 }
82
83 $(document).ready(function(){
84
85 // for updating the currently displayed chart (preview mode)
86 window.updateChartPreview = function(){
87 var event = new CustomEvent('visualizer:render:currentchart:update', {detail: {visualizer: visualizer}});
88 document.body.dispatchEvent(event);
89 };
90
91 // facade loads N times in the library (where N = the number of different chart libraries supported)
92 // so all charts are also loaded N times
93 // this will ensure that no matter how many times facade is loaded, it initializes all charts only once.
94 // fixed as part of the issue to add annotations.
95 if(visualizer.page_type === 'library'){
96 if(localStorage.getItem( 'viz-facade-loaded' ) === '1'){
97 // prevent library from hanging.
98 setTimeout( function(){
99 localStorage.removeItem( 'viz-facade-loaded' );
100 }, 2000);
101 return;
102 }
103 localStorage.setItem( 'viz-facade-loaded', '1');
104 // remove the flag so that repeated loading of the library does not cause problems.
105 setTimeout( function(){
106 localStorage.removeItem( 'viz-facade-loaded' );
107 }, 2000);
108 }
109 $('body').trigger('visualizer:render:chart:start', visualizer);
110 initActionsButtons(visualizer);
111 registerDefaultActions();
112 });
113
114 function registerDefaultActions(){
115 $('body').off('visualizer:action:specificchart:defaultprint').on('visualizer:action:specificchart:defaultprint', function(event, v){
116 var iframe = $('<iframe>').attr("name", "print-visualization").attr("id", "print-visualization").css("position", "absolute");
117 iframe.appendTo($('body'));
118 var iframe_doc = iframe.get(0).contentWindow || iframe.get(0).contentDocument.document || iframe.get(0).contentDocument;
119 iframe_doc.document.open();
120 iframe_doc.document.write(v.data);
121 iframe_doc.document.close();
122 setTimeout(function(){
123 window.frames['print-visualization'].focus();
124 window.frames['print-visualization'].print();
125 iframe.remove();
126 }, 500);
127 });
128 }
129 })(jQuery, visualizer);
130
131 (function ($) {
132 $.fn.lock = function () {
133 $(this).each(function () {
134 var $this = $(this);
135 var position = $this.css('position');
136
137 if (!position) {
138 position = 'static';
139 }
140
141 switch (position) {
142 case 'absolute':
143 case 'relative':
144 break;
145 default:
146 $this.css('position', 'relative');
147 break;
148 }
149 $this.data('position', position);
150
151 var width = $this.width(),
152 height = $this.height();
153
154 var locker = $('<div class="locker"></div>');
155 locker.width(width).height(height);
156
157 var loader = $('<div class="locker-loader"></div>');
158 loader.width(width).height(height);
159
160 locker.append(loader);
161 $this.append(locker);
162 $(window).resize(function () {
163 $this.find('.locker,.locker-loader').width($this.width()).height($this.height());
164 });
165 });
166
167 return $(this);
168 };
169
170 $.fn.unlock = function () {
171 $(this).each(function () {
172 $(this).find('.locker').remove();
173 $(this).css('position', $(this).data('position'));
174 });
175
176 return $(this);
177 };
178 })(jQuery);
179