PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.8
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.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 3.10.4 All 148 releases
visualizer / js / library.js

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

167 lines 5.8 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).width(width - 14).height(width * 0.75).parent().css('margin-right', margin + 'px').css('margin-bottom', margin + 'px');
46 });
47 };
48
49 $('.visualizer-chart-canvas').adjust();
50
51 $(document).ready(function () {
52 $('.visualizer-chart, .visualizer-library-pagination').fadeIn(500);
53
54 // clears the filters in the library form and submits.
55 $('#viz-lib-reset').on('click', function(e){
56 e.preventDefault();
57 $(this).parent('form')[0].reset();
58 $(this).parent('form').find('.viz-filter').each(function(index, el){
59 var tag = $(el).prop('tagName').toLowerCase() + (typeof $(el).attr('type') !== 'undefined' ? $(el).attr('type').toLowerCase() : '');
60 switch(tag){
61 case 'select':
62 $(el).prop('selectedIndex', 0);
63 break;
64 case 'inputtext':
65 $(el).val('');
66 break;
67 }
68
69 });
70 $(this).parent('form').submit();
71 });
72
73 $('.visualizer-chart-shortcode').click(function (e) {
74 var range, selection;
75
76 if (window.getSelection && document.createRange) {
77 selection = window.getSelection();
78 range = document.createRange();
79 range.selectNodeContents(e.target);
80 selection.removeAllRanges();
81 selection.addRange(range);
82 } else if (document.selection && document.body.createTextRange) {
83 range = document.body.createTextRange();
84 range.moveToElementText(e.target);
85 range.select();
86 }
87 });
88
89 $('.add-new-chart').click(function () {
90 var wnd = window,
91 view = new vmv.Chart({action: vu.create});
92
93 window.parent.addEventListener('message', function(event){
94 switch(event.data) {
95 case 'visualizer:mediaframe:close':
96 view.close();
97 break;
98 }
99 }, false);
100
101 // remove the 'type' while refreshing the library page on creation of a new chart.
102 // this is to avoid cases where users have filtered for chart type A and end up creating chart type B
103 // remove 'vaction' as well so that additional actions are removed
104 wnd.send_to_editor = function () {
105 wnd.location.href = vu.base.replace(/type=[a-zA-Z]*/, '').replace(/vaction/, '');
106 };
107 view.open();
108
109 return false;
110 });
111
112 $('.visualizer-chart-edit').click(function () {
113 var wnd = window,
114 view = new vmv.Chart({action: vu.edit + '&chart=' + $(this).attr('data-chart')});
115
116 wnd.send_to_editor = function () {
117 wnd.location.href = wnd.location.href.replace(/vaction/, '');
118 };
119
120 view.open();
121
122 return false;
123 });
124
125 $(".visualizer-chart-export").on("click", function () {
126 $.ajax({
127 url: $(this).attr("data-chart"),
128 method: "get",
129 success: function (data, textStatus, jqXHR) {
130 var a = document.createElement("a");
131 document.body.appendChild(a);
132 a.style = "display: none";
133 var blob = new Blob([data.data.csv], {type: "application/csv"}),
134 url = window.URL.createObjectURL(blob);
135 a.href = url;
136 a.download = data.data.name;
137 a.click();
138 setTimeout(function () {
139 window.URL.revokeObjectURL(url);
140 }, 100);
141 }
142 });
143 return false;
144 });
145
146 $(".visualizer-chart-image").on("click", function () {
147 $('body').trigger('visualizer:action:specificchart', {action: 'image', id: $(this).attr("data-chart"), data: null, dataObj: {name: $(this).attr("data-chart-title")}});
148 return false;
149 });
150
151 // if vaction=addnew is found as a GET request parameter, show the modal.
152 if(location.href.indexOf('vaction=addnew') !== -1){
153 $('.add-new-chart').first().trigger('click');
154 }
155
156 $(window).resize(function () {
157 clearTimeout(resizeTimeout);
158 resizeTimeout = setTimeout(function () {
159 $('.visualizer-chart-canvas').adjust();
160 }, 100);
161 });
162
163 $('.visualizer-error i.error').on('click', function(){
164 alert( $(this).attr('data-viz-error') );
165 });
166 });
167 })(jQuery, visualizer.media.view, visualizer.urls);