This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/period-chooser.js.es6
2017-07-27 14:55:41 -04:00

47 lines
1.1 KiB
JavaScript

import CleansUp from 'discourse/mixins/cleans-up';
export default Ember.Component.extend(CleansUp, {
classNames: 'period-chooser',
showPeriods: false,
cleanUp: function() {
this.set('showPeriods', false);
$('html').off('mousedown.top-period');
},
_clickToClose: function() {
const self = this;
$('html').off('mousedown.top-period').on('mousedown.top-period', function(e) {
const $target = $(e.target);
if (($target.prop('id') === 'topic-entrance') || (self.$().has($target).length !== 0)) {
return;
}
self.cleanUp();
});
},
click(e) {
if ($(e.target).closest('.period-popup').length) { return; }
if (!this.get('showPeriods')) {
if (!this.site.mobileView) {
const $chevron = this.$('.d-icon-caret-down');
this.$('#period-popup').css($chevron.position());
} else {
this.$('#period-popup').css({top: this.$().height()});
}
this.set('showPeriods', true);
this._clickToClose();
}
},
actions: {
changePeriod(p) {
this.cleanUp();
this.set('period', p);
this.sendAction('action', p);
}
}
});