1/** 2 * Version 2.1 3 * -Contributors: "mindinquiring" : filter to exclude any stylesheet other than print. 4 * Tested ONLY in IE 8 and FF 3.6. No official support for other browsers, but will 5 * TRY to accomodate challenges in other browsers. 6 * Example: 7 * Print Button: <div id="print_button">Print</div> 8 * Print Area : <div class="PrintArea"> ... html ... </div> 9 * Javascript : <script> 10 * $("div#print_button").click(function(){ 11 * $("div.PrintArea").printArea( [OPTIONS] ); 12 * }); 13 * </script> 14 * options are passed as json (json example: {mode: "popup", popClose: false}) 15 * 16 * {OPTIONS} | [type] | (default), values | Explanation 17 * --------- | --------- | ---------------------- | ----------- 18 * @mode | [string] | ("iframe"),"popup" | printable window is either iframe or browser popup 19 * @popHt | [number] | (500) | popup window height 20 * @popWd | [number] | (400) | popup window width 21 * @popX | [number] | (500) | popup window screen X position 22 * @popY | [number] | (500) | popup window screen Y position 23 * @popTitle | [string] | ('') | popup window title element 24 * @popClose | [boolean] | (false),true | popup window close after printing 25 * @strict | [boolean] | (undefined),true,false | strict or loose(Transitional) html 4.01 document standard or undefined to not include at all (only for popup option) 26 */ 27(function($) { 28 var counter = 0; 29 var modes = { iframe : "iframe", popup : "popup" }; 30 var defaults = { mode : modes.iframe, 31 popHt : 500, 32 popWd : 400, 33 popX : 200, 34 popY : 200, 35 popTitle : '', 36 popClose : false }; 37 38 var settings = {};//global settings 39 40 $.fn.printArea = function( options ) 41 { 42 $.extend( settings, defaults, options ); 43 44 counter++; 45 var idPrefix = "printArea_"; 46 $( "[id^=" + idPrefix + "]" ).remove(); 47 $( "#articlePage-mainArticleAllicos" ).remove(); 48 49 var ele = getFormData( $(this) ); 50 $( "#articlePage-mainArticleAllicos" ).show(); 51 settings.id = idPrefix + counter; 52 53 var writeDoc; 54 var printWindow; 55 56 switch ( settings.mode ) 57 { 58 case modes.iframe : 59 var f = new Iframe(); 60 writeDoc = f.doc; 61 printWindow = f.contentWindow || f; 62 break; 63 case modes.popup : 64 printWindow = new Popup(); 65 writeDoc = printWindow.doc; 66 } 67 68 writeDoc.open(); 69 writeDoc.write( docType() + "<html><style>a {color: #333;font-style: italic;text-decoration: none;}</style>" + getHead() + getBody(ele) + "</html>" ); 70 writeDoc.close(); 71 72 printWindow.focus(); 73 printWindow.print(); 74 75 if ( settings.mode == modes.popup && settings.popClose ) 76 printWindow.close(); 77 } 78 79 function docType() 80 { 81 if ( settings.mode == modes.iframe || !settings.strict ) return ""; 82 83 var standard = settings.strict == false ? " Trasitional" : ""; 84 var dtd = settings.strict == false ? "loose" : "strict"; 85 86 return '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01' + standard + '//EN" "http://www.w3.org/TR/html4/' + dtd + '.dtd">'; 87 } 88 89 function getHead() 90 { 91 var head = "<head><title>" + settings.popTitle + "</title>"; 92 $(document).find("link") 93 .filter(function(){ 94 return $(this).attr("rel").toLowerCase() == "stylesheet"; 95 }) 96 .filter(function(){ // this filter contributed by "mindinquiring" 97 var media = $(this).attr("media"); 98 return (media.toLowerCase() == "" || media.toLowerCase() == "print") 99 }) 100 .each(function(){ 101 head += '<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >'; 102 }); 103 head += "</head>"; 104 var head = ''; 105 return head; 106 } 107 108 function getBody( printElement ) 109 { 110 return '<body><div class="' + $(printElement).attr("class") + '">' + $(printElement).html() + '</div></body>'; 111 } 112 113 function getFormData( ele ) 114 { 115 $("input,select,textarea", ele).each(function(){ 116 // In cases where radio, checkboxes and select elements are selected and deselected, and the print 117 // button is pressed between select/deselect, the print screen shows incorrectly selected elements. 118 // To ensure that the correct inputs are selected, when eventually printed, we must inspect each dom element 119 var type = $(this).attr("type"); 120 if ( type == "radio" || type == "checkbox" ) 121 { 122 if ( $(this).is(":not(:checked)") ) this.removeAttribute("checked"); 123 else this.setAttribute( "checked", true ); 124 } 125 else if ( type == "text" ) 126 this.setAttribute( "value", $(this).val() ); 127 else if ( type == "select-multiple" || type == "select-one" ) 128 $(this).find( "option" ).each( function() { 129 if ( $(this).is(":not(:selected)") ) this.removeAttribute("selected"); 130 else this.setAttribute( "selected", true ); 131 }); 132 else if ( type == "textarea" ) 133 { 134 var v = $(this).attr( "value" ); 135 if ($.browser.mozilla) 136 { 137 if (this.firstChild) this.firstChild.textContent = v; 138 else this.textContent = v; 139 } 140 else this.innerHTML = v; 141 } 142 }); 143 return ele; 144 } 145 146 function Iframe() 147 { 148 var frameId = settings.id; 149 var iframeStyle = 'border:0;position:absolute;width:0px;height:0px;left:0px;top:0px;'; 150 var iframe; 151 152 try 153 { 154 iframe = document.createElement('iframe'); 155 document.body.appendChild(iframe); 156 $(iframe).attr({ style: iframeStyle, id: frameId, src: "" }); 157 iframe.doc = null; 158 iframe.doc = iframe.contentDocument ? iframe.contentDocument : ( iframe.contentWindow ? iframe.contentWindow.document : iframe.document); 159 } 160 catch( e ) { throw e + ". iframes may not be supported in this browser."; } 161 162 if ( iframe.doc == null ) throw "Cannot find document."; 163 164 return iframe; 165 } 166 167 function Popup() 168 { 169 var windowAttr = "location=yes,statusbar=no,directories=no,menubar=no,titlebar=no,toolbar=no,dependent=no";
170 windowAttr += ",width=" + settings.popWd + ",height=" + settings.popHt; 171 windowAttr += ",resizable=yes,screenX=" + settings.popX + ",screenY=" + settings.popY + ",personalbar=no,scrollbars=no"; 172 173 var newWin = window.open( "", "_blank", windowAttr ); 174 175 newWin.doc = newWin.document; 176 177 return newWin; 178 } 179})(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.