Repository navigation
Expand file tree
/
Copy pathhistory.min.js
More file actions
34 lines (34 loc) · 9.43 KB
/
Copy pathhistory.min.js
File metadata and controls
34 lines (34 loc) · 9.43 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
34
/*
* history API JavaScript Library v3.2.5
*
* Support: IE6+, FF3+, Opera 9+, Safari, Chrome, Firefox 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: 14-02-2013
*/
(function(d,w,o,k,V){function C(a,b,i,e){var c=Q(),d=l().a,h=i&&l(i),i=h?h.a:d;e&&c[d]&&delete c[d];if((!n||$)&&I&&a)c[i]=a,Q(c),a=k;W&&X?e?X.call(p,a,b,i):W.call(p,a,b,i):h&&h.d!=l().d&&(R=1,e?f.replace("#"+h.e):f.hash=h.e)}function J(a,b,i){var e=2===a?d.onhashchange:d.onpopstate,c=2===a?"hashchange":"popstate",g=x[c];r.createEvent?(a=r.createEvent("Events"),a.initEvent(c,o,o)):(a=r.createEventObject(),a.type=c);a.state=p.state;a.oldURL=b;a.newURL=i;e&&e.call(d,a);b=0;for(i=g.length;b<i;b++)g[b].call(d,
a)}function Q(a){return I?a?I.setItem("__hitoryapi__",K(a)):S(I.getItem("__hitoryapi__"))||{}:{}}function T(a,b,i){var e=a,c,g=o;if(D||E)for(c in b){if(F.call(b,c))if(E)b[c].get&&E.call(a,c,b[c].get),b[c].set&&aa.call(a,c,b[c].set);else if(D)try{D(a,c,b[c])}catch(h){if(i)return o;g=w;break}}else g=w;if(g&&y){i="StaticClass"+ba+y++;e=["Class "+i];"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+"]";F.call(a,"toString")&&(a.propertyIsEnumerable("toString")||(e[e.length]="Public [toString]"),b["(toString)"]={get:function(){return this.toString.call(this)}});for(c in b)if(F.call(b,c)&&(b[c].get&&(a["get "+c]=b[c].get,e.push("Public [get "+c+"]","Public "+("(toString)"===c?"Default ":"")+"Property Get ["+c+"]","Call VBCVal(me.[get "+c+"].call(me),["+c+"])","End Property")),b[c].set))a["set "+c]=b[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 "+i+"Factory()","Set "+i+"Factory=New "+i,"End Function");execVB(e.join("\n"));e=d[i+"Factory"]();for(c in a)e[c]=a[c];F.call(a,"toString")&&(e.toString=a.toString)}return e}var r=d.document,L=r.documentElement,s=d.history||{},f=d.location,n=!!s.pushState,$=n&&s.state===V,u=f.href,v=d.JSON||{},D=Object.defineProperty,E=Object.prototype.__defineGetter__,
aa=Object.prototype.__defineSetter__,W=s.pushState,X=s.replaceState,I=d.sessionStorage,F=Object.prototype.hasOwnProperty,ca=Object.prototype.toString,M=+((d.eval&&eval("/*@cc_on 1;@*/")&&/msie (\d+)/i.exec(navigator.userAgent)||[])[1]||0),ba=(new Date).getTime(),y=(D||E)&&(!M||8<M)?0:1,j=8>M?r.createElement("iframe"):o,z,G,H,A="",B=(z="addEventListener",d[z])||(z="attachEvent",A="on",d[z]),da=(G="removeEventListener",d[G])||(G="detachEvent",d[G]),ea=(H="dispatchEvent",d[H])||(H="fireEvent",d[H]),
N=[],Y=[],R=0,x={onpopstate:N,popstate:N,onhashchange:Y,hashchange:Y},q=function(){var a,b,d,e={basepath:"/",redirect:0,type:"/"};d=r.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]?w:"false"==b[1]?o:b[1]||"";e.basepath=e.basepath||"/";break}return e}(),l=
function(a){var b,d,e,c,g,h,t;return function(m,fa){var ga=RegExp("^"+q.basepath,"i");if(m){if(!n||M)var O=l(),j=O.f,k=O.i,m=/^(?:[\w0-9]+\:)?\/\//.test(m)?0===m.indexOf("/")?k+m:m:k+"//"+O.h+(0===m.indexOf("/")?m:0===m.indexOf("?")?j+m:0===m.indexOf("#")?j+O.g+m:j.replace(/[^\/]+$/g,"")+m)}else if(m=f.href,!n||fa)m=f.protocol+"//"+f.host+q.basepath+(m.replace(/^[^#]*/,"")||"#").replace(RegExp("^#[/]?(?:"+q.type+")?"),"");if(b!==m){a.href=b=m;h=a.port;g=a.host;t=a.pathname;if("http:"===a.protocol&&
80==h||"https:"===a.protocol&&443==h)g=a.hostname,h="";t=0===t.indexOf("/")?t:"/"+t;d=t+a.search+a.hash;c=t.replace(ga,q.type)+a.search;e=c+a.hash}return{a:a.protocol+"//"+g+d,i:a.protocol,h:g,j:a.hostname||f.hostname,k:h||f.port,f:t,g:a.search,b:a.hash,d:d,c:c,e:e}}}(r.createElement("a")),p=!y?s:{back:s.back,forward:s.forward,go:s.go,pushState:k,replaceState:k,emulate:!n,toString:function(){return"[object History]"}},P={state:{get:function(){return j&&j.storage||Q()[p.location.href]||k}},length:{get:function(){return s.length}},
location:{set:function(a){d.location=a},get:function(){return n?f:U}}},U={assign:function(a){f.assign(n||0!==a.indexOf("#")?a:"#"+l().c+a)},reload:f.reload,replace:function(a){f.replace(n||0!==a.indexOf("#")?a:"#"+l().c+a)},toString:function(){return this.href}},ha={href:{set:function(a){f.href=a},get:function(){return l().a}},protocol:{set:function(a){f.protocol=a},get:function(){return f.protocol}},host:{set:function(a){f.host=a},get:function(){return f.host}},hostname:{set:function(a){f.hostname=
a},get:function(){return f.hostname}},port:{set:function(a){f.port=a},get:function(){return f.port}},pathname:{set:function(a){f.pathname=a},get:function(){return l().f}},search:{set:function(a){f.search=a},get:function(){return l().g}},hash:{set:function(a){var a=0===a.indexOf("#")?a:"#"+a,b=l();j?a!=b.b&&(p.pushState(k,k,b.c+a),Z({oldURL:b.a})):f.hash="#"+b.c+a},get:function(){return l().b}}},K=v.stringify||function(a){function b(e){var c,g,h;c=(typeof e).charCodeAt(2);if(114===c)e=d(e);else if(109===
c)e=isFinite(e)?""+e:"null";else if(111===c||108===c)e=""+e;else if(106===c)if(e){g=(c="[object Array]"===ca.apply(e))?"[":"{";if(c)for(h=0;h<e.length;h++)g+=(0==h?"":",")+b(e[h]);else for(h in e)F.call(e,h)&&e[h]!==a&&(g+=(1==g.length?"":",")+d(h)+":"+b(e[h]));e=g+(c?"]":"}")}else e="null";else e=a;return e}function d(a){var c=/[\\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,b={"\u0008":"\\b","\t":"\\t","\n":"\\n",
"\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};c.lastIndex=0;return c.test(a)?'"'+a.replace(c,function(a){var c=b[a];return"string"===typeof c?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}return b}(),S=function(){var a=v.parse;return function(b){return b?a?a(b):(new Function("return "+b))():k}}(),Z=function(){function a(a){var b=l();if(R)return j=b.a,R=0;var d=a.oldURL||j,a=j=a.newURL||b.a,b=d.replace(/^.*?(#|$)/,""),e=a.replace(/^.*?(#|$)/,"");d!=a&&!c&&J();u=c=0;b!=
e&&J(2,d,a)}function b(){if(u&&!(u=0)&&h.d!==q.basepath)clearInterval(g),setTimeout(J,10)}var i=d.onpopstate||k,e=d.onhashchange||k,c=0,g=k,h=l(),j=h.a;h.b.replace(/^#/,"");B(A+"hashchange",a,o);B(A+"popstate",function(){if(u===f.href)return u=0;u=0;J(c=1)},o);p.redirect=function(a,b){q.type=a==k?q.type:a;q.basepath=b==k?q.basepath:b;if(d.top==d.self){var c=l(k,w).d,e=f.search,g=f.pathname,b=q.basepath;n?(c!=b&&RegExp("^"+b+"$","i").test(g)&&(f.href=c),RegExp("^"+b+"$","i").test(g+"/"))?f.href=b:
RegExp("^"+b,"i").test(g)||(f.href=g.replace(/^\//,b)+e):g!=b&&(f.href=b+"#"+g.replace(RegExp("^"+b,"i"),q.type)+e+f.hash)}};p=T(p,y?P:s.state===V?{state:P.state,location:P.location}:{location:P.location});U=T(U,ha);d[z]=function(a,c,d){x[a]?(x[a].push(c),!n&&N===x[a]&&b()):3<arguments.length?B(a,c,d,arguments[3]):B(a,c,d)};d[G]=function(a,b,c){var d=x[a];if(d)for(a=d.length;--a;){if(d[a]===b){d.splice(a,1);break}}else da(a,b,c)};d[H]=function(a,b){var c=x[a],e=c===N?d.onpopstate:d.onhashchange;if(c){b=
b||("string"==typeof a?d.event:a);try{b&&(b.target=d)}catch(g){try{b.srcElement=d}catch(f){}}e&&e.call(d,b);for(var e=0,h=c.length;e<h;e++)c[e].call(d,b);return w}return ea(a,b)};y&&execScript("Public history, onhashchange","VBScript");if((!D&&!E||!T(d,{onhashchange:{get:function(){return e},set:function(a){e=a||k}},onpopstate:{get:function(){return i},set:function(a){(i=a||k)&&!n&&b()}}},1))&&!n)g=setInterval(function(){d.onpopstate&&b()},100);q.redirect&&p.redirect();if(n)B(A+"load",function(){setTimeout(function(){u=
0},0)},o);else r[z](A+"click",function(a){var b=a||d.event,c=b.target||b.srcElement,a="defaultPrevented"in b?b.defaultPrevented:b.returnValue===o;if(c&&"A"===c.nodeName&&!a&&(a=l(c.getAttribute("href",2),w),a.b&&"#"!==a.b&&a.b===a.a.replace(l().a.split("#").shift(),""))){history.location.hash=a.b;a=a.b.replace(/^#/,"");if((c=r.getElementById(a))&&c.id===a&&"A"===c.nodeName)c=c.getBoundingClientRect(),d.scrollTo(L.scrollLeft||0,c.top+(L.scrollTop||0)-(L.clientTop||0));b.preventDefault?b.preventDefault():
b.returnValue=!1}},o);return a}();p.replaceState=function(a,b,d){C(a,b,d,1)};y?(d.history=p,function(a,b){if(j){var i,e=function(){var a=l().a;b!=a&&Z({oldURL:b,newURL:b=a})};i=setInterval(e,100);j.src="javascript:true;";j=L.firstChild.appendChild(j).contentWindow;C=function(a,c,d,m,k){var n=j.document,o=["<script>","lfirst=1;",,"storage="+K(a)+";","<\/script>"];if(d=d&&l(d)){k||clearInterval(i);if(m)j.lfirst?(history.back(),C(a,c,d.a,0,1)):(j.storage=a,f.replace("#"+d.e));else if(d.a!=b||k)j.lfirst||
(j.lfirst=1,C(j.storage,c,b,0,1)),o[2]='parent.location.hash="'+d.e.replace(/"/g,'\\"')+'";',n.open(),n.write(o.join("")),n.close();k||(b=l().a,i=setInterval(e,100))}else j.storage=a};B(A+"unload",function(){if(j.storage){var a={};a[l().a]=j.storage;r.cookie="_historyAPI="+escape(K(a))}clearInterval(i)},o);if(1<a.length){a=unescape(a.pop().split(";").shift());try{j.storage=S(a)[l().a]}catch(c){}}!v.parse&&!v.stringify&&(v.parse=S,v.stringify=K,d.JSON=v)}}(r.cookie.split("_historyAPI="),l().a)):d.history.emulate=
!n;p.pushState=C})(window,!0,!1,null);