liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
1
2
3
4
5
6
7
8
9
10
//>>built
define("dojo/_base/lang dojo/_base/declare dojo/topic dojo/on ../Controller ../utils/hash dojo/hash".split(" "),function(e,g,f,k,h,d){return g("dojox.app.controllers.HistoryHash",h,{constructor:function(a){this.events={"app-domNode":this.onDomNodeChange};if(this.app.domNode)this.onDomNodeChange({oldNode:null,newNode:this.app.domNode});f.subscribe("/dojo/hashchange",e.hitch(this,function(a){this._onHashChange(a)}));this._historyStack=[];this._historyDiff=this._historyLen=0;this._previous=this._next=
this._current=null;this._newHistoryLen=this._oldHistoryLen=this._index=0;this._startTransitionEvent=this._addToHistoryStack=!1;(a=window.location.hash)&&1<a.length&&(a=a.substr(1));this._historyStack.push({hash:a,url:window.location.href,detail:{target:a}});this._historyLen=window.history.length;this._index=this._historyStack.length-1;this._current=a;this._historyDiff=window.history.length-this._historyStack.length},onDomNodeChange:function(a){null!=a.oldNode&&this.unbind(a.oldNode,"startTransition");
this.bind(a.newNode,"startTransition",e.hitch(this,this.onStartTransition))},onStartTransition:function(a){var b=a.detail.target,c=/#(.+)/;!b&&c.test(a.detail.href)&&(b=a.detail.href.match(c)[1]);b=a.detail.url||"#"+b;a.detail.params&&(b=d.buildWithParams(b,a.detail.params));this._oldHistoryLen=window.history.length;window.location.hash=b;this._startTransitionEvent=this._addToHistoryStack=!0},_addHistory:function(a){this._historyStack.push({hash:a,url:window.location.href,detail:{target:a}});this._historyLen=
window.history.length;this._index=this._historyStack.length-1;this._previous=this._current;this._current=a;this._next=null;this._historyDiff=window.history.length-this._historyStack.length;this._addToHistoryStack=!1},_onHashChange:function(a){if(0>this._index||this._index>window.history.length-1)throw Error("Application history out of management.");this._newHistoryLen=window.history.length;this._oldHistoryLen>this._newHistoryLen&&(this._historyStack.splice(this._newHistoryLen-this._historyDiff-1,
this._historyStack.length-1),this._historyLen=this._historyStack.length,this._oldHistoryLen=0);if(this._addToHistoryStack&&this._oldHistoryLen===this._newHistoryLen)this._historyStack.splice(this._newHistoryLen-this._historyDiff-1,this._historyStack.length-1),this._addHistory(a);else{if(this._historyLen<window.history.length)this._addHistory(a),this._startTransitionEvent||this.app.emit("app-transition",{viewId:d.getTarget(a),opts:{params:d.getParams(a)||{}}});else if(a!=this._current)if(a===this._previous)this._back(a,
this._historyStack[this._index].detail);else if(a===this._next)this._forward(a,this._historyStack[this._index].detail);else{for(var b=-1,c=this._index;0<c;c--)if(a===this._historyStack[c].hash){b=c;break}if(-1===b)for(c=this._index;c<this._historyStack.length;c++)if(a===this._historyStack[c].hash){b=c;break}0<b<this._historyStack.length?this._go(b,b-this._index):this.app.log("go error. index out of history stack.")}this._startTransitionEvent=!1}},_back:function(a,b){this.app.log("back");this._next=
this._historyStack[this._index].hash;this._index--;this._previous=0<this._index?this._historyStack[this._index-1].hash:null;this._current=a;var c=d.getTarget(a,this.app.defaultView);f.publish("/app/history/back",{viewId:c,detail:b});this.app.emit("app-transition",{viewId:c,opts:e.mixin({reverse:!0},b,{params:d.getParams(a)})})},_forward:function(a,b){this.app.log("forward");this._previous=this._historyStack[this._index].hash;this._index++;this._next=this._index<this._historyStack.length-1?this._historyStack[this._index+
1].hash:null;this._current=a;var c=d.getTarget(a,this.app.defaultView);f.publish("/app/history/forward",{viewId:c,detail:b});this.app.emit("app-transition",{viewId:c,opts:e.mixin({reverse:!1},b,{params:d.getParams(a)})})},_go:function(a,b){if(0>a||a>window.history.length-1)throw Error("Application history.go steps out of management, index: "+a+" length: "+window.history.length);this._index=a;this._current=this._historyStack[a].hash;this._previous=this._historyStack[a-1]?this._historyStack[a-1].hash:
null;this._next=this._historyStack[a+1]?this._historyStack[a+1].hash:null;var c=d.getTarget(this._current,this.app.defaultView);f.publish("/app/history/go",{viewId:c,step:b,detail:this._historyStack[a].detail});this.app.emit("app-transition",{viewId:c,opts:e.mixin({reverse:0>=b},this._historyStack[a].detail,{params:d.getParams(this._current)})})}})});