Comparing version 1.0.61 to 1.0.62
@@ -107,24 +107,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\n__webpack_require__(/*! ./sass/index.scss */ \"./src/sass/index.scss\");\n\nvar _init = __webpack_require__(/*! ./js/init */ \"./src/js/init.js\");\n\nvar _init2 = _interopRequireDefault(_init);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar printJS = _init2.default.init;\n\nif (typeof window !== 'undefined') {\n window.printJS = printJS;\n}\n\nexports.default = printJS;\n\n//# sourceURL=webpack://printJS/./src/index.js?"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
__webpack_require__(/*! ./sass/index.scss */ "./src/sass/index.scss"); | ||
var _init = __webpack_require__(/*! ./js/init */ "./src/js/init.js"); | ||
var _init2 = _interopRequireDefault(_init); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var printJS = _init2.default.init; | ||
if (typeof window !== 'undefined') { | ||
window.printJS = printJS; | ||
} | ||
exports.default = printJS; | ||
/***/ }), | ||
@@ -140,34 +120,4 @@ | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nvar Browser = {\n // Firefox 1.0+\n isFirefox: function isFirefox() {\n return typeof InstallTrigger !== 'undefined';\n },\n // Internet Explorer 6-11\n isIE: function isIE() {\n return navigator.userAgent.indexOf('MSIE') !== -1 || !!document.documentMode;\n },\n // Edge 20+\n isEdge: function isEdge() {\n return !Browser.isIE() && !!window.StyleMedia;\n },\n // Chrome 1+\n isChrome: function isChrome() {\n var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;\n\n return !!context.chrome;\n },\n // At least Safari 3+: \"[object HTMLElementConstructor]\"\n isSafari: function isSafari() {\n return Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 || navigator.userAgent.toLowerCase().indexOf('safari') !== -1;\n },\n // IOS Chrome\n isIOSChrome: function isIOSChrome() {\n return navigator.userAgent.toLowerCase().indexOf('crios') !== -1;\n }\n};\n\nexports.default = Browser;\n\n//# sourceURL=webpack://printJS/./src/js/browser.js?"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var Browser = { | ||
// Firefox 1.0+ | ||
isFirefox: function isFirefox() { | ||
return typeof InstallTrigger !== 'undefined'; | ||
}, | ||
// Internet Explorer 6-11 | ||
isIE: function isIE() { | ||
return navigator.userAgent.indexOf('MSIE') !== -1 || !!document.documentMode; | ||
}, | ||
// Edge 20+ | ||
isEdge: function isEdge() { | ||
return !Browser.isIE() && !!window.StyleMedia; | ||
}, | ||
// Chrome 1+ | ||
isChrome: function isChrome() { | ||
var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window; | ||
return !!context.chrome; | ||
}, | ||
// At least Safari 3+: "[object HTMLElementConstructor]" | ||
isSafari: function isSafari() { | ||
return Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 || navigator.userAgent.toLowerCase().indexOf('safari') !== -1; | ||
} | ||
}; | ||
exports.default = Browser; | ||
/***/ }), | ||
@@ -183,122 +133,4 @@ | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\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 && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nexports.addWrapper = addWrapper;\nexports.capitalizePrint = capitalizePrint;\nexports.collectStyles = collectStyles;\nexports.addHeader = addHeader;\nexports.cleanUp = cleanUp;\nexports.isRawHTML = isRawHTML;\n\nvar _modal = __webpack_require__(/*! ./modal */ \"./src/js/modal.js\");\n\nvar _modal2 = _interopRequireDefault(_modal);\n\nvar _browser = __webpack_require__(/*! ./browser */ \"./src/js/browser.js\");\n\nvar _browser2 = _interopRequireDefault(_browser);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction addWrapper(htmlData, params) {\n var bodyStyle = 'font-family:' + params.font + ' !important; font-size: ' + params.font_size + ' !important; width:100%;';\n return '<div style=\"' + bodyStyle + '\">' + htmlData + '</div>';\n}\n\nfunction capitalizePrint(obj) {\n return obj.charAt(0).toUpperCase() + obj.slice(1);\n}\n\nfunction collectStyles(element, params) {\n var win = document.defaultView || window;\n\n // String variable to hold styling for each element\n var elementStyle = '';\n\n // Loop over computed styles\n var styles = win.getComputedStyle(element, '');\n\n Object.keys(styles).map(function (key) {\n // Check if style should be processed\n if (params.targetStyles.indexOf('*') !== -1 || params.targetStyle.indexOf(styles[key]) !== -1 || targetStylesMatch(params.targetStyles, styles[key])) {\n if (styles.getPropertyValue(styles[key])) elementStyle += styles[key] + ':' + styles.getPropertyValue(styles[key]) + ';';\n }\n });\n\n // Print friendly defaults (deprecated)\n elementStyle += 'max-width: ' + params.maxWidth + 'px !important;' + params.font_size + ' !important;';\n\n return elementStyle;\n}\n\nfunction targetStylesMatch(styles, value) {\n for (var i = 0; i < styles.length; i++) {\n if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value.indexOf(styles[i]) !== -1) return true;\n }\n return false;\n}\n\nfunction addHeader(printElement, params) {\n // Create the header container div\n var headerContainer = document.createElement('div');\n\n // Check if the header is text or raw html\n if (isRawHTML(params.header)) {\n headerContainer.innerHTML = params.header;\n } else {\n // Create header element\n var headerElement = document.createElement('h1');\n\n // Create header text node\n var headerNode = document.createTextNode(params.header);\n\n // Build and style\n headerElement.appendChild(headerNode);\n headerElement.setAttribute('style', params.headerStyle);\n headerContainer.appendChild(headerElement);\n }\n\n printElement.insertBefore(headerContainer, printElement.childNodes[0]);\n}\n\nfunction cleanUp(params) {\n // If we are showing a feedback message to user, remove it\n if (params.showModal) _modal2.default.close();\n\n // Check for a finished loading hook function\n if (params.onLoadingEnd) params.onLoadingEnd();\n\n // If preloading pdf files, clean blob url\n if (params.showModal || params.onLoadingStart) window.URL.revokeObjectURL(params.printable);\n\n // If a onPrintDialogClose callback is given, execute it\n if (params.onPrintDialogClose) {\n var event = 'mouseover';\n\n if (_browser2.default.isChrome() || _browser2.default.isFirefox()) {\n // Ps.: Firefox will require an extra click in the document to fire the focus event.\n event = 'focus';\n }\n var handler = function handler() {\n // Make sure the event only happens once.\n window.removeEventListener(event, handler);\n\n params.onPrintDialogClose();\n };\n\n window.addEventListener(event, handler);\n }\n}\n\nfunction isRawHTML(raw) {\n var regexHtml = new RegExp('<([A-Za-z][A-Za-z0-9]*)\\\\b[^>]*>(.*?)</\\\\1>');\n return regexHtml.test(raw);\n}\n\n//# sourceURL=webpack://printJS/./src/js/functions.js?"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
exports.addWrapper = addWrapper; | ||
exports.capitalizePrint = capitalizePrint; | ||
exports.collectStyles = collectStyles; | ||
exports.addHeader = addHeader; | ||
exports.cleanUp = cleanUp; | ||
exports.isRawHTML = isRawHTML; | ||
var _modal = __webpack_require__(/*! ./modal */ "./src/js/modal.js"); | ||
var _modal2 = _interopRequireDefault(_modal); | ||
var _browser = __webpack_require__(/*! ./browser */ "./src/js/browser.js"); | ||
var _browser2 = _interopRequireDefault(_browser); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function addWrapper(htmlData, params) { | ||
var bodyStyle = 'font-family:' + params.font + ' !important; font-size: ' + params.font_size + ' !important; width:100%;'; | ||
return '<div style="' + bodyStyle + '">' + htmlData + '</div>'; | ||
} | ||
function capitalizePrint(obj) { | ||
return obj.charAt(0).toUpperCase() + obj.slice(1); | ||
} | ||
function collectStyles(element, params) { | ||
var win = document.defaultView || window; | ||
// String variable to hold styling for each element | ||
var elementStyle = ''; | ||
// Loop over computed styles | ||
var styles = win.getComputedStyle(element, ''); | ||
Object.keys(styles).map(function (key) { | ||
// Check if style should be processed | ||
if (params.targetStyles.indexOf('*') !== -1 || params.targetStyle.indexOf(styles[key]) !== -1 || targetStylesMatch(params.targetStyles, styles[key])) { | ||
if (styles.getPropertyValue(styles[key])) elementStyle += styles[key] + ':' + styles.getPropertyValue(styles[key]) + ';'; | ||
} | ||
}); | ||
// Print friendly defaults (deprecated) | ||
elementStyle += 'max-width: ' + params.maxWidth + 'px !important;' + params.font_size + ' !important;'; | ||
return elementStyle; | ||
} | ||
function targetStylesMatch(styles, value) { | ||
for (var i = 0; i < styles.length; i++) { | ||
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value.indexOf(styles[i]) !== -1) return true; | ||
} | ||
return false; | ||
} | ||
function addHeader(printElement, params) { | ||
// Create the header container div | ||
var headerContainer = document.createElement('div'); | ||
// Check if the header is text or raw html | ||
if (isRawHTML(params.header)) { | ||
headerContainer.innerHTML = params.header; | ||
} else { | ||
// Create header element | ||
var headerElement = document.createElement('h1'); | ||
// Create header text node | ||
var headerNode = document.createTextNode(params.header); | ||
// Build and style | ||
headerElement.appendChild(headerNode); | ||
headerElement.setAttribute('style', params.headerStyle); | ||
headerContainer.appendChild(headerElement); | ||
} | ||
printElement.insertBefore(headerContainer, printElement.childNodes[0]); | ||
} | ||
function cleanUp(params) { | ||
// If we are showing a feedback message to user, remove it | ||
if (params.showModal) _modal2.default.close(); | ||
// Check for a finished loading hook function | ||
if (params.onLoadingEnd) params.onLoadingEnd(); | ||
// If preloading pdf files, clean blob url | ||
if (params.showModal || params.onLoadingStart) window.URL.revokeObjectURL(params.printable); | ||
// If a onPrintDialogClose callback is given, execute it | ||
if (params.onPrintDialogClose) { | ||
var event = 'mouseover'; | ||
if (_browser2.default.isChrome() || _browser2.default.isFirefox()) { | ||
// Ps.: Firefox will require an extra click in the document to fire the focus event. | ||
event = 'focus'; | ||
} | ||
var handler = function handler() { | ||
// Make sure the event only happens once. | ||
window.removeEventListener(event, handler); | ||
params.onPrintDialogClose(); | ||
}; | ||
window.addEventListener(event, handler); | ||
} | ||
} | ||
function isRawHTML(raw) { | ||
var regexHtml = new RegExp('<([A-Za-z][A-Za-z0-9]*)\\b[^>]*>(.*?)</\\1>'); | ||
return regexHtml.test(raw); | ||
} | ||
/***/ }), | ||
@@ -314,101 +146,4 @@ | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _functions = __webpack_require__(/*! ./functions */ \"./src/js/functions.js\");\n\nvar _print = __webpack_require__(/*! ./print */ \"./src/js/print.js\");\n\nvar _print2 = _interopRequireDefault(_print);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nexports.default = {\n print: function print(params, printFrame) {\n // Get the DOM printable element\n var printElement = document.getElementById(params.printable);\n\n // Check if the element exists\n if (!printElement) {\n window.console.error('Invalid HTML element id: ' + params.printable);\n return;\n }\n\n // Clone the target element including its children (if available)\n params.printableElement = cloneElement(printElement, params);\n\n // Add header\n if (params.header) {\n (0, _functions.addHeader)(params.printableElement, params);\n }\n\n // Print html element contents\n _print2.default.send(params, printFrame);\n }\n};\n\n\nfunction cloneElement(element, params) {\n // Clone the main node (if not already inside the recursion process)\n var clone = element.cloneNode();\n\n // Loop over and process the children elements / nodes (including text nodes)\n var _iteratorNormalCompletion = true;\n var _didIteratorError = false;\n var _iteratorError = undefined;\n\n try {\n for (var _iterator = element.childNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var child = _step.value;\n\n // Check if we are skiping the current element\n if (params.ignoreElements.indexOf(child.id) !== -1) {\n continue;\n }\n\n // Clone the child element\n var clonedChild = cloneElement(child, params);\n\n // Attach the cloned child to the cloned parent node\n clone.appendChild(clonedChild);\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n\n console.log(element.nodeType);\n // Get all styling for print element (for nodes of type element only)\n if (params.scanStyles && element.nodeType === 1) {\n clone.setAttribute('style', (0, _functions.collectStyles)(element, params));\n }\n\n // Check if the element needs any state processing (copy user input data)\n switch (element.tagName) {\n case 'SELECT':\n // Copy the current selection value to its clone\n clone.value = element.value;\n break;\n case 'CANVAS':\n // Copy the canvas content to its clone\n clone.getContext('2d').drawImage(element, 0, 0);\n break;\n }\n\n return clone;\n}\n\n//# sourceURL=webpack://printJS/./src/js/html.js?"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _functions = __webpack_require__(/*! ./functions */ "./src/js/functions.js"); | ||
var _print = __webpack_require__(/*! ./print */ "./src/js/print.js"); | ||
var _print2 = _interopRequireDefault(_print); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = { | ||
print: function print(params, printFrame) { | ||
// Get the DOM printable element | ||
var printElement = document.getElementById(params.printable); | ||
// Check if the element exists | ||
if (!printElement) { | ||
window.console.error('Invalid HTML element id: ' + params.printable); | ||
return; | ||
} | ||
// Clone the target element including its children (if available) | ||
params.printableElement = cloneElement(printElement, params); | ||
// Add header | ||
if (params.header) { | ||
(0, _functions.addHeader)(params.printableElement, params); | ||
} | ||
// Print html element contents | ||
_print2.default.send(params, printFrame); | ||
} | ||
}; | ||
function cloneElement(element, params) { | ||
// Clone the main node (if not already inside the recursion process) | ||
var clone = element.cloneNode(); | ||
// Loop over and process the children elements / nodes (including text nodes) | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = element.childNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var child = _step.value; | ||
// Check if we are skiping the current element | ||
if (params.ignoreElements.indexOf(child.id) !== -1) { | ||
continue; | ||
} | ||
// Clone the child element | ||
var clonedChild = cloneElement(child, params); | ||
// Attach the cloned child to the cloned parent node | ||
clone.appendChild(clonedChild); | ||
} | ||
// Get all styling for print element (for nodes of type element only) | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
if (params.scanStyles && element.nodeType === 1) { | ||
clone.setAttribute('style', (0, _functions.collectStyles)(element, params)); | ||
} | ||
// Check if the element needs any state processing (copy user input data) | ||
switch (element.tagName) { | ||
case 'SELECT': | ||
// Copy the current selection value to its clone | ||
clone.value = element.value; | ||
break; | ||
case 'CANVAS': | ||
// Copy the canvas content to its clone | ||
clone.getContext('2d').drawImage(element, 0, 0); | ||
break; | ||
} | ||
return clone; | ||
} | ||
/***/ }), | ||
@@ -424,54 +159,4 @@ | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _functions = __webpack_require__(/*! ./functions */ \"./src/js/functions.js\");\n\nvar _print = __webpack_require__(/*! ./print */ \"./src/js/print.js\");\n\nvar _print2 = _interopRequireDefault(_print);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nexports.default = {\n print: function print(params, printFrame) {\n // Check if we are printing one image or multiple images\n if (params.printable.constructor !== Array) {\n // Create array with one image\n params.printable = [params.printable];\n }\n\n // Create printable element (container)\n params.printableElement = document.createElement('div');\n\n // Create all image elements and append them to the printable container\n params.printable.forEach(function (src) {\n // Create the image element\n var img = document.createElement('img');\n img.setAttribute('style', params.imageStyle);\n\n // Set image src with the file url\n img.src = src;\n\n // Create the image wrapper\n var imageWrapper = document.createElement('div');\n\n // Append image to the wrapper element\n imageWrapper.appendChild(img);\n\n // Append wrapper to the printable element\n params.printableElement.appendChild(imageWrapper);\n });\n\n // Check if we are adding a print header\n if (params.header) (0, _functions.addHeader)(params.printableElement, params);\n\n // Print image\n _print2.default.send(params, printFrame);\n }\n};\n\n//# sourceURL=webpack://printJS/./src/js/image.js?"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _functions = __webpack_require__(/*! ./functions */ "./src/js/functions.js"); | ||
var _print = __webpack_require__(/*! ./print */ "./src/js/print.js"); | ||
var _print2 = _interopRequireDefault(_print); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = { | ||
print: function print(params, printFrame) { | ||
// Check if we are printing one image or multiple images | ||
if (params.printable.constructor !== Array) { | ||
// Create array with one image | ||
params.printable = [params.printable]; | ||
} | ||
// Create printable element (container) | ||
params.printableElement = document.createElement('div'); | ||
// Create all image elements and append them to the printable container | ||
params.printable.forEach(function (src) { | ||
// Create the image element | ||
var img = document.createElement('img'); | ||
img.setAttribute('style', params.imageStyle); | ||
// Set image src with the file url | ||
img.src = src; | ||
// Create the image wrapper | ||
var imageWrapper = document.createElement('div'); | ||
// Append image to the wrapper element | ||
imageWrapper.appendChild(img); | ||
// Append wrapper to the printable element | ||
params.printableElement.appendChild(imageWrapper); | ||
}); | ||
// Check if we are adding a print header | ||
if (params.header) (0, _functions.addHeader)(params.printableElement, params); | ||
// Print image | ||
_print2.default.send(params, printFrame); | ||
} | ||
}; | ||
/***/ }), | ||
@@ -487,197 +172,4 @@ | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\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 && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nvar _browser = __webpack_require__(/*! ./browser */ \"./src/js/browser.js\");\n\nvar _browser2 = _interopRequireDefault(_browser);\n\nvar _modal = __webpack_require__(/*! ./modal */ \"./src/js/modal.js\");\n\nvar _modal2 = _interopRequireDefault(_modal);\n\nvar _pdf = __webpack_require__(/*! ./pdf */ \"./src/js/pdf.js\");\n\nvar _pdf2 = _interopRequireDefault(_pdf);\n\nvar _html = __webpack_require__(/*! ./html */ \"./src/js/html.js\");\n\nvar _html2 = _interopRequireDefault(_html);\n\nvar _rawHtml = __webpack_require__(/*! ./raw-html */ \"./src/js/raw-html.js\");\n\nvar _rawHtml2 = _interopRequireDefault(_rawHtml);\n\nvar _image = __webpack_require__(/*! ./image */ \"./src/js/image.js\");\n\nvar _image2 = _interopRequireDefault(_image);\n\nvar _json = __webpack_require__(/*! ./json */ \"./src/js/json.js\");\n\nvar _json2 = _interopRequireDefault(_json);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar printTypes = ['pdf', 'html', 'image', 'json', 'raw-html'];\n\nexports.default = {\n init: function init() {\n var params = {\n printable: null,\n fallbackPrintable: null,\n type: 'pdf',\n header: null,\n headerStyle: 'font-weight: 300;',\n maxWidth: 800,\n font: 'TimesNewRoman',\n font_size: '12pt',\n honorMarginPadding: true,\n honorColor: false,\n properties: null,\n gridHeaderStyle: 'font-weight: bold; padding: 5px; border: 1px solid #dddddd;',\n gridStyle: 'border: 1px solid lightgray; margin-bottom: -1px;',\n showModal: false,\n onError: function onError(error) {\n throw error;\n },\n onLoadingStart: null,\n onLoadingEnd: null,\n onPrintDialogClose: null,\n onPdfOpen: null,\n onBrowserIncompatible: function onBrowserIncompatible() {\n return true;\n },\n modalMessage: 'Retrieving Document...',\n frameId: 'printJS',\n printableElement: null,\n documentTitle: 'Document',\n targetStyle: ['clear', 'display', 'width', 'min-width', 'height', 'min-height', 'max-height'],\n targetStyles: ['border', 'box', 'break', 'text-decoration'],\n ignoreElements: [],\n imageStyle: 'max-width: 100%;',\n repeatTableHeader: true,\n css: null,\n style: null,\n scanStyles: true,\n base64: false\n\n // Check if a printable document or object was supplied\n };var args = arguments[0];\n if (args === undefined) throw new Error('printJS expects at least 1 attribute.');\n\n // Process parameters\n switch (typeof args === 'undefined' ? 'undefined' : _typeof(args)) {\n case 'string':\n params.printable = encodeURI(args);\n params.fallbackPrintable = params.printable;\n params.type = arguments[1] || params.type;\n break;\n case 'object':\n params.printable = args.printable;\n params.base64 = typeof args.base64 !== 'undefined';\n params.fallbackPrintable = typeof args.fallbackPrintable !== 'undefined' ? args.fallbackPrintable : params.printable;\n params.fallbackPrintable = params.base64 ? 'data:application/pdf;base64,' + params.fallbackPrintable : params.fallbackPrintable;\n for (var k in params) {\n if (k === 'printable' || k === 'fallbackPrintable' || k === 'base64') continue;\n\n params[k] = typeof args[k] !== 'undefined' ? args[k] : params[k];\n }\n break;\n default:\n throw new Error('Unexpected argument type! Expected \"string\" or \"object\", got ' + (typeof args === 'undefined' ? 'undefined' : _typeof(args)));\n }\n\n // Validate printable\n if (!params.printable) throw new Error('Missing printable information.');\n\n // Validate type\n if (!params.type || typeof params.type !== 'string' || printTypes.indexOf(params.type.toLowerCase()) === -1) {\n throw new Error('Invalid print type. Available types are: pdf, html, image and json.');\n }\n\n // Check if we are showing a feedback message to the user (useful for large files)\n if (params.showModal) _modal2.default.show(params);\n\n // Check for a print start hook function\n if (params.onLoadingStart) params.onLoadingStart();\n\n // To prevent duplication and issues, remove any used printFrame from the DOM\n var usedFrame = document.getElementById(params.frameId);\n\n if (usedFrame) usedFrame.parentNode.removeChild(usedFrame);\n\n // Create a new iframe or embed element (IE prints blank pdf's if we use iframe)\n var printFrame = void 0;\n\n // Create iframe element\n printFrame = document.createElement('iframe');\n\n // Hide iframe\n printFrame.setAttribute('style', 'visibility: hidden; height: 0; width: 0; position: absolute;');\n\n // Set iframe element id\n printFrame.setAttribute('id', params.frameId);\n\n // For non pdf printing, pass an html document string to srcdoc (force onload callback)\n if (params.type !== 'pdf') {\n printFrame.srcdoc = '<html><head><title>' + params.documentTitle + '</title>';\n\n // Attach css files\n if (params.css) {\n // Add support for single file\n if (!Array.isArray(params.css)) params.css = [params.css];\n\n // Create link tags for each css file\n params.css.forEach(function (file) {\n printFrame.srcdoc += '<link rel=\"stylesheet\" href=\"' + file + '\">';\n });\n }\n\n printFrame.srcdoc += '</head><body></body></html>';\n }\n\n // Check printable type\n switch (params.type) {\n case 'pdf':\n // Check browser support for pdf and if not supported we will just open the pdf file instead\n if (_browser2.default.isFirefox() || _browser2.default.isEdge() || _browser2.default.isIE()) {\n try {\n console.info('PrintJS currently doesn\\'t support PDF printing in Firefox, Internet Explorer and Edge.');\n if (params.onBrowserIncompatible() === true) {\n var win = window.open(params.fallbackPrintable, '_blank');\n win.focus();\n if (params.onPdfOpen) params.onPdfOpen();\n }\n } catch (e) {\n params.onError(e);\n } finally {\n // Make sure there is no loading modal opened\n if (params.showModal) _modal2.default.close();\n if (params.onLoadingEnd) params.onLoadingEnd();\n }\n } else {\n _pdf2.default.print(params, printFrame);\n }\n break;\n case 'image':\n _image2.default.print(params, printFrame);\n break;\n case 'html':\n _html2.default.print(params, printFrame);\n break;\n case 'raw-html':\n _rawHtml2.default.print(params, printFrame);\n break;\n case 'json':\n _json2.default.print(params, printFrame);\n break;\n }\n }\n};\n\n//# sourceURL=webpack://printJS/./src/js/init.js?"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _browser = __webpack_require__(/*! ./browser */ "./src/js/browser.js"); | ||
var _browser2 = _interopRequireDefault(_browser); | ||
var _modal = __webpack_require__(/*! ./modal */ "./src/js/modal.js"); | ||
var _modal2 = _interopRequireDefault(_modal); | ||
var _pdf = __webpack_require__(/*! ./pdf */ "./src/js/pdf.js"); | ||
var _pdf2 = _interopRequireDefault(_pdf); | ||
var _html = __webpack_require__(/*! ./html */ "./src/js/html.js"); | ||
var _html2 = _interopRequireDefault(_html); | ||
var _rawHtml = __webpack_require__(/*! ./raw-html */ "./src/js/raw-html.js"); | ||
var _rawHtml2 = _interopRequireDefault(_rawHtml); | ||
var _image = __webpack_require__(/*! ./image */ "./src/js/image.js"); | ||
var _image2 = _interopRequireDefault(_image); | ||
var _json = __webpack_require__(/*! ./json */ "./src/js/json.js"); | ||
var _json2 = _interopRequireDefault(_json); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var printTypes = ['pdf', 'html', 'image', 'json', 'raw-html']; | ||
exports.default = { | ||
init: function init() { | ||
var params = { | ||
printable: null, | ||
fallbackPrintable: null, | ||
type: 'pdf', | ||
header: null, | ||
headerStyle: 'font-weight: 300;', | ||
maxWidth: 800, | ||
font: 'TimesNewRoman', | ||
font_size: '12pt', | ||
honorMarginPadding: true, | ||
honorColor: false, | ||
properties: null, | ||
gridHeaderStyle: 'font-weight: bold; padding: 5px; border: 1px solid #dddddd;', | ||
gridStyle: 'border: 1px solid lightgray; margin-bottom: -1px;', | ||
showModal: false, | ||
onError: function onError(error) { | ||
throw error; | ||
}, | ||
onLoadingStart: null, | ||
onLoadingEnd: null, | ||
onPrintDialogClose: null, | ||
onPdfOpen: null, | ||
onBrowserIncompatible: function onBrowserIncompatible() { | ||
return true; | ||
}, | ||
modalMessage: 'Retrieving Document...', | ||
frameId: 'printJS', | ||
printableElement: null, | ||
documentTitle: 'Document', | ||
targetStyle: ['clear', 'display', 'width', 'min-width', 'height', 'min-height', 'max-height'], | ||
targetStyles: ['border', 'box', 'break', 'text-decoration'], | ||
ignoreElements: [], | ||
imageStyle: 'max-width: 100%;', | ||
repeatTableHeader: true, | ||
css: null, | ||
style: null, | ||
scanStyles: true, | ||
base64: false | ||
// Check if a printable document or object was supplied | ||
};var args = arguments[0]; | ||
if (args === undefined) throw new Error('printJS expects at least 1 attribute.'); | ||
// Process parameters | ||
switch (typeof args === 'undefined' ? 'undefined' : _typeof(args)) { | ||
case 'string': | ||
params.printable = encodeURI(args); | ||
params.fallbackPrintable = params.printable; | ||
params.type = arguments[1] || params.type; | ||
break; | ||
case 'object': | ||
params.printable = args.printable; | ||
params.base64 = typeof args.base64 !== 'undefined'; | ||
params.fallbackPrintable = typeof args.fallbackPrintable !== 'undefined' ? args.fallbackPrintable : params.printable; | ||
params.fallbackPrintable = params.base64 ? 'data:application/pdf;base64,' + params.fallbackPrintable : params.fallbackPrintable; | ||
for (var k in params) { | ||
if (k === 'printable' || k === 'fallbackPrintable' || k === 'base64') continue; | ||
params[k] = typeof args[k] !== 'undefined' ? args[k] : params[k]; | ||
} | ||
break; | ||
default: | ||
throw new Error('Unexpected argument type! Expected "string" or "object", got ' + (typeof args === 'undefined' ? 'undefined' : _typeof(args))); | ||
} | ||
// Validate printable | ||
if (!params.printable) throw new Error('Missing printable information.'); | ||
// Validate type | ||
if (!params.type || typeof params.type !== 'string' || printTypes.indexOf(params.type.toLowerCase()) === -1) { | ||
throw new Error('Invalid print type. Available types are: pdf, html, image and json.'); | ||
} | ||
// Check if we are showing a feedback message to the user (useful for large files) | ||
if (params.showModal) _modal2.default.show(params); | ||
// Check for a print start hook function | ||
if (params.onLoadingStart) params.onLoadingStart(); | ||
// To prevent duplication and issues, remove any used printFrame from the DOM | ||
var usedFrame = document.getElementById(params.frameId); | ||
if (usedFrame) usedFrame.parentNode.removeChild(usedFrame); | ||
// Create a new iframe or embed element (IE prints blank pdf's if we use iframe) | ||
var printFrame = void 0; | ||
// Create iframe element | ||
printFrame = document.createElement('iframe'); | ||
// Hide iframe | ||
printFrame.setAttribute('style', 'visibility: hidden; height: 0; width: 0; position: absolute;'); | ||
// Set iframe element id | ||
printFrame.setAttribute('id', params.frameId); | ||
// For non pdf printing, pass an html document string to srcdoc (force onload callback) | ||
if (params.type !== 'pdf') { | ||
printFrame.srcdoc = '<html><head><title>' + params.documentTitle + '</title>'; | ||
// Attach css files | ||
if (params.css) { | ||
// Add support for single file | ||
if (!Array.isArray(params.css)) params.css = [params.css]; | ||
// Create link tags for each css file | ||
params.css.forEach(function (file) { | ||
printFrame.srcdoc += '<link rel="stylesheet" href="' + file + '">'; | ||
}); | ||
} | ||
printFrame.srcdoc += '</head><body></body></html>'; | ||
} | ||
// Check printable type | ||
switch (params.type) { | ||
case 'pdf': | ||
// Check browser support for pdf and if not supported we will just open the pdf file instead | ||
if (_browser2.default.isFirefox() || _browser2.default.isEdge() || _browser2.default.isIE()) { | ||
try { | ||
console.info('PrintJS currently doesn\'t support PDF printing in Firefox, Internet Explorer and Edge.'); | ||
if (params.onBrowserIncompatible() === true) { | ||
var win = window.open(params.fallbackPrintable, '_blank'); | ||
win.focus(); | ||
if (params.onPdfOpen) params.onPdfOpen(); | ||
} | ||
} catch (e) { | ||
params.onError(e); | ||
} finally { | ||
// Make sure there is no loading modal opened | ||
if (params.showModal) _modal2.default.close(); | ||
if (params.onLoadingEnd) params.onLoadingEnd(); | ||
} | ||
} else { | ||
_pdf2.default.print(params, printFrame); | ||
} | ||
break; | ||
case 'image': | ||
_image2.default.print(params, printFrame); | ||
break; | ||
case 'html': | ||
_html2.default.print(params, printFrame); | ||
break; | ||
case 'raw-html': | ||
_rawHtml2.default.print(params, printFrame); | ||
break; | ||
case 'json': | ||
_json2.default.print(params, printFrame); | ||
break; | ||
} | ||
} | ||
}; | ||
/***/ }), | ||
@@ -693,126 +185,4 @@ | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\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 && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nvar _functions = __webpack_require__(/*! ./functions */ \"./src/js/functions.js\");\n\nvar _print = __webpack_require__(/*! ./print */ \"./src/js/print.js\");\n\nvar _print2 = _interopRequireDefault(_print);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nexports.default = {\n print: function print(params, printFrame) {\n // Check if we received proper data\n if (_typeof(params.printable) !== 'object') {\n throw new Error('Invalid javascript data object (JSON).');\n }\n\n // Validate repeatTableHeader\n if (typeof params.repeatTableHeader !== 'boolean') {\n throw new Error('Invalid value for repeatTableHeader attribute (JSON).');\n }\n\n // Validate properties\n if (!params.properties || !Array.isArray(params.properties)) {\n throw new Error('Invalid properties array for your JSON data.');\n }\n\n // We will format the property objects to keep the JSON api compatible with older releases\n params.properties = params.properties.map(function (property) {\n return {\n field: (typeof property === 'undefined' ? 'undefined' : _typeof(property)) === 'object' ? property.field : property,\n displayName: (typeof property === 'undefined' ? 'undefined' : _typeof(property)) === 'object' ? property.displayName : property,\n columnSize: (typeof property === 'undefined' ? 'undefined' : _typeof(property)) === 'object' && property.columnSize ? property.columnSize + ';' : 100 / params.properties.length + '%;'\n };\n });\n\n // Create a print container element\n params.printableElement = document.createElement('div');\n\n // Check if we are adding a print header\n if (params.header) {\n (0, _functions.addHeader)(params.printableElement, params);\n }\n\n // Build the printable html data\n params.printableElement.innerHTML += jsonToHTML(params);\n\n // Print the json data\n _print2.default.send(params, printFrame);\n }\n};\n\n\nfunction jsonToHTML(params) {\n // Get the row and column data\n var data = params.printable;\n var properties = params.properties;\n\n // Create a html table\n var htmlData = '<table style=\"border-collapse: collapse; width: 100%;\">';\n\n // Check if the header should be repeated\n if (params.repeatTableHeader) {\n htmlData += '<thead>';\n }\n\n // Add the table header row\n htmlData += '<tr>';\n\n // Add the table header columns\n for (var a = 0; a < properties.length; a++) {\n htmlData += '<th style=\"width:' + properties[a].columnSize + ';' + params.gridHeaderStyle + '\">' + (0, _functions.capitalizePrint)(properties[a].displayName) + '</th>';\n }\n\n // Add the closing tag for the table header row\n htmlData += '</tr>';\n\n // If the table header is marked as repeated, add the closing tag\n if (params.repeatTableHeader) {\n htmlData += '</thead>';\n }\n\n // Create the table body\n htmlData += '<tbody>';\n\n // Add the table data rows\n for (var i = 0; i < data.length; i++) {\n // Add the row starting tag\n htmlData += '<tr>';\n\n // Print selected properties only\n for (var n = 0; n < properties.length; n++) {\n var stringData = data[i];\n\n // Support nested objects\n var property = properties[n].field.split('.');\n if (property.length > 1) {\n for (var p = 0; p < property.length; p++) {\n stringData = stringData[property[p]];\n }\n } else {\n stringData = stringData[properties[n].field];\n }\n\n // Add the row contents and styles\n htmlData += '<td style=\"width:' + properties[n].columnSize + params.gridStyle + '\">' + stringData + '</td>';\n }\n\n // Add the row closing tag\n htmlData += '</tr>';\n }\n\n // Add the table and body closing tags\n htmlData += '</tbody></table>';\n\n return htmlData;\n}\n\n//# sourceURL=webpack://printJS/./src/js/json.js?"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _functions = __webpack_require__(/*! ./functions */ "./src/js/functions.js"); | ||
var _print = __webpack_require__(/*! ./print */ "./src/js/print.js"); | ||
var _print2 = _interopRequireDefault(_print); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = { | ||
print: function print(params, printFrame) { | ||
// Check if we received proper data | ||
if (_typeof(params.printable) !== 'object') { | ||
throw new Error('Invalid javascript data object (JSON).'); | ||
} | ||
// Validate repeatTableHeader | ||
if (typeof params.repeatTableHeader !== 'boolean') { | ||
throw new Error('Invalid value for repeatTableHeader attribute (JSON).'); | ||
} | ||
// Validate properties | ||
if (!params.properties || !Array.isArray(params.properties)) { | ||
throw new Error('Invalid properties array for your JSON data.'); | ||
} | ||
// We will format the property objects to keep the JSON api compatible with older releases | ||
params.properties = params.properties.map(function (property) { | ||
return { | ||
field: (typeof property === 'undefined' ? 'undefined' : _typeof(property)) === 'object' ? property.field : property, | ||
displayName: (typeof property === 'undefined' ? 'undefined' : _typeof(property)) === 'object' ? property.displayName : property, | ||
columnSize: (typeof property === 'undefined' ? 'undefined' : _typeof(property)) === 'object' && property.columnSize ? property.columnSize + ';' : 100 / params.properties.length + '%;' | ||
}; | ||
}); | ||
// Create a print container element | ||
params.printableElement = document.createElement('div'); | ||
// Check if we are adding a print header | ||
if (params.header) { | ||
(0, _functions.addHeader)(params.printableElement, params); | ||
} | ||
// Build the printable html data | ||
params.printableElement.innerHTML += jsonToHTML(params); | ||
// Print the json data | ||
_print2.default.send(params, printFrame); | ||
} | ||
}; | ||
function jsonToHTML(params) { | ||
// Get the row and column data | ||
var data = params.printable; | ||
var properties = params.properties; | ||
// Create a html table | ||
var htmlData = '<table style="border-collapse: collapse; width: 100%;">'; | ||
// Check if the header should be repeated | ||
if (params.repeatTableHeader) { | ||
htmlData += '<thead>'; | ||
} | ||
// Add the table header row | ||
htmlData += '<tr>'; | ||
// Add the table header columns | ||
for (var a = 0; a < properties.length; a++) { | ||
htmlData += '<th style="width:' + properties[a].columnSize + ';' + params.gridHeaderStyle + '">' + (0, _functions.capitalizePrint)(properties[a].displayName) + '</th>'; | ||
} | ||
// Add the closing tag for the table header row | ||
htmlData += '</tr>'; | ||
// If the table header is marked as repeated, add the closing tag | ||
if (params.repeatTableHeader) { | ||
htmlData += '</thead>'; | ||
} | ||
// Create the table body | ||
htmlData += '<tbody>'; | ||
// Add the table data rows | ||
for (var i = 0; i < data.length; i++) { | ||
// Add the row starting tag | ||
htmlData += '<tr>'; | ||
// Print selected properties only | ||
for (var n = 0; n < properties.length; n++) { | ||
var stringData = data[i]; | ||
// Support nested objects | ||
var property = properties[n].field.split('.'); | ||
if (property.length > 1) { | ||
for (var p = 0; p < property.length; p++) { | ||
stringData = stringData[property[p]]; | ||
} | ||
} else { | ||
stringData = stringData[properties[n].field]; | ||
} | ||
// Add the row contents and styles | ||
htmlData += '<td style="width:' + properties[n].columnSize + params.gridStyle + '">' + stringData + '</td>'; | ||
} | ||
// Add the row closing tag | ||
htmlData += '</tr>'; | ||
} | ||
// Add the table and body closing tags | ||
htmlData += '</tbody></table>'; | ||
return htmlData; | ||
} | ||
/***/ }), | ||
@@ -828,56 +198,4 @@ | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nvar Modal = {\n show: function show(params) {\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(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 document.getElementById('printClose').addEventListener('click', function () {\n Modal.close();\n });\n },\n close: function close() {\n var printFrame = document.getElementById('printJS-Modal');\n\n printFrame.parentNode.removeChild(printFrame);\n }\n};\n\nexports.default = Modal;\n\n//# sourceURL=webpack://printJS/./src/js/modal.js?"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var Modal = { | ||
show: function show(params) { | ||
// Build modal | ||
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;'; | ||
// Create wrapper | ||
var printModal = document.createElement('div'); | ||
printModal.setAttribute('style', modalStyle); | ||
printModal.setAttribute('id', 'printJS-Modal'); | ||
// Create content div | ||
var contentDiv = document.createElement('div'); | ||
contentDiv.setAttribute('style', 'display:table-cell; vertical-align:middle; padding-bottom:100px;'); | ||
// Add close button (requires print.css) | ||
var closeButton = document.createElement('div'); | ||
closeButton.setAttribute('class', 'printClose'); | ||
closeButton.setAttribute('id', 'printClose'); | ||
contentDiv.appendChild(closeButton); | ||
// Add spinner (requires print.css) | ||
var spinner = document.createElement('span'); | ||
spinner.setAttribute('class', 'printSpinner'); | ||
contentDiv.appendChild(spinner); | ||
// Add message | ||
var messageNode = document.createTextNode(params.modalMessage); | ||
contentDiv.appendChild(messageNode); | ||
// Add contentDiv to printModal | ||
printModal.appendChild(contentDiv); | ||
// Append print modal element to document body | ||
document.getElementsByTagName('body')[0].appendChild(printModal); | ||
// Add event listener to close button | ||
document.getElementById('printClose').addEventListener('click', function () { | ||
Modal.close(); | ||
}); | ||
}, | ||
close: function close() { | ||
var printFrame = document.getElementById('printJS-Modal'); | ||
printFrame.parentNode.removeChild(printFrame); | ||
} | ||
}; | ||
exports.default = Modal; | ||
/***/ }), | ||
@@ -893,65 +211,4 @@ | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _print = __webpack_require__(/*! ./print */ \"./src/js/print.js\");\n\nvar _print2 = _interopRequireDefault(_print);\n\nvar _functions = __webpack_require__(/*! ./functions */ \"./src/js/functions.js\");\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nexports.default = {\n print: function print(params, printFrame) {\n // Check if we have base64 data\n if (params.base64) {\n var bytesArray = Uint8Array.from(atob(params.printable), function (c) {\n return c.charCodeAt(0);\n });\n createBlobAndPrint(params, printFrame, bytesArray);\n return;\n }\n\n // Format pdf url\n params.printable = /^(blob|http)/i.test(params.printable) ? params.printable : window.location.origin + (params.printable.charAt(0) !== '/' ? '/' + params.printable : params.printable);\n\n // Get the file through a http request (Preload)\n var req = new window.XMLHttpRequest();\n req.responseType = 'arraybuffer';\n\n req.addEventListener('load', function () {\n // Check for errors\n if ([200, 201].indexOf(req.status) === -1) {\n (0, _functions.cleanUp)(params);\n params.onError(req.statusText);\n\n // Since we don't have a pdf document available, we will stop the print job\n return;\n }\n\n // Print requested document\n createBlobAndPrint(params, printFrame, req.response);\n });\n\n req.open('GET', params.printable, true);\n req.send();\n }\n};\n\n\nfunction createBlobAndPrint(params, printFrame, data) {\n // Pass response or base64 data to a blob and create a local object url\n var localPdf = new window.Blob([data], { type: 'application/pdf' });\n localPdf = window.URL.createObjectURL(localPdf);\n\n // Set iframe src with pdf document url\n printFrame.setAttribute('src', localPdf);\n\n _print2.default.send(params, printFrame);\n}\n\n//# sourceURL=webpack://printJS/./src/js/pdf.js?"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _print = __webpack_require__(/*! ./print */ "./src/js/print.js"); | ||
var _print2 = _interopRequireDefault(_print); | ||
var _functions = __webpack_require__(/*! ./functions */ "./src/js/functions.js"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = { | ||
print: function print(params, printFrame) { | ||
// Check if we have base64 data | ||
if (params.base64) { | ||
var bytesArray = Uint8Array.from(atob(params.printable), function (c) { | ||
return c.charCodeAt(0); | ||
}); | ||
createBlobAndPrint(params, printFrame, bytesArray); | ||
return; | ||
} | ||
// Format pdf url | ||
params.printable = /^(blob|http)/i.test(params.printable) ? params.printable : window.location.origin + (params.printable.charAt(0) !== '/' ? '/' + params.printable : params.printable); | ||
// Get the file through a http request (Preload) | ||
var req = new window.XMLHttpRequest(); | ||
req.responseType = 'arraybuffer'; | ||
req.addEventListener('load', function () { | ||
// Check for errors | ||
if ([200, 201].indexOf(req.status) === -1) { | ||
(0, _functions.cleanUp)(params); | ||
params.onError(req.statusText); | ||
// Since we don't have a pdf document available, we will stop the print job | ||
return; | ||
} | ||
// Print requested document | ||
createBlobAndPrint(params, printFrame, req.response); | ||
}); | ||
req.open('GET', params.printable, true); | ||
req.send(); | ||
} | ||
}; | ||
function createBlobAndPrint(params, printFrame, data) { | ||
// Pass response or base64 data to a blob and create a local object url | ||
var localPdf = new window.Blob([data], { type: 'application/pdf' }); | ||
localPdf = window.URL.createObjectURL(localPdf); | ||
// Set iframe src with pdf document url | ||
printFrame.setAttribute('src', localPdf); | ||
_print2.default.send(params, printFrame); | ||
} | ||
/***/ }), | ||
@@ -967,126 +224,4 @@ | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _browser = __webpack_require__(/*! ./browser */ \"./src/js/browser.js\");\n\nvar _browser2 = _interopRequireDefault(_browser);\n\nvar _functions = __webpack_require__(/*! ./functions */ \"./src/js/functions.js\");\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar Print = {\n send: function send(params, printFrame) {\n // Append iframe element to document body\n document.getElementsByTagName('body')[0].appendChild(printFrame);\n\n // Get iframe element\n var iframeElement = document.getElementById(params.frameId);\n\n // Wait for iframe to load all content\n iframeElement.onload = function () {\n if (params.type === 'pdf') {\n performPrint(iframeElement, params);\n return;\n }\n\n // Get iframe element document\n var printDocument = iframeElement.contentWindow || iframeElement.contentDocument;\n if (printDocument.document) printDocument = printDocument.document;\n\n // Append printable element to the iframe body\n printDocument.body.appendChild(params.printableElement);\n\n // Add custom style\n if (params.type !== 'pdf' && params.style) {\n // Create style element\n var style = document.createElement('style');\n style.innerHTML = params.style;\n\n // Append style element to iframe's head\n printDocument.head.appendChild(style);\n }\n\n // If printing images, wait for them to load inside the iframe\n var images = printDocument.getElementsByTagName('img');\n\n if (images.length > 0) {\n loadIframeImages(images).then(function () {\n return performPrint(iframeElement, params);\n });\n } else {\n performPrint(iframeElement, params);\n }\n };\n }\n};\n\nfunction performPrint(iframeElement, params) {\n try {\n iframeElement.focus();\n\n // If Edge or IE, try catch with execCommand\n if (_browser2.default.isEdge() || _browser2.default.isIE()) {\n try {\n iframeElement.contentWindow.document.execCommand('print', false, null);\n } catch (e) {\n iframeElement.contentWindow.print();\n }\n } else {\n // Other browsers\n iframeElement.contentWindow.print();\n }\n } catch (error) {\n params.onError(error);\n } finally {\n (0, _functions.cleanUp)(params);\n }\n}\n\nfunction loadIframeImages(images) {\n var promises = [];\n\n var _iteratorNormalCompletion = true;\n var _didIteratorError = false;\n var _iteratorError = undefined;\n\n try {\n for (var _iterator = images[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var image = _step.value;\n\n promises.push(loadIframeImage(image));\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n\n return Promise.all(promises);\n}\n\nfunction loadIframeImage(image) {\n return new Promise(function (resolve) {\n var pollImage = function pollImage() {\n !image || typeof image.naturalWidth === 'undefined' || image.naturalWidth === 0 || !image.complete ? setTimeout(pollImage, 500) : resolve();\n };\n pollImage();\n });\n}\n\nexports.default = Print;\n\n//# sourceURL=webpack://printJS/./src/js/print.js?"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _browser = __webpack_require__(/*! ./browser */ "./src/js/browser.js"); | ||
var _browser2 = _interopRequireDefault(_browser); | ||
var _functions = __webpack_require__(/*! ./functions */ "./src/js/functions.js"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Print = { | ||
send: function send(params, printFrame) { | ||
// Append iframe element to document body | ||
document.getElementsByTagName('body')[0].appendChild(printFrame); | ||
// Get iframe element | ||
var iframeElement = document.getElementById(params.frameId); | ||
// Wait for iframe to load all content | ||
iframeElement.onload = function () { | ||
if (params.type === 'pdf') { | ||
performPrint(iframeElement, params); | ||
return; | ||
} | ||
// Get iframe element document | ||
var printDocument = iframeElement.contentWindow || iframeElement.contentDocument; | ||
if (printDocument.document) printDocument = printDocument.document; | ||
// Append printable element to the iframe body | ||
printDocument.body.appendChild(params.printableElement); | ||
// Add custom style | ||
if (params.type !== 'pdf' && params.style) { | ||
// Create style element | ||
var style = document.createElement('style'); | ||
style.innerHTML = params.style; | ||
// Append style element to iframe's head | ||
printDocument.head.appendChild(style); | ||
} | ||
// If printing images, wait for them to load inside the iframe | ||
var images = printDocument.getElementsByTagName('img'); | ||
if (images.length > 0) { | ||
loadIframeImages(images).then(function () { | ||
return performPrint(iframeElement, params); | ||
}); | ||
} else { | ||
performPrint(iframeElement, params); | ||
} | ||
}; | ||
} | ||
}; | ||
function performPrint(iframeElement, params) { | ||
try { | ||
iframeElement.focus(); | ||
// If Edge or IE, try catch with execCommand | ||
if (_browser2.default.isEdge() || _browser2.default.isIE()) { | ||
try { | ||
iframeElement.contentWindow.document.execCommand('print', false, null); | ||
} catch (e) { | ||
iframeElement.contentWindow.print(); | ||
} | ||
} else { | ||
// Other browsers | ||
iframeElement.contentWindow.print(); | ||
} | ||
} catch (error) { | ||
params.onError(error); | ||
} finally { | ||
(0, _functions.cleanUp)(params); | ||
} | ||
} | ||
function loadIframeImages(images) { | ||
var promises = []; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = images[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var image = _step.value; | ||
promises.push(loadIframeImage(image)); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
return Promise.all(promises); | ||
} | ||
function loadIframeImage(image) { | ||
return new Promise(function (resolve) { | ||
var pollImage = function pollImage() { | ||
!image || typeof image.naturalWidth === 'undefined' || image.naturalWidth === 0 || !image.complete ? setTimeout(pollImage, 500) : resolve(); | ||
}; | ||
pollImage(); | ||
}); | ||
} | ||
exports.default = Print; | ||
/***/ }), | ||
@@ -1102,28 +237,4 @@ | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _print = __webpack_require__(/*! ./print */ \"./src/js/print.js\");\n\nvar _print2 = _interopRequireDefault(_print);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nexports.default = {\n print: function print(params, printFrame) {\n // Create printable element (container)\n params.printableElement = document.createElement('div');\n params.printableElement.setAttribute('style', 'width:100%');\n\n // Set our raw html as the printable element inner html content\n params.printableElement.innerHTML = params.printable;\n\n // Print html contents\n _print2.default.send(params, printFrame);\n }\n};\n\n//# sourceURL=webpack://printJS/./src/js/raw-html.js?"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _print = __webpack_require__(/*! ./print */ "./src/js/print.js"); | ||
var _print2 = _interopRequireDefault(_print); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = { | ||
print: function print(params, printFrame) { | ||
// Create printable element (container) | ||
params.printableElement = document.createElement('div'); | ||
params.printableElement.setAttribute('style', 'width:100%'); | ||
// Set our raw html as the printable element inner html content | ||
params.printableElement.innerHTML = params.printable; | ||
// Print html contents | ||
_print2.default.send(params, printFrame); | ||
} | ||
}; | ||
/***/ }), | ||
@@ -1138,3 +249,3 @@ | ||
// extracted by mini-css-extract-plugin | ||
eval("// extracted by mini-css-extract-plugin\n\n//# sourceURL=webpack://printJS/./src/sass/index.scss?"); | ||
@@ -1150,9 +261,7 @@ /***/ }), | ||
module.exports = __webpack_require__(/*! ./src/index.js */"./src/index.js"); | ||
eval("module.exports = __webpack_require__(/*! ./src/index.js */\"./src/index.js\");\n\n\n//# sourceURL=webpack://printJS/multi_./src/index.js?"); | ||
/***/ }) | ||
/******/ })["default"]; | ||
}); | ||
//# sourceMappingURL=print.map | ||
}); |
@@ -5,3 +5,3 @@ { | ||
"description": "A tiny javascript library to help printing from the web.", | ||
"version": "1.0.61", | ||
"version": "1.0.62", | ||
"main": "dist/print.js", | ||
@@ -13,25 +13,25 @@ "types": "src/index.d.ts", | ||
"devDependencies": { | ||
"babel-core": "^6.26.3", | ||
"babel-loader": "^7.1.5", | ||
"babel-preset-env": "^1.7.0", | ||
"coveralls": "^3.0.2", | ||
"css-loader": "^2.1.1", | ||
"istanbul-instrumenter-loader": "^3.0.1", | ||
"jasmine-core": "^3.2.1", | ||
"karma": "^4.0.1", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-coverage": "^1.1.2", | ||
"karma-jasmine": "^2.0.1", | ||
"karma-phantomjs-launcher": "^1.0.4", | ||
"karma-sourcemap-loader": "^0.3.7", | ||
"karma-webpack": "^3.0.5", | ||
"mini-css-extract-plugin": "^0.5.0", | ||
"node-sass": "^4.9.3", | ||
"optimize-css-assets-webpack-plugin": "^5.0.0", | ||
"sass-loader": "^7.1.0", | ||
"standard": "^12.0.1", | ||
"uglifyjs-webpack-plugin": "^2.0.1", | ||
"webpack": "^4.29.6", | ||
"webpack-cli": "^3.2.3", | ||
"webpack-dev-server": "^3.2.1" | ||
"@babel/core": "7.4.5", | ||
"@babel/preset-env": "7.4.5", | ||
"babel-loader": "8.0.6", | ||
"coveralls": "3.0.4", | ||
"css-loader": "2.1.1", | ||
"istanbul-instrumenter-loader": "3.0.1", | ||
"jasmine-core": "3.4.0", | ||
"karma": "4.1.0", | ||
"karma-chrome-launcher": "2.2.0", | ||
"karma-coverage": "1.1.2", | ||
"karma-jasmine": "2.0.1", | ||
"karma-phantomjs-launcher": "1.0.4", | ||
"karma-sourcemap-loader": "0.3.7", | ||
"karma-webpack": "3.0.5", | ||
"mini-css-extract-plugin": "0.7.0", | ||
"node-sass": "4.12.0", | ||
"optimize-css-assets-webpack-plugin": "5.0.1", | ||
"sass-loader": "7.1.0", | ||
"standard": "12.0.1", | ||
"uglifyjs-webpack-plugin": "2.1.3", | ||
"webpack": "4.33.0", | ||
"webpack-cli": "3.3.3", | ||
"webpack-dev-server": "3.7.1" | ||
}, | ||
@@ -38,0 +38,0 @@ "scripts": { |
@@ -10,5 +10,4 @@ # Print.js | ||
>For documentation and examples please visit: [printjs.crabbly.com](http://printjs.crabbly.com) | ||
> For documentation and examples please visit: [printjs.crabbly.com](http://printjs.crabbly.com) | ||
## Installation | ||
@@ -30,3 +29,3 @@ | ||
When installing via npm or yarn, import the library into your project: | ||
Import the library into your project: | ||
@@ -41,3 +40,2 @@ ```js | ||
## Contributing to Print.js | ||
@@ -47,7 +45,5 @@ | ||
[![dependencies Status](https://david-dm.org/crabbly/print.js/status.svg)](https://david-dm.org/crabbly/print.js) | ||
[![slack](https://img.shields.io/badge/slack-printjs-orange.svg?logo=slack)](https://publicslack.com/slacks/printjs/invites/new) | ||
Contributions to Print.js are welcome and encouraged. | ||
##### Using issues | ||
@@ -61,3 +57,2 @@ | ||
##### Reporting bugs | ||
@@ -72,3 +67,2 @@ | ||
##### Pull requests | ||
@@ -75,0 +69,0 @@ |
@@ -22,2 +22,6 @@ const Browser = { | ||
navigator.userAgent.toLowerCase().indexOf('safari') !== -1 | ||
}, | ||
// IOS Chrome | ||
isIOSChrome: () => { | ||
return navigator.userAgent.toLowerCase().indexOf('crios') !== -1 | ||
} | ||
@@ -24,0 +28,0 @@ } |
@@ -33,5 +33,6 @@ import { collectStyles, addHeader } from './functions' | ||
// Loop over and process the children elements / nodes (including text nodes) | ||
for (let child of element.childNodes) { | ||
const childNodesArray = Array.prototype.slice.call(element.childNodes) | ||
for (let i = 0; i < childNodesArray.length; i++) { | ||
// Check if we are skiping the current element | ||
if (params.ignoreElements.indexOf(child.id) !== -1) { | ||
if (params.ignoreElements.indexOf(childNodesArray[i].id) !== -1) { | ||
continue | ||
@@ -41,3 +42,3 @@ } | ||
// Clone the child element | ||
const clonedChild = cloneElement(child, params) | ||
const clonedChild = cloneElement(childNodesArray[i], params) | ||
@@ -44,0 +45,0 @@ // Attach the cloned child to the cloned parent node |
@@ -71,8 +71,8 @@ import Browser from './browser' | ||
function loadIframeImages (images) { | ||
const promises = [] | ||
const promises = images.map(image => { | ||
if (image.src && image.src !== window.location.href) { | ||
return loadIframeImage(image) | ||
} | ||
}) | ||
for (let image of images) { | ||
promises.push(loadIframeImage(image)) | ||
} | ||
return Promise.all(promises) | ||
@@ -79,0 +79,0 @@ } |
Sorry, the diff of this file is not supported yet
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
125308
24
1032
98
1