PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.3
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.3
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.3, at js/library.js

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