forked from devote/HTML5-History-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.ielte7.min.js
35 lines (35 loc) · 10.2 KB
/
history.ielte7.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
31
32
33
34
35
/*!
* History API JavaScript Library v4.2.0
*
* Support: IE6+, FF3+, Opera 9+, Safari, Chrome and other
*
* Copyright 2011-2014, 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: 2014-11-06 21:35
*/
(function(Q){"function"===typeof define&&define.amd?define("object"!==typeof document||"loading"!==document.readyState?[]:"html5-history-api",Q):Q()})(function(){var j=!0,k=null,n=!1;function R(a,b){var c=d.history!==o;c&&(d.history=o);a.apply(o,b);c&&(d.history=l)}function J(){}function i(a,b,c){if(a!=k&&""!==a&&!b){var b=i(),e=g.getElementsByTagName("base")[0];!c&&e&&e.getAttribute("href")&&(e.href=e.href,b=i(e.href,k,j));c=b.e;e=b.h;a=""+a;a=/^(?:\w+\:)?\/\//.test(a)?0===a.indexOf("/")?e+a:a:e+"//"+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:f.href,!s||c)a=a.replace(/^[^#]*/,"")||"#",a=f.protocol.replace(/:.*$|$/,
":")+"//"+f.host+h.basepath+a.replace(RegExp("^#[/]?(?:"+h.type+")?"),"");S.href=a;var a=/(?:(\w+\:))?(?:\/\/(?:[^@]*@)?([^\/:\?#]+)(?::([0-9]+))?)?([^\?#]*)(?:(\?[^#]+)|\?)?(?:(#.*))?/.exec(S.href),b=a[2]+(a[3]?":"+a[3]:""),c=a[4]||"/",e=a[5]||"",d="#"===a[6]?"":a[6]||"",p=c+e+d,w=c.replace(RegExp("^"+h.basepath,"i"),h.type)+e;return{a:a[1]+"//"+b+p,h:a[1],g:b,i:a[2],k:a[3]||"",e:c,f:e,b:d,c:p,j:w,d:w+d}}function ba(){var a;try{a=d.sessionStorage,a.setItem(E+"t","1"),a.removeItem(E+"t")}catch(b){a=
{getItem:function(a){a=g.cookie.split(a+"=");return 1<a.length&&a.pop().split(";").shift()||"null"},setItem:function(a){var b={};if(b[f.href]=l.state)g.cookie=a+"="+t.stringify(b)}}}try{q=t.parse(a.getItem(E))||{}}catch(c){q={}}v(x+"unload",function(){a.setItem(E,t.stringify(q))},n)}function y(a,b,c,e){var f=0;c||(c={set:J},f=1);var g=!c.set,w=!c.get,K={configurable:j,set:function(){g=1},get:function(){w=1}};try{C(a,b,K),a[b]=a[b],C(a,b,c)}catch(ia){}if(!g||!w)if(a.__defineGetter__&&(a.__defineGetter__(b,
K.get),a.__defineSetter__(b,K.set),a[b]=a[b],c.get&&a.__defineGetter__(b,c.get),c.set&&a.__defineSetter__(b,c.set)),!g||!w){if(f)return n;if(a===d){try{var ca=a[b];a[b]=k}catch(ja){}if("execScript"in d)d.execScript("Public "+b,"VBScript"),d.execScript("var "+b+";","JavaScript");else try{C(a,b,{value:J})}catch(l){"onpopstate"===b&&(v("popstate",c=function(){L("popstate",c,n);var b=a.onpopstate;a.onpopstate=k;setTimeout(function(){a.onpopstate=b},1)},n),T=0)}a[b]=ca}else try{try{var i=F.create(a);C(F.getPrototypeOf(i)===
a?i:a,b,c);for(var h in a)"function"===typeof a[h]&&(i[h]=a[h].bind(a));try{e.call(i,i,a)}catch(m){}a=i}catch(o){C(a.constructor.prototype,b,c)}}catch(q){return n}}return a}function da(a,b,c){c=c||{};a=a===M?f:a;c.set=c.set||function(c){a[b]=c};c.get=c.get||function(){return a[b]};return c}function G(a,b){var c=(""+("string"===typeof a?a:a.type)).replace(/^on/,""),e=z[c];if(e){b="string"===typeof a?b:a;if(b.target==k)for(var f=["target","currentTarget","srcElement","type"];a=f.pop();)b=y(b,a,{get:"type"===
a?function(){return c}:function(){return d}});T&&(("popstate"===c?d.onpopstate:d.onhashchange)||J).call(d,b);for(var f=0,g=e.length;f<g;f++)e[f].call(d,b);return j}return ea(a,b)}function U(){var a=g.createEvent?g.createEvent("Event"):g.createEventObject();a.initEvent?a.initEvent("popstate",n,n):a.type="popstate";a.state=l.state;G(a)}function u(a,b,c,d){s?A=f.href:(0===m&&(m=2),b=i(b,2===m&&-1!==(""+b).indexOf("#")),b.c!==i().c&&(A=d,c?f.replace("#"+b.d):f.hash=b.d));!H&&a&&(q[f.href]=a);D=n}function N(a){var b=
A;A=f.href;if(b){V!==f.href&&U();var a=a||d.event,b=i(b,j),c=i();a.oldURL||(a.oldURL=b.a,a.newURL=c.a);b.b!==c.b&&G(a)}}function W(a){setTimeout(function(){v("popstate",function(a){V=f.href;H||(a=y(a,"state",{get:function(){return l.state}}));G(a)},n)},0);!s&&a!==j&&"location"in l&&(X(r.hash),D&&(D=n,U()))}function fa(a){var a=a||d.event,b;a:{for(b=a.target||a.srcElement;b;){if("A"===b.nodeName)break a;b=b.parentNode}b=void 0}var c="defaultPrevented"in a?a.defaultPrevented:a.returnValue===n;b&&"A"===
b.nodeName&&!c&&(c=i(),b=i(b.getAttribute("href",2)),c.a.split("#").shift()===b.a.split("#").shift()&&b.b&&(c.b!==b.b&&(r.hash=b.b),X(b.b),a.preventDefault?a.preventDefault():a.returnValue=n))}function X(a){var b=g.getElementById(a=(a||"").replace(/^#/,""));b&&b.id===a&&"A"===b.nodeName&&(a=b.getBoundingClientRect(),d.scrollTo(I.scrollLeft||0,a.top+(I.scrollTop||0)-(I.clientTop||0)))}function ga(){function a(a){var b=[],e="VBHistoryClass"+(new Date).getTime()+c++,f=["Class "+e],g;for(g in a)if(a.hasOwnProperty(g)){var h=
a[g];h&&(h.get||h.set)?(h.get&&f.push("Public "+("_"===g?"Default ":"")+"Property Get ["+g+"]","Call VBCVal([(accessors)].["+g+"].get.call(me),["+g+"])","End Property"),h.set&&f.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),f.push("Public ["+g+"]"))}f.push("Private [(accessors)]","Private Sub Class_Initialize()","Set [(accessors)]="+e+"FactoryJS()","End Sub","End Class","Function "+e+"Factory()",
"Set "+e+"Factory=New "+e,"End Function");d.execScript(f.join("\n"),"VBScript");d[e+"FactoryJS"]=function(){return a};e=d[e+"Factory"]();for(f=0;f<b.length;f++)e[b[f]]=a[b[f]];return e}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=d.execScript&&(d.execScript("var documentMsie/*@cc_on =1@*/;","JavaScript"),d.documentMsie);if(c&&!(g.documentMode&&7<g.documentMode)){var e=y,h=i().a,p=g.createElement("iframe");p.src="javascript:true;";p=I.firstChild.appendChild(p).contentWindow;d.execScript("Public history\nFunction VBCVal(o,r) If IsObject(o) Then Set r=o Else r=o End If End Function","VBScript");r={_:{get:M.toString}};l={back:o.back,forward:o.forward,go:o.go,emulate:k,
_:{get:function(){return"[object History]"}}};t={parse:function(a){try{return(new Function("","return "+a))()}catch(b){return k}},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 e=(c="[object Array]"===F.prototype.toString.call(a))?"[":"{";if(c)for(var d=0;d<a.length;d++)e+=(0==d?"":",")+t.stringify(a[d]);else for(d in a)a.hasOwnProperty(d)&&(e+=(1==e.length?"":",")+b(d)+":"+
t.stringify(a[d]));a=e+(c?"]":"}")}else a="null";else a="void 0";return a}};u=function(a,b,c,e,d){var g=p.document;0===m&&(m=2);b=i(b,2===m&&-1!==(""+b).indexOf("#"));D=n;if(b.c===i().c&&!d)a&&(q[f.href]=a);else{A=e;if(c)p.lfirst?(history.back(),u(a,b.a,0,e,1)):f.replace("#"+b.d);else if(b.a!=h||d)p.lfirst?d&&(d=0,a=q[f.href]):(p.lfirst=1,u(a,h,0,e,1)),g.open(),g.write('<script>lfirst=1;parent.location.hash="'+b.d.replace(/"/g,'\\"')+'";<\/script>'),g.close();!d&&a&&(q[f.href]=a)}};y=function(b,c,
f,g){e.apply(this,arguments)||(b===r?r[c]=f:b===l?(l[c]=f,"state"===c&&(r=a(r),d.history=l=a(l),d.execScript("var history = window.history;","JavaScript"))):b[c]=f.get&&f.get());return b};setInterval(function(){var a=i().a;if(a!=h){var b=g.createEventObject();b.oldURL=h;b.newURL=h=a;b.type="hashchange";N(b)}},100);d.JSON=t}}var d=("object"===typeof window?window:this)||{};if(!d.history||"emulate"in d.history)return d.history;var g=d.document,I=g.documentElement,F=d.Object,t=d.JSON,f=d.location,o=
d.history,l=o,O=o.pushState,Y=o.replaceState,s=!!O,H="state"in o,C=F.defineProperty,r=y({},"t")?{}:g.createElement("a"),x="",P=d.addEventListener?"addEventListener":(x="on")&&"attachEvent",Z=d.removeEventListener?"removeEventListener":"detachEvent",$=d.dispatchEvent?"dispatchEvent":"fireEvent",v=d[P],L=d[Z],ea=d[$],h={basepath:"/",redirect:0,type:"/",init:0},E="__historyAPI__",S=g.createElement("a"),A=f.href,V="",T=1,D=n,m=0,q={},z={},B=g.title,ha={onhashchange:k,onpopstate:k},aa={setup:function(a,
b,c){h.basepath=(""+(a==k?h.basepath:a)).replace(/(?:^|\/)[^\/]*$/,"/");h.type=b==k?h.type:b;h.redirect=c==k?h.redirect:!!c},redirect:function(a,b){l.setup(b,a);b=h.basepath;if(d.top==d.self){var c=i(k,n,j).c,e=f.pathname+f.search;s?(e=e.replace(/([^\/])$/,"$1/"),c!=b&&RegExp("^"+b+"$","i").test(e)&&f.replace(c)):e!=b&&(e=e.replace(/([^\/])\?/,"$1/?"),RegExp("^"+b,"i").test(e)&&f.replace(b+"#"+e.replace(RegExp("^"+b,"i"),h.type)+f.hash))}},pushState:function(a,b,c){var d=g.title;B!=k&&(g.title=B);
O&&R(O,arguments);u(a,c);g.title=d;B=b},replaceState:function(a,b,c){var d=g.title;B!=k&&(g.title=B);delete q[f.href];Y&&R(Y,arguments);u(a,c,j);g.title=d;B=b},location:{set:function(a){0===m&&(m=1);d.location=a},get:function(){0===m&&(m=1);return s?f:r}},state:{get:function(){return q[f.href]||k}}},M={assign:function(a){0===(""+a).indexOf("#")?u(k,a):f.assign(a)},reload:function(){f.reload()},replace:function(a){0===(""+a).indexOf("#")?u(k,a,j):f.replace(a)},toString:function(){return this.href},
href:{get:function(){return i().a}},protocol:k,host:k,hostname:k,port:k,pathname:{get:function(){return i().e}},search:{get:function(){return i().f}},hash:{set:function(a){u(k,(""+a).replace(/^(#|)/,"#"),n,A)},get:function(){return i().b}}};if(function(){var a=g.getElementsByTagName("script"),a=(a[a.length-1]||{}).src||"";(-1!==a.indexOf("?")?a.split("?").pop():"").replace(/(\w+)(?:=([^&]*))?/g,function(a,b,c){h[b]=(c||"").replace(/^(0|false)$/,"")});ga();v(x+"hashchange",N,n);var b=[M,r,ha,d,aa,
l];H&&delete aa.state;for(var c=0;c<b.length;c+=2)for(var e in b[c])if(b[c].hasOwnProperty(e))if("function"===typeof b[c][e])b[c+1][e]=b[c][e];else{a=da(b[c],e,b[c][e]);if(!y(b[c+1],e,a,function(a,e){if(e===l)d.history=l=b[c+1]=a}))return L(x+"hashchange",N,n),n;b[c+1]===d&&(z[e]=z[e.substr(2)]=[])}l.setup();h.redirect&&l.redirect();h.init&&(m=1);!H&&t&&ba();if(!s)g[P](x+"click",fa,n);"complete"===g.readyState?W(j):(!s&&i().c!==h.basepath&&(D=j),v(x+"load",W,n));return j}())return l.emulate=!s,d[P]=
function(a,b,c){a in z?z[a].push(b):3<arguments.length?v(a,b,c,arguments[3]):v(a,b,c)},d[Z]=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 L(a,b,c)},d[$]=G,l});