| 1 |
define(["dojo/_base/lang", "dojo/_base/declare", "dojo/sniff", "dojo/_base/window", "dojo/_base/config", |
| 2 |
"dojo/dom-attr", "dojo/topic", "dojo/dom-style", "../utils/constraints", "../Controller"], |
| 3 |
function(lang, declare, has, win, config, domAttr, topic, domStyle, constraints, Controller){ |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
return declare("dojox.app.controllers.LayoutBase", Controller, { |
| 10 |
|
| 11 |
constructor: function(app, events){ |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
this.events = { |
| 20 |
"app-initLayout": this.initLayout, |
| 21 |
"app-layoutView": this.layoutView, |
| 22 |
"app-resize": this.onResize |
| 23 |
}; |
| 24 |
|
| 25 |
|
| 26 |
if(config.mblHideAddressBar){ |
| 27 |
topic.subscribe("/dojox/mobile/afterResizeAll", lang.hitch(this, this.onResize)); |
| 28 |
}else{ |
| 29 |
|
| 30 |
this.bind(win.global, has("ios") ? "orientationchange" : "resize", lang.hitch(this, this.onResize)); |
| 31 |
} |
| 32 |
}, |
| 33 |
|
| 34 |
onResize: function(){ |
| 35 |
this._doResize(this.app); |
| 36 |
|
| 37 |
|
| 38 |
for(var hash in this.app.selectedChildren){ |
| 39 |
if(this.app.selectedChildren[hash]){ |
| 40 |
this._doResize(this.app.selectedChildren[hash]); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
}, |
| 45 |
|
| 46 |
initLayout: function(event){ |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
domAttr.set(event.view.domNode, "id", event.view.id); |
| 57 |
if(event.callback){ |
| 58 |
event.callback(); |
| 59 |
} |
| 60 |
}, |
| 61 |
|
| 62 |
_doLayout: function(view){ |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
if(!view){ |
| 70 |
console.warn("layout empty view."); |
| 71 |
} |
| 72 |
}, |
| 73 |
|
| 74 |
_doResize: function(view){ |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
this.app.log("in LayoutBase _doResize called for view.id="+view.id+" view=",view); |
| 81 |
this._doLayout(view); |
| 82 |
}, |
| 83 |
|
| 84 |
layoutView: function(event){ |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
var parent = event.parent || this.app; |
| 95 |
var view = event.view; |
| 96 |
|
| 97 |
if(!view){ |
| 98 |
return; |
| 99 |
} |
| 100 |
|
| 101 |
this.app.log("in LayoutBase layoutView called for event.view.id="+event.view.id); |
| 102 |
|
| 103 |
|
| 104 |
var parentSelChild = constraints.getSelectedChild(parent, view.constraint); |
| 105 |
if(event.removeView){ |
| 106 |
view.viewShowing = false; |
| 107 |
this.hideView(view); |
| 108 |
if(view == parentSelChild){ |
| 109 |
constraints.setSelectedChild(parent, view.constraint, null); |
| 110 |
} |
| 111 |
}else if(view !== parentSelChild){ |
| 112 |
if(parentSelChild){ |
| 113 |
|
| 114 |
parentSelChild.viewShowing = false; |
| 115 |
if(event.transition == "none" || event.currentLastSubChildMatch !== parentSelChild){ |
| 116 |
this.hideView(parentSelChild); |
| 117 |
} |
| 118 |
} |
| 119 |
view.viewShowing = true; |
| 120 |
this.showView(view); |
| 121 |
|
| 122 |
constraints.setSelectedChild(parent, view.constraint, view); |
| 123 |
}else{ |
| 124 |
view.viewShowing = true; |
| 125 |
} |
| 126 |
}, |
| 127 |
|
| 128 |
hideView: function(view){ |
| 129 |
this.app.log("logTransitions:","LayoutBase"+" setting domStyle display none for view.id=["+view.id+"], visibility=["+view.domNode.style.visibility+"]"); |
| 130 |
domStyle.set(view.domNode, "display", "none"); |
| 131 |
}, |
| 132 |
|
| 133 |
showView: function(view){ |
| 134 |
if(view.domNode){ |
| 135 |
this.app.log("logTransitions:","LayoutBase"+" setting domStyle display to display for view.id=["+view.id+"], visibility=["+view.domNode.style.visibility+"]"); |
| 136 |
domStyle.set(view.domNode, "display", ""); |
| 137 |
} |
| 138 |
} |
| 139 |
}); |
| 140 |
}); |