You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
3.4 KiB
JavaScript

(function(e){var a=0;var d={iframe:"iframe",popup:"popup"};var b={strict:"strict",loose:"loose",html5:"html5"};var f={mode:d.iframe,standard:b.html5,popHt:500,popWd:400,popX:200,popY:200,popTitle:"",popClose:false,extraCss:"",extraHead:"",retainAttr:["id","class","style"]};var c={};e.fn.printArea=function(i){e.extend(c,f,i);a++;var j="printArea_";e("[id^="+j+"]").remove();c.id=j+a;var k=e(this);var h=g.getPrintWindow();g.write(h.doc,k);setTimeout(function(){g.print(h)},1000)};var g={print:function(h){var i=h.win;e(h.doc).ready(function(){i.focus();i.print();if(c.mode==d.popup&&c.popClose){setTimeout(function(){i.close()},2000)}})},write:function(h,i){h.open();h.write(g.docType()+"<html>"+g.getHead()+g.getBody(i)+"</html>");h.close()},docType:function(){if(c.mode==d.iframe){return""}if(c.standard==b.html5){return"<!DOCTYPE html>"}var i=c.standard==b.loose?" Transitional":"";var h=c.standard==b.loose?"loose":"strict";return'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01'+i+'//EN" "http://www.w3.org/TR/html4/'+h+'.dtd">'},getHead:function(){var i="";var h="";if(c.extraHead){c.extraHead.replace(/([^,]+)/g,function(j){i+=j})}e(document).find("link").filter(function(){var j=e(this).attr("rel");return(e.type(j)==="undefined")==false&&j.toLowerCase()=="stylesheet"}).filter(function(){var j=e(this).attr("media");return e.type(j)==="undefined"||j==""||j.toLowerCase()=="print"||j.toLowerCase()=="all"}).each(function(){h+='<link type="text/css" rel="stylesheet" href="'+e(this).attr("href")+'" >'});if(c.extraCss){c.extraCss.replace(/([^,\s]+)/g,function(j){h+='<link type="text/css" rel="stylesheet" href="'+j+'">'})}return"<head><title>"+c.popTitle+"</title>"+i+h+"</head>"},getBody:function(j){var i="";var h=c.retainAttr;j.each(function(){var n=g.getFormData(e(this));var m="";for(var k=0;k<h.length;k++){var l=e(n).attr(h[k]);if(l){m+=(m.length>0?" ":"")+h[k]+"='"+l+"'"}}i+="<div "+m+">"+e(n).html()+"</div>"});return"<body>"+i+"</body>"},getFormData:function(i){var j=i.clone();var h=e("input,select,textarea",j);e("input,select,textarea",i).each(function(l){var k=e(this).attr("type");if(e.type(k)==="undefined"){k=e(this).is("select")?"select":e(this).is("textarea")?"textarea":""}var m=h.eq(l);if(k=="radio"||k=="checkbox"){m.attr("checked",e(this).is(":checked"))}else{if(k=="text"){m.attr("value",e(this).val())}else{if(k=="select"){e(this).find("option").each(function(n){if(e(this).is(":selected")){e("option",m).eq(n).attr("selected",true)}})}else{if(k=="textarea"){m.text(e(this).val())}}}}});return j},getPrintWindow:function(){switch(c.mode){case d.iframe:var h=new g.Iframe();return{win:h.contentWindow||h,doc:h.doc};case d.popup:var i=new g.Popup();return{win:i,doc:i.doc}}},Iframe:function(){var j=c.id;var h="border:0;position:absolute;width:0px;height:0px;right:0px;top:0px;";var i;try{i=document.createElement("iframe");document.body.appendChild(i);e(i).attr({style:h,id:j,src:"#"+new Date().getTime()});i.doc=null;i.doc=i.contentDocument?i.contentDocument:(i.contentWindow?i.contentWindow.document:i.document)}catch(k){throw k+". iframes may not be supported in this browser."}if(i.doc==null){throw"Cannot find document."}return i},Popup:function(){var i="location=yes,statusbar=no,directories=no,menubar=no,titlebar=no,toolbar=no,dependent=no";i+=",width="+c.popWd+",height="+c.popHt;i+=",resizable=yes,screenX="+c.popX+",screenY="+c.popY+",personalbar=no,scrollbars=yes";var h=window.open("","_blank",i);h.doc=h.document;return h}}})(jQuery);