Skip to content

Instantly share code, notes, and snippets.

@max
Last active August 29, 2015 14:21
Show Gist options
  • Save max/769547803d129159ae20 to your computer and use it in GitHub Desktop.
Save max/769547803d129159ae20 to your computer and use it in GitHub Desktop.
Ember.js Pop-over
<div class="MyExample">
{{#pop-over contentComponentClass='someComponent'}}
{{x-icon name='someIcon' size=24}} Open Pop-over
{{/pop-over}}
</div>
<a href="#" class="PopOver-trigger" {{action 'toggleContentVisibility' bubbles=false}}>{{yield}}</a>
<div {{bind-attr class=":PopOver-content contentVisible:is-visible"}}>
{{component contentComponentClass}}
</div>
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['PopOver'],
contentVisible: false,
didInsertElement: function didInsertElement() {
this.set('hidePopoverFn', e => {
if (!this.$('.PopOver-content').get(0).contains(e.target)) {
this.set('contentVisible', false);
}
});
Ember.$(document).on('click', this.get('hidePopoverFn'));
},
willDestroyElement: function willDestroyElement() {
Ember.$(document).off('click', this.get('hidePopoverFn'));
},
actions: {
toggleContentVisibility: function toggleContentVisibility() {
this.toggleProperty('contentVisible');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment