UNPKG

@xysfe/memento-core

Version:

record and replay the web

40 lines (38 loc) 1.28 kB
var CHANGE_STATE_EVENT = '__changestate__'; var XFix = (function () { function XFix() { this.handlerHistory(); } XFix.getInstance = function () { this.instance = this.instance || new XFix(); return this.instance; }; XFix.prototype.handlerHistory = function () { var createEvent = function () { if (window.Event) { return new window.Event(CHANGE_STATE_EVENT); } if (document) { var e = document.createEvent('HTMLEvents'); e.initEvent(CHANGE_STATE_EVENT, !1, !0); return e; } return null; }; var handler = function (key) { var origin = window.history[key]; return function () { var result = origin.apply(this, arguments); var event = createEvent(); if (event) { window.dispatchEvent(event); } return result; }; }; window.history.pushState = handler('pushState'); window.history.replaceState = handler('replaceState'); }; return XFix; }()); export { CHANGE_STATE_EVENT, XFix as default };