-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
287 additions
and
328 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import print from './js/init' | ||
|
||
const printJS = print.init | ||
const printjs = print.init | ||
|
||
if (typeof window !== 'undefined') { | ||
window.printJS = printJS | ||
window.printjs = printjs | ||
} | ||
|
||
export default printJS | ||
export default printjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,24 @@ | ||
export default { | ||
const Browser = { | ||
// Firefox 1.0+ | ||
isFirefox: function () { | ||
isFirefox: () => { | ||
return typeof InstallTrigger !== 'undefined' | ||
}, | ||
|
||
// Internet Explorer 6-11 | ||
isIE: function () { | ||
isIE: () => { | ||
return !!document.documentMode | ||
}, | ||
|
||
// Edge 20+ | ||
isEdge: function () { | ||
return !this.isIE() && !!window.StyleMedia | ||
isEdge: () => { | ||
return !Browser.isIE() && !!window.StyleMedia | ||
}, | ||
|
||
// Chrome 1+ | ||
isChrome: function () { | ||
isChrome: () => { | ||
return !!window.chrome && !!window.chrome.webstore | ||
}, | ||
|
||
// Opera 8.0+ | ||
// let isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0 | ||
|
||
// At least Safari 3+: "[object HTMLElementConstructor]" | ||
isSafari: function () { | ||
isSafari: () => { | ||
return Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 | ||
} | ||
} | ||
|
||
export default Browser |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,51 @@ | ||
import { collectStyles, loopNodesCollectStyles, addWrapper, addHeader } from './functions' | ||
import Print from './print' | ||
|
||
export default function (PrintJS) { | ||
PrintJS.prototype.html = function () { | ||
// get HTML printable element | ||
let printElement = document.getElementById(this.params.printable) | ||
export default { | ||
print: (params, printFrame) => { | ||
// Get HTML printable element | ||
let printElement = document.getElementById(params.printable) | ||
|
||
// check if element exists | ||
// Check if element exists | ||
if (!printElement) { | ||
window.console.error('Invalid HTML element id: ' + this.params.printable) | ||
window.console.error('Invalid HTML element id: ' + params.printable) | ||
|
||
return false | ||
} | ||
|
||
// make a copy of the printElement to prevent DOM changes | ||
// Make a copy of the printElement to prevent DOM changes | ||
let printableElement = document.createElement('div') | ||
printableElement.appendChild(printElement.cloneNode(true)) | ||
|
||
// add cloned element to DOM, to have DOM element methods available. It will also be easier to colect styles | ||
// Add cloned element to DOM, to have DOM element methods available. It will also be easier to colect styles | ||
printableElement.setAttribute('style', 'display:none;') | ||
printableElement.setAttribute('id', 'printJS-html') | ||
printElement.parentNode.appendChild(printableElement) | ||
|
||
// update printableElement variable with newly created DOM element | ||
// Update printableElement variable with newly created DOM element | ||
printableElement = document.getElementById('printJS-html') | ||
|
||
// get main element styling | ||
printableElement.setAttribute('style', collectStyles(printableElement, this.params) + 'margin:0 !important;') | ||
// Get main element styling | ||
printableElement.setAttribute('style', collectStyles(printableElement, params) + 'margin:0 !important;') | ||
|
||
// get all children elements | ||
// Get all children elements | ||
let elements = printableElement.children | ||
|
||
// get styles for all children elements | ||
loopNodesCollectStyles(elements, this.params) | ||
// Get styles for all children elements | ||
loopNodesCollectStyles(elements, params) | ||
|
||
// add header if any | ||
if (this.params.header) { | ||
addHeader(printableElement, this.params.header) | ||
// Add header if any | ||
if (params.header) { | ||
addHeader(printableElement, params.header) | ||
} | ||
|
||
// remove DOM printableElement | ||
// Remove DOM printableElement | ||
printableElement.parentNode.removeChild(printableElement) | ||
|
||
// store html data | ||
this.params.htmlData = addWrapper(printableElement.innerHTML, this.params) | ||
// Store html data | ||
params.htmlData = addWrapper(printableElement.innerHTML, params) | ||
|
||
// print html element contents | ||
this.print() | ||
// Print html element contents | ||
Print.send(params, printFrame) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,46 @@ | ||
import { addHeader } from './functions' | ||
import browser from './browser' | ||
import Browser from './browser' | ||
import Print from './print' | ||
|
||
export default function (PrintJS) { | ||
PrintJS.prototype.image = function () { | ||
// create the image element | ||
export default { | ||
print: (params, printFrame) => { | ||
// Create the image element | ||
let img = document.createElement('img') | ||
|
||
// Set image src with image file url | ||
img.src = params.printable | ||
|
||
img.setAttribute('style', 'width:100%;') | ||
img.setAttribute('id', 'printableImage') | ||
|
||
// set image src with image file url | ||
img.src = this.params.printable | ||
|
||
// create wrapper | ||
// Create wrapper | ||
let printableElement = document.createElement('div') | ||
printableElement.setAttribute('style', 'width:100%') | ||
|
||
// to prevent firefox from not loading images within iframe, we can use base64-encoded data URL of images pixel data | ||
if (browser.isFirefox()) { | ||
// let's make firefox happy | ||
// To prevent firefox from not loading images within iframe, we can use base64-encoded data URL of images pixel data | ||
if (Browser.isFirefox()) { | ||
// Let's make firefox happy | ||
let canvas = document.createElement('canvas') | ||
canvas.setAttribute('width', img.width) | ||
canvas.setAttribute('height', img.height) | ||
let context = canvas.getContext('2d') | ||
context.drawImage(img, 0, 0) | ||
|
||
// reset img src attribute with canvas dataURL | ||
// Reset img src attribute with canvas dataURL | ||
img.setAttribute('src', canvas.toDataURL('JPEG', 1.0)) | ||
} | ||
|
||
printableElement.appendChild(img) | ||
|
||
// add header if any | ||
if (this.params.header) { | ||
// Check if we are adding a header for the image | ||
if (params.header) { | ||
addHeader(printableElement) | ||
} | ||
|
||
// store html data | ||
this.params.htmlData = printableElement.outerHTML | ||
// Store html data | ||
params.htmlData = printableElement.outerHTML | ||
|
||
// print image | ||
this.print() | ||
// Print image | ||
Print.send(params, printFrame) | ||
} | ||
} |
Oops, something went wrong.