history-min.js revision 25f90bf4c6f5a6680335821bcff312fcd2598107
YUI.add("history-base",function(B){var I=B.Lang,E=B.Object,L=YUI.namespace("Env.History"),M=B.Array,F=B.config.doc.documentMode,J=B.config.win,C={merge:true},H="change",A="add",G="replace";function D(){this._init.apply(this,arguments);}B.augment(D,B.EventTarget,null,null,{emitFacade:true,prefix:"history",preventable:false,queueable:true});if(!L._state){L._state={};}function K(N){return I.type(N)==="object";}D.NAME="historyBase";D.SRC_ADD=A;D.SRC_REPLACE=G;D.html5=!!(J.history&&J.history.pushState&&J.history.replaceState&&("onpopstate" in J||B.UA.gecko>=2));D.nativeHashChange="onhashchange" in J&&(!F||F>7);B.mix(D.prototype,{_init:function(O){var N;O=this._config=O||{};N=this._initialState=this._initialState||O.initialState||null;this.publish(H,{broadcast:2,defaultFn:this._defChangeFn});if(N){this.add(N);}},add:function(){var N=M(arguments,0,true);N.unshift(A);return this._change.apply(this,N);},addValue:function(O,Q,N){var P={};P[O]=Q;return this._change(A,P,N);},get:function(O){var P=L._state,N=K(P);if(O){return N&&E.owns(P,O)?P[O]:undefined;}else{return N?B.mix({},P,true):P;}},replace:function(){var N=M(arguments,0,true);N.unshift(G);return this._change.apply(this,N);},replaceValue:function(O,Q,N){var P={};P[O]=Q;return this._change(G,P,N);},_change:function(P,O,N){N=N?B.merge(C,N):C;if(N.merge&&K(O)&&K(L._state)){O=B.merge(L._state,O);}this._resolveChanges(P,O,N);return this;},_fireEvents:function(P,O,N){this.fire(H,{_options:N,changed:O.changed,newVal:O.newState,prevVal:O.prevState,removed:O.removed,src:P});E.each(O.changed,function(R,Q){this._fireChangeEvent(P,Q,R);},this);E.each(O.removed,function(R,Q){this._fireRemoveEvent(P,Q,R);},this);},_fireChangeEvent:function(P,N,O){this.fire(N+"Change",{newVal:O.newVal,prevVal:O.prevVal,src:P});},_fireRemoveEvent:function(P,N,O){this.fire(N+"Remove",{prevVal:O,src:P});},_resolveChanges:function(T,R,O){var S={},N,Q=L._state,P={};if(!R){R={};}if(!O){O={};}if(K(R)&&K(Q)){E.each(R,function(U,V){var W=Q[V];if(U!==W){S[V]={newVal:U,prevVal:W};N=true;}},this);E.each(Q,function(V,U){if(!E.owns(R,U)||R[U]===null){delete R[U];P[U]=V;N=true;}},this);}else{N=R!==Q;}if(N){this._fireEvents(T,{changed:S,newState:R,prevState:Q,removed:P},O);}},_storeState:function(O,N){L._state=N||{};},_defChangeFn:function(N){this._storeState(N.src,N.newVal,N._options);}},true);B.HistoryBase=D;},"@VERSION@",{requires:["event-custom-complex"]});YUI.add("history-hash",function(A){var C=A.HistoryBase,F=A.Lang,K=A.Array,J=YUI.namespace("Env.HistoryHash"),B="hash",E,D,I,H=A.config.win,L=H.location,M=A.config.useHistoryHTML5;function G(){G.superclass.constructor.apply(this,arguments);}A.extend(G,C,{_init:function(N){var O=G.parseHash();N=N||{};this._initialState=N.initialState?A.merge(N.initialState,O):O;A.after("hashchange",A.bind(this._afterHashChange,this),H);G.superclass._init.apply(this,arguments);},_storeState:function(P,O){var N=G.createHash(O);G.superclass._storeState.apply(this,arguments);if(G.getHash()!==N){G[P===C.SRC_REPLACE?"replaceHash":"setHash"](N);}},_afterHashChange:function(N){this._resolveChanges(B,G.parseHash(N.newHash),{});}},{NAME:"historyHash",SRC_HASH:B,hashPrefix:"",_REGEX_HASH:/([^\?#&]+)=([^&]+)/g,createHash:function(P){var N=G.encode,O=[];A.Object.each(P,function(R,Q){if(F.isValue(R)){O.push(N(Q)+"="+N(R));}});return O.join("&");},decode:function(N){return decodeURIComponent(N.replace(/\+/g," "));},encode:function(N){return encodeURIComponent(N).replace(/%20/g,"+");},getHash:(A.UA.gecko?function(){var O=/#(.*)$/.exec(L.href),P=O&&O[1]||"",N=G.hashPrefix;return N&&P.indexOf(N)===0?P.replace(N,""):P;}:function(){var O=L.hash.substr(1),N=G.hashPrefix;return N&&O.indexOf(N)===0?O.replace(N,""):O;}),getUrl:function(){return L.href;},parseHash:function(Q){var N=G.decode,R,U,S,O,P={},T=G.hashPrefix,V;Q=F.isValue(Q)?Q:G.getHash();if(T){V=Q.indexOf(T);if(V===0||(V===1&&Q.charAt(0)==="#")){Q=Q.replace(T,"");}}S=Q.match(G._REGEX_HASH)||[];for(R=0,U=S.length;R<U;++R){O=S[R].split("=");P[N(O[0])]=N(O[1]);}return P;},replaceHash:function(N){if(N.charAt(0)==="#"){N=N.substr(1);}L.replace("#"+(G.hashPrefix||"")+N);},setHash:function(N){if(N.charAt(0)==="#"){N=N.substr(1);}L.hash=(G.hashPrefix||"")+N;}});E=J._notifiers;if(!E){E=J._notifiers=[];}A.Event.define("hashchange",{on:function(P,N,O){if(P.compareTo(H)||P.compareTo(A.config.doc.body)){E.push(O);}},detach:function(Q,O,P){var N=K.indexOf(E,P);if(N!==-1){E.splice(N,1);}}});D=G.getHash();I=G.getUrl();if(C.nativeHashChange){A.Event.attach("hashchange",function(P){var N=G.getHash(),O=G.getUrl();K.each(E.concat(),function(Q){Q.fire({_event:P,oldHash:D,oldUrl:I,newHash:N,newUrl:O});});D=N;I=O;},H);}else{if(!J._hashPoll){if(A.UA.webkit&&!A.UA.chrome&&navigator.vendor.indexOf("Apple")!==-1){A.on("unload",function(){},H);}J._hashPoll=A.later(50,null,function(){var N=G.getHash(),O;if(D!==N){O=G.getUrl();K.each(E,function(P){P.fire({oldHash:D,oldUrl:I,newHash:N,newUrl:O});});D=N;I=O;}},null,true);}}A.HistoryHash=G;if(M===false||(!A.History&&M!==true&&(!C.html5||!A.HistoryHTML5))){A.History=G;}},"@VERSION@",{requires:["event-synthetic","history-base","yui-later"]});YUI.add("history-hash-ie",function(G){if(G.UA.ie&&!G.HistoryBase.nativeHashChange){var C=G.Do,D=YUI.namespace("Env.HistoryHash"),B=G.HistoryHash,E=D._iframe,F=G.config.win,A=F.location;B.getHash=function(){var H=B.hashPrefix,I=E?E.contentWindow.location.hash.substr(1):A.hash.substr(1);return H&&I.indexOf(H)===0?I.replace(H,""):I;};B.getUrl=function(){var H=B.getHash();if(H&&H!==A.hash.substr(1)){return A.href.replace(/#.*$/,"")+"#"+H;}else{return A.href;}};B._updateIframe=function(I,H){var J=E.contentWindow.document,K=J.location;J.open().close();if(H){K.replace(I.charAt(0)==="#"?I:"#"+I);}else{K.hash=I;}};C.after(B._updateIframe,B,"replaceHash",B,true);C.after(B._updateIframe,B,"setHash");if(!E){G.on("domready",function(){E=D._iframe=G.Node.getDOMNode(G.Node.create('<iframe src="javascript:0" style="display:none" height="0" width="0" tabindex="-1" title="empty"/>'));
G.config.doc.documentElement.appendChild(E);B._updateIframe(A.hash.substr(1));});G.on("hashchange",function(H){if(A.hash.substr(1)!==H.newHash){A.hash=H.newHash;}},F);}}},"@VERSION@",{requires:["history-hash","node-base"]});YUI.add("history-html5",function(A){var C=A.HistoryBase,J=A.config.doc,G=A.config.win,I=G.sessionStorage,L=A.config.useHistoryHTML5,K=A.JSON||G.JSON,E="enableSessionFallback",B="YUI_HistoryHTML5_state",D="popstate",F=C.SRC_REPLACE;function H(){H.superclass.constructor.apply(this,arguments);}A.extend(H,C,{_init:function(M){A.on("popstate",this._onPopState,G,this);H.superclass._init.apply(this,arguments);if(M&&M[E]&&YUI.Env.windowLoaded){this._loadSessionState();}},_getSessionKey:function(){return B+"_"+G.location.pathname;},_loadSessionState:function(){var M=K&&I&&I[this._getSessionKey()];if(M){try{this._resolveChanges(D,K.parse(M)||null);}catch(N){}}},_storeSessionState:function(M){if(this._config[E]&&K&&I){I[this._getSessionKey()]=K.stringify(M||null);}},_storeState:function(O,N,M){if(O!==D){G.history[O===F?"replaceState":"pushState"](N,M.title||J.title||"",M.url||null);}this._storeSessionState(N);H.superclass._storeState.apply(this,arguments);},_onPopState:function(N){var M=N._event.state;this._storeSessionState(M);this._resolveChanges(D,M||null);}},{NAME:"historyhtml5",SRC_POPSTATE:D});if(!A.Node.DOM_EVENTS.popstate){A.Node.DOM_EVENTS.popstate=1;}A.HistoryHTML5=H;if(L===true||(L!==false&&C.html5)){A.History=H;}},"@VERSION@",{optional:["json"],requires:["event-base","history-base","node-base"]});YUI.add("history",function(A){},"@VERSION@",{use:["history-base","history-hash","history-hash-ie","history-html5"]});