1/** 2 * Version 2.4.0 Copyright (C) 2013 3 * Tested in IE 11, FF 28.0 and Chrome 33.0.1750.154 4 * No official support for other browsers, but will TRY to accommodate challenges in other browsers. 5 * Example: 6 * Print Button: <div id="print_button">Print</div> 7 * Print Area : <div class="PrintArea" id="MyId" class="MyClass"> ... html ... </div> 8 * Javascript : <script> 9 * $("div#print_button").click(function(){ 10 * $("div.PrintArea").printArea( [OPTIONS] ); 11 * }); 12 * </script> 13 * options are passed as json (example: {mode: "popup", popClose: false}) 14 * 15 * {OPTIONS} | [type] | (default), values | Explanation 16 * --------- | --------- | ---------------------- | ----------- 17 * @mode | [string] | (iframe),popup | printable window is either iframe or browser popup 18 * @popHt | [number] | (500) | popup window height 19 * @popWd | [number] | (400) | popup window width 20 * @popX | [number] | (500) | popup window screen X position 21 * @popY | [number] | (500) | popup window screen Y position 22 * @popTitle | [string] | ('') | popup window title element 23 * @popClose | [boolean] | (false),true | popup window close after printing 24 * @extraCss | [string] | ('') | comma separated list of extra css to include 25 * @retainAttr | [string[]] | ["id","class","style"] | string array of attributes to retain for the containment area. (ie: id, style, class) 26 * @standard | [string] | strict, loose, (html5) | Only for popup. For html 4.01, strict or loose document standard, or html 5 standard 27 * @extraHead | [string] | ('') | comma separated list of extra elements to be appended to the head tag 28 */ 29(function($) { 30 var counter = 0; 31 var modes = { iframe : "iframe", popup : "popup" }; 32 var standards = { strict : "strict", loose : "loose", html5 : "html5" }; 33 var defaults = { mode : modes.iframe, 34 standard : standards.html5, 35 popHt : 500, 36 popWd : 400, 37 popX : 200, 38 popY : 200, 39 popTitle : '', 40 popClose : false, 41 extraCss : '', 42 extraHead : '', 43 retainAttr : ["id","class","style"] }; 44 45 var settings = {};//global settings 46 47 $.fn.printArea = function( options ) 48 { 49 $.extend( settings, defaults, options ); 50 51 counter++; 52 var idPrefix = "printArea_"; 53 $( "[id^=" + idPrefix + "]" ).remove(); 54 55 settings.id = idPrefix + counter; 56 57 var $printSource = $(this); 58 59 var PrintAreaWindow = PrintArea.getPrintWindow(); 60 61 PrintArea.write( PrintAreaWindow.doc, $printSource ); 62 63 setTimeout( function () { PrintArea.print( PrintAreaWindow ); }, 1000 ); 64 }; 65 66 var PrintArea = { 67 print : function( PAWindow ) { 68 var paWindow = PAWindow.win; 69 70 $(PAWindow.doc).ready(function(){ 71 paWindow.focus(); 72 paWindow.print(); 73 74 if ( settings.mode == modes.popup && settings.popClose ) 75 setTimeout(function() { paWindow.close(); }, 2000); 76 }); 77 }, 78 write : function ( PADocument, $ele ) { 79 PADocument.open(); 80 PADocument.write( PrintArea.docType() + "<html>" + PrintArea.getHead() + PrintArea.getBody( $ele ) + "</html>" ); 81 PADocument.close(); 82 }, 83 docType : function() { 84 if ( settings.mode == modes.iframe ) return ""; 85 86 if ( settings.standard == standards.html5 ) return "<!DOCTYPE html>"; 87 88 var transitional = settings.standard == standards.loose ? " Transitional" : ""; 89 var dtd = settings.standard == standards.loose ? "loose" : "strict"; 90 91 return '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01' + transitional + '//EN" "http://www.w3.org/TR/html4/' + dtd + '.dtd">'; 92 }, 93 getHead : function() { 94 var extraHead = ""; 95 var links = ""; 96 97 if ( settings.extraHead ) settings.extraHead.replace( /([^,]+)/g, function(m){ extraHead += m }); 98 99 $(document).find("link") 100 .filter(function(){ // Requirement: <link> element MUST have rel="stylesheet" to be considered in print document 101 var relAttr = $(this).attr("rel"); 102 return ($.type(relAttr) === 'undefined') == false && relAttr.toLowerCase() == 'stylesheet'; 103 }) 104 .filter(function(){ // Include if media is undefined, empty, print or all 105 var mediaAttr = $(this).attr("media"); 106 return $.type(mediaAttr) === 'undefined' || mediaAttr == "" || mediaAttr.toLowerCase() == 'print' || mediaAttr.toLowerCase() == 'all' 107 }) 108 .each(function(){ 109 links += '<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >'; 110 });
111 if ( settings.extraCss ) settings.extraCss.replace( /([^,\s]+)/g, function(m){ links += '<link type="text/css" rel="stylesheet" href="' + m + '">' }); 112 113 var centerCss = "<style>" + ".s_con {margin:20px 20px 20px 20px;}"; // ì ë ¬í기 ìí¨_lmj_170726 114 centerCss += ".over_table{overflow-x:inherit;overflow-y:inherit;} .over_table table{width:100%;min-width:0px!important}" + "</style>"; // over_table ì¤í¬ë¡¤ëì¤ë íì ìì _lmj_170726 115 return "<head><title>" + settings.popTitle + "</title>" + extraHead + centerCss + links + "</head>"; 116 }, 117 getBody : function ( elements ) { 118 var htm = ""; 119 var attrs = settings.retainAttr; 120 elements.each(function() { 121 var ele = PrintArea.getFormData( $(this) ); 122 123 var attributes = "" 124 for ( var x = 0; x < attrs.length; x++ ) 125 { 126 var eleAttr = $(ele).attr( attrs[x] ); 127 if ( eleAttr ) attributes += (attributes.length > 0 ? " ":"") + attrs[x] + "='" + eleAttr + "'"; 128 } 129 130 htm += '<div ' + attributes + '>' + $(ele).html() + '</div>'; 131 }); 132 133 return "<body>" + htm + "</body>"; 134 }, 135 getFormData : function ( ele ) { 136 var copy = ele.clone(); 137 var copiedInputs = $("input,select,textarea", copy); 138 $("input,select,textarea", ele).each(function( i ){ 139 var typeInput = $(this).attr("type"); 140 if ($.type(typeInput) === 'undefined') typeInput = $(this).is("select") ? "select" : $(this).is("textarea") ? "textarea" : ""; 141 var copiedInput = copiedInputs.eq( i ); 142 143 if ( typeInput == "radio" || typeInput == "checkbox" ) copiedInput.attr( "checked", $(this).is(":checked") ); 144 else if ( typeInput == "text" ) copiedInput.attr( "value", $(this).val() ); 145 else if ( typeInput == "select" ) 146 $(this).find( "option" ).each( function( i ) { 147 if ( $(this).is(":selected") ) $("option", copiedInput).eq( i ).attr( "selected", true ); 148 }); 149 else if ( typeInput == "textarea" ) copiedInput.text( $(this).val() ); 150 }); 151 return copy; 152 }, 153 getPrintWindow : function () { 154 switch ( settings.mode ) 155 { 156 case modes.iframe : 157 var f = new PrintArea.Iframe(); 158 return { win : f.contentWindow || f, doc : f.doc }; 159 case modes.popup : 160 var p = new PrintArea.Popup(); 161 return { win : p, doc : p.doc }; 162 } 163 }, 164 Iframe : function () { 165 var frameId = settings.id; 166 var iframeStyle = 'border:0;position:absolute;width:0px;height:0px;right:0px;top:0px;'; 167 var iframe; 168 169 try 170 { 171 iframe = document.createElement('iframe'); 172 document.body.appendChild(iframe); 173 $(iframe).attr({ style: iframeStyle, id: frameId, src: "#" + new Date().getTime() }); 174 iframe.doc = null; 175 iframe.doc = iframe.contentDocument ? iframe.contentDocument : ( iframe.contentWindow ? iframe.contentWindow.document : iframe.document); 176 } 177 catch( e ) { throw e + ". iframes may not be supported in this browser."; } 178 179 if ( iframe.doc == null ) throw "Cannot find document."; 180 181 return iframe; 182 }, 183 Popup : function () { 184 var windowAttr = "location=yes,statusbar=no,directories=no,menubar=no,titlebar=no,toolbar=no,dependent=no"; 185 windowAttr += ",width=" + settings.popWd + ",height=" + settings.popHt; 186 windowAttr += ",resizable=yes,screenX=" + settings.popX + ",screenY=" + settings.popY + ",personalbar=no,scrollbars=yes"; 187 188 var newWin = window.open( "", "_blank", windowAttr ); 189 190 newWin.doc = newWin.document; 191 192 return newWin; 193 } 194 }; 195})(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.