| 1 |
|
| 2 |
define([ |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/_base/array", |
| 6 |
"dojo/_base/window", |
| 7 |
"dojo/dom-class", |
| 8 |
"dijit/registry", |
| 9 |
"dojo/dom", |
| 10 |
"dojo/dom-construct", |
| 11 |
"dojox/mobile/scrollable"], |
| 12 |
function(declare, lang, array, win, domClass, registry, dom, domConstruct, Scrollable){ |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
return declare("dojox.app.widgets._ScrollableMixin", Scrollable, { |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
scrollableParams: null, |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
appBars: true, |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
allowNestedScrolls: true, |
| 37 |
|
| 38 |
constructor: function(){ |
| 39 |
this.scrollableParams = {noResize: true}; |
| 40 |
}, |
| 41 |
|
| 42 |
destroy: function(){ |
| 43 |
this.cleanup(); |
| 44 |
this.inherited(arguments); |
| 45 |
}, |
| 46 |
|
| 47 |
startup: function(){ |
| 48 |
if(this._started){ return; } |
| 49 |
this.findAppBars(); |
| 50 |
var node, params = this.scrollableParams; |
| 51 |
if(this.fixedHeader){ |
| 52 |
node = dom.byId(this.fixedHeader); |
| 53 |
if(node.parentNode == this.domNode){ |
| 54 |
this.isLocalHeader = true; |
| 55 |
} |
| 56 |
params.fixedHeaderHeight = node.offsetHeight; |
| 57 |
} |
| 58 |
if(this.fixedFooter){ |
| 59 |
node = dom.byId(this.fixedFooter); |
| 60 |
if(node){ |
| 61 |
if(node.parentNode == this.domNode){ |
| 62 |
this.isLocalFooter = true; |
| 63 |
node.style.bottom = "0px"; |
| 64 |
} |
| 65 |
params.fixedFooterHeight = node.offsetHeight; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
this.init(params); |
| 70 |
this.inherited(arguments); |
| 71 |
this.reparent(); |
| 72 |
}, |
| 73 |
|
| 74 |
|
| 75 |
buildRendering: function(){ |
| 76 |
this.inherited(arguments); |
| 77 |
domClass.add(this.domNode, "mblScrollableView"); |
| 78 |
this.domNode.style.overflow = "hidden"; |
| 79 |
this.domNode.style.top = "0px"; |
| 80 |
this.containerNode = domConstruct.create("div", {className:"mblScrollableViewContainer"}, this.domNode); |
| 81 |
this.containerNode.style.position = "absolute"; |
| 82 |
this.containerNode.style.top = "0px"; |
| 83 |
if(this.scrollDir === "v"){ |
| 84 |
this.containerNode.style.width = "100%"; |
| 85 |
} |
| 86 |
}, |
| 87 |
|
| 88 |
|
| 89 |
reparent: function(){ |
| 90 |
|
| 91 |
|
| 92 |
var i, idx, len, c; |
| 93 |
for(i = 0, idx = 0, len = this.domNode.childNodes.length; i < len; i++){ |
| 94 |
c = this.domNode.childNodes[idx]; |
| 95 |
|
| 96 |
|
| 97 |
if(c === this.containerNode || this.checkFixedBar(c, true)){ |
| 98 |
idx++; |
| 99 |
continue; |
| 100 |
} |
| 101 |
this.containerNode.appendChild(this.domNode.removeChild(c)); |
| 102 |
} |
| 103 |
}, |
| 104 |
|
| 105 |
|
| 106 |
resize: function(){ |
| 107 |
|
| 108 |
|
| 109 |
this.inherited(arguments); |
| 110 |
array.forEach(this.getChildren(), function(child){ |
| 111 |
if(child.resize){ child.resize(); } |
| 112 |
}); |
| 113 |
}, |
| 114 |
|
| 115 |
|
| 116 |
findAppBars: function(){ |
| 117 |
|
| 118 |
|
| 119 |
if(!this.appBars){ return; } |
| 120 |
var i, len, c; |
| 121 |
for(i = 0, len = win.body().childNodes.length; i < len; i++){ |
| 122 |
c = win.body().childNodes[i]; |
| 123 |
this.checkFixedBar(c, false); |
| 124 |
} |
| 125 |
if(this.domNode.parentNode){ |
| 126 |
for(i = 0, len = this.domNode.parentNode.childNodes.length; i < len; i++){ |
| 127 |
c = this.domNode.parentNode.childNodes[i]; |
| 128 |
this.checkFixedBar(c, false); |
| 129 |
} |
| 130 |
} |
| 131 |
this.fixedFooterHeight = this.fixedFooter ? this.fixedFooter.offsetHeight : 0; |
| 132 |
}, |
| 133 |
|
| 134 |
|
| 135 |
checkFixedBar: function(node, local){ |
| 136 |
|
| 137 |
|
| 138 |
if(node.nodeType === 1){ |
| 139 |
var fixed = node.getAttribute("data-app-constraint") |
| 140 |
|| (registry.byNode(node) && registry.byNode(node)["data-app-constraint"]); |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
if(fixed === "bottom"){ |
| 151 |
domClass.add(node, "mblFixedBottomBar"); |
| 152 |
if(local){ |
| 153 |
this.fixedFooter = node; |
| 154 |
}else{ |
| 155 |
this._fixedAppFooter = node; |
| 156 |
} |
| 157 |
return fixed; |
| 158 |
} |
| 159 |
} |
| 160 |
return null; |
| 161 |
} |
| 162 |
|
| 163 |
}); |
| 164 |
}); |