Skip to content

Commit

Permalink
corrected indentation to pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crabbly committed Apr 25, 2017
1 parent 01f9bed commit b5ffff8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 59 deletions.
115 changes: 57 additions & 58 deletions src/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,77 +36,76 @@ let defaultParams = {
}

export default {
init() {
init () {
// Check if a printable document or object was supplied
let args = arguments[0]
if (args === undefined) {
throw new Error('printJS expects at least 1 attribute.')
}
let args = arguments[0]
if (args === undefined) {
throw new Error('printJS expects at least 1 attribute.')
}

let params = extend({}, defaultParams)
let params = extend({}, defaultParams)

switch (typeof args) {
case 'string':
params.printable = encodeURI(args)
params.type = arguments[1] || defaultParams.type
break
switch (typeof args) {
case 'string':
params.printable = encodeURI(args)
params.type = arguments[1] || defaultParams.type
break

case 'object':
params.printable = args.printable
params.type = args.type || defaultParams.type
params.frameId = args.frameId || defaultParams.frameId
params.header = args.header || defaultParams.header
params.maxWidth = args.maxWidth || defaultParams.maxWidth
params.font = args.font || defaultParams.font
params.font_size = args.font_size || defaultParams.font_size
params.honorMarginPadding = (typeof args.honorMarginPadding !== 'undefined') ? args.honorMarginPadding : defaultParams.honorMarginPadding
params.properties = args.properties || defaultParams.properties
params.showModal = (typeof args.showModal !== 'undefined') ? args.showModal : defaultParams.showModal
params.modalMessage = args.modalMessage || defaultParams.modalMessage
break
case 'object':
params.printable = args.printable
params.type = args.type || defaultParams.type
params.frameId = args.frameId || defaultParams.frameId
params.header = args.header || defaultParams.header
params.maxWidth = args.maxWidth || defaultParams.maxWidth
params.font = args.font || defaultParams.font
params.font_size = args.font_size || defaultParams.font_size
params.honorMarginPadding = (typeof args.honorMarginPadding !== 'undefined') ? args.honorMarginPadding : defaultParams.honorMarginPadding
params.properties = args.properties || defaultParams.properties
params.showModal = (typeof args.showModal !== 'undefined') ? args.showModal : defaultParams.showModal
params.modalMessage = args.modalMessage || defaultParams.modalMessage
break

default:
throw new Error('Unexpected argument type! Expected "string" or "object", got ' + typeof args)
}
default:
throw new Error('Unexpected argument type! Expected "string" or "object", got ' + typeof args)
}

if (!params.printable) {
throw new Error('Missing printable information.')
}
if (!params.printable) {
throw new Error('Missing printable information.')
}

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.')
}
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.')
}

// Instantiate print object
let printJS = new PrintJS(params)
let printJS = new PrintJS(params)

// Check printable type
switch (params.type) {
case 'pdf':
switch (params.type) {
case 'pdf':
// Firefox doesn't support iframe pdf printing, we will just open the pdf file instead
if (browser.isFirefox()) {
console.log('PrintJS doesn\'t support PDF printing in Firefox.')
let win = window.open(params.printable, '_blank')
win.focus()
if (browser.isFirefox()) {
console.log('PrintJS doesn\'t support PDF printing in Firefox.')
let win = window.open(params.printable, '_blank')
win.focus()
// Make sure there is no loading modal opened
if (params.showModal) printJS.disablePrintModal()
} else {
printJS.pdf()
}
break
case 'image':
printJS.image()
break
case 'html':
printJS.html()
break
case 'json':
printJS.json()
break
default:
throw new Error('Invalid print type. Available types are: pdf, html, image and json.')
}
if (params.showModal) printJS.disablePrintModal()
} else {
printJS.pdf()
}
break
case 'image':
printJS.image()
break
case 'html':
printJS.html()
break
case 'json':
printJS.json()
break
default:
throw new Error('Invalid print type. Available types are: pdf, html, image and json.')
}
}
}


2 changes: 1 addition & 1 deletion webpack.mix.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const { mix } = require('laravel-mix')

mix.js('src/index.js', 'dist/print.min.js').styles('src/css/print.css', 'dist/print.min.css')
mix.js('src/index.js', 'dist/print.min.js').styles('src/css/print.css', 'dist/print.min.css')

0 comments on commit b5ffff8

Please sign in to comment.