-
Notifications
You must be signed in to change notification settings - Fork 0
/
hasher.min.js
7 lines (7 loc) · 2.75 KB
/
hasher.min.js
1
2
3
4
5
6
7
/*!
* Hasher <http://github.com/millermedeiros/hasher>
* @author Miller Medeiros
* @version 1.1.0 (2011/11/01 07:15 PM)
* Released under the MIT License
*/
(function(a){a("hasher",["signals"],function(b){var c=(function(l){var p=25,r=l.document,d=l.location,o=l.history,w=b.Signal,g,v,n,E,f,C,t=/#(.*)$/,k=/(\?.*)|(\#.*)/,h=/^\#/,j=(!+"\v1"),A=("onhashchange" in l),e=j&&!A,s=(d.protocol==="file:");function u(G){if(!G){return""}var F=new RegExp("^\\"+g.prependHash+"|\\"+g.appendHash+"$","g");return G.replace(F,"")}function D(){var F=t.exec(g.getURL());return(F&&F[1])?decodeURIComponent(F[1]):""}function z(){return(f)?f.contentWindow.frameHash:null}function y(){f=r.createElement("iframe");f.src="about:blank";f.style.display="none";r.body.appendChild(f)}function i(){if(f&&v!==z()){var F=f.contentWindow.document;F.open();F.write("<html><head><title>"+r.title+'</title><script type="text/javascript">var frameHash="'+v+'";<\/script></head><body> </body></html>');F.close()}}function m(F,G){F=decodeURIComponent(F);if(v!==F){var H=v;v=F;if(e){if(!G){i()}else{f.contentWindow.frameHash=F}}g.changed.dispatch(u(F),u(H))}}if(e){C=function(){var G=D(),F=z();if(F!==v&&F!==G){g.setHash(u(F))}else{if(G!==v){m(G)}}}}else{C=function(){var F=D();if(F!==v){m(F)}}}function B(H,F,G){if(H.addEventListener){H.addEventListener(F,G,false)}else{if(H.attachEvent){H.attachEvent("on"+F,G)}}}function x(H,F,G){if(H.removeEventListener){H.removeEventListener(F,G,false)}else{if(H.detachEvent){H.detachEvent("on"+F,G)}}}function q(G){G=Array.prototype.slice.call(arguments);var F=G.join(g.separator);F=F?g.prependHash+F.replace(h,"")+g.appendHash:F;if(j&&s){F=F.replace(/\?/,"%3F")}return F}g={VERSION:"1.1.0",appendHash:"",prependHash:"/",separator:"/",changed:new w(),stopped:new w(),initialized:new w(),init:function(){if(E){return}v=D();if(A){B(l,"hashchange",C)}else{if(e){if(!f){y()}i()}n=setInterval(C,p)}E=true;g.initialized.dispatch(u(v))},stop:function(){if(!E){return}if(A){x(l,"hashchange",C)}else{clearInterval(n);n=null}E=false;g.stopped.dispatch(u(v))},isActive:function(){return E},getURL:function(){return d.href},getBaseURL:function(){return g.getURL().replace(k,"")},setHash:function(F){F=q.apply(null,arguments);if(F!==v){m(F);d.hash="#"+encodeURI(F)}},replaceHash:function(F){F=q.apply(null,arguments);if(F!==v){m(F,true);d.replace("#"+encodeURI(F))}},getHash:function(){return u(v)},getHashAsArray:function(){return g.getHash().split(g.separator)},dispose:function(){g.stop();g.initialized.dispose();g.stopped.dispose();g.changed.dispose();f=g=l.hasher=null},toString:function(){return'[hasher version="'+g.VERSION+'" hash="'+g.getHash()+'"]'}};g.initialized.memorize=true;return g}(window));return c})}(typeof define==="function"&&define.amd?define:function(c,b,a){window[c]=a(window[b[0]])}));