vendor: 8,129 bytes, lines 1-205
1/* 2 * printThis v1.4 3 * @desc Printing plug-in for jQuery 4 * @author Jason Day 5 * 6 * Resources (based on) : 7 * jPrintArea: http://plugins.jquery.com/project/jPrintArea 8 * jqPrint: https://github.com/permanenttourist/jquery.jqprint 9 * Ben Nadal: http://www.bennadel.com/blog/1591-Ask-Ben-Print-Part-Of-A-Web-Page-With-jQuery.htm 10 * 11 * Licensed under the MIT licence: 12 * http://www.opensource.org/licenses/mit-license.php 13 * 14 * (c) Jason Day 2014 15 * 16 * Usage: 17 * 18 * $("#mySelector").printThis({ 19 * debug: false, * show the iframe for debugging 20 * importCSS: true, * import page CSS 21 * printContainer: true, * grab outer container as well as the contents of the selector 22 * loadCSS: "path/to/my.css", * path to additional css file 23 * pageTitle: "", * add title to print page 24 * removeInline: false, * remove all inline styles from print elements 25 * printDelay: 333, * variable print delay 26 * header: null, * prefix to html 27 * formValues: true * preserve input/form values 28 * }); 29 * 30 * Notes: 31 * - the loadCSS will load additional css (with or without @media print) into the iframe, adjusting layout 32 */ 33; 34(function($) { 35 var opt; 36 $.fn.printThis = function(options) { 37 opt = $.extend({}, $.fn.printThis.defaults, options); 38 var $element = this instanceof jQuery ? this : $(this); 39 40 var strFrameName = "printThis-" + (new Date()).getTime(); 41 42 if (window.location.hostname !== document.domain && navigator.userAgent.match(/msie/i)) { 43 // Ugly IE hacks due to IE not inheriting document.domain from parent 44 // checks if document.domain is set by comparing the host name against document.domain 45 var iframeSrc = "javascript:document.write(\"<head><script>document.domain=\\\"" + document.domain + "\\\";</script></head><body></body>\")"; 46 var printI = document.createElement('iframe'); 47 printI.name = "printIframe"; 48 printI.id = strFrameName; 49 printI.className = "MSIE"; 50 document.body.appendChild(printI); 51 printI.src = iframeSrc; 52 53 } else { 54 // other browsers inherit document.domain, and IE works if document.domain is not explicitly set 55 var $frame = $("<iframe id='" + strFrameName + "' name='printIframe' />"); 56 $frame.appendTo("body"); 57 } 58 59 60 var $iframe = $("#" + strFrameName); 61 62 // show frame if in debug mode 63 if (!opt.debug) $iframe.css({ 64 position: "absolute", 65 width: "0px", 66 height: "0px", 67 left: "-600px", 68 top: "-600px" 69 }); 70 71 72 // $iframe.ready() and $iframe.load were inconsistent between browsers 73 setTimeout(function() { 74 75 var $doc = $iframe.contents(); 76 77 // import page stylesheets 78 if (opt.importCSS) $("link[rel=stylesheet]").each(function() { 79 var href = $(this).attr("href"); 80 if (href) { 81 var media = $(this).attr("media") || "all"; 82 $doc.find("head").append("<link type='text/css' rel='stylesheet' href='" + href + "' media='" + media + "'>") 83 } 84 }); 85 86 //add title of the page 87 if (opt.pageTitle) $doc.find("head").append("<title>" + opt.pageTitle + "</title>"); 88 89 // import additional stylesheet 90 if (opt.loadCSS) $doc.find("head").append("<link type='text/css' rel='stylesheet' href='" + opt.loadCSS + "'>"); 91 92 // print header 93 if (opt.header) $doc.find("body").append(opt.header); 94 95 // grab $.selector as container 96 if (opt.printContainer) $doc.find("body").append($element.outer()); 97 98 // otherwise just print interior elements of container 99 else $element.each(function() { 100 $doc.find("body").append($(this).html()); 101 }); 102 103 // capture form/field values 104 if (opt.formValues) { 105 // loop through inputs 106 var $input = $element.find('input'); 107 if ($input.length) { 108 $input.each(function() { 109 var $this = $(this), 110 $name = $(this).attr('name'), 111 $checker = $this.is(':checkbox') || $this.is(':radio'), 112 $iframeInput = $doc.find('input[name="' + $name + '"]'), 113 $value = $this.val(); 114 115 //order matters here 116 if (!$checker) { 117 $iframeInput.val($value); 118 } else if ($this.is(':checked')) { 119 if ($this.is(':checkbox')) { 120 $iframeInput.attr('checked', 'checked'); 121 } else if ($this.is(':radio')) { 122 $doc.find('input[name="' + $name + '"][value=' + $value + ']').attr('checked', 'checked'); 123 } 124 } 125 126 }); 127 } 128 129 //loop through selects 130 var $select = $element.find('select'); 131 if ($select.length) { 132 $select.each(function() { 133 var $this = $(this), 134 $name = $(this).attr('name'), 135 $value = $this.val(); 136 $doc.find('select[name="' + $name + '"]').val($value); 137 }); 138 } 139 140 //loop through textareas 141 var $textarea = $element.find('textarea'); 142 if ($textarea.length) { 143 $textarea.each(function() { 144 var $this = $(this), 145 $name = $(this).attr('name'), 146 $value = $this.val(); 147 $doc.find('textarea[name="' + $name + '"]').val($value); 148 }); 149 } 150 } // end capture form/field values 151 152 // remove inline styles 153 if (opt.removeInline) { 154 // $.removeAttr available jQuery 1.7+ 155 if ($.isFunction($.removeAttr)) { 156 $doc.find("body *").removeAttr("style"); 157 } else { 158 $doc.find("body *").attr("style", ""); 159 } 160 } 161 162 setTimeout(function() { 163 if ($iframe.hasClass("MSIE")) { 164 // check if the iframe was created with the ugly hack 165 // and perform another ugly hack out of neccessity 166 window.frames["printIframe"].focus(); 167 $doc.find("head").append("<script> window.print(); </script>"); 168 } else { 169 // proper method 170 $iframe[0].contentWindow.focus(); 171 $iframe[0].contentWindow.print(); 172 } 173 174 $element.trigger("done"); 175 //remove iframe after print 176 if (!opt.debug) { 177 setTimeout(function() { 178 $iframe.remove(); 179 }, 1000); 180 } 181 182 }, opt.printDelay); 183 184 }, 333); 185 186 }; 187 188 // defaults 189 $.fn.printThis.defaults = { 190 debug: false, // show the iframe for debugging 191 importCSS: true, // import parent page css 192 printContainer: true, // print outer container/$.selector 193 loadCSS: "", // load an additional css file 194 pageTitle: "", // add title to print page 195 removeInline: false, // remove all inline styles 196 printDelay: 333, // variable print delay 197 header: null, // prefix to html 198 formValues: true // preserve input/form values 199 }; 200 201 // $.selector container 202 jQuery.fn.outer = function() { 203 return $($("<div></div>").html(this.clone())).html() 204 } 205})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.