Migrate `onToolbarCreate` to the DiscourseAPI
This commit is contained in:
parent
7b8e313dac
commit
f6aa1ac37a
|
@ -176,8 +176,13 @@ class Toolbar {
|
|||
}
|
||||
}
|
||||
|
||||
export function onToolbarCreate(func) {
|
||||
export function addToolbarCallback(func) {
|
||||
_createCallbacks.push(func);
|
||||
}
|
||||
|
||||
export function onToolbarCreate(func) {
|
||||
console.warn('`onToolbarCreate` is deprecated, use the plugin api instead.');
|
||||
addToolbarCallback(func);
|
||||
};
|
||||
|
||||
export default Ember.Component.extend({
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { onToolbarCreate } from 'discourse/components/d-editor';
|
||||
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||
|
||||
export default {
|
||||
name: 'enable-emoji',
|
||||
|
@ -7,13 +7,15 @@ export default {
|
|||
const siteSettings = container.lookup('site-settings:main');
|
||||
|
||||
if (siteSettings.enable_emoji) {
|
||||
onToolbarCreate(toolbar => {
|
||||
toolbar.addButton({
|
||||
id: 'emoji',
|
||||
group: 'extras',
|
||||
icon: 'smile-o',
|
||||
action: 'emoji',
|
||||
title: 'composer.emoji'
|
||||
withPluginApi('0.1', api => {
|
||||
api.onToolbarCreate(toolbar => {
|
||||
toolbar.addButton({
|
||||
id: 'emoji',
|
||||
group: 'extras',
|
||||
icon: 'smile-o',
|
||||
action: 'emoji',
|
||||
title: 'composer.emoji'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import ComposerEditor from 'discourse/components/composer-editor';
|
|||
import { addPosterIcon } from 'discourse/widgets/poster-name';
|
||||
import { addButton } from 'discourse/widgets/post-menu';
|
||||
import { includeAttributes } from 'discourse/lib/transform-post';
|
||||
import { addToolbarCallback } from 'discourse/components/d-editor';
|
||||
|
||||
let _decorateId = 0;
|
||||
function decorate(klass, evt, cb) {
|
||||
|
@ -86,6 +87,10 @@ class PluginApi {
|
|||
addButton(name, callback);
|
||||
}
|
||||
|
||||
onToolbarCreate(callback) {
|
||||
addToolbarCallback(callback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let _pluginv01;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import componentTest from 'helpers/component-test';
|
||||
import { onToolbarCreate } from 'discourse/components/d-editor';
|
||||
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||
|
||||
moduleForComponent('d-editor', {integration: true});
|
||||
|
||||
|
@ -540,12 +540,14 @@ componentTest('emoji', {
|
|||
template: '{{d-editor value=value}}',
|
||||
setup() {
|
||||
// Test adding a custom button
|
||||
onToolbarCreate(toolbar => {
|
||||
toolbar.addButton({
|
||||
id: 'emoji',
|
||||
group: 'extras',
|
||||
icon: 'smile-o',
|
||||
action: 'emoji'
|
||||
withPluginApi('0.1', api => {
|
||||
api.onToolbarCreate(toolbar => {
|
||||
toolbar.addButton({
|
||||
id: 'emoji',
|
||||
group: 'extras',
|
||||
icon: 'smile-o',
|
||||
action: 'emoji'
|
||||
});
|
||||
});
|
||||
});
|
||||
this.set('value', 'hello world.');
|
||||
|
|
Loading…
Reference in New Issue