Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "DEV: Switch theme to use new `addComposerToolbarPopupMenuOpti… #62

Merged
merged 1 commit into from Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .discourse-compatibility
@@ -1,4 +1,3 @@
< 3.2.0.beta2-dev: 566d79fa39eacfa299a7e60afe5b8d75020f7f7c
3.1.999: 323bd485b08889360edcae826d6272fd8e77d180
2.7.13: 5b2f5a455e1adf8ce5e8c1cfb7fbc3c388d3d82a
2.6.0.beta3: 68d40fe9f5b625cf465adc31b502a54e16d02cc6
34 changes: 21 additions & 13 deletions javascripts/discourse/initializers/disco-toc-composer.js
Expand Up @@ -5,7 +5,7 @@ export default {
name: "disco-toc-composer",

initialize() {
withPluginApi("1.14.0", (api) => {
withPluginApi("1.0.0", (api) => {
const currentUser = api.getCurrentUser();
if (!currentUser) {
return;
Expand All @@ -19,20 +19,28 @@ export default {
}
I18n.translations[I18n.currentLocale()].js.composer.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.modifyClass("controller:composer", {
pluginId: "DiscoTOC",

actions: {
insertDtoc() {
this.get("toolbarEvent").applySurround(
`<div data-theme-toc="true">`,
`</div>`,
"contains_dtoc"
);
},
},
});

api.addToolbarPopupMenuOptionsCallback((controller) => {
return {
action: "insertDtoc",
icon: "align-left",
label: themePrefix("insert_table_of_contents"),
condition: controller.get("model.topicFirstPost"),
};
});
}
});
},
Expand Down
17 changes: 3 additions & 14 deletions test/acceptance/toc-composer-test.js
@@ -1,4 +1,3 @@
import I18n from "I18n";
import {
acceptance,
exists,
Expand All @@ -20,10 +19,7 @@ acceptance("DiscoTOC - Composer", function (needs) {
await click("#create-topic");
const toolbarPopupMenu = selectKit(".toolbar-popup-menu-options");
await toolbarPopupMenu.expand();

await toolbarPopupMenu.selectRowByName(
I18n.t(themePrefix("insert_table_of_contents"))
);
await toolbarPopupMenu.selectRowByValue("insertDtoc");

assert.ok(query(".d-editor-input").value.includes('data-theme-toc="true"'));
});
Expand All @@ -37,10 +33,7 @@ acceptance("DiscoTOC - Composer", function (needs) {

const toolbarPopupMenu = selectKit(".toolbar-popup-menu-options");
await toolbarPopupMenu.expand();

await toolbarPopupMenu.selectRowByName(
I18n.t(themePrefix("insert_table_of_contents"))
);
await toolbarPopupMenu.selectRowByValue("insertDtoc");

assert.ok(query(".d-editor-input").value.includes('data-theme-toc="true"'));
});
Expand All @@ -51,10 +44,6 @@ acceptance("DiscoTOC - Composer", function (needs) {
const toolbarPopupMenu = selectKit(".toolbar-popup-menu-options");
await toolbarPopupMenu.expand();

assert.notOk(
toolbarPopupMenu
.rowByName(I18n.t(themePrefix("insert_table_of_contents")))
.exists()
);
assert.notOk(toolbarPopupMenu.rowByValue("insertDtoc").exists());
});
});