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 / library.js

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

139 lines 4.6 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 $('.visualizer-chart-shortcode').click(function (e) {
51 var range, selection;
52
53 if (window.getSelection && document.createRange) {
54 selection = window.getSelection();
55 range = document.createRange();
56 range.selectNodeContents(e.target);
57 selection.removeAllRanges();
58 selection.addRange(range);
59 } else if (document.selection && document.body.createTextRange) {
60 range = document.body.createTextRange();
61 range.moveToElementText(e.target);
62 range.select();
63 }
64 });
65
66 $('.add-new-chart').click(function () {
67 var wnd = window,
68 view = new vmv.Chart({action: vu.create});
69
70 window.parent.addEventListener('message', function(event){
71 switch(event.data) {
72 case 'visualizer:mediaframe:close':
73 view.close();
74 break;
75 }
76 }, false);
77
78 // remove the 'type' while refreshing the library page on creation of a new chart.
79 // this is to avoid cases where users have filtered for chart type A and end up creating chart type B
80 // remove 'vaction' as well so that additional actions are removed
81 wnd.send_to_editor = function () {
82 wnd.location.href = vu.base.replace(/type=[a-zA-Z]*/, '').replace(/vaction/, '');
83 };
84 view.open();
85
86 return false;
87 });
88
89 $('.visualizer-chart-edit').click(function () {
90 var wnd = window,
91 view = new vmv.Chart({action: vu.edit + '&chart=' + $(this).attr('data-chart')});
92
93 wnd.send_to_editor = function () {
94 wnd.location.href = wnd.location.href.replace(/vaction/, '');
95 };
96
97 view.open();
98
99 return false;
100 });
101
102 $(".visualizer-chart-export").on("click", function () {
103 $.ajax({
104 url: $(this).attr("data-chart"),
105 method: "get",
106 success: function (data, textStatus, jqXHR) {
107 var a = document.createElement("a");
108 document.body.appendChild(a);
109 a.style = "display: none";
110 var blob = new Blob([data.data.csv], {type: "application/csv"}),
111 url = window.URL.createObjectURL(blob);
112 a.href = url;
113 a.download = data.data.name;
114 a.click();
115 setTimeout(function () {
116 window.URL.revokeObjectURL(url);
117 }, 100);
118 }
119 });
120 return false;
121 });
122
123 // if vaction=addnew is found as a GET request parameter, show the modal.
124 if(location.href.indexOf('vaction=addnew') !== -1){
125 $('.add-new-chart').trigger('click');
126 }
127
128 $(window).resize(function () {
129 clearTimeout(resizeTimeout);
130 resizeTimeout = setTimeout(function () {
131 $('.visualizer-chart-canvas').adjust();
132 }, 100);
133 });
134
135 $('.visualizer-error i.error').on('click', function(){
136 alert( $(this).attr('data-viz-error') );
137 });
138 });
139 })(jQuery, visualizer.media.view, visualizer.urls);