1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-20 13:49:42 +02:00

Use tether service to determine environment app is running

This commit is contained in:
zinyando 2016-07-19 15:46:44 +02:00
parent 400f0d26ce
commit a74b14ae76

View file

@ -32,6 +32,7 @@ export default Ember.Component.extend({
targetOffset: "10px 0", targetOffset: "10px 0",
constrainToWindow: true, constrainToWindow: true,
constrainToScrollParent: true, constrainToScrollParent: true,
tether: Ember.inject.service(),
hasSecondButton: Ember.computed('button2', 'color2', function () { hasSecondButton: Ember.computed('button2', 'color2', function () {
return is.not.empty(this.get('button2')) && is.not.empty(this.get('color2')); return is.not.empty(this.get('button2')) && is.not.empty(this.get('color2'));
@ -43,9 +44,10 @@ export default Ember.Component.extend({
didInsertElement() { didInsertElement() {
this._super(...arguments); this._super(...arguments);
// TODO: refactor to eliminate self
let self = this; let self = this;
let drop = new Drop({ let drop = this.get('tether').createDrop({
target: document.getElementById(self.get('target')), target: document.getElementById(self.get('target')),
content: self.$(".dropdown-dialog")[0], content: self.$(".dropdown-dialog")[0],
classes: 'drop-theme-basic', classes: 'drop-theme-basic',
@ -65,8 +67,7 @@ export default Ember.Component.extend({
remove: true remove: true
}); });
self.set('drop', drop); if (drop) {
drop.on('open', function () { drop.on('open', function () {
if (is.not.null(self.get("focusOn"))) { if (is.not.null(self.get("focusOn"))) {
document.getElementById(self.get("focusOn")).focus(); document.getElementById(self.get("focusOn")).focus();
@ -80,15 +81,24 @@ export default Ember.Component.extend({
self.attrs.onOpenCallback(drop); self.attrs.onOpenCallback(drop);
} }
}); });
self.set('drop', drop);
}
}, },
willDestroyElement() { willDestroyElement() {
this.get('drop').destroy(); let drop = this.get('drop');
if (drop) {
drop.destroy();
}
}, },
actions: { actions: {
onCancel() { onCancel() {
this.get('drop').close(); let drop = this.get('drop');
if (drop) {
drop.close();
}
}, },
onAction() { onAction() {
@ -98,8 +108,9 @@ export default Ember.Component.extend({
let close = this.attrs.onAction(); let close = this.attrs.onAction();
if (close) { let drop = this.get('drop');
this.get('drop').close(); if (close && drop) {
drop.close();
} }
}, },
@ -110,8 +121,9 @@ export default Ember.Component.extend({
let close = this.attrs.onAction2(); let close = this.attrs.onAction2();
if (close) { let drop = this.get('drop');
this.get('drop').close(); if (close && drop) {
drop.close();
} }
} }
} }