-
Notifications
You must be signed in to change notification settings - Fork 0
/
histery.min.js
1 lines (1 loc) · 2.96 KB
/
histery.min.js
1
!function(a,b,c){"object"==typeof module&&"object"==typeof module.exports?void 0!==(b=a(require,exports))&&(module.exports=b):"function"==typeof define&&define.amd?define("histery",["require","exports"],a):(a(void 0,b={}),this.$H=b.$H)}(function(a,b){"use strict";function c(a){return"function"==typeof a}function d(a){return"string"==typeof a}function e(a){return a&&a.constructor===x}function f(a,b){return b=location,a&&(b=document.createElement("a"),b.href=a),b=b.pathname+b.search+(b.hash.length>1?b.hash:""),"/"===b[0]?b:"/"+b}function g(a,b,d,e,f){if(b instanceof RegExp?(d=0,e=a.replace(b,function(){return d++,f=Array.prototype.slice.call(f=arguments,1,f.length-2),""})):c(b)?(d=1,f=b(a)):a===b&&(d=1,f=[]),1===d&&!e)return f}function h(a,b,c,d,f){if(a.replace(/^([^?#]+)(?:\?([^#]*))?(?:#(.*))?$/,function(a,b,e,g){c=b||"",d=e||"",f=g||""}),c&&(e(b)?(c=b.pathname?g(c,b.pathname):[],d=b.search?g(d,b.search):[],f=b.hash?g(f,b.hash):[]):(c=g(c,b),d=f=[]),c&&d&&f))return[a].concat(c,d,f)}function i(a,b,c,d,e){for(d=0;d<b.length;d++)e=b[d],e[0]===a&&c.push(e[1])}function j(a,b){for(;b=a.shift();)b()}function k(a,b,c,d){if(a=a||[],b=b||[],a.length!==b.length)d=!1;else for(d=!0,c=2;c<a.length;c++)if(!l.eq(a[c],b[c])){d=!1;break}return d}var l,m,n,o,p,q,r=void 0,s=window.history||{},t=[],u={},v=[],w=[],x={}.constructor;b.$H=l={state:function(a,b){if(b===r)return p[a];null===b?delete p[a]:p[a]=b,s.replaceState&&s.replaceState(p,null)},run:function(){var a=document.createEvent("HTMLEvents"),b=function(a){"popstate"!==a.type&&q===location.href||(o=!0,p=s.state||{},l.go()),q="popstate"===a.type?location.href:r};return addEventListener("popstate",b),addEventListener("hashchange",b),a.initEvent("popstate",!0,!0),dispatchEvent(a),l},go:function(a,b,d){var e,g,l,q,x=[],y=!1,z={},A=[],B=[];for(a=f(a),g=0;g<t.length;g++)m=t[g],(e=m.h)&&!(l=h(u[a]||a,e))||(e?z[g]=y=!0:l=[a],function(a,d,f){d.unshift(r),d[0]=k(a.cur,d),b||(a.cur=d);var g=!!e;c(f)&&(f=f()),f.go&&A.push([g,function(){f.go.apply(f,d)}]),f.leave&&B.push([g,function(){d[0]=k(a.cur,d),f.leave.apply(f,d)}])}(m,l,m.c));if(i(y,A,x),q=x.length>0,!b){for(e=0;e<t.length;e++)m=t[e],m.cur=y&&z[e]||!y&&!m.h?m.cur:null;for(j(w),i(y,B,w),n&&(s.pushState&&x.length?o||s[d?"replaceState":"pushState"](p={},null,a):location.href=a),n=!0,o=!1,j(x),e=0;e<v.length;e++)v[e](a)}return q},on:function(a,b){return a===r?v.push(b):d(a)&&d(b)?u[f(a)]=f(b):t.push({h:a,c:b,cur:null}),l},off:function(a,b){var c,e;if(d(a)&&d(b)&&u[c=f(a)]===f(b))delete u[c];else if(a===r)for(c=v.length;c--;)v[c]===b&&v.splice(c,1);else for(a||b||(t=[]),c=t.length;c--;)e=t[c],e.h!==a||b&&e.c!==b||t.splice(c,1);return l},eq:function a(b,c){var d,f,g;if(e(b)&&e(c)){d=[],f=[];for(g in b){if(!(g in c))return!1;d.push(g)}for(g in c){if(!(g in b))return!1;f.push(g)}if(d.length!==f.length)return!1;for(g=0;g<d.length;g++)if(!a(b[d[g]],c[d[g]]))return!1;return!0}if(b instanceof Array&&c instanceof Array&&b.length===c.length){for(g=b.length;g--;)if(!a(b[g],c[g]))return!1;return!0}return b===c}}});