Migrate `onToolbarCreate` to the DiscourseAPI

This commit is contained in:
Robin Ward 2016-02-18 12:42:15 -05:00
parent 7b8e313dac
commit f6aa1ac37a
4 changed files with 30 additions and 16 deletions

View File

@ -176,8 +176,13 @@ class Toolbar {
} }
} }
export function onToolbarCreate(func) { export function addToolbarCallback(func) {
_createCallbacks.push(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({ export default Ember.Component.extend({

View File

@ -1,4 +1,4 @@
import { onToolbarCreate } from 'discourse/components/d-editor'; import { withPluginApi } from 'discourse/lib/plugin-api';
export default { export default {
name: 'enable-emoji', name: 'enable-emoji',
@ -7,7 +7,8 @@ export default {
const siteSettings = container.lookup('site-settings:main'); const siteSettings = container.lookup('site-settings:main');
if (siteSettings.enable_emoji) { if (siteSettings.enable_emoji) {
onToolbarCreate(toolbar => { withPluginApi('0.1', api => {
api.onToolbarCreate(toolbar => {
toolbar.addButton({ toolbar.addButton({
id: 'emoji', id: 'emoji',
group: 'extras', group: 'extras',
@ -16,6 +17,7 @@ export default {
title: 'composer.emoji' title: 'composer.emoji'
}); });
}); });
});
// enable plugin emojis // enable plugin emojis
Discourse.Emoji.applyCustomEmojis(); Discourse.Emoji.applyCustomEmojis();

View File

@ -3,6 +3,7 @@ import ComposerEditor from 'discourse/components/composer-editor';
import { addPosterIcon } from 'discourse/widgets/poster-name'; import { addPosterIcon } from 'discourse/widgets/poster-name';
import { addButton } from 'discourse/widgets/post-menu'; import { addButton } from 'discourse/widgets/post-menu';
import { includeAttributes } from 'discourse/lib/transform-post'; import { includeAttributes } from 'discourse/lib/transform-post';
import { addToolbarCallback } from 'discourse/components/d-editor';
let _decorateId = 0; let _decorateId = 0;
function decorate(klass, evt, cb) { function decorate(klass, evt, cb) {
@ -86,6 +87,10 @@ class PluginApi {
addButton(name, callback); addButton(name, callback);
} }
onToolbarCreate(callback) {
addToolbarCallback(callback);
}
} }
let _pluginv01; let _pluginv01;

View File

@ -1,5 +1,5 @@
import componentTest from 'helpers/component-test'; 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}); moduleForComponent('d-editor', {integration: true});
@ -540,7 +540,8 @@ componentTest('emoji', {
template: '{{d-editor value=value}}', template: '{{d-editor value=value}}',
setup() { setup() {
// Test adding a custom button // Test adding a custom button
onToolbarCreate(toolbar => { withPluginApi('0.1', api => {
api.onToolbarCreate(toolbar => {
toolbar.addButton({ toolbar.addButton({
id: 'emoji', id: 'emoji',
group: 'extras', group: 'extras',
@ -548,6 +549,7 @@ componentTest('emoji', {
action: 'emoji' action: 'emoji'
}); });
}); });
});
this.set('value', 'hello world.'); this.set('value', 'hello world.');
}, },
test(assert) { test(assert) {