diff --git a/app/assets/javascripts/discourse/components/popup-menu.js.es6 b/app/assets/javascripts/discourse/components/popup-menu.js.es6 new file mode 100644 index 00000000000..1f5de232ae6 --- /dev/null +++ b/app/assets/javascripts/discourse/components/popup-menu.js.es6 @@ -0,0 +1,45 @@ +import { on } from 'ember-addons/ember-computed-decorators'; + +export default Ember.Component.extend({ + classNameBindings: ["visible::hidden", ":popup-menu"], + + @on('didInsertElement') + _setup() { + this.appEvents.on("popup-menu:open", this, "_changeLocation"); + + $('html').on(`mouseup.popup-menu-${this.get('elementId')}`, (e) => { + const $target = $(e.target); + if ($target.is("button") || this.$().has($target).length === 0) { + this.sendAction('hide'); + } + }); + }, + + @on('willDestroyElement') + _cleanup() { + $('html').off(`mouseup.popup-menu-${this.get('elementId')}`); + this.appEvents.off("popup-menu:open"); + }, + + _changeLocation(location) { + const $this = this.$(); + switch (location.position) { + case "absolute": { + $this.css({ + position: "absolute", + top: location.top - $this.innerHeight() + 5, + left: location.left, + }); + break; + } + case "fixed": { + $this.css({ + position: "fixed", + top: location.top, + left: location.left - $this.innerWidth(), + }); + break; + } + } + } +}); diff --git a/app/assets/javascripts/discourse/components/post-menu.js.es6 b/app/assets/javascripts/discourse/components/post-menu.js.es6 index 33800387f2c..9981c5330bc 100644 --- a/app/assets/javascripts/discourse/components/post-menu.js.es6 +++ b/app/assets/javascripts/discourse/components/post-menu.js.es6 @@ -369,13 +369,13 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, { unhidePostIcon = iconHTML('eye'), unhidePostText = I18n.t('post.controls.unhide'); - const html = '