PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.7.9
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.7.9
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 / library.js

library.js in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.7.9, at js/library.js

174 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global visualizer */
2 /* global alert */
3
4 (function (wpmv) {
5 var vm, vmv;
6
7 vm = visualizer.media = {};
8 vmv = vm.view = {};
9
10 vmv.Chart = wpmv.MediaFrame.extend({
11 initialize: function () {
12 var self = this;
13
14 _.defaults(self.options, {
15 action: '',
16 state: 'iframe:visualizer'
17 });
18
19 wpmv.MediaFrame.prototype.initialize.apply(self, arguments);
20
21 wpmv.settings.tabUrl = self.options.action;
22 self.createIframeStates();
23 },
24
25 open: function () {
26 try{
27 wpmv.MediaFrame.prototype.open.apply(this, arguments);
28 }catch(error){
29 alert(visualizer.i10n.conflict);
30 }
31 this.$el.addClass('hide-menu');
32 }
33 });
34 })(wp.media.view);
35
36 (function ($, vmv, vu) {
37 var resizeTimeout;
38
39 $.fn.adjust = function () {
40 return $(this).each(function () {
41 var width = $('#visualizer-library').width(),
42 margin = width * 0.02;
43
44 width *= 0.305;
45 $(this).prev( '.visualizer-chart-title' ).width(width - 14);
46 var ChartHeight = width * 0.93;
47 if ( $( '.visualizer-nochart-canvas' ).length === 0 ) {
48 ChartHeight = width * 0.78;
49 if ( $( '#visualizer-sidebar' ).hasClass('one-columns') ) {
50 ChartHeight = width * 0.92;
51 }
52 }
53 $(this).width(width).height( ChartHeight );
54 });
55 };
56
57 $('.visualizer-chart-canvas').adjust();
58
59 $(document).ready(function () {
60 // clears the filters in the library form and submits.
61 $('#viz-lib-reset').on('click', function(e){
62 e.preventDefault();
63 $(this).parent('form')[0].reset();
64 $(this).parent('form').find('.viz-filter').each(function(index, el){
65 var tag = $(el).prop('tagName').toLowerCase() + (typeof $(el).attr('type') !== 'undefined' ? $(el).attr('type').toLowerCase() : '');
66 switch(tag){
67 case 'select':
68 $(el).prop('selectedIndex', 0);
69 break;
70 case 'inputtext':
71 $(el).val('');
72 break;
73 }
74
75 });
76 $(this).parent('form').submit();
77 });
78
79 $('.visualizer-chart-shortcode').click(function (e) {
80 var range, selection;
81
82 if (window.getSelection && document.createRange) {
83 selection = window.getSelection();
84 range = document.createRange();
85 range.selectNodeContents(e.target);
86 selection.removeAllRanges();
87 selection.addRange(range);
88 } else if (document.selection && document.body.createTextRange) {
89 range = document.body.createTextRange();
90 range.moveToElementText(e.target);
91 range.select();
92 }
93 });
94
95 $('.add-new-chart').click(function () {
96 var wnd = window,
97 view = new vmv.Chart({action: vu.create});
98
99 window.parent.addEventListener('message', function(event){
100 switch(event.data) {
101 case 'visualizer:mediaframe:close':
102 view.close();
103 break;
104 }
105 }, false);
106
107 // remove the 'type' while refreshing the library page on creation of a new chart.
108 // this is to avoid cases where users have filtered for chart type A and end up creating chart type B
109 // remove 'vaction' as well so that additional actions are removed
110 wnd.send_to_editor = function () {
111 wnd.location.href = vu.base.replace(/type=[a-zA-Z]*/, '').replace(/vaction/, '');
112 };
113 view.open();
114
115 return false;
116 });
117
118 $('.visualizer-chart-edit').click(function () {
119 var wnd = window,
120 view = new vmv.Chart({action: vu.edit + '&chart=' + $(this).attr('data-chart')});
121
122 wnd.send_to_editor = function () {
123 wnd.location.href = wnd.location.href.replace(/vaction/, '');
124 };
125
126 view.open();
127
128 return false;
129 });
130
131 $(".visualizer-chart-export").on("click", function () {
132 $.ajax({
133 url: $(this).attr("data-chart"),
134 method: "get",
135 success: function (data, textStatus, jqXHR) {
136 var a = document.createElement("a");
137 document.body.appendChild(a);
138 a.style = "display: none";
139 var blob = new Blob([data.data.csv], {type: "application/csv"}),
140 url = window.URL.createObjectURL(blob);
141 a.href = url;
142 a.download = data.data.name;
143 a.click();
144 setTimeout(function () {
145 window.URL.revokeObjectURL(url);
146 }, 100);
147 }
148 });
149 return false;
150 });
151
152 $(".visualizer-chart-image").on("click", function () {
153 $('body').trigger('visualizer:action:specificchart', {action: 'image', id: $(this).attr("data-chart"), data: null, dataObj: {name: $(this).attr("data-chart-title")}});
154 return false;
155 });
156
157 // if vaction=addnew is found as a GET request parameter, show the modal.
158 if(location.href.indexOf('vaction=addnew') !== -1){
159 $('.add-new-chart').first().trigger('click');
160 }
161
162 $(window).resize(function () {
163 clearTimeout(resizeTimeout);
164 resizeTimeout = setTimeout(function () {
165 $('.visualizer-chart-canvas').adjust();
166 }, 100);
167 });
168
169 $('.visualizer-error i.error').on('click', function(){
170 alert( $(this).attr('data-viz-error') );
171 });
172 $('.visualizer-chart:not(.visualizer-chart-display), .visualizer-library-pagination').fadeIn(500);
173 });
174 })(jQuery, visualizer.media.view, visualizer.urls);