Comparing version 1.2.0 to 1.3.0
@@ -197,3 +197,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var styles = win.getComputedStyle(element, ''); | ||
Object.keys(styles).map(function (key) { | ||
for (var key = 0; key < styles.length; key++) { | ||
// Check if style should be processed | ||
@@ -203,4 +204,5 @@ if (params.targetStyles.indexOf('*') !== -1 || params.targetStyle.indexOf(styles[key]) !== -1 || targetStylesMatch(params.targetStyles, styles[key])) { | ||
} | ||
}); // Print friendly defaults (deprecated) | ||
} // Print friendly defaults (deprecated) | ||
elementStyle += 'max-width: ' + params.maxWidth + 'px !important;' + params.font_size + ' !important;'; | ||
@@ -356,4 +358,6 @@ return elementStyle; | ||
/* harmony import */ var _print__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./print */ "./src/js/print.js"); | ||
/* harmony import */ var _browser__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./browser */ "./src/js/browser.js"); | ||
/* harmony default export */ __webpack_exports__["default"] = ({ | ||
@@ -375,4 +379,11 @@ print: function print(params, printFrame) { | ||
img.src = src; // Create the image wrapper | ||
img.src = src; // The following block is for Firefox, which for some reason requires the image's src to be fully qualified in | ||
// order to print it | ||
if (_browser__WEBPACK_IMPORTED_MODULE_2__["default"].isFirefox()) { | ||
var fullyQualifiedSrc = img.src; | ||
img.src = fullyQualifiedSrc; | ||
} // Create the image wrapper | ||
var imageWrapper = document.createElement('div'); // Append image to the wrapper element | ||
@@ -505,6 +516,15 @@ | ||
var printFrame = document.createElement('iframe'); // Hide iframe | ||
var printFrame = document.createElement('iframe'); | ||
printFrame.setAttribute('style', 'visibility: hidden; height: 0; width: 0; position: absolute;'); // Set iframe element id | ||
if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isFirefox()) { | ||
// Set the iframe to be is visible on the page (guaranteed by fixed position) but hidden using opacity 0, because | ||
// this works in Firefox. The height needs to be sufficient for some part of the document other than the PDF | ||
// viewer's toolbar to be visible in the page | ||
printFrame.setAttribute('style', 'width: 1px; height: 100px; position: fixed; left: 0; top: 0; opacity: 0; border-width: 0; margin: 0; padding: 0'); | ||
} else { | ||
// Hide the iframe in other browsers | ||
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) | ||
@@ -531,5 +551,5 @@ | ||
// Check browser support for pdf and if not supported we will just open the pdf file instead | ||
if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isFirefox() || _browser__WEBPACK_IMPORTED_MODULE_0__["default"].isIE()) { | ||
if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isIE()) { | ||
try { | ||
console.info('PrintJS currently doesn\'t support PDF printing in Firefox and Internet Explorer.'); | ||
console.info('PrintJS currently doesn\'t support PDF printing in Internet Explorer.'); | ||
@@ -771,2 +791,6 @@ if (params.onBrowserIncompatible() === true) { | ||
req.responseType = 'arraybuffer'; | ||
req.addEventListener('error', function () { | ||
Object(_functions__WEBPACK_IMPORTED_MODULE_1__["cleanUp"])(params); | ||
params.onError(req.statusText); // Since we don't have a pdf document available, we will stop the print job | ||
}); | ||
req.addEventListener('load', function () { | ||
@@ -824,3 +848,11 @@ // Check for errors | ||
if (params.type === 'pdf') { | ||
performPrint(iframeElement, params); | ||
// Add a delay for Firefox. In my tests, 1000ms was sufficient but 100ms was not | ||
if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isFirefox()) { | ||
setTimeout(function () { | ||
return performPrint(iframeElement, params); | ||
}, 1000); | ||
} else { | ||
performPrint(iframeElement, params); | ||
} | ||
return; | ||
@@ -874,2 +906,8 @@ } // Get iframe element document | ||
} finally { | ||
if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isFirefox()) { | ||
// Move the iframe element off-screen and make it invisible | ||
iframeElement.style.visibility = 'hidden'; | ||
iframeElement.style.left = '-1px'; | ||
} | ||
Object(_functions__WEBPACK_IMPORTED_MODULE_1__["cleanUp"])(params); | ||
@@ -876,0 +914,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"description": "A tiny javascript library to help printing from the web.", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"main": "dist/print.js", | ||
@@ -43,3 +43,4 @@ "types": "src/index.d.ts", | ||
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", | ||
"start": "webpack-dev-server --public http://localhost:8080/test/manual --open" | ||
"start": "webpack-dev-server --public http://localhost:8080/test/manual --open", | ||
"standard:fix": "standard --fix" | ||
}, | ||
@@ -46,0 +47,0 @@ "author": "Rodrigo Vieira <rodrigo@crabbly.com>", |
@@ -22,3 +22,3 @@ import Modal from './modal' | ||
Object.keys(styles).map(key => { | ||
for (let key = 0; key < styles.length; key++) { | ||
// Check if style should be processed | ||
@@ -28,3 +28,3 @@ if (params.targetStyles.indexOf('*') !== -1 || params.targetStyle.indexOf(styles[key]) !== -1 || targetStylesMatch(params.targetStyles, styles[key])) { | ||
} | ||
}) | ||
} | ||
@@ -31,0 +31,0 @@ // Print friendly defaults (deprecated) |
import { addHeader } from './functions' | ||
import Print from './print' | ||
import Browser from './browser' | ||
@@ -24,2 +25,9 @@ export default { | ||
// The following block is for Firefox, which for some reason requires the image's src to be fully qualified in | ||
// order to print it | ||
if (Browser.isFirefox()) { | ||
const fullyQualifiedSrc = img.src | ||
img.src = fullyQualifiedSrc | ||
} | ||
// Create the image wrapper | ||
@@ -26,0 +34,0 @@ const imageWrapper = document.createElement('div') |
@@ -99,4 +99,11 @@ 'use strict' | ||
// Hide iframe | ||
printFrame.setAttribute('style', 'visibility: hidden; height: 0; width: 0; position: absolute;') | ||
if (Browser.isFirefox()) { | ||
// Set the iframe to be is visible on the page (guaranteed by fixed position) but hidden using opacity 0, because | ||
// this works in Firefox. The height needs to be sufficient for some part of the document other than the PDF | ||
// viewer's toolbar to be visible in the page | ||
printFrame.setAttribute('style', 'width: 1px; height: 100px; position: fixed; left: 0; top: 0; opacity: 0; border-width: 0; margin: 0; padding: 0') | ||
} else { | ||
// Hide the iframe in other browsers | ||
printFrame.setAttribute('style', 'visibility: hidden; height: 0; width: 0; position: absolute;') | ||
} | ||
@@ -128,5 +135,5 @@ // Set iframe element id | ||
// Check browser support for pdf and if not supported we will just open the pdf file instead | ||
if (Browser.isFirefox() || Browser.isIE()) { | ||
if (Browser.isIE()) { | ||
try { | ||
console.info('PrintJS currently doesn\'t support PDF printing in Firefox and Internet Explorer.') | ||
console.info('PrintJS currently doesn\'t support PDF printing in Internet Explorer.') | ||
if (params.onBrowserIncompatible() === true) { | ||
@@ -133,0 +140,0 @@ const win = window.open(params.fallbackPrintable, '_blank') |
@@ -22,2 +22,9 @@ import Print from './print' | ||
req.addEventListener('error', () => { | ||
cleanUp(params) | ||
params.onError(req.statusText) | ||
// Since we don't have a pdf document available, we will stop the print job | ||
}) | ||
req.addEventListener('load', () => { | ||
@@ -24,0 +31,0 @@ // Check for errors |
@@ -15,3 +15,8 @@ import Browser from './browser' | ||
if (params.type === 'pdf') { | ||
performPrint(iframeElement, params) | ||
// Add a delay for Firefox. In my tests, 1000ms was sufficient but 100ms was not | ||
if (Browser.isFirefox()) { | ||
setTimeout(() => performPrint(iframeElement, params), 1000) | ||
} else { | ||
performPrint(iframeElement, params) | ||
} | ||
return | ||
@@ -67,2 +72,8 @@ } | ||
} finally { | ||
if (Browser.isFirefox()) { | ||
// Move the iframe element off-screen and make it invisible | ||
iframeElement.style.visibility = 'hidden' | ||
iframeElement.style.left = '-1px' | ||
} | ||
cleanUp(params) | ||
@@ -69,0 +80,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
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
126219
1523