History.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //>>built
  2. define("dojox/app/controllers/History",["dojo/_base/lang","dojo/_base/declare","dojo/on","../Controller","../utils/hash","dojo/topic"],function(_1,_2,on,_3,_4,_5){
  3. return _2("dojox.app.controllers.History",_3,{_currentPosition:0,currentState:{},constructor:function(){
  4. this.events={"app-domNode":this.onDomNodeChange};
  5. if(this.app.domNode){
  6. this.onDomNodeChange({oldNode:null,newNode:this.app.domNode});
  7. }
  8. this.bind(window,"popstate",_1.hitch(this,this.onPopState));
  9. },onDomNodeChange:function(_6){
  10. if(_6.oldNode!=null){
  11. this.unbind(_6.oldNode,"startTransition");
  12. }
  13. this.bind(_6.newNode,"startTransition",_1.hitch(this,this.onStartTransition));
  14. },onStartTransition:function(_7){
  15. var _8=window.location.hash;
  16. var _9=_4.getTarget(_8,this.app.defaultView);
  17. var _a=_4.getParams(_8);
  18. var _b=_1.clone(_7.detail);
  19. _b.target=_b.title=_9;
  20. _b.url=_8;
  21. _b.params=_a;
  22. _b.id=this._currentPosition;
  23. if(history.length==1){
  24. history.pushState(_b,_b.href,_8);
  25. }
  26. _b.bwdTransition=_b.transition;
  27. _1.mixin(this.currentState,_b);
  28. history.replaceState(this.currentState,this.currentState.href,_8);
  29. this._currentPosition+=1;
  30. _7.detail.id=this._currentPosition;
  31. var _c=_7.detail.url||"#"+_7.detail.target;
  32. if(_7.detail.params){
  33. _c=_4.buildWithParams(_c,_7.detail.params);
  34. }
  35. _7.detail.fwdTransition=_7.detail.transition;
  36. history.pushState(_7.detail,_7.detail.href,_c);
  37. this.currentState=_1.clone(_7.detail);
  38. _5.publish("/app/history/pushState",_7.detail.target);
  39. },onPopState:function(_d){
  40. if((this.app.getStatus()!==this.app.lifecycle.STARTED)||!_d.state){
  41. return;
  42. }
  43. var _e=_d.state.id<this._currentPosition;
  44. _e?this._currentPosition-=1:this._currentPosition+=1;
  45. var _f=_1.mixin({reverse:_e?true:false},_d.state);
  46. _f.transition=_e?_f.bwdTransition:_f.fwdTransition;
  47. this.app.emit("app-transition",{viewId:_d.state.target,opts:_f});
  48. _5.publish("/app/history/popState",_d.state.target);
  49. }});
  50. });