Debian Codegraph @

dojox/app/widgets/_ScrollableMixin.js

raw symbols SCIP
1 // This module is modified from dojox/mobile/_ScrollableMixin and dojox/mobile/ScrollableView
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 // module:
14 // dojox/mobile/_ScrollableMixin
15 // summary:
16 // Mixin for widgets to have a touch scrolling capability.
17
18 return declare("dojox.app.widgets._ScrollableMixin", Scrollable, {
19 // summary:
20 // Mixin for widgets to have a touch scrolling capability.
21 // description:
22 // Actual implementation is in dojox/mobile/scrollable.js.
23 // scrollable.js is not a dojo class, but just a collection
24 // of functions. This module makes scrollable.js a dojo class.
25
26 // scrollableParams: Object
27 // Parameters for dojox/mobile/scrollable.init().
28 scrollableParams: null,
29
30 // appBars: Boolean
31 // Enables the search for application-specific bars (header or footer).
32 appBars: true,
33
34 // allowNestedScrolls: Boolean
35 // e.g. Allow ScrollableView in a SwapView.
36 allowNestedScrolls: true,
37
38 constructor: function(){
39 this.scrollableParams = {noResize: true}; // set noResize to true to match the way it was done in app/widgets/scrollable.js
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){ // local footer
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){ // local footer
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 // build scrollable container domNode. This method from dojox/mobile/ScrollableView
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"; // view bar is relative
83 if(this.scrollDir === "v"){
84 this.containerNode.style.width = "100%";
85 }
86 },
87
88 // This method from dojox/mobile/ScrollableView
89 reparent: function(){
90 // summary:
91 // Moves all the children to containerNode.
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 // search for view-specific header or footer
96 // if(c === this.containerNode){
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 // This method from dojox/mobile/ScrollableView
106 resize: function(){
107 // summary:
108 // Calls resize() of each child widget.
109 this.inherited(arguments); // scrollable#resize() will be called
110 array.forEach(this.getChildren(), function(child){
111 if(child.resize){ child.resize(); }
112 });
113 },
114
115
116 findAppBars: function(){
117 // summary:
118 // Search for application-specific header or footer.
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(/*DomNode*/node, /*Boolean*/local){
136 // summary:
137 // Checks if the given node is a fixed bar or not.
138 if(node.nodeType === 1){
139 var fixed = node.getAttribute("data-app-constraint")
140 || (registry.byNode(node) && registry.byNode(node)["data-app-constraint"]);
141 /* if(fixed === "top"){
142 domClass.add(node, "mblFixedHeaderBar");
143 if(local){
144 node.style.top = "0px";
145 this.fixedHeader = node;
146 }
147 return fixed;
148 }else
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 });