Created
November 12, 2018 16:01
-
-
Save frcake/88fe5bc042f696f2c48f83751d708850 to your computer and use it in GitHub Desktop.
printit
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
import Ember from 'ember'; | |
import layout from '../templates/components/print-this'; | |
export default Ember.Component.extend({ | |
layout, | |
printService: Ember.inject.service(''), | |
defaultPrintClass: 'content__printThis', | |
classNameBindings: ['defaultPrintClass'], | |
printSelector: null, | |
autoPrint: false, | |
options: null, | |
model:null, | |
deliveryReportDateAttribute:'', | |
deliveryReportValue:null, | |
actions: { | |
doPrint() { | |
this._print(); | |
} | |
}, | |
didInsertElement() { | |
if(this.get('autoPrint')) { | |
this._print(); | |
} | |
}, | |
_print() { | |
const printSelector = this.get('printSelector') || ''; | |
this.get('printService').print(printSelector, this.get('options') || {}, this.$.bind(this)); | |
}, | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Service.extend({ | |
print(printSelector, options, jQuery = Ember.$) { | |
const environment = Ember.getOwner(this).resolveRegistration('config:environment'); | |
const mergedOptions = this._constructPrintOptions(environment, options); | |
this._selectElement(printSelector, jQuery).printThis(mergedOptions); | |
}, | |
_constructPrintOptions(environment = { rootURL: '/' }, userOptions = {}) { | |
const base = environment.rootURL || environment.baseURL; | |
const options = base === '/' ? { } : { base }; | |
return Ember.merge(options, userOptions) | |
}, | |
_selectElement: function(toSelect, jQuery) { | |
return jQuery(toSelect); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment