forked from devote/HTML5-History-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.iegte8.min.js
30 lines (30 loc) · 7.48 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.5
*
* 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: 14-02-2013
*/
(function(d,s,j,k,Q){function C(a,f,b){var e=2===a?d.onhashchange:d.onpopstate,c=2===a?"hashchange":"popstate",i=t[c];o.createEvent?(a=o.createEvent("Events"),a.initEvent(c,j,j)):(a=o.createEventObject(),a.type=c);a.state=l.state;a.oldURL=f;a.newURL=b;e&&e.call(d,a);f=0;for(b=i.length;f<b;f++)i[f].call(d,a)}function J(a){return D?a?D.setItem("__hitoryapi__",E.stringify(a)):E.parse(D.getItem("__hitoryapi__"))||{}:{}}function K(a,f,b){var e=a,c,i=j;if(w||x)for(c in f){if(p.call(f,c))if(x)f[c].get&&
x.call(a,c,f[c].get),f[c].set&&U.call(a,c,f[c].set);else if(w)try{w(a,c,f[c])}catch(m){if(b)return j;i=s;break}}else i=s;if(i&&u){b="StaticClass"+V+u++;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+"]";p.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(p.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");execVB(e.join("\n"));e=d[b+"Factory"]();for(c in a)e[c]=a[c];p.call(a,"toString")&&(e.toString=a.toString)}return e}var o=d.document,M=o.documentElement,g=d.history||{},b=d.location,m=!!g.pushState,W=m&&g.state===Q,r=b.href,E=d.JSON||{},w=Object.defineProperty,x=Object.prototype.__defineGetter__,U=Object.prototype.__defineSetter__,R=g.pushState,S=g.replaceState,D=d.sessionStorage,p=Object.prototype.hasOwnProperty,
q=+((d.eval&&eval("/*@cc_on 1;@*/")&&/msie (\d+)/i.exec(navigator.userAgent)||[])[1]||0),V=(new Date).getTime(),u=(w||x)&&(!q||8<q)?0:1,v,y,z,A="",B=(v="addEventListener",d[v])||(v="attachEvent",A="on",d[v]),X=(y="removeEventListener",d[y])||(y="detachEvent",d[y]),Y=(z="dispatchEvent",d[z])||(z="fireEvent",d[z]),F=[],T=[],N=0,t={onpopstate:F,popstate:F,onhashchange:T,hashchange:T},n=function(){var a,b,d,e={basepath:"/",redirect:0,type:"/"};d=o.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]?s:"false"==b[1]?j:b[1]||"";e.basepath=e.basepath||"/";break}return e}(),i=function(a){var d,k,e,c,l,j,g;return function(h,Z){var G=RegExp("^"+n.basepath,"i");if(h){if(!m||q)var H=i(),O=H.e,o=H.i,h=/^(?:[\w0-9]+\:)?\/\//.test(h)?0===h.indexOf("/")?o+h:h:o+"//"+
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,!m||Z)h=b.protocol+"//"+b.host+n.basepath+(h.replace(/^[^#]*/,"")||"#").replace(RegExp("^#[/]?(?:"+n.type+")?"),"");if(d!==h){a.href=d=h;j=a.port;l=a.host;g=a.pathname;if("http:"===a.protocol&&80==j||"https:"===a.protocol&&443==j)l=a.hostname,j="";g=0===g.indexOf("/")?g:"/"+g;k=g+a.search+a.hash;c=g.replace(G,n.type)+a.search;e=c+a.hash}return{a:a.protocol+"//"+l+k,i:a.protocol,
h:l,j:a.hostname||b.hostname,k:j||b.port,e:g,f:a.search,b:a.hash,c:k,d:c,g:e}}}(o.createElement("a")),l=!u?g:{back:g.back,forward:g.forward,go:g.go,pushState:k,replaceState:k,emulate:!m,toString:function(){return"[object History]"}},I={state:{get:function(){return J()[l.location.href]||k}},length:{get:function(){return g.length}},location:{set:function(a){d.location=a},get:function(){return m?b:P}}},P={assign:function(a){b.assign(m||0!==a.indexOf("#")?a:"#"+i().d+a)},reload:b.reload,replace:function(a){b.replace(m||
0!==a.indexOf("#")?a:"#"+i().d+a)},toString:function(){return this.href}},$={href:{set:function(a){b.href=a},get:function(){return i().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 i().e}},search:{set:function(a){b.search=
a},get:function(){return i().f}},hash:{set:function(a){b.hash="#"+i().d+(0===a.indexOf("#")?a:"#"+a)},get:function(){return i().b}}};(!q||7<q)&&function(){function a(){if(r&&!(r=0)&&p.c!==n.basepath)clearInterval(c),setTimeout(C,10)}var f=d.onpopstate||k,q=d.onhashchange||k,e=0,c=k,p=i(),L=p.a;p.b.replace(/^#/,"");B(A+"hashchange",function(a){var b=i();if(N)return L=b.a,N=0;var d=a.oldURL||L,a=L=a.newURL||b.a,b=d.replace(/^.*?(#|$)/,""),c=a.replace(/^.*?(#|$)/,"");d!=a&&!e&&C();r=e=0;b!=c&&C(2,d,
a)},j);B(A+"popstate",function(){if(r===b.href)return r=0;r=0;C(e=1)},j);l.redirect=function(a,c){n.type=a==k?n.type:a;n.basepath=c==k?n.basepath:c;if(d.top==d.self){var G=i(k,s).c,e=b.search,f=b.pathname,c=n.basepath;m?(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"),n.type)+e+b.hash)}};l=K(l,u?I:g.state===Q?{state:I.state,location:I.location}:{location:I.location});
P=K(P,$);d[v]=function(h,b,c){t[h]?(t[h].push(b),!m&&F===t[h]&&a()):3<arguments.length?B(h,b,c,arguments[3]):B(h,b,c)};d[y]=function(a,b,c){var d=t[a];if(d)for(a=d.length;--a;){if(d[a]===b){d.splice(a,1);break}}else X(a,b,c)};d[z]=function(a,b){var c=t[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(i){}}e&&e.call(d,b);for(var e=0,g=c.length;e<g;e++)c[e].call(d,b);return s}return Y(a,b)};u&&execScript("Public history, onhashchange",
"VBScript");if((!w&&!x||!K(d,{onhashchange:{get:function(){return q},set:function(a){q=a||k}},onpopstate:{get:function(){return f},set:function(b){(f=b||k)&&!m&&a()}}},1))&&!m)c=setInterval(function(){d.onpopstate&&a()},100);n.redirect&&l.redirect();if(m)B(A+"load",function(){setTimeout(function(){r=0},0)},j);else o[v](A+"click",function(a){var b=a||d.event,c=b.target||b.srcElement,a="defaultPrevented"in b?b.defaultPrevented:b.returnValue===j;if(c&&"A"===c.nodeName&&!a&&(a=i(c.getAttribute("href",
2),s),a.b&&"#"!==a.b&&a.b===a.a.replace(i().a.split("#").shift(),""))){history.location.hash=a.b;a=a.b.replace(/^#/,"");if((c=o.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}},j);var E=l.pushState=function(a,c,d,e){var f=J(),g=i().a,j=d&&i(d),d=j?j.a:g;e&&f[g]&&delete f[g];if((!m||W)&&D&&a)f[d]=a,J(f),a=k;R&&S?e?S.call(l,a,c,d):R.call(l,a,c,d):j&&j.c!=
i().c&&(N=1,e?b.replace("#"+j.g):b.hash=j.g)};l.replaceState=function(a,b,c){E(a,b,c,1)};u?d.history=l:d.history.emulate=!m}()})(window,!0,!1,null);