|
|
@@ -28,29 +28,10 @@
|
|
|
const FETCH_REQUEST_EVENT = "single-file-request-fetch";
|
|
|
const FETCH_RESPONSE_EVENT = "single-file-response-fetch";
|
|
|
|
|
|
- const history = window.history;
|
|
|
const dispatchEvent = window.dispatchEvent;
|
|
|
const CustomEvent = window.CustomEvent;
|
|
|
const fetch = window.fetch;
|
|
|
const addEventListener = window.addEventListener;
|
|
|
- const pushState = history.pushState;
|
|
|
- const console = window.console;
|
|
|
- const warn = (console && console.warn) || (() => { });
|
|
|
-
|
|
|
- let warningDisplayed;
|
|
|
- history.pushState = function (state, title, url) {
|
|
|
- if (!warningDisplayed) {
|
|
|
- warningDisplayed = true;
|
|
|
- warn.call(console, "SingleFile is hooking the history.pushState API to detect navigation."); // eslint-disable-line no-console
|
|
|
- }
|
|
|
- try {
|
|
|
- dispatchEvent.call(window, new CustomEvent("single-file-push-state", { detail: { state, title, url } }));
|
|
|
- } catch (error) {
|
|
|
- // ignored
|
|
|
- }
|
|
|
- pushState.call(history, state, title, url);
|
|
|
- };
|
|
|
- history.pushState.toString = function () { return "function pushState() { [native code] }"; };
|
|
|
|
|
|
addEventListener.call(window, FETCH_REQUEST_EVENT, async event => {
|
|
|
const url = event.detail;
|