Last active
May 4, 2018 08:53
-
-
Save wiseoldman/e24f018c2406ed754c65658acfdb46a3 to your computer and use it in GitHub Desktop.
[PrintButton] Small snippet for creating a print button
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
class PrintButton { | |
constructor(PRINT_CLASS = '.print') { | |
this.PRINT_CLASS = PRINT_CLASS; | |
this.PRINT_TARGETS = document.querySelectorAll(this.PRINT_CLASS); | |
if (this.PRINT_TARGETS.length) { | |
this.addPrintListener(); | |
} | |
} | |
addPrintListener() { | |
for (let i = 0; i < this.PRINT_TARGETS.length; i++) { | |
const TARGET = this.PRINT_TARGETS[i]; | |
TARGET.addEventListener('click', (e) => { | |
e.preventDefault(); | |
window.print(); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment