forked from devote/HTML5-History-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistory.min.js
More file actions
33 lines (33 loc) · 9.04 KB
/
history.min.js
File metadata and controls
33 lines (33 loc) · 9.04 KB
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
31
32
33
/*
* History API JavaScript Library v4.0.5
*
* Support: IE6+, FF3+, Opera 9+, Safari, Chrome and other
*
* Copyright 2011-2013, Dmitrii Pakhtinov ( spb.piksel@gmail.com )
*
* 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: 20.08.13 21:16
*/
(function(f){var i=!0,j=null,o=!1;function K(){}function h(a,b,c){if(a&&!b)var b=h(),c=b.e,d=b.h,a=/^(?:[\w0-9]+\:)?\/\//.test(a)?0===a.indexOf("/")?d+a:a:d+"//"+b.g+(0===a.indexOf("/")?a:0===a.indexOf("?")?c+a:0===a.indexOf("#")?c+b.f+a:c.replace(/[^\/]+$/g,"")+a);else if(a=b?a:e.href,!p||c)a=a.replace(/^[^#]*/,"")||"#",a=e.protocol+"//"+e.host+m.basepath+a.replace(RegExp("^#[/]?(?:"+m.type+")?"),"");P.href=a;var a=/(?:([\w0-9]+:))?(?:\/\/(?:[^@]*@)?([^\/:\?#]+)(?::([0-9]+))?)?([^\?#]*)(?:(\?[^#]+)|\?)?(?:(#.*))?/.exec(P.href),b=
a[2]+(a[3]?":"+a[3]:""),c=a[4]||"/",d=a[5]||"",f="#"===a[6]?"":a[6]||"",k=c+d+f,u=c.replace(RegExp("^"+m.basepath,"i"),m.type)+d;return{a:a[1]+"//"+b+k,h:a[1],g:b,i:a[2],k:a[3]||"",e:c,f:d,b:f,c:k,j:u,d:u+f}}function $(){var a="";if(C)a+=C.getItem(F);else{var b=l.cookie.split(F+"=");1<b.length&&(a+=b.pop().split(";").shift()||"null")}try{q=r.parse(a)||{}}catch(c){q={}}v(w+"unload",function(){if(C)C.setItem(F,r.stringify(q));else{var a={};if(a[e.href]=g.state)l.cookie=F+"="+r.stringify(a)}},o)}function x(a,
b,c,d){var c=c||{set:K},e=!c.set,k=!c.get,u={configurable:i,set:function(){e=1},get:function(){k=1}};try{D(a,b,u),a[b]=a[b],D(a,b,c)}catch(ga){}if(!e||!k)if(a.__defineGetter__&&(a.__defineGetter__(b,u.get),a.__defineSetter__(b,u.set),a[b]=a[b],c.get&&a.__defineGetter__(b,c.get),c.set&&a.__defineSetter__(b,c.set)),(!e||!k)&&a===f){try{var aa=a[b];a[b]=j}catch(ha){}if("execScript"in f)f.execScript("Public "+b,"VBScript");else try{D(a,b,{value:K})}catch(h){}a[b]=aa}else if(!e||!k)try{try{var y=G.create(a);
D(G.getPrototypeOf(y)===a?y:a,b,c);for(var g in a)"function"===typeof a[g]&&(y[g]=a[g].bind(a));try{d.call(y,y,a)}catch(l){}a=y}catch(m){D(a.constructor.prototype,b,c)}}catch(n){return o}return a}function ba(a,b,c){c=c||{};a=a===L?e:a;c.set=c.set||function(c){a[b]=c};c.get=c.get||function(){return a[b]};return c}function H(a,b){var c=(""+("string"===typeof a?a:a.type)).replace(/^on/,""),d=z[c];if(d){b="string"===typeof a?b:a;if(b.target==j)for(var e=["target","currentTarget","srcElement","type"];a=
e.pop();)b=x(b,a,{get:"type"===a?function(){return c}:function(){return f}});(("popstate"===c?f.onpopstate:f.onhashchange)||K).call(f,b);for(var e=0,g=d.length;e<g;e++)d[e].call(f,b);return i}return ca(a,b)}function Q(){var a=l.createEvent?l.createEvent("Event"):l.createEventObject();a.initEvent?a.initEvent("popstate",o,o):a.type="popstate";a.state=g.state;H(a)}function s(a,b,c,f){p||(b=h(b),b.c!==h().c&&(A=f,c?e.replace("#"+b.d):e.hash=b.d));!I&&a&&(q[e.href]=a);E=o}function M(a){if(A){R!==e.href&&
Q();var a=a||f.event,b=h(A,i),c=h();a.oldURL||(a.oldURL=b.a,a.newURL=c.a);b.b!==c.b&&H(a)}A=e.href}function S(a){setTimeout(function(){v("popstate",function(a){R=e.href;I||(a=x(a,"state",{get:function(){return g.state}}));H(a)},o)},0);!p&&a!==i&&g.location&&(T(g.location.hash),E&&(E=o,Q()))}function da(a){var a=a||f.event,b=a.target||a.srcElement,c="defaultPrevented"in a?a.defaultPrevented:a.returnValue===o;b&&"A"===b.nodeName&&!c&&(c=h(),b=h(b.getAttribute("href",2)),c.a.split("#").shift()===b.a.split("#").shift()&&
b.b&&(c.b!==b.b&&(g.location.hash=b.b),T(b.b),a.preventDefault?a.preventDefault():a.returnValue=o))}function T(a){var b=l.getElementById(a=(a||"").replace(/^#/,""));b&&b.id===a&&"A"===b.nodeName&&(a=b.getBoundingClientRect(),f.scrollTo(J.scrollLeft||0,a.top+(J.scrollTop||0)-(J.clientTop||0)))}function ea(){function a(a){var b=[],d="VBHistoryClass"+(new Date).getTime()+c++,e=["Class "+d],g;for(g in a)if(a.hasOwnProperty(g)){var h=a[g];h&&(h.get||h.set)?(h.get&&e.push("Public "+("_"===g?"Default ":
"")+"Property Get ["+g+"]","Call VBCVal([(accessors)].["+g+"].get.call(me),["+g+"])","End Property"),h.set&&e.push("Public Property Let ["+g+"](val)",h="Call [(accessors)].["+g+"].set.call(me,val)\nEnd Property","Public Property Set ["+g+"](val)",h)):(b.push(g),e.push("Public ["+g+"]"))}e.push("Private [(accessors)]","Private Sub Class_Initialize()","Set [(accessors)]="+d+"FactoryJS()","End Sub","End Class","Function "+d+"Factory()","Set "+d+"Factory=New "+d,"End Function");f.execScript(e.join("\n"),
"VBScript");f[d+"FactoryJS"]=function(){return a};d=f[d+"Factory"]();for(e=0;e<b.length;e++)d[b[e]]=a[b[e]];return d}function b(a){var b=/[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,c={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};return b.test(a)?'"'+a.replace(b,function(a){return a in c?c[a]:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}var c=f.eval&&
eval("/*@cc_on 1;@*/");if(c&&!(7<+(/msie (\d+)/i.exec(navigator.userAgent)||[,8])[1])){var d=x,B=h().a,k=l.createElement("iframe");k.src="javascript:true;";k=J.firstChild.appendChild(k).contentWindow;f.execScript("Public history\nFunction VBCVal(o,r) If IsObject(o) Then Set r=o Else r=o End If End Function","VBScript");t={_:{get:L.toString}};g={back:n.back,forward:n.forward,go:n.go,emulate:j,_:{get:function(){return"[object History]"}}};r={parse:function(a){try{return(new Function("","return "+a))()}catch(b){return j}},
stringify:function(a){var c=(typeof a).charCodeAt(2);if(114===c)a=b(a);else if(109===c)a=isFinite(a)?""+a:"null";else if(111===c||108===c)a=""+a;else if(106===c)if(a){var d=(c="[object Array]"===G.prototype.toString.call(a))?"[":"{";if(c)for(var f=0;f<a.length;f++)d+=(0==f?"":",")+r.stringify(a[f]);else for(f in a)a.hasOwnProperty(f)&&(d+=(1==d.length?"":",")+b(f)+":"+r.stringify(a[f]));a=d+(c?"]":"}")}else a="null";else a="void 0";return a}};s=function(a,b,c,d,f){var g=k.document,b=h(b);E=o;if(b.c===
h().c&&!f)a&&(q[e.href]=a);else{A=d;if(c)k.lfirst?(history.back(),s(a,b.a,0,d,1)):e.replace("#"+b.d);else if(b.a!=B||f)k.lfirst||(k.lfirst=1,s(a,B,0,d,1)),g.open(),g.write('<script>lfirst=1;parent.location.hash="'+b.d.replace(/"/g,'\\"')+'";<\/script>'),g.close();!f&&a&&(q[e.href]=a)}};x=function(b,c,e,h){d.apply(this,arguments)||(b===t?t[c]=e:b===g?(g[c]=e,"state"===c&&(t=a(t),f.history=g=a(g))):b[c]=e.get&&e.get());return b};setInterval(function(){var a=h().a;if(a!=B){var b=l.createEventObject();
b.oldURL=B;b.newURL=B=a;b.type="hashchange";M(b)}},100);f.JSON=r}}if(f.history){var l=f.document,J=l.documentElement,C=j,G=f.Object,r=f.JSON,e=f.location,n=f.history,g=n,N=n.pushState,U=n.replaceState,p=!!N,I="state"in n,D=G.defineProperty,t=x({},"t")?{}:l.createElement("a"),w="",O=f.addEventListener?"addEventListener":(w="on")&&"attachEvent",V=f.removeEventListener?"removeEventListener":"detachEvent",W=f.dispatchEvent?"dispatchEvent":"fireEvent",v=f[O],X=f[V],ca=f[W],m={basepath:"/",redirect:0,type:"/"},
F="__historyAPI__",P=l.createElement("a"),A=e.href,R="",E=o,q={},z={},fa={onhashchange:j,onpopstate:j},Y=function(a,b){var c=f.history!==n;c&&(f.history=n);a.apply(n,b);c&&(f.history=g)},Z={redirect:function(a,b){m.basepath=b=b==j?m.basepath:b;m.type=a=a==j?m.type:a;if(f.top==f.self){var c=h(j,o,i).c,d=e.pathname+e.search;p?(d=d.replace(/([^\/])$/,"$1/"),c!=b&&RegExp("^"+b+"$","i").test(d)&&e.replace(c)):d!=b&&(d=d.replace(/([^\/])\?/,"$1/?"),RegExp("^"+b,"i").test(d)&&e.replace(b+"#"+d.replace(RegExp("^"+
b,"i"),a)+e.hash))}},pushState:function(a,b,c){N&&Y(N,arguments);s(a,c)},replaceState:function(a,b,c){delete q[e.href];U&&Y(U,arguments);s(a,c,i)},location:{set:function(a){f.location=a},get:function(){return p?e:t}},state:{get:function(){return q[e.href]||j}}},L={assign:function(a){0===(""+a).indexOf("#")?s(j,a):e.assign(a)},reload:function(){e.reload()},replace:function(a){0===(""+a).indexOf("#")?s(j,a,i):e.replace(a)},toString:function(){return this.href},href:{get:function(){return h().a}},protocol:j,
host:j,hostname:j,port:j,pathname:{get:function(){return h().e}},search:{get:function(){return h().f}},hash:{set:function(a){s(j,(""+a).replace(/^(#|)/,"#"),o,A)},get:function(){return h().b}}};(function(){var a=l.getElementsByTagName("script"),a=(a[a.length-1]||{}).src||"";(-1!==a.indexOf("?")?a.split("?").pop():"").replace(/(\w+)(?:=([^&]*))?/g,function(a,b,c){m[b]=(c||("basepath"===b?"/":"")).replace(/^(0|false)$/,"")});try{C=f.sessionStorage}catch(b){}ea();v(w+"hashchange",M,o);var c=[L,t,fa,
f,Z,g];I&&delete Z.state;for(var d=0;d<c.length;d+=2)for(var e in c[d])if(c[d].hasOwnProperty(e))if("function"===typeof c[d][e])c[d+1][e]=c[d][e];else{a=ba(c[d],e,c[d][e]);if(!x(c[d+1],e,a,function(a,b){if(b===g)f.history=g=c[d+1]=a}))return X(w+"hashchange",M,o),o;c[d+1]===f&&(z[e]=z[e.substr(2)]=[])}m.redirect&&g.redirect();!I&&r&&$();if(!p)l[O](w+"click",da,o);"complete"===l.readyState?S(i):(!p&&h().c!==m.basepath&&(E=i),v(w+"load",S,o));return i})()&&(g.emulate=!p,f[O]=function(a,b,c){a in z?
z[a].push(b):3<arguments.length?v(a,b,c,arguments[3]):v(a,b,c)},f[V]=function(a,b,c){var d=z[a];if(d)for(a=d.length;--a;){if(d[a]===b){d.splice(a,1);break}}else X(a,b,c)},f[W]=H)}})(window);