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

133 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global visualizer */
2 (function (wpmv) {
3 var vm, vmv;
4
5 vm = visualizer.media = {};
6 vmv = vm.view = {};
7
8 vmv.Chart = wpmv.MediaFrame.extend({
9 initialize: function () {
10 var self = this;
11
12 _.defaults(self.options, {
13 action: '',
14 state: 'iframe:visualizer'
15 });
16
17 wpmv.MediaFrame.prototype.initialize.apply(self, arguments);
18
19 wpmv.settings.tabUrl = self.options.action;
20 self.createIframeStates();
21 },
22
23 open: function () {
24 wpmv.MediaFrame.prototype.open.apply(this, arguments);
25 this.$el.addClass('hide-menu');
26 }
27 });
28 })(wp.media.view);
29
30 (function ($, vmv, vu) {
31 var resizeTimeout;
32
33 $.fn.adjust = function () {
34 return $(this).each(function () {
35 var width = $('#visualizer-library').width(),
36 margin = width * 0.02;
37
38 width *= 0.305;
39 $(this).width(width - 14).height(width * 0.75).parent().css('margin-right', margin + 'px').css('margin-bottom', margin + 'px');
40 });
41 };
42
43 $('.visualizer-chart-canvas').adjust();
44
45 $(document).ready(function () {
46 $('.visualizer-chart, .visualizer-library-pagination').fadeIn(500);
47
48 $('.visualizer-chart-shortcode').click(function (e) {
49 var range, selection;
50
51 if (window.getSelection && document.createRange) {
52 selection = window.getSelection();
53 range = document.createRange();
54 range.selectNodeContents(e.target);
55 selection.removeAllRanges();
56 selection.addRange(range);
57 } else if (document.selection && document.body.createTextRange) {
58 range = document.body.createTextRange();
59 range.moveToElementText(e.target);
60 range.select();
61 }
62 });
63
64 $('.add-new-chart').click(function () {
65 var wnd = window,
66 view = new vmv.Chart({action: vu.create});
67
68 window.parent.addEventListener('message', function(event){
69 switch(event.data) {
70 case 'visualizer:mediaframe:close':
71 view.close();
72 break;
73 }
74 }, false);
75
76 // remove the 'type' while refreshing the library page on creation of a new chart.
77 // this is to avoid cases where users have filtered for chart type A and end up creating chart type B
78 // remove 'vaction' as well so that additional actions are removed
79 wnd.send_to_editor = function () {
80 wnd.location.href = vu.base.replace(/type=[a-zA-Z]*/, '').replace(/vaction/, '');
81 };
82 view.open();
83
84 return false;
85 });
86
87 $('.visualizer-chart-edit').click(function () {
88 var wnd = window,
89 view = new vmv.Chart({action: vu.edit + '&chart=' + $(this).attr('data-chart')});
90
91 wnd.send_to_editor = function () {
92 wnd.location.href = wnd.location.href.replace(/vaction/, '');
93 };
94
95 view.open();
96
97 return false;
98 });
99
100 $(".visualizer-chart-export").on("click", function () {
101 $.ajax({
102 url: $(this).attr("data-chart"),
103 method: "get",
104 success: function (data, textStatus, jqXHR) {
105 var a = document.createElement("a");
106 document.body.appendChild(a);
107 a.style = "display: none";
108 var blob = new Blob([data.data.csv], {type: "application/csv"}),
109 url = window.URL.createObjectURL(blob);
110 a.href = url;
111 a.download = data.data.name;
112 a.click();
113 setTimeout(function () {
114 window.URL.revokeObjectURL(url);
115 }, 100);
116 }
117 });
118 return false;
119 });
120
121 // if vaction=addnew is found as a GET request parameter, show the modal.
122 if(location.href.indexOf('vaction=addnew') !== -1){
123 $('.add-new-chart').trigger('click');
124 }
125
126 $(window).resize(function () {
127 clearTimeout(resizeTimeout);
128 resizeTimeout = setTimeout(function () {
129 $('.visualizer-chart-canvas').adjust();
130 }, 100);
131 });
132 });
133 })(jQuery, visualizer.media.view, visualizer.urls);