Skip to content

Commit

Permalink
add option to ignore html elements
Browse files Browse the repository at this point in the history
  • Loading branch information
crabbly committed Mar 25, 2018
1 parent 135cefa commit 3f8af9d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "print-js",
"homepage": "http://printjs.crabbly.com",
"description": "A tiny javascript library to help printing from the web.",
"version": "1.0.34",
"version": "1.0.35",
"main": "dist/print.js",
"repository": "https://github.com/crabbly/Print.js",
"license": "MIT",
Expand Down
6 changes: 6 additions & 0 deletions src/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export function loopNodesCollectStyles (elements, params) {
for (let n = 0; n < elements.length; n++) {
let currentElement = elements[n]

// Check if we are skiping this element
if (params.ignoreElements.indexOf(currentElement.getAttribute('id')) !== -1) {
currentElement.parentNode.removeChild(currentElement)
continue
}

// Form Printing - check if is element Input
let tag = currentElement.tagName
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') {
Expand Down
4 changes: 3 additions & 1 deletion src/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export default {
htmlData: '',
documentTitle: 'Document',
targetStyle: null,
targetStyles: null
targetStyles: null,
ignoreElements: []
}

// Check if a printable document or object was supplied
Expand Down Expand Up @@ -70,6 +71,7 @@ export default {
params.documentTitle = typeof args.documentTitle !== 'undefined' ? args.documentTitle : params.documentTitle
params.targetStyle = typeof args.targetStyle !== 'undefined' ? args.targetStyle : params.targetStyle
params.targetStyles = typeof args.targetStyles !== 'undefined' ? args.targetStyles : params.targetStyles
params.ignoreElements = typeof args.ignoreElements !== 'undefined' ? args.ignoreElements : params.ignoreElements
break
default:
throw new Error('Unexpected argument type! Expected "string" or "object", got ' + typeof args)
Expand Down

0 comments on commit 3f8af9d

Please sign in to comment.