// ----------------------------------------------------------------------- // eros fratini - eros@recoding.it // jqprint 0.3 // // - 19/06/2009 - some new implementations, added opera support // - 11/05/2009 - first sketch // // printing plug-in for jquery, evolution of jprintarea: http://plugins.jquery.com/project/jprintarea // requires jquery 1.3.x // // licensed under the mit license: http://www.opensource.org/licenses/mit-license.php //------------------------------------------------------------------------ (function($) { var opt; $.fn.jqprint = function (options) { opt = $.extend({}, $.fn.jqprint.defaults, options); var $element = (this instanceof jquery) ? this : $(this); if (opt.operasupport && $.support.opera) { var tab = window.open("","jqprint-preview"); tab.document.open(); var doc = tab.document; } else { var $iframe = $(""); if (!opt.debug) { $iframe.css({ position: "absolute", width: "0px", height: "0px", left: "-600px", top: "-600px" }); } $iframe.appendto("body"); var doc = $iframe[0].contentwindow.document; } if (opt.importcss) { if ($("link[media=print]").length > 0) { $("link[media=print]").each( function() { doc.write(""); }); } else { $("link").each( function() { doc.write(""); }); } } if (opt.printcontainer) { doc.write($element.outer()); } else { $element.each( function() { doc.write($(this).html()); }); } doc.close(); (opt.operasupport && $.support.opera ? tab : $iframe[0].contentwindow).focus(); settimeout( function() { (opt.operasupport && $.support.opera ? tab : $iframe[0].contentwindow).print(); if (tab) { tab.close(); } }, 1000); } $.fn.jqprint.defaults = { debug: false, importcss: true, printcontainer: true, operasupport: true }; // thanks to 9__, found at http://users.livejournal.com/9__/380664.html jquery.fn.outer = function() { return $($('
').html(this.clone())).html(); } })(jquery);