| 1 |
dojo.provide("dojox.mobile.app.StageController"); |
| 2 |
dojo.experimental("dojox.mobile.app.StageController"); |
| 3 |
|
| 4 |
dojo.require("dojox.mobile.app.SceneController"); |
| 5 |
|
| 6 |
dojo.declare("dojox.mobile.app.StageController", null,{ |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
scenes: null, |
| 11 |
|
| 12 |
effect: "fade", |
| 13 |
|
| 14 |
constructor: function(node){ |
| 15 |
this.domNode = node; |
| 16 |
this.scenes = []; |
| 17 |
|
| 18 |
if(dojo.config.mobileAnim){ |
| 19 |
this.effect = dojo.config.mobileAnim; |
| 20 |
} |
| 21 |
}, |
| 22 |
|
| 23 |
getActiveSceneController: function(){ |
| 24 |
return this.scenes[this.scenes.length - 1]; |
| 25 |
}, |
| 26 |
|
| 27 |
pushScene: function(sceneName, params){ |
| 28 |
if(this._opInProgress){ |
| 29 |
return; |
| 30 |
} |
| 31 |
this._opInProgress = true; |
| 32 |
|
| 33 |
|
| 34 |
var node = dojo.create("div", { |
| 35 |
"class": "scene-wrapper", |
| 36 |
style: { |
| 37 |
visibility: "hidden" |
| 38 |
} |
| 39 |
}, this.domNode); |
| 40 |
|
| 41 |
var controller = new dojox.mobile.app.SceneController({}, node); |
| 42 |
|
| 43 |
if(this.scenes.length > 0){ |
| 44 |
this.scenes[this.scenes.length -1].assistant.deactivate(); |
| 45 |
} |
| 46 |
|
| 47 |
this.scenes.push(controller); |
| 48 |
|
| 49 |
var _this = this; |
| 50 |
|
| 51 |
dojo.forEach(this.scenes, this.setZIndex); |
| 52 |
|
| 53 |
controller.stageController = this; |
| 54 |
|
| 55 |
controller.init(sceneName, params).addCallback(function(){ |
| 56 |
|
| 57 |
if(_this.scenes.length == 1){ |
| 58 |
controller.domNode.style.visibility = "visible"; |
| 59 |
_this.scenes[_this.scenes.length - 1].assistant.activate(params); |
| 60 |
_this._opInProgress = false; |
| 61 |
}else{ |
| 62 |
_this.scenes[_this.scenes.length - 2] |
| 63 |
.performTransition( |
| 64 |
_this.scenes[_this.scenes.length - 1].domNode, |
| 65 |
1, |
| 66 |
_this.effect, |
| 67 |
null, |
| 68 |
function(){ |
| 69 |
|
| 70 |
_this.scenes[_this.scenes.length - 1].assistant.activate(params); |
| 71 |
_this._opInProgress = false; |
| 72 |
}); |
| 73 |
} |
| 74 |
}); |
| 75 |
}, |
| 76 |
|
| 77 |
setZIndex: function(controller, idx){ |
| 78 |
dojo.style(controller.domNode, "zIndex", idx + 1); |
| 79 |
}, |
| 80 |
|
| 81 |
popScene: function(data){ |
| 82 |
|
| 83 |
|
| 84 |
if(this._opInProgress){ |
| 85 |
return; |
| 86 |
} |
| 87 |
|
| 88 |
var _this = this; |
| 89 |
if(this.scenes.length > 1){ |
| 90 |
|
| 91 |
this._opInProgress = true; |
| 92 |
this.scenes[_this.scenes.length - 2].assistant.activate(data); |
| 93 |
this.scenes[_this.scenes.length - 1] |
| 94 |
.performTransition( |
| 95 |
_this.scenes[this.scenes.length - 2].domNode, |
| 96 |
-1, |
| 97 |
this.effect, |
| 98 |
null, |
| 99 |
function(){ |
| 100 |
|
| 101 |
_this._destroyScene(_this.scenes[_this.scenes.length - 1]); |
| 102 |
_this.scenes.splice(_this.scenes.length - 1, 1); |
| 103 |
_this._opInProgress = false; |
| 104 |
}); |
| 105 |
}else{ |
| 106 |
console.log("cannot pop the scene if there is just one"); |
| 107 |
} |
| 108 |
}, |
| 109 |
|
| 110 |
popScenesTo: function(sceneName, data){ |
| 111 |
if(this._opInProgress){ |
| 112 |
return; |
| 113 |
} |
| 114 |
|
| 115 |
while(this.scenes.length > 2 && |
| 116 |
this.scenes[this.scenes.length - 2].sceneName != sceneName){ |
| 117 |
this._destroyScene(this.scenes[this.scenes.length - 2]); |
| 118 |
this.scenes.splice(this.scenes.length - 2, 1); |
| 119 |
} |
| 120 |
|
| 121 |
this.popScene(data); |
| 122 |
}, |
| 123 |
|
| 124 |
_destroyScene: function(scene){ |
| 125 |
scene.assistant.deactivate(); |
| 126 |
scene.assistant.destroy(); |
| 127 |
scene.destroyRecursive(); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
}); |
| 132 |
|