diff --git a/dist/print.min.js.map b/dist/print.min.js.map index 2d3a7c3..e46696f 100644 --- a/dist/print.min.js.map +++ b/dist/print.min.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["print.min.js"],"sourcesContent":["(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o= 0\n\n // At least Safari 3+: \"[object HTMLElementConstructor]\"\n // let isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0\n\n // Edge 20+\n // let isEdge = !isIE && !!window.StyleMedia\n\n // Chrome 1+\n // let isChrome = !!window.chrome && !!window.chrome.webstore\n\n};\n\n},{}],2:[function(require,module,exports){\n'use strict';\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol ? \"symbol\" : typeof obj; };\n\nvar browser = require('./browser');\n\nvar printTypes = ['pdf', 'html', 'image', 'json'];\n\nvar defaultParams = {\n printable: null,\n type: 'pdf',\n header: null,\n maxWidth: 800,\n font: 'TimesNewRoman',\n font_size: '12pt',\n honorMarginPadding: true,\n honorColor: false,\n properties: null,\n showModal: false,\n modalMessage: 'Retrieving Document...',\n frameId: 'printJS',\n border: true,\n htmlData: ''\n};\n\nvar printFriendlyElement = void 0,\n bodyStyle = void 0,\n headerStyle = void 0;\n\nmodule.exports = function () {\n // check if a printable document or object was supplied\n if (arguments[0] === undefined) {\n window.console.error('printJS expects at least 1 attribute.');\n return false;\n }\n\n // instantiate print object\n var printJS = new PrintJS(arguments);\n\n // print friendly defaults\n printFriendlyElement = 'max-width: ' + printJS.params.maxWidth + 'px !important;' + printJS.params.font_size + ' !important;';\n bodyStyle = 'font-family:' + printJS.params.font + ' !important; font-size: ' + printJS.params.font_size + ' !important; width:100%;';\n headerStyle = 'font-weight:300;';\n\n // check printable type\n switch (printJS.params.type) {\n case 'pdf':\n // firefox doesn't support iframe printing, we will just open the pdf file instead\n if (browser.isFirefox()) {\n console.log('PrintJS doesn\\'t support PDF printing in Firefox.');\n var win = window.open(printJS.params.printable, '_blank');\n win.focus();\n // make sure there is no loading modal opened\n if (printJS.params.showModal) printJS.disablePrintModal();\n } else {\n printJS.pdf();\n }\n break;\n case 'image':\n printJS.image();\n break;\n case 'html':\n printJS.html();\n break;\n case 'json':\n printJS.json();\n break;\n default:\n // throw invalid type error\n throw new Error('Invalid print type. Available types are: pdf, html, image and json.');\n }\n};\n\n// printJS class\nvar PrintJS = function PrintJS() {\n var args = arguments[0];\n\n var print = this;\n\n print.params = extend({}, defaultParams);\n\n switch (_typeof(args[0])) {\n case 'string':\n print.params.printable = encodeURI(args[0]);\n print.params.type = args[1] || defaultParams.type;\n break;\n\n case 'object':\n print.params.printable = args[0].printable;\n print.params.type = args[0].type || defaultParams.type;\n print.params.frameId = args[0].frameId || defaultParams.frameId;\n print.params.header = args[0].header || defaultParams.header;\n print.params.maxWidth = args[0].maxWidth || defaultParams.maxWidth;\n print.params.font = args[0].font || defaultParams.font;\n print.params.font_size = args[0].font_size || defaultParams.font_size;\n print.params.honorMarginPadding = typeof args[0].honorMarginPadding !== 'undefined' ? args[0].honorMarginPadding : defaultParams.honorMarginPadding;\n print.params.properties = args[0].properties || defaultParams.properties;\n print.params.showModal = typeof args[0].showModal !== 'undefined' ? args[0].showModal : defaultParams.showModal;\n print.params.modalMessage = args[0].modalMessage || defaultParams.modalMessage;\n break;\n\n default:\n throw new Error('Unexpected argument type! Expected \"string\" or \"object\", got ' + _typeof(args[0]));\n }\n\n // some validation\n print.validateInput();\n\n // check if showing feedback to user (useful for large files)\n if (print.params.showModal) {\n print.showModal();\n }\n\n // to prevent duplication and issues, remove print.printFrame from DOM, if it exists\n var usedFrame = document.getElementById(print.params.frameId);\n\n if (usedFrame) {\n usedFrame.parentNode.removeChild(usedFrame);\n }\n\n // create a new iframe or embed element (IE prints blank pdf's if we use iframe)\n if (browser.isIE() && print.params.type === 'pdf') {\n // create embed element\n print.printFrame = document.createElement('embed');\n print.printFrame.setAttribute('type', 'application/pdf');\n\n // hide embed\n print.printFrame.setAttribute('style', 'width:0px;height:0px;');\n } else {\n // create iframe element\n print.printFrame = document.createElement('iframe');\n\n // hide iframe\n print.printFrame.setAttribute('style', 'display:none;');\n }\n\n // set element id\n print.printFrame.setAttribute('id', print.params.frameId);\n\n // for non pdf printing, pass empty html document to srcdoc (force onload callback)\n if (print.params.type !== 'pdf') print.printFrame.srcdoc = '';\n};\n\nPrintJS.prototype.pdf = function () {\n var print = this;\n\n // if showing feedback to user, pre load pdf files (hacky)\n // since we will be using promises, we can't use this feature in IE\n if (print.params.showModal && !browser.isIE()) {\n (function () {\n var pdfObject = document.createElement('img');\n pdfObject.src = print.params.printable;\n\n var pdf = new Promise(function (resolve, reject) {\n var loadPDF = setInterval(checkPDFload, 100);\n\n function checkPDFload() {\n if (pdfObject.complete) {\n window.clearInterval(loadPDF);\n resolve('PrintJS: PDF loaded. Read to print.');\n }\n }\n });\n\n pdf.then(function (result) {\n console.log(result);\n // set iframe src with pdf document url\n print.printFrame.setAttribute('src', print.params.printable);\n\n // print pdf document\n print.print();\n });\n })();\n } else {\n // set iframe src with pdf document url\n print.printFrame.setAttribute('src', print.params.printable);\n\n // print pdf\n print.print();\n }\n};\n\nPrintJS.prototype.image = function () {\n // create the image element\n var img = document.createElement('img');\n img.setAttribute('style', 'width:100%;');\n\n // set image src with image file url\n img.src = this.params.printable;\n\n // assign `this` to a variable, to be used within the promise\n var print = this;\n\n // if browser isn't IE, load image using promises\n if (!browser.isIE()) {\n var loadImage = new Promise(function (resolve, reject) {\n var loadPrintableImg = setInterval(checkImgLoad, 100);\n\n function checkImgLoad() {\n if (img.complete) {\n window.clearInterval(loadPrintableImg);\n resolve();\n console.log('PrintJS: Image loaded. Read to print.');\n }\n }\n });\n\n loadImage.then(function () {\n printImage();\n });\n } else {\n printImage();\n }\n\n function printImage() {\n // create wrapper\n var printableElement = document.createElement('div');\n printableElement.setAttribute('style', 'width:100%');\n\n // to prevent firefox from not loading images within iframe, we can use base64-encoded data URL of images pixel data\n if (browser.isFirefox()) {\n // let's make firefox happy\n var canvas = document.createElement('canvas');\n canvas.setAttribute('width', img.width);\n canvas.setAttribute('height', img.height);\n var context = canvas.getContext('2d');\n context.drawImage(img, 0, 0);\n\n // reset img src attribute with canvas dataURL\n img.setAttribute('src', canvas.toDataURL('JPEG', 1.0));\n }\n\n printableElement.appendChild(img);\n\n // add header if any\n if (print.params.header) {\n print.addHeader(printableElement);\n }\n\n // store html data\n print.params.htmlData = printableElement.outerHTML;\n\n // print image\n print.print();\n }\n};\n\nPrintJS.prototype.html = function () {\n // get HTML printable element\n var printElement = document.getElementById(this.params.printable);\n\n // check if element exists\n if (!printElement) {\n window.console.error('Invalid HTML element id: ' + this.params.printable);\n\n return false;\n }\n\n // make a copy of the printElement to prevent DOM changes\n var printableElement = document.createElement('div');\n printableElement.appendChild(printElement.cloneNode(true));\n\n // add cloned element to DOM, to have DOM element methods available. It will also be easier to colect styles\n printableElement.setAttribute('style', 'display:none;');\n printableElement.setAttribute('id', 'printJS-html');\n printElement.parentNode.appendChild(printableElement);\n\n // update printableElement variable with newly created DOM element\n printableElement = document.getElementById('printJS-html');\n\n // get main element styling\n printableElement.setAttribute('style', this.collectStyles(printableElement) + 'margin:0 !important;');\n\n // get all children elements\n var elements = printableElement.children;\n\n // get styles for all children elements\n this.loopNodesCollectStyles(elements);\n\n // add header if any\n if (this.params.header) {\n this.addHeader(printableElement);\n }\n\n // remove DOM printableElement\n printableElement.parentNode.removeChild(printableElement);\n\n // store html data\n this.params.htmlData = addWrapper(printableElement.innerHTML);\n\n // print html element contents\n this.print();\n};\n\nPrintJS.prototype.json = function () {\n // check if we received proper data\n if (_typeof(this.params.printable) !== 'object') {\n throw new Error('Invalid javascript data object (JSON).');\n }\n\n // check if properties were provided\n if (!this.params.properties || _typeof(this.params.properties) !== 'object') {\n throw new Error('Invalid properties array for your JSON data.');\n }\n\n // variable to hold html string\n var htmlData = '';\n\n // check print has header\n if (this.params.header) {\n htmlData += '

' + this.params.header + '

';\n }\n\n // function to build html templates for json data\n htmlData += this.jsonToHTML();\n\n // store html data\n this.params.htmlData = addWrapper(htmlData);\n\n // print json data\n this.print();\n};\n\nPrintJS.prototype.print = function () {\n var print = this;\n\n // append iframe element to document body\n document.getElementsByTagName('body')[0].appendChild(print.printFrame);\n\n // get iframe element\n var printJS = document.getElementById(print.params.frameId);\n\n // if printing pdf in IE\n if (browser.isIE() && print.params.type === 'pdf') {\n finishPrintPdfIe();\n } else {\n // wait for iframe to load all content\n print.printFrame.onload = function () {\n if (print.params.type === 'pdf') {\n finishPrint();\n } else {\n // get iframe element document\n var printDocument = printJS.contentWindow || printJS.contentDocument;\n if (printDocument.document) printDocument = printDocument.document;\n\n // inject printable html into iframe body\n printDocument.body.innerHTML = print.params.htmlData;\n\n finishPrint();\n }\n };\n }\n\n function finishPrint() {\n // print iframe document\n printJS.focus();\n\n // if IE, try catch with execCommand\n if (browser.isIE() && print.params.type !== 'pdf') {\n try {\n printJS.contentWindow.document.execCommand('print', false, null);\n } catch (e) {\n printJS.contentWindow.print();\n }\n } else {\n printJS.contentWindow.print();\n }\n\n // if showing feedback to user, remove processing message (close modal)\n if (print.params.showModal) {\n print.disablePrintModal();\n }\n }\n\n function finishPrintPdfIe() {\n // wait until pdf is ready to print\n if (typeof printJS.print === 'undefined') {\n setTimeout(function () {\n finishPrintPdfIe();\n }, 1000);\n } else {\n printJS.print();\n\n // remove embed (just because it isn't 100% hidden when using h/w = 0)\n setTimeout(function () {\n printJS.parentNode.removeChild(printJS);\n }, 2000);\n }\n }\n};\n\nPrintJS.prototype.collectStyles = function (element) {\n var win = document.defaultView || window;\n\n var style = [];\n\n // string variable to hold styling for each element\n var elementStyle = '';\n\n if (win.getComputedStyle) {\n // modern browsers\n style = win.getComputedStyle(element, '');\n\n for (var i = 0; i < style.length; i++) {\n // styles including\n var targetStyles = ['border', 'float', 'box'];\n // exact\n var targetStyle = ['clear', 'display', 'width', 'min-width', 'height', 'min-height', 'max-height'];\n\n // optinal - include margin and padding\n if (this.params.honorMarginPadding) {\n targetStyle.push('margin', 'padding');\n }\n\n // optinal - include color\n if (this.params.honorColor) {\n targetStyle.push('color');\n }\n\n for (var s = 0; s < targetStyle.length; s++) {\n if (style[i].indexOf(targetStyles[s]) !== -1 || style[i].indexOf(targetStyle[s]) === 0) {\n elementStyle += style[i] + ':' + style.getPropertyValue(style[i]) + ';';\n }\n }\n }\n } else if (element.currentStyle) {\n // IE\n style = element.currentStyle;\n\n for (var name in style) {\n if (style.indexOf('border') !== -1 && style.indexOf('color') !== -1) {\n elementStyle += name + ':' + style[name] + ';';\n }\n }\n }\n\n // add printer friendly\n elementStyle += printFriendlyElement;\n\n return elementStyle;\n};\n\nPrintJS.prototype.loopNodesCollectStyles = function (elements) {\n for (var n = 0; n < elements.length; n++) {\n var currentElement = elements[n];\n\n // Form Printing - check if is element Input\n var tag = currentElement.tagName;\n if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') {\n // save style to variable\n var textStyle = this.collectStyles(currentElement);\n\n // remove INPUT element and insert a text node\n var parent = currentElement.parentNode;\n\n // get text value\n var textNode = tag === 'SELECT' ? document.createTextNode(currentElement.options[currentElement.selectedIndex].text) : document.createTextNode(currentElement.value);\n\n // create text element\n var textElement = document.createElement('div');\n textElement.appendChild(textNode);\n\n // add style to text\n textElement.setAttribute('style', textStyle);\n\n // add text\n parent.appendChild(textElement);\n\n // remove input\n parent.removeChild(currentElement);\n } else {\n // get all styling for print element\n currentElement.setAttribute('style', this.collectStyles(currentElement));\n }\n\n // check if more elements in tree\n var children = currentElement.children;\n\n if (children.length) {\n this.loopNodesCollectStyles(children);\n }\n }\n};\n\nPrintJS.prototype.addHeader = function (printElement) {\n // create header element\n var headerElement = document.createElement('h1');\n\n // create header text node\n var headerNode = document.createTextNode(this.params.header);\n\n // build and style\n headerElement.appendChild(headerNode);\n headerElement.setAttribute('style', headerStyle);\n\n printElement.insertBefore(headerElement, printElement.childNodes[0]);\n};\n\nPrintJS.prototype.jsonToHTML = function () {\n var data = this.params.printable;\n var properties = this.params.properties;\n\n var htmlData = '
';\n\n // header\n htmlData += '
';\n\n for (var a = 0; a < properties.length; a++) {\n htmlData += '
' + capitalizePrint(properties[a]) + '
';\n }\n\n htmlData += '
';\n\n // create html data\n for (var i = 0; i < data.length; i++) {\n htmlData += '
';\n }\n\n htmlData += '
';\n }\n\n htmlData += '
';\n\n return htmlData;\n};\n\nPrintJS.prototype.validateInput = function () {\n if (!this.params.printable) {\n throw new Error('Missing printable information.');\n }\n\n if (!this.params.type || typeof this.params.type !== 'string' || printTypes.indexOf(this.params.type.toLowerCase()) === -1) {\n throw new Error('Invalid print type. Available types are: pdf, html, image and json.');\n }\n};\n\nPrintJS.prototype.showModal = function () {\n // build modal\n var modalStyle = 'font-family:sans-serif; ' + 'display:table; ' + 'text-align:center; ' + 'font-weight:300; ' + 'font-size:30px; ' + 'left:0; top:0;' + 'position:fixed; ' + 'z-index: 9990;' + 'color: #0460B5; ' + 'width: 100%; ' + 'height: 100%; ' + 'background-color:rgba(255,255,255,.9);' + 'transition: opacity .3s ease;';\n\n // create wrapper\n var printModal = document.createElement('div');\n printModal.setAttribute('style', modalStyle);\n printModal.setAttribute('id', 'printJS-Modal');\n\n // create content div\n var contentDiv = document.createElement('div');\n contentDiv.setAttribute('style', 'display:table-cell; vertical-align:middle; padding-bottom:100px;');\n\n // add close button (requires print.css)\n var closeButton = document.createElement('div');\n closeButton.setAttribute('class', 'printClose');\n closeButton.setAttribute('id', 'printClose');\n contentDiv.appendChild(closeButton);\n\n // add spinner (requires print.css)\n var spinner = document.createElement('span');\n spinner.setAttribute('class', 'printSpinner');\n contentDiv.appendChild(spinner);\n\n // add message\n var messageNode = document.createTextNode(this.params.modalMessage);\n contentDiv.appendChild(messageNode);\n\n // add contentDiv to printModal\n printModal.appendChild(contentDiv);\n\n // append print modal element to document body\n document.getElementsByTagName('body')[0].appendChild(printModal);\n\n // add event listener to close button\n var print = this;\n document.getElementById('printClose').addEventListener('click', function () {\n print.disablePrintModal();\n });\n};\n\nPrintJS.prototype.disablePrintModal = function () {\n var printFrame = document.getElementById('printJS-Modal');\n\n printFrame.parentNode.removeChild(printFrame);\n};\n\nfunction addWrapper(htmlData) {\n return '
' + htmlData + '
';\n}\n\n// update default print.params with user input\nfunction extend(a, b) {\n for (var key in b) {\n if (b.hasOwnProperty(key)) {\n a[key] = b[key];\n }\n }\n\n return a;\n}\n\n// capitalize string\nfunction capitalizePrint(string) {\n return string.charAt(0).toUpperCase() + string.slice(1);\n}\n\n},{\"./browser\":1}],3:[function(require,module,exports){\n'use strict';\n\n/*\n * Print.js\n * http://printjs.crabbly.com\n * Version: 1.0.11\n *\n * Copyright 2016 Rodrigo Vieira (@crabbly)\n * Released under the MIT license\n * https://github.com/crabbly/Print.js/blob/master/LICENSE\n */\n\nwindow.printJS = require('./js/print');\n\n},{\"./js/print\":2}]},{},[3]);\n"],"file":"print.min.js","sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"names":[],"mappings":"","sources":["print.min.js"],"sourcesContent":["(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o= 0\n\n // At least Safari 3+: \"[object HTMLElementConstructor]\"\n // let isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0\n\n // Edge 20+\n // let isEdge = !isIE && !!window.StyleMedia\n\n // Chrome 1+\n // let isChrome = !!window.chrome && !!window.chrome.webstore\n\n};\n\n},{}],2:[function(require,module,exports){\n'use strict';\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol ? \"symbol\" : typeof obj; };\n\nvar browser = require('./browser');\n\nvar printTypes = ['pdf', 'html', 'image', 'json'];\n\nvar defaultParams = {\n printable: null,\n type: 'pdf',\n header: null,\n maxWidth: 800,\n font: 'TimesNewRoman',\n font_size: '12pt',\n honorMarginPadding: true,\n honorColor: false,\n properties: null,\n showModal: false,\n modalMessage: 'Retrieving Document...',\n frameId: 'printJS',\n border: true,\n htmlData: ''\n};\n\nvar printFriendlyElement = void 0,\n bodyStyle = void 0,\n headerStyle = void 0;\n\nmodule.exports = function () {\n // check if a printable document or object was supplied\n if (arguments[0] === undefined) {\n window.console.error('printJS expects at least 1 attribute.');\n return false;\n }\n\n // instantiate print object\n var printJS = new PrintJS(arguments);\n\n // print friendly defaults\n printFriendlyElement = 'max-width: ' + printJS.params.maxWidth + 'px !important;' + printJS.params.font_size + ' !important;';\n bodyStyle = 'font-family:' + printJS.params.font + ' !important; font-size: ' + printJS.params.font_size + ' !important; width:100%;';\n headerStyle = 'font-weight:300;';\n\n // check printable type\n switch (printJS.params.type) {\n case 'pdf':\n // firefox doesn't support iframe printing, we will just open the pdf file instead\n if (browser.isFirefox()) {\n console.log('PrintJS doesn\\'t support PDF printing in Firefox.');\n var win = window.open(printJS.params.printable, '_blank');\n win.focus();\n // make sure there is no loading modal opened\n if (printJS.params.showModal) printJS.disablePrintModal();\n } else {\n printJS.pdf();\n }\n break;\n case 'image':\n printJS.image();\n break;\n case 'html':\n printJS.html();\n break;\n case 'json':\n printJS.json();\n break;\n default:\n // throw invalid type error\n throw new Error('Invalid print type. Available types are: pdf, html, image and json.');\n }\n};\n\n// printJS class\nvar PrintJS = function PrintJS() {\n var args = arguments[0];\n\n var print = this;\n\n print.params = extend({}, defaultParams);\n\n switch (_typeof(args[0])) {\n case 'string':\n print.params.printable = encodeURI(args[0]);\n print.params.type = args[1] || defaultParams.type;\n break;\n\n case 'object':\n print.params.printable = args[0].printable;\n print.params.type = args[0].type || defaultParams.type;\n print.params.frameId = args[0].frameId || defaultParams.frameId;\n print.params.header = args[0].header || defaultParams.header;\n print.params.maxWidth = args[0].maxWidth || defaultParams.maxWidth;\n print.params.font = args[0].font || defaultParams.font;\n print.params.font_size = args[0].font_size || defaultParams.font_size;\n print.params.honorMarginPadding = typeof args[0].honorMarginPadding !== 'undefined' ? args[0].honorMarginPadding : defaultParams.honorMarginPadding;\n print.params.properties = args[0].properties || defaultParams.properties;\n print.params.showModal = typeof args[0].showModal !== 'undefined' ? args[0].showModal : defaultParams.showModal;\n print.params.modalMessage = args[0].modalMessage || defaultParams.modalMessage;\n break;\n\n default:\n throw new Error('Unexpected argument type! Expected \"string\" or \"object\", got ' + _typeof(args[0]));\n }\n\n // some validation\n print.validateInput();\n\n // check if showing feedback to user (useful for large files)\n if (print.params.showModal) {\n print.showModal();\n }\n\n // to prevent duplication and issues, remove print.printFrame from DOM, if it exists\n var usedFrame = document.getElementById(print.params.frameId);\n\n if (usedFrame) {\n usedFrame.parentNode.removeChild(usedFrame);\n }\n\n // create a new iframe or embed element (IE prints blank pdf's if we use iframe)\n if (browser.isIE() && print.params.type === 'pdf') {\n // create embed element\n print.printFrame = document.createElement('embed');\n print.printFrame.setAttribute('type', 'application/pdf');\n\n // hide embed\n print.printFrame.setAttribute('style', 'width:0px;height:0px;');\n } else {\n // create iframe element\n print.printFrame = document.createElement('iframe');\n\n // hide iframe\n print.printFrame.setAttribute('style', 'display:none;');\n }\n\n // set element id\n print.printFrame.setAttribute('id', print.params.frameId);\n\n // for non pdf printing, pass empty html document to srcdoc (force onload callback)\n if (print.params.type !== 'pdf') print.printFrame.srcdoc = '';\n};\n\nPrintJS.prototype.pdf = function () {\n var print = this;\n\n // if showing feedback to user, pre load pdf files (hacky)\n // since we will be using promises, we can't use this feature in IE\n if (print.params.showModal && !browser.isIE()) {\n (function () {\n var pdfObject = document.createElement('img');\n pdfObject.src = print.params.printable;\n\n var pdf = new Promise(function (resolve, reject) {\n var loadPDF = setInterval(checkPDFload, 100);\n\n function checkPDFload() {\n if (pdfObject.complete) {\n window.clearInterval(loadPDF);\n resolve('PrintJS: PDF loaded. Read to print.');\n }\n }\n });\n\n pdf.then(function (result) {\n console.log(result);\n // set iframe src with pdf document url\n print.printFrame.setAttribute('src', print.params.printable);\n\n // print pdf document\n print.print();\n });\n })();\n } else {\n // set iframe src with pdf document url\n print.printFrame.setAttribute('src', print.params.printable);\n\n // print pdf\n print.print();\n }\n};\n\nPrintJS.prototype.image = function () {\n // create the image element\n var img = document.createElement('img');\n img.setAttribute('style', 'width:100%;');\n\n // set image src with image file url\n img.src = this.params.printable;\n\n // assign `this` to a variable, to be used within the promise\n var print = this;\n\n // if browser isn't IE, load image using promises\n if (!browser.isIE()) {\n var loadImage = new Promise(function (resolve, reject) {\n var loadPrintableImg = setInterval(checkImgLoad, 100);\n\n function checkImgLoad() {\n if (img.complete) {\n window.clearInterval(loadPrintableImg);\n resolve();\n }\n }\n });\n\n loadImage.then(function () {\n console.log('PrintJS: Image loaded. Read to print.');\n printImage();\n });\n } else {\n console.log('got here');\n printImage();\n }\n\n function printImage() {\n // create wrapper\n var printableElement = document.createElement('div');\n printableElement.setAttribute('style', 'width:100%');\n\n // to prevent firefox from not loading images within iframe, we can use base64-encoded data URL of images pixel data\n if (browser.isFirefox()) {\n // let's make firefox happy\n var canvas = document.createElement('canvas');\n canvas.setAttribute('width', img.width);\n canvas.setAttribute('height', img.height);\n var context = canvas.getContext('2d');\n context.drawImage(img, 0, 0);\n\n // reset img src attribute with canvas dataURL\n img.setAttribute('src', canvas.toDataURL('JPEG', 1.0));\n }\n\n printableElement.appendChild(img);\n\n // add header if any\n if (print.params.header) {\n print.addHeader(printableElement);\n }\n\n // store html data\n print.params.htmlData = printableElement.outerHTML;\n\n // print image\n print.print();\n }\n};\n\nPrintJS.prototype.html = function () {\n // get HTML printable element\n var printElement = document.getElementById(this.params.printable);\n\n // check if element exists\n if (!printElement) {\n window.console.error('Invalid HTML element id: ' + this.params.printable);\n\n return false;\n }\n\n // make a copy of the printElement to prevent DOM changes\n var printableElement = document.createElement('div');\n printableElement.appendChild(printElement.cloneNode(true));\n\n // add cloned element to DOM, to have DOM element methods available. It will also be easier to colect styles\n printableElement.setAttribute('style', 'display:none;');\n printableElement.setAttribute('id', 'printJS-html');\n printElement.parentNode.appendChild(printableElement);\n\n // update printableElement variable with newly created DOM element\n printableElement = document.getElementById('printJS-html');\n\n // get main element styling\n printableElement.setAttribute('style', this.collectStyles(printableElement) + 'margin:0 !important;');\n\n // get all children elements\n var elements = printableElement.children;\n\n // get styles for all children elements\n this.loopNodesCollectStyles(elements);\n\n // add header if any\n if (this.params.header) {\n this.addHeader(printableElement);\n }\n\n // remove DOM printableElement\n printableElement.parentNode.removeChild(printableElement);\n\n // store html data\n this.params.htmlData = addWrapper(printableElement.innerHTML);\n\n // print html element contents\n this.print();\n};\n\nPrintJS.prototype.json = function () {\n // check if we received proper data\n if (_typeof(this.params.printable) !== 'object') {\n throw new Error('Invalid javascript data object (JSON).');\n }\n\n // check if properties were provided\n if (!this.params.properties || _typeof(this.params.properties) !== 'object') {\n throw new Error('Invalid properties array for your JSON data.');\n }\n\n // variable to hold html string\n var htmlData = '';\n\n // check print has header\n if (this.params.header) {\n htmlData += '

' + this.params.header + '

';\n }\n\n // function to build html templates for json data\n htmlData += this.jsonToHTML();\n\n // store html data\n this.params.htmlData = addWrapper(htmlData);\n\n // print json data\n this.print();\n};\n\nPrintJS.prototype.print = function () {\n var print = this;\n\n // append iframe element to document body\n document.getElementsByTagName('body')[0].appendChild(print.printFrame);\n\n // get iframe element\n var printJS = document.getElementById(print.params.frameId);\n\n // if printing pdf in IE\n if (browser.isIE() && print.params.type === 'pdf') {\n finishPrintPdfIe();\n } else {\n // wait for iframe to load all content\n print.printFrame.onload = function () {\n if (print.params.type === 'pdf') {\n finishPrint();\n } else {\n // get iframe element document\n var printDocument = printJS.contentWindow || printJS.contentDocument;\n if (printDocument.document) printDocument = printDocument.document;\n\n // inject printable html into iframe body\n printDocument.body.innerHTML = print.params.htmlData;\n\n finishPrint();\n }\n };\n }\n\n function finishPrint() {\n // print iframe document\n printJS.focus();\n\n // if IE, try catch with execCommand\n if (browser.isIE() && print.params.type !== 'pdf') {\n try {\n printJS.contentWindow.document.execCommand('print', false, null);\n } catch (e) {\n printJS.contentWindow.print();\n }\n } else {\n printJS.contentWindow.print();\n }\n\n // if showing feedback to user, remove processing message (close modal)\n if (print.params.showModal) {\n print.disablePrintModal();\n }\n }\n\n function finishPrintPdfIe() {\n // wait until pdf is ready to print\n if (typeof printJS.print === 'undefined') {\n setTimeout(function () {\n finishPrintPdfIe();\n }, 1000);\n } else {\n printJS.print();\n\n // remove embed (just because it isn't 100% hidden when using h/w = 0)\n setTimeout(function () {\n printJS.parentNode.removeChild(printJS);\n }, 2000);\n }\n }\n};\n\nPrintJS.prototype.collectStyles = function (element) {\n var win = document.defaultView || window;\n\n var style = [];\n\n // string variable to hold styling for each element\n var elementStyle = '';\n\n if (win.getComputedStyle) {\n // modern browsers\n style = win.getComputedStyle(element, '');\n\n for (var i = 0; i < style.length; i++) {\n // styles including\n var targetStyles = ['border', 'float', 'box'];\n // exact\n var targetStyle = ['clear', 'display', 'width', 'min-width', 'height', 'min-height', 'max-height'];\n\n // optinal - include margin and padding\n if (this.params.honorMarginPadding) {\n targetStyle.push('margin', 'padding');\n }\n\n // optinal - include color\n if (this.params.honorColor) {\n targetStyle.push('color');\n }\n\n for (var s = 0; s < targetStyle.length; s++) {\n if (style[i].indexOf(targetStyles[s]) !== -1 || style[i].indexOf(targetStyle[s]) === 0) {\n elementStyle += style[i] + ':' + style.getPropertyValue(style[i]) + ';';\n }\n }\n }\n } else if (element.currentStyle) {\n // IE\n style = element.currentStyle;\n\n for (var name in style) {\n if (style.indexOf('border') !== -1 && style.indexOf('color') !== -1) {\n elementStyle += name + ':' + style[name] + ';';\n }\n }\n }\n\n // add printer friendly\n elementStyle += printFriendlyElement;\n\n return elementStyle;\n};\n\nPrintJS.prototype.loopNodesCollectStyles = function (elements) {\n for (var n = 0; n < elements.length; n++) {\n var currentElement = elements[n];\n\n // Form Printing - check if is element Input\n var tag = currentElement.tagName;\n if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') {\n // save style to variable\n var textStyle = this.collectStyles(currentElement);\n\n // remove INPUT element and insert a text node\n var parent = currentElement.parentNode;\n\n // get text value\n var textNode = tag === 'SELECT' ? document.createTextNode(currentElement.options[currentElement.selectedIndex].text) : document.createTextNode(currentElement.value);\n\n // create text element\n var textElement = document.createElement('div');\n textElement.appendChild(textNode);\n\n // add style to text\n textElement.setAttribute('style', textStyle);\n\n // add text\n parent.appendChild(textElement);\n\n // remove input\n parent.removeChild(currentElement);\n } else {\n // get all styling for print element\n currentElement.setAttribute('style', this.collectStyles(currentElement));\n }\n\n // check if more elements in tree\n var children = currentElement.children;\n\n if (children.length) {\n this.loopNodesCollectStyles(children);\n }\n }\n};\n\nPrintJS.prototype.addHeader = function (printElement) {\n // create header element\n var headerElement = document.createElement('h1');\n\n // create header text node\n var headerNode = document.createTextNode(this.params.header);\n\n // build and style\n headerElement.appendChild(headerNode);\n headerElement.setAttribute('style', headerStyle);\n\n printElement.insertBefore(headerElement, printElement.childNodes[0]);\n};\n\nPrintJS.prototype.jsonToHTML = function () {\n var data = this.params.printable;\n var properties = this.params.properties;\n\n var htmlData = '
';\n\n // header\n htmlData += '
';\n\n for (var a = 0; a < properties.length; a++) {\n htmlData += '
' + capitalizePrint(properties[a]) + '
';\n }\n\n htmlData += '
';\n\n // create html data\n for (var i = 0; i < data.length; i++) {\n htmlData += '
';\n }\n\n htmlData += '
';\n }\n\n htmlData += '
';\n\n return htmlData;\n};\n\nPrintJS.prototype.validateInput = function () {\n if (!this.params.printable) {\n throw new Error('Missing printable information.');\n }\n\n if (!this.params.type || typeof this.params.type !== 'string' || printTypes.indexOf(this.params.type.toLowerCase()) === -1) {\n throw new Error('Invalid print type. Available types are: pdf, html, image and json.');\n }\n};\n\nPrintJS.prototype.showModal = function () {\n // build modal\n var modalStyle = 'font-family:sans-serif; ' + 'display:table; ' + 'text-align:center; ' + 'font-weight:300; ' + 'font-size:30px; ' + 'left:0; top:0;' + 'position:fixed; ' + 'z-index: 9990;' + 'color: #0460B5; ' + 'width: 100%; ' + 'height: 100%; ' + 'background-color:rgba(255,255,255,.9);' + 'transition: opacity .3s ease;';\n\n // create wrapper\n var printModal = document.createElement('div');\n printModal.setAttribute('style', modalStyle);\n printModal.setAttribute('id', 'printJS-Modal');\n\n // create content div\n var contentDiv = document.createElement('div');\n contentDiv.setAttribute('style', 'display:table-cell; vertical-align:middle; padding-bottom:100px;');\n\n // add close button (requires print.css)\n var closeButton = document.createElement('div');\n closeButton.setAttribute('class', 'printClose');\n closeButton.setAttribute('id', 'printClose');\n contentDiv.appendChild(closeButton);\n\n // add spinner (requires print.css)\n var spinner = document.createElement('span');\n spinner.setAttribute('class', 'printSpinner');\n contentDiv.appendChild(spinner);\n\n // add message\n var messageNode = document.createTextNode(this.params.modalMessage);\n contentDiv.appendChild(messageNode);\n\n // add contentDiv to printModal\n printModal.appendChild(contentDiv);\n\n // append print modal element to document body\n document.getElementsByTagName('body')[0].appendChild(printModal);\n\n // add event listener to close button\n var print = this;\n document.getElementById('printClose').addEventListener('click', function () {\n print.disablePrintModal();\n });\n};\n\nPrintJS.prototype.disablePrintModal = function () {\n var printFrame = document.getElementById('printJS-Modal');\n\n printFrame.parentNode.removeChild(printFrame);\n};\n\nfunction addWrapper(htmlData) {\n return '
' + htmlData + '
';\n}\n\n// update default print.params with user input\nfunction extend(a, b) {\n for (var key in b) {\n if (b.hasOwnProperty(key)) {\n a[key] = b[key];\n }\n }\n\n return a;\n}\n\n// capitalize string\nfunction capitalizePrint(string) {\n return string.charAt(0).toUpperCase() + string.slice(1);\n}\n\n},{\"./browser\":1}],3:[function(require,module,exports){\n'use strict';\n\n/*\n * Print.js\n * http://printjs.crabbly.com\n * Version: 1.0.11\n *\n * Copyright 2016 Rodrigo Vieira (@crabbly)\n * Released under the MIT license\n * https://github.com/crabbly/Print.js/blob/master/LICENSE\n */\n\nwindow.printJS = require('./js/print');\n\n},{\"./js/print\":2}]},{},[3]);\n"],"file":"print.min.js","sourceRoot":"/source/"} \ No newline at end of file