-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtml5-history-anchor.html
4 lines (4 loc) · 1.3 KB
/
html5-history-anchor.html
1
2
3
4
<!-- Copyright (C) 2014 Erik Ringsmuth - MIT license -->
<script type="text/javascript">
!function(){function t(t){if(!t.ctrlKey&&!t.metaKey&&2!==t.which){if(this.hasAttribute("pushstate")&&(window.history.pushState(JSON.parse(this.getAttribute("state")),this.getAttribute("title"),this.getAttribute("href")),t.preventDefault()),this.hasAttribute("replacestate")&&(window.history.replaceState(JSON.parse(this.getAttribute("state")),this.getAttribute("title"),this.getAttribute("href")),t.preventDefault()),this.hasAttribute("popstate")){try{var e=new PopStateEvent("popstate",{bubbles:!1,cancelable:!1,state:window.history.state});"dispatchEvent_"in window?window.dispatchEvent_(e):window.dispatchEvent(e)}catch(i){var a=document.createEvent("CustomEvent");a.initCustomEvent("popstate",!1,!1,{state:window.history.state}),window.dispatchEvent(a)}t.preventDefault()}if(this.hasAttribute("go")){var r=this.getAttribute("go");r=r?parseInt(r):0,window.history.go(r),t.preventDefault()}this.hasAttribute("back")&&(window.history.back(),t.preventDefault()),this.hasAttribute("forward")&&(window.history.forward(),t.preventDefault())}}var e=Object.create(HTMLAnchorElement.prototype);e.createdCallback=function(){this.addEventListener("click",t,!1)},document.registerElement("html5-history-anchor",{prototype:e,"extends":"a"})}();
</script>