The app's wrapper element ID is different in tests. `app.rootElement` allows us to consistently obtain the selector in the initializer, so it works correctly regardless of the app's configuration.
21 lines
580 B
JavaScript
21 lines
580 B
JavaScript
import DiscourseURL from "discourse/lib/url";
|
|
import interceptClick from "discourse/lib/intercept-click";
|
|
|
|
export default {
|
|
name: "click-interceptor",
|
|
initialize(container, app) {
|
|
this.selector = app.rootElement;
|
|
$(this.selector).on("click.discourse", "a", interceptClick);
|
|
window.addEventListener("hashchange", this.hashChanged);
|
|
},
|
|
|
|
hashChanged() {
|
|
DiscourseURL.routeTo(document.location.hash);
|
|
},
|
|
|
|
teardown() {
|
|
$(this.selector).off("click.discourse", "a", interceptClick);
|
|
window.removeEventListener("hashchange", this.hashChanged);
|
|
},
|
|
};
|