| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | /* global visualizer */ |
| 2 | +/* global alert */ | |
| 3 | + | |
| 2 | 4 | (function (wpmv) { |
| 3 | 5 | var vm, vmv; |
| 4 | 6 | |
| 5 | 7 | vm = visualizer.media = {}; |
| @@ -20,9 +22,13 @@ | ||
| 20 | 22 | self.createIframeStates(); |
| 21 | 23 | }, |
| 22 | 24 | |
| 23 | 25 | open: function () { |
| 24 | - wpmv.MediaFrame.prototype.open.apply(this, arguments); | |
| 26 | + try{ | |
| 27 | + wpmv.MediaFrame.prototype.open.apply(this, arguments); | |
| 28 | + }catch(error){ | |
| 29 | + alert(visualizer.i10n.conflict); | |
| 30 | + } | |
| 25 | 31 | this.$el.addClass('hide-menu'); |
| 26 | 32 | } |
| 27 | 33 | }); |
| 28 | 34 | })(wp.media.view); |
| @@ -44,8 +50,27 @@ | ||
| 44 | 50 | |
| 45 | 51 | $(document).ready(function () { |
| 46 | 52 | $('.visualizer-chart, .visualizer-library-pagination').fadeIn(500); |
| 47 | 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 | + | |
| 48 | 73 | $('.visualizer-chart-shortcode').click(function (e) { |
| 49 | 74 | var range, selection; |
| 50 | 75 | |
| 51 | 76 | if (window.getSelection && document.createRange) { |
| @@ -60,14 +85,25 @@ | ||
| 60 | 85 | range.select(); |
| 61 | 86 | } |
| 62 | 87 | }); |
| 63 | 88 | |
| 64 | - $('.add-new-h2').click(function () { | |
| 89 | + $('.add-new-chart').click(function () { | |
| 65 | 90 | var wnd = window, |
| 66 | 91 | view = new vmv.Chart({action: vu.create}); |
| 67 | 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 | |
| 68 | 104 | wnd.send_to_editor = function () { |
| 69 | - wnd.location.href = vu.base; | |
| 105 | + wnd.location.href = vu.base.replace(/type=[a-zA-Z]*/, '').replace(/vaction/, ''); | |
| 70 | 106 | }; |
| 71 | 107 | view.open(); |
| 72 | 108 | |
| 73 | 109 | return false; |
| @@ -77,9 +113,9 @@ | ||
| 77 | 113 | var wnd = window, |
| 78 | 114 | view = new vmv.Chart({action: vu.edit + '&chart=' + $(this).attr('data-chart')}); |
| 79 | 115 | |
| 80 | 116 | wnd.send_to_editor = function () { |
| 81 | - wnd.location.reload(); | |
| 117 | + wnd.location.href = wnd.location.href.replace(/vaction/, ''); | |
| 82 | 118 | }; |
| 83 | 119 | |
| 84 | 120 | view.open(); |
| 85 | 121 | |
| @@ -105,12 +141,27 @@ | ||
| 105 | 141 | } |
| 106 | 142 | }); |
| 107 | 143 | return false; |
| 108 | 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 | + | |
| 109 | 156 | $(window).resize(function () { |
| 110 | 157 | clearTimeout(resizeTimeout); |
| 111 | 158 | resizeTimeout = setTimeout(function () { |
| 112 | 159 | $('.visualizer-chart-canvas').adjust(); |
| 113 | 160 | }, 100); |
| 161 | + }); | |
| 162 | + | |
| 163 | + $('.visualizer-error i.error').on('click', function(){ | |
| 164 | + alert( $(this).attr('data-viz-error') ); | |
| 114 | 165 | }); |
| 115 | 166 | }); |
| 116 | 167 | })(jQuery, visualizer.media.view, visualizer.urls); |