This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/initializers/click-interceptor.js
David Taylor ef37186be3
DEV: Allow click-interceptor in tests and add navigation test (#15499)
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.
2022-01-10 15:45:44 +00:00

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);
},
};