Skip to content

Commit 13a4f0e

Browse files
committed
first commit
0 parents  commit 13a4f0e

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

README

Whitespace-only changes.

jquery.jqprint-0.3.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// -----------------------------------------------------------------------
2+
// Eros Fratini - [email protected]
3+
// jqprint 0.3
4+
//
5+
// - 19/06/2009 - some new implementations, added Opera support
6+
// - 11/05/2009 - first sketch
7+
//
8+
// Printing plug-in for jQuery, evolution of jPrintArea: http://plugins.jquery.com/project/jPrintArea
9+
// requires jQuery 1.3.x
10+
//
11+
// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
12+
//------------------------------------------------------------------------
13+
14+
(function($) {
15+
var opt;
16+
17+
$.fn.jqprint = function (options) {
18+
opt = $.extend({}, $.fn.jqprint.defaults, options);
19+
20+
var $element = (this instanceof jQuery) ? this : $(this);
21+
22+
if (opt.operaSupport && $.browser.opera)
23+
{
24+
var tab = window.open("","jqPrint-preview");
25+
tab.document.open();
26+
27+
var doc = tab.document;
28+
}
29+
else
30+
{
31+
var $iframe = $("<iframe />");
32+
33+
if (!opt.debug) { $iframe.css({ position: "absolute", width: "0px", height: "0px", left: "-600px", top: "-600px" }); }
34+
35+
$iframe.appendTo("body");
36+
var doc = $iframe[0].contentWindow.document;
37+
}
38+
39+
if (opt.importCSS)
40+
{
41+
if ($("link[media=print]").length > 0)
42+
{
43+
$("link[media=print]").each( function() {
44+
doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' media='print' />");
45+
});
46+
}
47+
else
48+
{
49+
$("link").each( function() {
50+
doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' />");
51+
});
52+
}
53+
}
54+
55+
if (opt.printContainer) { doc.write($element.outer()); }
56+
else { $element.each( function() { doc.write($(this).html()); }); }
57+
58+
doc.close();
59+
60+
(opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).focus();
61+
setTimeout( function() { (opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).print(); if (tab) { tab.close(); } }, 1000);
62+
}
63+
64+
$.fn.jqprint.defaults = {
65+
debug: false,
66+
importCSS: true,
67+
printContainer: true,
68+
operaSupport: true
69+
};
70+
71+
// Thanks to 9__, found at http://users.livejournal.com/9__/380664.html
72+
jQuery.fn.outer = function() {
73+
return $($('<div></div>').html(this.clone())).html();
74+
}
75+
})(jQuery);

0 commit comments

Comments
 (0)