Comparing version 1.4.1 to 1.4.2
@@ -11,2 +11,3 @@ export declare function createStyle(doc: Document, cssText: string): HTMLStyleElement; | ||
bodyElements?: HTMLElement[]; | ||
[key: string]: HTMLElement | HTMLElement[] | undefined; | ||
} | ||
@@ -13,0 +14,0 @@ export interface PrintdCallbackArgs { |
44
index.js
@@ -7,4 +7,4 @@ "use strict"; | ||
function createStyle(doc, cssText) { | ||
var style = doc.createElement('style'); | ||
style.type = 'text/css'; | ||
var style = doc.createElement("style"); | ||
style.type = "text/css"; | ||
style.appendChild(window.document.createTextNode(cssText)); | ||
@@ -15,5 +15,5 @@ return style; | ||
function createLinkStyle(doc, url) { | ||
var style = doc.createElement('link'); | ||
style.type = 'text/css'; | ||
style.rel = 'stylesheet'; | ||
var style = doc.createElement("link"); | ||
style.type = "text/css"; | ||
style.rel = "stylesheet"; | ||
style.href = url; | ||
@@ -24,9 +24,8 @@ return style; | ||
function createIFrame(parent) { | ||
var el = window.document.createElement('iframe'); | ||
var css = 'visibility:hidden;width:0;height:0;position:absolute;z-index:-9999;bottom:0;'; | ||
el.setAttribute('src', 'about:blank'); | ||
el.setAttribute('style', css); | ||
el.setAttribute('width', '0'); | ||
el.setAttribute('height', '0'); | ||
el.setAttribute('wmode', 'opaque'); | ||
var el = window.document.createElement("iframe"); | ||
el.setAttribute("src", "about:blank"); | ||
el.setAttribute("style", "visibility:hidden;width:0;height:0;position:absolute;z-index:-9999;bottom:0;"); | ||
el.setAttribute("width", "0"); | ||
el.setAttribute("height", "0"); | ||
el.setAttribute("wmode", "opaque"); | ||
parent.appendChild(el); | ||
@@ -46,3 +45,7 @@ return el; | ||
this.hasEvents = false; | ||
this.opts = Object.assign(DEFAULT_OPTIONS, (options || {})); | ||
// IE 11+ "Object.assign" polyfill | ||
this.opts = [DEFAULT_OPTIONS, options || {}].reduce(function (a, b) { | ||
Object.keys(b).forEach(function (k) { return (a[k] = b[k]); }); | ||
return a; | ||
}, {}); | ||
this.iframe = createIFrame(this.opts.parent); | ||
@@ -68,3 +71,3 @@ } | ||
return; | ||
this.iframe.src = 'about:blank'; | ||
this.iframe.src = "about:blank"; | ||
this.elCopy = el.cloneNode(true); | ||
@@ -93,8 +96,3 @@ if (!this.elCopy) | ||
if (value) { | ||
if (isValidURL(value)) { | ||
doc.head.appendChild(createLinkStyle(doc, value)); | ||
} | ||
else { | ||
doc.head.appendChild(createStyle(doc, value)); | ||
} | ||
doc.head.appendChild(isValidURL(value) ? createLinkStyle(doc, value) : createStyle(doc, value)); | ||
} | ||
@@ -109,3 +107,3 @@ }); | ||
if (value) { | ||
var script = doc.createElement('script'); | ||
var script = doc.createElement("script"); | ||
if (isValidURL(value)) { | ||
@@ -138,3 +136,3 @@ script.src = value; | ||
Printd.prototype.launchPrint = function (contentWindow) { | ||
var result = contentWindow.document.execCommand('print', false, null); | ||
var result = contentWindow.document.execCommand("print", false, undefined); | ||
if (!result) { | ||
@@ -148,3 +146,3 @@ contentWindow.print(); | ||
this.hasEvents = true; | ||
this.iframe.addEventListener('load', function () { return _this.onLoad(); }, false); | ||
this.iframe.addEventListener("load", function () { return _this.onLoad(); }, false); | ||
} | ||
@@ -151,0 +149,0 @@ }; |
{ | ||
"name": "printd", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "Print HTML elements in modern browsers.", | ||
@@ -72,5 +72,5 @@ "repository": "joseluisq/printd", | ||
"tslint": "5.18.0", | ||
"tslint-config-standard-plus": "2.2.0", | ||
"tslint-config-standard-plus": "^2.3.0", | ||
"typescript": "2.9.2" | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).printd={})}(this,function(t){"use strict";const e=/^(((http[s]?)|file):)?(\/\/)+([0-9a-zA-Z-_.=?&].+)$/,i=/^((\.|\.\.)?\/)([0-9a-zA-Z-_.=?&]+\/)*([0-9a-zA-Z-_.=?&]+)$/,n=t=>e.test(t)||i.test(t);function s(t,e){const i=t.createElement("style");return i.type="text/css",i.appendChild(window.document.createTextNode(e)),i}function a(t,e){const i=t.createElement("link");return i.type="text/css",i.rel="stylesheet",i.href=e,i}function r(t){const e=window.document.createElement("iframe");return e.setAttribute("src","about:blank"),e.setAttribute("style","visibility:hidden;width:0;height:0;position:absolute;z-index:-9999;bottom:0;"),e.setAttribute("width","0"),e.setAttribute("height","0"),e.setAttribute("wmode","opaque"),t.appendChild(e),e}const o={parent:window.document.body,headElements:[],bodyElements:[]};class d{constructor(t){this.isLoading=!1,this.hasEvents=!1,this.opts=Object.assign(o,t||{}),this.iframe=r(this.opts.parent)}getIFrame(){return this.iframe}print(t,e,i,r){if(this.isLoading)return;const{contentDocument:o,contentWindow:d}=this.iframe;if(!o||!d)return;if(this.iframe.src="about:blank",this.elCopy=t.cloneNode(!0),!this.elCopy)return;this.isLoading=!0,this.callback=r;const h=d.document;h.open(),h.write('<!DOCTYPE html><html><head><meta charset="utf-8"></head><body></body></html>'),this.addEvents();const{headElements:c,bodyElements:l}=this.opts;Array.isArray(c)&&c.forEach(t=>h.head.appendChild(t)),Array.isArray(l)&&l.forEach(t=>h.body.appendChild(t)),Array.isArray(e)&&e.forEach(t=>{t&&(n(t)?h.head.appendChild(a(h,t)):h.head.appendChild(s(h,t)))}),h.body.appendChild(this.elCopy),Array.isArray(i)&&i.forEach(t=>{if(t){const e=h.createElement("script");n(t)?e.src=t:e.innerText=t,h.body.appendChild(e)}}),h.close()}printURL(t,e){this.isLoading||(this.addEvents(),this.isLoading=!0,this.callback=e,this.iframe.src=t)}launchPrint(t){t.document.execCommand("print",!1,null)||t.print()}addEvents(){this.hasEvents||(this.hasEvents=!0,this.iframe.addEventListener("load",()=>this.onLoad(),!1))}onLoad(){if(this.iframe){this.isLoading=!1;const{contentDocument:t,contentWindow:e}=this.iframe;if(!t||!e)return;this.callback?this.callback({iframe:this.iframe,element:this.elCopy,launchPrint:()=>this.launchPrint(e)}):this.launchPrint(e)}}}t.createStyle=s,t.createLinkStyle=a,t.createIFrame=r,t.default=d,t.Printd=d,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).printd={})}(this,function(t){"use strict";const e=/^(((http[s]?)|file):)?(\/\/)+([0-9a-zA-Z-_.=?&].+)$/,i=/^((\.|\.\.)?\/)([0-9a-zA-Z-_.=?&]+\/)*([0-9a-zA-Z-_.=?&]+)$/,n=t=>e.test(t)||i.test(t);function s(t,e){const i=t.createElement("style");return i.type="text/css",i.appendChild(window.document.createTextNode(e)),i}function r(t,e){const i=t.createElement("link");return i.type="text/css",i.rel="stylesheet",i.href=e,i}function a(t){const e=window.document.createElement("iframe");return e.setAttribute("src","about:blank"),e.setAttribute("style","visibility:hidden;width:0;height:0;position:absolute;z-index:-9999;bottom:0;"),e.setAttribute("width","0"),e.setAttribute("height","0"),e.setAttribute("wmode","opaque"),t.appendChild(e),e}const o={parent:window.document.body,headElements:[],bodyElements:[]};class d{constructor(t){this.isLoading=!1,this.hasEvents=!1,this.opts=[o,t||{}].reduce((t,e)=>(Object.keys(e).forEach(i=>t[i]=e[i]),t),{}),this.iframe=a(this.opts.parent)}getIFrame(){return this.iframe}print(t,e,i,a){if(this.isLoading)return;const{contentDocument:o,contentWindow:d}=this.iframe;if(!o||!d)return;if(this.iframe.src="about:blank",this.elCopy=t.cloneNode(!0),!this.elCopy)return;this.isLoading=!0,this.callback=a;const h=d.document;h.open(),h.write('<!DOCTYPE html><html><head><meta charset="utf-8"></head><body></body></html>'),this.addEvents();const{headElements:c,bodyElements:l}=this.opts;Array.isArray(c)&&c.forEach(t=>h.head.appendChild(t)),Array.isArray(l)&&l.forEach(t=>h.body.appendChild(t)),Array.isArray(e)&&e.forEach(t=>{t&&h.head.appendChild(n(t)?r(h,t):s(h,t))}),h.body.appendChild(this.elCopy),Array.isArray(i)&&i.forEach(t=>{if(t){const e=h.createElement("script");n(t)?e.src=t:e.innerText=t,h.body.appendChild(e)}}),h.close()}printURL(t,e){this.isLoading||(this.addEvents(),this.isLoading=!0,this.callback=e,this.iframe.src=t)}launchPrint(t){t.document.execCommand("print",!1,void 0)||t.print()}addEvents(){this.hasEvents||(this.hasEvents=!0,this.iframe.addEventListener("load",()=>this.onLoad(),!1))}onLoad(){if(this.iframe){this.isLoading=!1;const{contentDocument:t,contentWindow:e}=this.iframe;if(!t||!e)return;this.callback?this.callback({iframe:this.iframe,element:this.elCopy,launchPrint:()=>this.launchPrint(e)}):this.launchPrint(e)}}}t.createStyle=s,t.createLinkStyle=r,t.createIFrame=a,t.default=d,t.Printd=d,Object.defineProperty(t,"__esModule",{value:!0})}); |
@@ -1,2 +0,2 @@ | ||
# Printd [![npm](https://img.shields.io/npm/v/printd.svg)](https://www.npmjs.com/package/printd) [![npm](https://img.shields.io/npm/dt/printd.svg)](https://www.npmjs.com/package/printd) [![Build Status](https://travis-ci.org/joseluisq/printd.svg?branch=master)](https://travis-ci.org/joseluisq/printd) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
# Printd [![Build Status](https://travis-ci.com/joseluisq/printd.svg?branch=master)](https://travis-ci.com/joseluisq/printd) [![npm](https://img.shields.io/npm/v/printd.svg)](https://www.npmjs.com/package/printd) [![npm](https://img.shields.io/npm/dt/printd.svg)](https://www.npmjs.com/package/printd) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
@@ -3,0 +3,0 @@ > [Print](https://developer.mozilla.org/en-US/docs/Web/API/Window/print) HTML elements or pages in modern browsers. :printer: |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20616
226