| 1 |
(function(wpmv) { |
| 2 |
var vm, vmv; |
| 3 |
|
| 4 |
vm = visualizer.media = {}; |
| 5 |
vmv = vm.view = {}; |
| 6 |
|
| 7 |
vmv.Chart = wpmv.MediaFrame.extend({ |
| 8 |
initialize: function() { |
| 9 |
var self = this; |
| 10 |
|
| 11 |
_.defaults(self.options, { |
| 12 |
action: '', |
| 13 |
state: 'iframe:visualizer' |
| 14 |
}); |
| 15 |
|
| 16 |
wpmv.MediaFrame.prototype.initialize.apply(self, arguments); |
| 17 |
|
| 18 |
wpmv.settings.tabUrl = self.options.action; |
| 19 |
self.createIframeStates(); |
| 20 |
}, |
| 21 |
|
| 22 |
open: function() { |
| 23 |
wpmv.MediaFrame.prototype.open.apply(this, arguments); |
| 24 |
this.$el.addClass('hide-menu'); |
| 25 |
} |
| 26 |
}); |
| 27 |
})(wp.media.view); |
| 28 |
|
| 29 |
(function($, vmv, vu) { |
| 30 |
var resizeTimeout; |
| 31 |
|
| 32 |
$.fn.adjust = function() { |
| 33 |
return $(this).each(function() { |
| 34 |
var width = $('#visualizer-library').width(), |
| 35 |
margin = width * 0.02; |
| 36 |
|
| 37 |
width *= 0.305; |
| 38 |
$(this).width(width - 14).height(width * 0.75).parent().css('margin-right', margin + 'px').css('margin-bottom', margin + 'px'); |
| 39 |
}); |
| 40 |
} |
| 41 |
|
| 42 |
$('.visualizer-chart-canvas').adjust(); |
| 43 |
|
| 44 |
$(document).ready(function() { |
| 45 |
$('.visualizer-chart, .visualizer-library-pagination').fadeIn(500); |
| 46 |
|
| 47 |
$('.visualizer-chart-shortcode').click(function(e) { |
| 48 |
var range, selection; |
| 49 |
|
| 50 |
if (window.getSelection && document.createRange) { |
| 51 |
selection = window.getSelection(); |
| 52 |
range = document.createRange(); |
| 53 |
range.selectNodeContents(e.target); |
| 54 |
selection.removeAllRanges(); |
| 55 |
selection.addRange(range); |
| 56 |
} else if (document.selection && document.body.createTextRange) { |
| 57 |
range = document.body.createTextRange(); |
| 58 |
range.moveToElementText(e.target); |
| 59 |
range.select(); |
| 60 |
} |
| 61 |
}); |
| 62 |
|
| 63 |
$('.add-new-h2').click(function() { |
| 64 |
var wnd = window, |
| 65 |
view = new vmv.Chart({action: vu.create}); |
| 66 |
|
| 67 |
wnd.send_to_editor = function() { |
| 68 |
wnd.location.href = vu.base; |
| 69 |
}; |
| 70 |
view.open(); |
| 71 |
|
| 72 |
return false; |
| 73 |
}); |
| 74 |
|
| 75 |
$('.visualizer-chart-edit').click(function() { |
| 76 |
var wnd = window, |
| 77 |
view = new vmv.Chart({action: vu.edit + '&chart=' + $(this).attr('data-chart')}); |
| 78 |
|
| 79 |
wnd.send_to_editor = function() { |
| 80 |
wnd.location.reload(); |
| 81 |
}; |
| 82 |
|
| 83 |
view.open(); |
| 84 |
|
| 85 |
return false; |
| 86 |
}); |
| 87 |
|
| 88 |
$(".visualizer-chart-export").on("click", function() { |
| 89 |
$.ajax({ |
| 90 |
url: $(this).attr("data-chart"), |
| 91 |
method: "get", |
| 92 |
success: function( data, textStatus, jqXHR ){ |
| 93 |
var a = document.createElement("a"); |
| 94 |
document.body.appendChild(a); |
| 95 |
a.style = "display: none"; |
| 96 |
var blob = new Blob([data.data.csv], {type: "application/csv"}), |
| 97 |
url = window.URL.createObjectURL(blob); |
| 98 |
a.href = url; |
| 99 |
a.download = data.data.name; |
| 100 |
a.click(); |
| 101 |
window.URL.revokeObjectURL(url); |
| 102 |
} |
| 103 |
}); |
| 104 |
return false; |
| 105 |
}); |
| 106 |
|
| 107 |
$(window).resize(function() { |
| 108 |
clearTimeout(resizeTimeout); |
| 109 |
resizeTimeout = setTimeout(function() { |
| 110 |
$('.visualizer-chart-canvas').adjust(); |
| 111 |
}, 100); |
| 112 |
}); |
| 113 |
}); |
| 114 |
})(jQuery, visualizer.media.view, visualizer.urls); |