mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
Add support for app events in plugin api, plus an event for custom html
This commit is contained in:
@ -2,6 +2,8 @@ import { getCustomHTML } from 'discourse/helpers/custom-html';
|
|||||||
import { getOwner } from 'discourse-common/lib/get-owner';
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
|
triggerAppEvent: null,
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this._super();
|
this._super();
|
||||||
const name = this.get('name');
|
const name = this.get('name');
|
||||||
@ -16,5 +18,19 @@ export default Ember.Component.extend({
|
|||||||
this.set('layoutName', name);
|
this.set('layoutName', name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
didInsertElement() {
|
||||||
|
this._super();
|
||||||
|
if (this.get('triggerAppEvent') === 'true') {
|
||||||
|
this.appEvents.trigger(`inserted-custom-html:${this.get('name')}`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
willDestroyElement() {
|
||||||
|
this._super();
|
||||||
|
if (this.get('triggerAppEvent') === 'true') {
|
||||||
|
this.appEvents.trigger(`destroyed-custom-html:${this.get('name')}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -24,7 +24,7 @@ import { replaceFormatter } from 'discourse/lib/utilities';
|
|||||||
import { modifySelectKit } from "select-kit/mixins/plugin-api";
|
import { modifySelectKit } from "select-kit/mixins/plugin-api";
|
||||||
|
|
||||||
// If you add any methods to the API ensure you bump up this number
|
// If you add any methods to the API ensure you bump up this number
|
||||||
const PLUGIN_API_VERSION = '0.8.13';
|
const PLUGIN_API_VERSION = '0.8.14';
|
||||||
|
|
||||||
class PluginApi {
|
class PluginApi {
|
||||||
constructor(version, container) {
|
constructor(version, container) {
|
||||||
@ -350,10 +350,24 @@ class PluginApi {
|
|||||||
```
|
```
|
||||||
**/
|
**/
|
||||||
onPageChange(fn) {
|
onPageChange(fn) {
|
||||||
let appEvents = this.container.lookup('app-events:main');
|
this.onAppEvent('page:changed', data => fn(data.url, data.title));
|
||||||
appEvents.on('page:changed', data => fn(data.url, data.title));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Listen for a triggered `AppEvent` from Discourse.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
api.onAppEvent('inserted-custom-html', () => {
|
||||||
|
console.log('a custom footer was rendered');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
**/
|
||||||
|
onAppEvent(name, fn) {
|
||||||
|
let appEvents = this.container.lookup('app-events:main');
|
||||||
|
appEvents.on(name, fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes a setting associated with a widget. For example, if
|
* Changes a setting associated with a widget. For example, if
|
||||||
* you wanted small avatars in the post stream:
|
* you wanted small avatars in the post stream:
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
{{plugin-outlet name="above-footer" args=(hash showFooter=showFooter)}}
|
{{plugin-outlet name="above-footer" args=(hash showFooter=showFooter)}}
|
||||||
{{#if showFooter}}
|
{{#if showFooter}}
|
||||||
{{custom-html name="footer"}}
|
{{custom-html name="footer" triggerAppEvent="true"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{plugin-outlet name="below-footer" args=(hash showFooter=showFooter)}}
|
{{plugin-outlet name="below-footer" args=(hash showFooter=showFooter)}}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user