Created
January 26, 2013 13:21
-
-
Save yelcat/4642348 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addJqplotImageButton() { | |
if (!$.jqplot.use_excanvas) { | |
var targets = $('div.jqplot-target'); | |
if (targets.length < 1) { | |
setTimeout(addJqplotImageButton, 2000) | |
return; | |
} | |
targets.each(function(){ | |
var outerDiv = $(document.createElement('div')); | |
var header = $(document.createElement('div')); | |
var div = $(document.createElement('div')); | |
outerDiv.append(header); | |
outerDiv.append(div); | |
outerDiv.addClass('jqplot-image-container'); | |
header.addClass('jqplot-image-container-header'); | |
div.addClass('jqplot-image-container-content'); | |
header.html('右键保存图片...'); | |
var close = $(document.createElement('a')); | |
close.addClass('jqplot-image-container-close'); | |
close.html('Close'); | |
close.attr('href', '#'); | |
close.click(function() { | |
$(this).parents('div.jqplot-image-container').hide(500); | |
}) | |
header.append(close); | |
$(this).after(outerDiv); | |
outerDiv.hide(); | |
outerDiv = header = div = close = null; | |
if (!$.jqplot._noToImageButton) { | |
var btn = $(document.createElement('button')); | |
btn.text('查看图片'); | |
btn.addClass('jqplot-image-button'); | |
btn.bind('click', {chart: $(this)}, function(evt) { | |
var imgelem = evt.data.chart.jqplotToImageElem(); | |
var div = $(this).nextAll('div.jqplot-image-container').first(); | |
div.children('div.jqplot-image-container-content').empty(); | |
div.children('div.jqplot-image-container-content').append(imgelem); | |
div.show(500); | |
div = null; | |
}); | |
$(this).after(btn); | |
btn.after('<br />'); | |
btn = null; | |
} | |
}); | |
} | |
} | |
$(document).ready(addJqplotImageButton); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment