www.lightcourse.com/public/static/plugins/jquery.printarea.js

26 lines
809 B
JavaScript
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

(function($) {
var printAreaCount = 0;
$.fn.printArea = function()
{
var ele = $(this);
var idPrefix = "printArea_";
removePrintArea( idPrefix + printAreaCount );
printAreaCount++;
var iframeId = idPrefix + printAreaCount;
var iframeStyle = 'position:absolute;width:0px;height:0px;left:-730px;top:-730px;';
iframe = document.createElement('IFRAME');
$(iframe).attr({ style : iframeStyle,id    : iframeId});
document.body.appendChild(iframe);
var doc = iframe.contentWindow.document;
doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
doc.close();
var frameWindow = iframe.contentWindow;
frameWindow.close();
frameWindow.focus();
frameWindow.print();
}
var removePrintArea = function(id){
$( "iframe#" + id ).remove();
};
})(jQuery);