2 lines
3.9 KiB
JavaScript
2 lines
3.9 KiB
JavaScript
(function(t){function S(c,a){!a||c.append(a.jquery?a.clone():a)}function C(c,a,o){var d=a.clone(o.formValues);o.formValues&&x(a,d,"select, textarea"),o.removeScripts&&d.find("script").remove(),o.printContainer?d.appendTo(c):d.each(function(){t(this).children().appendTo(c)})}function x(c,a,o){var d=c.find(o);a.find(o).each(function(u,v){t(v).val(d.eq(u).val())})}var e;t.fn.printThis=function(c){e=t.extend({},t.fn.printThis.defaults,c);var a=this instanceof jQuery?this:t(this),o="printThis-"+new Date().getTime();if(window.location.hostname!==document.domain&&navigator.userAgent.match(/msie/i)){var d='javascript:document.write("<head><script>document.domain=\\"'+document.domain+'\\";</script></head><body></body>")',u=document.createElement("iframe");u.name="printIframe",u.id=o,u.className="MSIE",document.body.appendChild(u),u.src=d}else{var v=t("<iframe id='"+o+"' name='printIframe' />");v.appendTo("body")}var s=t("#"+o);e.debug||s.css({position:"absolute",width:"0px",height:"0px",left:"-600px",top:"-600px"}),typeof e.beforePrint=="function"&&e.beforePrint(),setTimeout(function(){function w(f,r){var n,p;n=f.get(0),n=n.contentWindow||n.contentDocument||n,p=n.document||n.contentDocument||n,p.open(),p.write(r),p.close()}e.doctypeString&&w(s,e.doctypeString);var h=s.contents(),m=h.find("head"),l=h.find("body"),g=t("base"),y;e.base===!0&&g.length>0?y=g.attr("href"):typeof e.base=="string"?y=e.base:y=document.location.protocol+"//"+document.location.host,m.append('<base href="'+y+'">'),e.importCSS&&t("link[rel=stylesheet]").each(function(){var f=t(this).attr("href");if(f){var r=t(this).attr("media")||"all";m.append("<link type='text/css' rel='stylesheet' href='"+f+"' media='"+r+"'>")}}),e.importStyle&&t("style").each(function(){m.append(this.outerHTML)}),e.pageTitle&&m.append("<title>"+e.pageTitle+"</title>"),e.loadCSS&&(t.isArray(e.loadCSS)?jQuery.each(e.loadCSS,function(f,r){m.append("<link type='text/css' rel='stylesheet' href='"+this+"'>")}):m.append("<link type='text/css' rel='stylesheet' href='"+e.loadCSS+"'>"));var b=t("html")[0];h.find("html").prop("style",b.style.cssText);var i=e.copyTagClasses;if(i&&(i=i===!0?"bh":i,i.indexOf("b")!==-1&&l.addClass(t("body")[0].className),i.indexOf("h")!==-1&&h.find("html").addClass(b.className)),i=e.copyTagStyles,i&&(i=i===!0?"bh":i,i.indexOf("b")!==-1&&l.attr("style",t("body")[0].style.cssText),i.indexOf("h")!==-1&&h.find("html").attr("style",b.style.cssText)),S(l,e.header),e.canvas){var D=0;a.find("canvas").addBack("canvas").each(function(){t(this).attr("data-printthis",D++)})}if(C(l,a,e),e.canvas&&l.find("canvas").each(function(){var f=t(this).data("printthis"),r=t('[data-printthis="'+f+'"]');this.getContext("2d").drawImage(r[0],0,0),t.isFunction(t.fn.removeAttr)?r.removeAttr("data-printthis"):t.each(r,function(n,p){p.removeAttribute("data-printthis")})}),e.removeInline){var T=e.removeInlineSelector||"*";t.isFunction(t.removeAttr)?l.find(T).removeAttr("style"):l.find(T).attr("style","")}S(l,e.footer);function E(f,r){var n=f.get(0);n=n.contentWindow||n.contentDocument||n,typeof r=="function"&&("matchMedia"in n?n.matchMedia("print").addListener(function(p){p.matches&&r()}):n.onbeforeprint=r)}E(s,e.beforePrintEvent),setTimeout(function(){s.hasClass("MSIE")?(window.frames.printIframe.focus(),m.append("<script> window.print(); </script>")):document.queryCommandSupported("print")?s[0].contentWindow.document.execCommand("print",!1,null):(s[0].contentWindow.focus(),s[0].contentWindow.print()),e.debug||setTimeout(function(){s.remove()},1e3),typeof e.afterPrint=="function"&&e.afterPrint()},e.printDelay)},333)},t.fn.printThis.defaults={debug:!1,importCSS:!0,importStyle:!0,printContainer:!0,loadCSS:"",pageTitle:"",removeInline:!1,removeInlineSelector:"*",printDelay:1e3,header:null,footer:null,base:!1,formValues:!0,canvas:!0,doctypeString:"<!DOCTYPE html>",removeScripts:!1,copyTagClasses:!0,copyTagStyles:!0,beforePrintEvent:null,beforePrint:null,afterPrint:null}})(jQuery);
|