forked from devote/HTML5-History-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.iegte8.min.js
30 lines (30 loc) · 7.54 KB
/
history.iegte8.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
* history API JavaScript Library v3.2.6
*
* Support: IE8+, FF3+, Opera 9+, Safari, Chrome, Firefox and other
*
* Copyright 2011-2013, Dmitrii Pakhtinov ( [email protected] )
*
* http://spb-piksel.ru/
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Update: 26-04-2013
*/
(function(d,t,n,l,Q){function D(a,f,b){var e=2===a?d.onhashchange:d.onpopstate,c=2===a?"hashchange":"popstate",g=p.createEvent?p.createEvent("Events"):p.createEventObject(),a={},k=u[c],i;for(i in g)a[i]="function"===typeof g[i]?function(){}:g[i];a.target=a.currentTarget=a.srcElement=d;a.type=c;a.state=m.state;a.oldURL=f;a.newURL=b;e&&e.call(d,a);f=0;for(b=k.length;f<b;f++)k[f].call(d,a)}function K(a){return E?a?E.setItem("__hitoryapi__",R.stringify(a)):R.parse(E.getItem("__hitoryapi__"))||{}:{}}function L(a,
f,b){var e=a,c,g=n;if(x||y)for(c in f){if(r.call(f,c))if(y)f[c].get&&y.call(a,c,f[c].get),f[c].set&&V.call(a,c,f[c].set);else if(x)try{x(a,c,f[c])}catch(k){if(b)return n;g=t;break}}else g=t;if(g&&v){b="StaticClass"+W+v++;e=["Class "+b];"execVB"in d||execScript("Function execVB(c) ExecuteGlobal(c) End Function","VBScript");"VBCVal"in d||execScript("Function VBCVal(o,r) If IsObject(o) Then Set r=o Else r=o End If End Function","VBScript");for(c in a)e[e.length]="Public ["+c+"]";r.call(a,"toString")&&
(a.propertyIsEnumerable("toString")||(e[e.length]="Public [toString]"),f["(toString)"]={get:function(){return this.toString.call(this)}});for(c in f)if(r.call(f,c)&&(f[c].get&&(a["get "+c]=f[c].get,e.push("Public [get "+c+"]","Public "+("(toString)"===c?"Default ":"")+"Property Get ["+c+"]","Call VBCVal(me.[get "+c+"].call(me),["+c+"])","End Property")),f[c].set))a["set "+c]=f[c].set,e.push("Public [set "+c+"]","Public Property Let ["+c+"](v)","Call me.[set "+c+"].call(me,v)","End Property","Public Property Set ["+
c+"](v)","Call me.[set "+c+"].call(me,v)","End Property");e.push("End Class","Function "+b+"Factory()","Set "+b+"Factory=New "+b,"End Function");d.execVB(e.join("\n"));e=d[b+"Factory"]();for(c in a)e[c]=a[c];r.call(a,"toString")&&(e.toString=a.toString)}return e}var p=d.document,M=p.documentElement,j=d.history||{},b=d.location,k=!!j.pushState,X=k&&j.state===Q,s=b.href,R=d.JSON||{},x=Object.defineProperty,y=Object.prototype.__defineGetter__,V=Object.prototype.__defineSetter__,S=j.pushState,T=j.replaceState,
E=d.sessionStorage,r=Object.prototype.hasOwnProperty,q=+((d.eval&&eval("/*@cc_on 1;@*/")&&/msie (\d+)/i.exec(navigator.userAgent)||[])[1]||0),W=(new Date).getTime(),v=(x||y)&&(!q||8<q)?0:1,w,z,A,B="",C=(w="addEventListener",d[w])||(w="attachEvent",B="on",d[w]),Y=(z="removeEventListener",d[z])||(z="detachEvent",d[z]),Z=(A="dispatchEvent",d[A])||(A="fireEvent",d[A]),F=[],U=[],N=0,u={onpopstate:F,popstate:F,onhashchange:U,hashchange:U},o=function(){var a,b,d,e={basepath:"/",redirect:0,type:"/"};d=p.getElementsByTagName("SCRIPT");
for(a=0;d[a];a++)if(b=/(.*)\/(?:history|spike)(?:\.iegte8)?(?:-\d\.\d(?:\.\d)?\w?)?(?:\.min)?.js\?(.*)$/i.exec(d[a].src)||a===d.length-1&&2===(b=d[a].src.split("?")).length&&(b[2]=b[1])&&b){a=0;for(d=b[2].split("&");d[a];)b=d[a++].split("="),e[b[0]]="true"==b[1]?t:"false"==b[1]?n:b[1]||"";e.basepath=e.basepath||"/";break}return e}(),g=function(a){var d,l,e,c,m,j,i;return function(h,$){var G=RegExp("^"+o.basepath,"i");if(h){if(!k||q)var H=g(),O=H.e,n=H.i,h=/^(?:[\w0-9]+\:)?\/\//.test(h)?0===h.indexOf("/")?
n+h:h:n+"//"+H.h+(0===h.indexOf("/")?h:0===h.indexOf("?")?O+h:0===h.indexOf("#")?O+H.f+h:O.replace(/[^\/]+$/g,"")+h)}else if(h=b.href,!k||$)h=b.protocol+"//"+b.host+o.basepath+(h.replace(/^[^#]*/,"")||"#").replace(RegExp("^#[/]?(?:"+o.type+")?"),"");if(d!==h){a.href=d=h;j=a.port;m=a.host;i=a.pathname;if("http:"===a.protocol&&80==j||"https:"===a.protocol&&443==j)m=a.hostname,j="";i=0===i.indexOf("/")?i:"/"+i;l=i+a.search+a.hash;c=i.replace(G,o.type)+a.search;e=c+a.hash}return{a:a.protocol+"//"+m+l,
i:a.protocol,h:m,j:a.hostname||b.hostname,k:j||b.port,e:i,f:a.search,b:a.hash,c:l,d:c,g:e}}}(p.createElement("a")),m=!v?j:{back:j.back,forward:j.forward,go:j.go,pushState:l,replaceState:l,emulate:!k,toString:function(){return"[object History]"}},I={state:{get:function(){return K()[m.location.href]||l}},length:{get:function(){return j.length}},location:{set:function(a){d.location=a},get:function(){return k?b:P}}},P={assign:function(a){b.assign(k||0!==a.indexOf("#")?a:"#"+g().d+a)},reload:b.reload,
replace:function(a){b.replace(k||0!==a.indexOf("#")?a:"#"+g().d+a)},toString:function(){return this.href}},aa={href:{set:function(a){b.href=a},get:function(){return g().a}},protocol:{set:function(a){b.protocol=a},get:function(){return b.protocol}},host:{set:function(a){b.host=a},get:function(){return b.host}},hostname:{set:function(a){b.hostname=a},get:function(){return b.hostname}},port:{set:function(a){b.port=a},get:function(){return b.port}},pathname:{set:function(a){b.pathname=a},get:function(){return g().e}},
search:{set:function(a){b.search=a},get:function(){return g().f}},hash:{set:function(a){b.hash="#"+g().d+(0===a.indexOf("#")?a:"#"+a)},get:function(){return g().b}}};(!q||7<q)&&function(){function a(){if(s&&!(s=0)&&r.c!==o.basepath)clearInterval(c),setTimeout(D,10)}var f=d.onpopstate||l,q=d.onhashchange||l,e=0,c=l,r=g(),J=r.a;C(B+"hashchange",function(a){var b=g();if(N)return J=b.a,N=0;var d=a.oldURL||J,a=J=a.newURL||b.a,b=d.replace(/^.*?(#|$)/,""),c=a.replace(/^.*?(#|$)/,"");d!=a&&!e&&D();s=e=0;
b!=c&&D(2,d,a)},n);C(B+"popstate",function(){if(s===b.href)return s=0;s=0;D(e=1)},n);m.redirect=function(a,c){o.type=a==l?o.type:a;o.basepath=c=c==l?o.basepath:c;if(d.top==d.self){var G=g(l,t).c,e=b.search,f=b.pathname;k?(G!=c&&RegExp("^"+c+"$","i").test(f)&&(b.href=G),RegExp("^"+c+"$","i").test(f+"/"))?b.href=c:RegExp("^"+c,"i").test(f)||(b.href=f.replace(/^\//,c)+e):f!=c&&(b.href=c+"#"+f.replace(RegExp("^"+c,"i"),o.type)+e+b.hash)}};m=L(m,v?I:j.state===Q?{state:I.state,location:I.location}:{location:I.location});
P=L(P,aa);d[w]=function(h,b,d){u[h]?(u[h].push(b),!k&&F===u[h]&&a()):3<arguments.length?C(h,b,d,arguments[3]):C(h,b,d)};d[z]=function(a,b,d){var c=u[a];if(c)for(a=c.length;--a;){if(c[a]===b){c.splice(a,1);break}}else Y(a,b,d)};d[A]=function(a,b){var c=u[a],e=c===F?d.onpopstate:d.onhashchange;if(c){b=b||("string"==typeof a?d.event:a);try{b&&(b.target=d)}catch(f){try{b.srcElement=d}catch(g){}}e&&e.call(d,b);for(var e=0,k=c.length;e<k;e++)c[e].call(d,b);return t}return Z(a,b)};v&&execScript("Public history, onhashchange",
"VBScript");if((!x&&!y||!L(d,{onhashchange:{get:function(){return q},set:function(a){q=a||l}},onpopstate:{get:function(){return f},set:function(b){(f=b||l)&&!k&&a()}}},1))&&!k)c=setInterval(function(){d.onpopstate&&a()},100);o.redirect&&m.redirect();if(k)C(B+"load",function(){setTimeout(function(){s=0},0)},n);else p[w](B+"click",function(a){var b=a||d.event,c=b.target||b.srcElement,a="defaultPrevented"in b?b.defaultPrevented:b.returnValue===n;if(c&&"A"===c.nodeName&&!a&&(a=g(c.getAttribute("href",
2),t),a.b&&"#"!==a.b&&a.b===a.a.replace(g().a.split("#").shift(),""))){history.location.hash=a.b;a=a.b.replace(/^#/,"");if((c=p.getElementById(a))&&c.id===a&&"A"===c.nodeName)c=c.getBoundingClientRect(),d.scrollTo(M.scrollLeft||0,c.top+(M.scrollTop||0)-(M.clientTop||0));b.preventDefault?b.preventDefault():b.returnValue=!1}},n);var i=m.pushState=function(a,c,d,e){var f=K(),j=g().a,i=d&&g(d),d=i?i.a:j;e&&f[j]&&delete f[j];if((!k||X)&&E&&a)f[d]=a,K(f),a=l;S&&T?e?T.call(m,a,c,d):S.call(m,a,c,d):i&&i.c!=
g().c&&(N=1,e?b.replace("#"+i.g):b.hash=i.g)};m.replaceState=function(a,b,c){i(a,b,c,1)};v?d.history=m:d.history.emulate=!k}()})(window,!0,!1,null);