print-html-element
Version:
Prints the HTML of a provided element.
1 lines • 2.67 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.printHtmlElement=e():t.printHtmlElement=e()}(this,function(){return function(t){function e(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return t[o].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e){"use strict";function n(){function t(t,e){var o=t.outerHTML;n(o,e)}function e(t,e){n(t,e)}function n(t,e){e=e||{},e={printMode:e.printMode||"",pageTitle:e.pageTitle||"",templateString:e.templateString||"",popupProperties:e.popupProperties||"",stylesheets:e.stylesheets||null,styles:e.styles||null};var n,r,s,p,l=i(t,e);"popup"===e.printMode.toLowerCase()?(n=window.open("about:blank","printElementWindow",e.popupProperties),s=n.document):(p="printElement_"+Math.round(99999*Math.random()).toString(),r=document.createElement("iframe"),r.setAttribute("id",p),r.setAttribute("src","about:blank"),r.setAttribute("frameBorder","0"),r.setAttribute("scrolling","no"),r.setAttribute("style","position:fixed;bottom:100%;right:100%;"),document.body.appendChild(r),s=r.contentWindow||r.contentDocument,s.document&&(s=s.document),r=document.frames?document.frames[p]:document.getElementById(p),n=r.contentWindow||r),focus(),s.open(),setTimeout(function(){s.write(l),s.close()}),o(n,r)}function o(t,e){t&&t.printPage?(t.printPage(),e&&document.body.removeChild(e)):setTimeout(function(){o(t,e)},50)}function r(){var t=window.location.port?":"+window.location.port:"";return window.location.protocol+"//"+window.location.hostname+t+window.location.pathname}function i(t,e){var n,o,i=e.templateString,s=new RegExp(/{{\s*printBody\s*}}/gi),p=[];return i&&s.test(i)&&(t=i.replace(s,t)),p.push("<html><head><title>"+(e.pageTitle||"")+"</title>"),n=e.stylesheets?Array.isArray(e.stylesheets)?e.stylesheets:[e.stylesheets]:Array.prototype.slice.call(document.getElementsByTagName("link")).map(function(t){return t.href}),n.forEach(function(t){p.push('<link rel="stylesheet" href="'+t+'">')}),o=e.styles?Array.isArray(e.styles)?e.styles:[e.styles]:Array.prototype.slice.call(document.getElementsByTagName("style")).map(function(t){return t.innerHTML}),o.forEach(function(t){p.push('<style type="text/css">'+t+"</style>")}),p.push('<base href="'+r()+'" />'),p.push('</head><body class="pe-body">'),p.push(t),p.push('<script type="text/javascript">function printPage(){focus();print();'+("popup"==e.printMode.toLowerCase()?"close();":"")+"}</script>"),p.push("</body></html>"),p.join("")}return{printElement:t,printHtml:e}}t.exports=n()}])});