hash.js
2.12 KB
//>>built
define("./_base/kernel require ./_base/config ./aspect ./_base/lang ./topic ./domReady ./sniff".split(" "),function(d,y,n,z,h,A,B,k){function u(a,b){b=a.indexOf(b);return 0<=b?a.substring(b+1):""}function e(){return u(location.href,"#")}function p(){A.publish("/dojo/hashchange",e())}function l(){e()!==c&&(c=e(),p())}function w(a){if(f)if(f.isTransitioning())setTimeout(h.hitch(null,w,a),q);else{var b=f.iframe.location.href,c=b.indexOf("?");f.iframe.location.replace(b.substring(0,c)+"?"+a)}else b=location.href.replace(/#.*/,
""),location.replace(b+"#"+a),!x&&l()}function C(){function a(){c=e();k=g?c:u(v.href,"?");r=!1;t=null}var b=document.createElement("iframe"),f=n.dojoBlankHtmlUrl||y.toUrl("./resources/blank.html");n.useXDomain&&!n.dojoBlankHtmlUrl&&console.warn("dojo/hash: When using cross-domain Dojo builds, please save dojo/resources/blank.html to your domain and set djConfig.dojoBlankHtmlUrl to the path on your domain to blank.html");b.id="dojo-hash-iframe";b.src=f+"?"+e();b.style.display="none";document.body.appendChild(b);
this.iframe=d.global["dojo-hash-iframe"];var k,r,t,l,g,v=this.iframe.location;this.isTransitioning=function(){return r};this.pollLocation=function(){if(!g)try{var d=u(v.href,"?");document.title!=l&&(l=this.iframe.document.title=document.title)}catch(D){g=!0,console.error("dojo/hash: Error adding history entry. Server unreachable.")}var m=e();if(r&&c===m)if(g||d===t)a(),p();else{setTimeout(h.hitch(this,this.pollLocation),0);return}else if(c!==m||!g&&k!==d){if(c!==m){c=m;r=!0;t=m;b.src=f+"?"+t;g=!1;
setTimeout(h.hitch(this,this.pollLocation),0);return}g||(location.href="#"+v.search.substring(1),a(),p())}setTimeout(h.hitch(this,this.pollLocation),q)};a();setTimeout(h.hitch(this,this.pollLocation),q)}d.hash=function(a,b){if(!arguments.length)return e();"#"==a.charAt(0)&&(a=a.substring(1));b?w(a):location.hash="#"+a;return a};var c,f,x,q=n.hashPollFrequency||100;B(function(){"onhashchange"in d.global&&(!k("ie")||8<=k("ie")&&"BackCompat"!=document.compatMode)?x=z.after(d.global,"onhashchange",p,
!0):document.addEventListener?(c=e(),setInterval(l,q)):document.attachEvent&&(f=new C)});return d.hash});