mirror of
https://github.com/discourse/DiscoTOC.git
synced 2026-09-16 23:42:13 -04:00
DEV: Switch theme to use new addComposerToolbarPopupMenuOption api (#61)
Why this change? The new API is better and allows us to avoid modifying the composer service.
This commit is contained in:
@@ -5,7 +5,7 @@ export default {
|
||||
name: "disco-toc-composer",
|
||||
|
||||
initialize() {
|
||||
withPluginApi("1.0.0", (api) => {
|
||||
withPluginApi("1.14.0", (api) => {
|
||||
const currentUser = api.getCurrentUser();
|
||||
if (!currentUser) {
|
||||
return;
|
||||
@@ -19,27 +19,19 @@ export default {
|
||||
}
|
||||
I18n.translations[I18n.currentLocale()].js.composer.contains_dtoc = " ";
|
||||
|
||||
api.modifyClass("controller:composer", {
|
||||
pluginId: "DiscoTOC",
|
||||
|
||||
actions: {
|
||||
insertDtoc() {
|
||||
this.get("toolbarEvent").applySurround(
|
||||
`<div data-theme-toc="true">`,
|
||||
`</div>`,
|
||||
"contains_dtoc"
|
||||
);
|
||||
},
|
||||
api.addComposerToolbarPopupMenuOption({
|
||||
action: (toolbarEvent) => {
|
||||
toolbarEvent.applySurround(
|
||||
`<div data-theme-toc="true">`,
|
||||
`</div>`,
|
||||
"contains_dtoc"
|
||||
);
|
||||
},
|
||||
icon: "align-left",
|
||||
label: themePrefix("insert_table_of_contents"),
|
||||
condition: (composer) => {
|
||||
return composer.model.topicFirstPost;
|
||||
},
|
||||
});
|
||||
|
||||
api.addToolbarPopupMenuOptionsCallback((controller) => {
|
||||
return {
|
||||
action: "insertDtoc",
|
||||
icon: "align-left",
|
||||
label: themePrefix("insert_table_of_contents"),
|
||||
condition: controller.get("model.topicFirstPost"),
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user