/* jQuery.print, version 1.0 * (c) Sathvik Ponangi * Licence: CC-By (http://creativecommons.org/licenses/by/3.0/) *--------------------------------------------------------------------------*/ (function($) { // A nice closure for our definitions $.print = $.fn.print = function() { // Print a given set of elements var isNode = function(o) { /* http://stackoverflow.com/a/384380/937891 */ return (typeof Node === "object" ? o instanceof Node : o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName === "string"); } var options, $this; if (isNode(this)) { // If `this` is a HTML element, i.e. for // $(selector).print() $this = $(this); } else { if (arguments.length > 0) { // $.print(selector,options) $this = $(arguments[0]); if (isNode($this[0])) { if (arguments.length > 1) { options = arguments[1]; } } else { // $.print(options) options = arguments[0]; $this = $(this); } } else { // $.print() $this = $(this); } } var defaults = { addGlobalStyles : true, stylesheet : null, rejectWindow : true, noPrintSelector : ".no-print", iframe : true, append : null, prepend : null }; // Default options options = $.extend(defaults, options); // Merge with user-options if (options.rejectWindow && $this[0] === window) { // Use document instead of window as it holds all HTML $this = $(document); } var styles = $(""); if (options.addGlobalStyles) { // Apply the stlyes from the current sheet to the printed page styles = $("style, link"); } if (options.stylesheet) { // Add a custom stylesheet if given styles = $.merge(styles, $('')); } var copy = $this.clone(); // Create a copy of the element to print copy = $("").append(copy); copy.find(options.noPrintSelector).remove();// Remove unwanted elements copy.append(styles.clone()); copy.append($(options.append).clone()); copy.prepend($(options.prepend).clone()); var content = copy.html(); copy.remove(); var w, wdoc; if (options.iframe) { // Use an iframe for printing try { $iframe = $(options.iframe + ""); var iframeCount = $iframe.length; if (iframeCount === 0) { // Create a new iFrame if none is given $iframe = $('