diff --git a/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6 b/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6 index d9aad34dcc..aeb9db8baa 100644 --- a/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6 @@ -1,6 +1,7 @@ import computed from 'ember-addons/ember-computed-decorators'; +import DelegatedActions from 'discourse/mixins/delegated-actions'; -export default Ember.Component.extend({ +export default Ember.Component.extend(DelegatedActions, { elementId: 'topic-footer-buttons', // Allow us to extend it @@ -8,15 +9,7 @@ export default Ember.Component.extend({ init() { this._super(); - - this._actions = this._actions || {}; - - (this.get('topicDelegated') || []).forEach(m => { - this._actions[m] = function() { - this.sendAction(m); - }; - this.set(m, m); - }); + this.delegateAll(this.get('topicDelegated')); }, @computed('topic.details.can_invite_to') diff --git a/app/assets/javascripts/discourse/mixins/delegated-actions.js.es6 b/app/assets/javascripts/discourse/mixins/delegated-actions.js.es6 new file mode 100644 index 0000000000..8940c1d49b --- /dev/null +++ b/app/assets/javascripts/discourse/mixins/delegated-actions.js.es6 @@ -0,0 +1,16 @@ + +export const TARGET_NAME = (Ember.VERSION[0] === "2") ? 'actions' : '_actions'; + +export default Ember.Mixin.create({ + + delegateAll(actionNames) { + actionNames = actionNames || []; + + this[TARGET_NAME] = this[TARGET_NAME] || {}; + + actionNames.forEach(m => { + this[TARGET_NAME][m] = function() { this.sendAction(m); }; + this.set(m, m); + }); + } +}); diff --git a/app/assets/javascripts/discourse/widgets/widget.js.es6 b/app/assets/javascripts/discourse/widgets/widget.js.es6 index bef20bf04e..851ad09bd9 100644 --- a/app/assets/javascripts/discourse/widgets/widget.js.es6 +++ b/app/assets/javascripts/discourse/widgets/widget.js.es6 @@ -1,6 +1,11 @@ -import { WidgetClickHook, WidgetClickOutsideHook, WidgetKeyUpHook, WidgetKeyDownHook, WidgetDragHook } from 'discourse/widgets/hooks'; +import { WidgetClickHook, + WidgetClickOutsideHook, + WidgetKeyUpHook, + WidgetKeyDownHook, + WidgetDragHook } from 'discourse/widgets/hooks'; import { h } from 'virtual-dom'; import DecoratorHelper from 'discourse/widgets/decorator-helper'; +import { TARGET_NAME } from 'discourse/mixins/delegated-actions'; function emptyContent() { } @@ -266,7 +271,7 @@ export default class Widget { if (target) { // TODO: Use ember closure actions - const actions = target._actions || target.actionHooks || {}; + const actions = target[TARGET_NAME] || target.actionHooks || {}; const method = actions[actionName]; if (method) { promise = method.call(target, param); diff --git a/app/assets/javascripts/main_include.js b/app/assets/javascripts/main_include.js index 96b3abcd9d..c18248dffb 100644 --- a/app/assets/javascripts/main_include.js +++ b/app/assets/javascripts/main_include.js @@ -25,6 +25,7 @@ //= require ./discourse/lib/formatter //= require ./discourse/lib/eyeline //= require ./discourse/mixins/scrolling +//= require ./discourse/mixins/scrolling //= require ./discourse/models/model //= require ./discourse/models/rest //= require ./discourse/models/badge-grouping