discourse/plugins/discourse-narrative-bot/assets/javascripts/initializers/new-user-narrative.js.es6

40 lines
1.1 KiB
Plaintext
Raw Normal View History

2018-06-16 00:42:20 +08:00
import { withPluginApi } from "discourse/lib/plugin-api";
function initialize(api) {
2018-06-16 00:42:20 +08:00
const messageBus = api.container.lookup("message-bus:main");
const currentUser = api.getCurrentUser();
2018-06-16 00:42:20 +08:00
const appEvents = api.container.lookup("app-events:main");
2018-06-16 00:42:20 +08:00
api.modifyClass("component:site-header", {
didInsertElement() {
this._super(...arguments);
2018-06-16 00:42:20 +08:00
this.dispatch("header:search-context-trigger", "header");
}
});
2018-06-16 00:42:20 +08:00
api.attachWidgetAction("header", "headerSearchContextTrigger", function() {
if (this.site.mobileView) {
this.state.skipSearchContext = false;
} else {
this.state.contextEnabled = true;
2018-06-16 00:42:20 +08:00
this.state.searchContextType = "topic";
}
});
if (messageBus && currentUser) {
messageBus.subscribe(`/new_user_narrative/tutorial_search`, () => {
2018-06-16 00:42:20 +08:00
appEvents.trigger("header:search-context-trigger");
});
}
}
export default {
name: "new-user-narratve",
initialize(container) {
2018-06-16 00:42:20 +08:00
const siteSettings = container.lookup("site-settings:main");
if (siteSettings.discourse_narrative_bot_enabled)
withPluginApi("0.8.7", initialize);
}
};