Last active
November 8, 2018 10:32
-
-
Save olegdovger/70772b3c3644fa55f7c78fe41e9413a7 to your computer and use it in GitHub Desktop.
ui-positional-overlay
This file contains hidden or 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.Controller.extend({ | |
appName: 'Ember Twiddle', | |
isShow: false, | |
isShowInput: false, | |
actions: { | |
doAction() { | |
console.log('DO ACTION', this.get('isShow')); | |
return true; | |
}, | |
toggleBtn() { | |
this.toggleProperty('isShow'); | |
}, | |
toggleInputCard() { | |
this.toggleProperty('isShowInput'); | |
} | |
} | |
}); |
This file contains hidden or 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.Component.extend({ | |
classNames: ['fly-card'], | |
classNameBindings: ['isShow::fly-card__hidden'], | |
attributeBindings: ['tabindex', 'autofocus'], | |
position: Em.computed({ | |
get() { | |
return { | |
N: () => {}, | |
S: () => {}, | |
W: () => {}, | |
E: () => {}, | |
}; | |
} | |
}), | |
// 16 positions | |
/** | |
* @description Define behaviour type | |
* "focus" is default behaviour | |
*/ | |
//behaviour: null, // toggle, //toggle-focusout, focus | |
//animation: null, | |
tabindex: -1, | |
autofocus: true, | |
isShow: false, | |
name: null, | |
timeout: 100, | |
'on-change': function(value) {}, | |
showCard() { | |
this.set('isShow', true); | |
this.get('on-change')(true); | |
}, | |
hideCard() { | |
this.set('isShow', false); | |
this.get('on-change')(false); | |
}, | |
didInsertElement() { | |
var cardName = this.get('name'); | |
var selector; | |
if (cardName) { | |
selector = document.querySelector(`[data-card=${cardName}]`); | |
} | |
if (cardName) { | |
var process = () => { | |
selector.addEventListener('focus', _ => { | |
this.showCard(); | |
this.setPosition(selector); | |
if (this.get('hideOn') && this.get('hideOn') === 'focusOutCard') { | |
Ember.run.later(_ => { | |
this.$().focus(); | |
this.$().one('blur', _ => { | |
if (this.get('isShow')) { | |
Ember.run.later(_ => { | |
this.hideCard(); | |
this._blurOnNode(selector); | |
}, this.get('timeout')); | |
} | |
}); | |
Ember.run.debounce(this, '_blurOnNode', selector, this.get('timeout')); | |
}, this.get('timeout')); | |
} | |
}); | |
if (!this.get('hideOn')) { | |
selector.addEventListener('blur', _ => { | |
if (this.get('isShow')) { | |
Ember.run.later(_ => { | |
this.hideCard(); | |
}, this.get('timeout')); | |
} | |
}); | |
} | |
}; | |
if (selector) { | |
process(); | |
} | |
} | |
}, | |
_blurOnNode(selector) { | |
selector.blur(); | |
console.log('_blurOnNode'); | |
}, | |
setPosition(selector) { | |
var rect = selector.getBoundingClientRect(); | |
var element = this.$().get(0); | |
element.style.position = 'absolute'; | |
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; | |
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft; | |
element.style.top = (rect.top + rect.height + scrollTop) + 'px'; | |
element.style.left = (rect.left + scrollLeft) + 'px'; | |
} | |
}); |
This file contains hidden or 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
{ | |
"version": "0.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment