| 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 |
var width = $('#visualizer-library').width(), |
| 34 |
margin = width * 0.02; |
| 35 |
|
| 36 |
width *= 0.305; |
| 37 |
$(this).width(width - 14).height(width * 0.75).parent().css('margin-right', margin + 'px').css('margin-bottom', margin + 'px'); |
| 38 |
} |
| 39 |
|
| 40 |
$('.visualizer-chart-canvas').adjust(); |
| 41 |
|
| 42 |
$(document).ready(function() { |
| 43 |
$('.visualizer-chart-shortcode').click(function(e) { |
| 44 |
var range, selection; |
| 45 |
|
| 46 |
if (window.getSelection && document.createRange) { |
| 47 |
selection = window.getSelection(); |
| 48 |
range = document.createRange(); |
| 49 |
range.selectNodeContents(e.target); |
| 50 |
selection.removeAllRanges(); |
| 51 |
selection.addRange(range); |
| 52 |
} else if (document.selection && document.body.createTextRange) { |
| 53 |
range = document.body.createTextRange(); |
| 54 |
range.moveToElementText(e.target); |
| 55 |
range.select(); |
| 56 |
} |
| 57 |
}); |
| 58 |
|
| 59 |
$('.add-new-h2').click(function() { |
| 60 |
var wnd = window, |
| 61 |
view = new vmv.Chart({action: vu.create}); |
| 62 |
|
| 63 |
wnd.send_to_editor = function() { |
| 64 |
wnd.location.href = vu.base; |
| 65 |
}; |
| 66 |
view.open(); |
| 67 |
|
| 68 |
return false; |
| 69 |
}); |
| 70 |
|
| 71 |
$('.visualizer-chart-edit').click(function() { |
| 72 |
var wnd = window, |
| 73 |
view = new vmv.Chart({action: vu.edit + '&chart=' + $(this).attr('data-chart')}); |
| 74 |
|
| 75 |
wnd.send_to_editor = function() { |
| 76 |
wnd.location.reload(); |
| 77 |
}; |
| 78 |
|
| 79 |
view.open(); |
| 80 |
|
| 81 |
return false; |
| 82 |
}); |
| 83 |
|
| 84 |
$(window).resize(function() { |
| 85 |
clearTimeout(resizeTimeout); |
| 86 |
resizeTimeout = setTimeout(function() { |
| 87 |
$('.visualizer-chart-canvas').adjust(); |
| 88 |
}, 100); |
| 89 |
}); |
| 90 |
}); |
| 91 |
})(jQuery, visualizer.media.view, visualizer.urls); |