1 | define([ |
---|
2 | "dojo/_base/array", |
---|
3 | "dojo/_base/declare", |
---|
4 | "dojo/dom-class", |
---|
5 | "dojo/dom-construct", |
---|
6 | "dijit/registry", // registry.byNode |
---|
7 | "./View", |
---|
8 | "./_ScrollableMixin" |
---|
9 | ], function(array, declare, domClass, domConstruct, registry, View, ScrollableMixin){ |
---|
10 | |
---|
11 | /*===== |
---|
12 | var View = dojox.mobile.View; |
---|
13 | var ScrollableMixin = dojox.mobile._ScrollableMixin; |
---|
14 | =====*/ |
---|
15 | |
---|
16 | // module: |
---|
17 | // dojox/mobile/ScrollableView |
---|
18 | // summary: |
---|
19 | // A container that has a touch scrolling capability. |
---|
20 | |
---|
21 | return declare("dojox.mobile.ScrollableView", [View, ScrollableMixin], { |
---|
22 | // summary: |
---|
23 | // A container that has a touch scrolling capability. |
---|
24 | // description: |
---|
25 | // ScrollableView is a subclass of View (=dojox.mobile.View). |
---|
26 | // Unlike the base View class, ScrollableView's domNode always stays |
---|
27 | // at the top of the screen and its height is "100%" of the screen. |
---|
28 | // In this fixed domNode, containerNode scrolls. Browser's default |
---|
29 | // scrolling behavior is disabled, and the scrolling machinery is |
---|
30 | // re-implemented with JavaScript. Thus the user does not need to use the |
---|
31 | // two-finger operation to scroll an inner DIV (containerNode). |
---|
32 | // The main purpose of this widget is to realize fixed-positioned header |
---|
33 | // and/or footer bars. |
---|
34 | |
---|
35 | // scrollableParams: Object |
---|
36 | // Parameters for dojox.mobile.scrollable.init(). |
---|
37 | scrollableParams: null, |
---|
38 | |
---|
39 | // keepScrollPos: Boolean |
---|
40 | // Overrides dojox.mobile.View.keepScrollPos. |
---|
41 | keepScrollPos: false, |
---|
42 | |
---|
43 | constructor: function(){ |
---|
44 | this.scrollableParams = {noResize: true}; |
---|
45 | }, |
---|
46 | |
---|
47 | buildRendering: function(){ |
---|
48 | this.inherited(arguments); |
---|
49 | domClass.add(this.domNode, "mblScrollableView"); |
---|
50 | this.domNode.style.overflow = "hidden"; |
---|
51 | this.domNode.style.top = "0px"; |
---|
52 | this.containerNode = domConstruct.create("DIV", |
---|
53 | {className:"mblScrollableViewContainer"}, this.domNode); |
---|
54 | this.containerNode.style.position = "absolute"; |
---|
55 | this.containerNode.style.top = "0px"; // view bar is relative |
---|
56 | if(this.scrollDir === "v"){ |
---|
57 | this.containerNode.style.width = "100%"; |
---|
58 | } |
---|
59 | this.reparent(); |
---|
60 | this.findAppBars(); |
---|
61 | }, |
---|
62 | |
---|
63 | resize: function(){ |
---|
64 | // summary: |
---|
65 | // Calls resize() of each child widget. |
---|
66 | this.inherited(arguments); // scrollable#resize() will be called |
---|
67 | array.forEach(this.getChildren(), function(child){ |
---|
68 | if(child.resize){ child.resize(); } |
---|
69 | }); |
---|
70 | }, |
---|
71 | |
---|
72 | isTopLevel: function(e){ |
---|
73 | // summary: |
---|
74 | // Returns true if this is a top-level widget. |
---|
75 | // Overrides dojox.mobile.scrollable. |
---|
76 | var parent = this.getParent && this.getParent(); |
---|
77 | return (!parent || !parent.resize); // top level widget |
---|
78 | }, |
---|
79 | |
---|
80 | addChild: function(widget, /*Number?*/insertIndex){ |
---|
81 | var c = widget.domNode; |
---|
82 | var fixed = this.checkFixedBar(c, true); |
---|
83 | if(fixed){ |
---|
84 | // Addition of a fixed bar is an exceptional case. |
---|
85 | // It has to be added to domNode, not containerNode. |
---|
86 | // In this case, insertIndex is ignored. |
---|
87 | this.domNode.appendChild(c); |
---|
88 | if(fixed === "top"){ |
---|
89 | this.fixedHeaderHeight = c.offsetHeight; |
---|
90 | this.isLocalHeader = true; |
---|
91 | }else if(fixed === "bottom"){ |
---|
92 | this.fixedFooterHeight = c.offsetHeight; |
---|
93 | this.isLocalFooter = true; |
---|
94 | c.style.bottom = "0px"; |
---|
95 | } |
---|
96 | this.resize(); |
---|
97 | if(this._started && !widget._started){ |
---|
98 | widget.startup(); |
---|
99 | } |
---|
100 | }else{ |
---|
101 | this.inherited(arguments); |
---|
102 | } |
---|
103 | }, |
---|
104 | |
---|
105 | reparent: function(){ |
---|
106 | // summary: |
---|
107 | // Moves all the children, except header and footer, to |
---|
108 | // containerNode. |
---|
109 | var i, idx, len, c; |
---|
110 | for(i = 0, idx = 0, len = this.domNode.childNodes.length; i < len; i++){ |
---|
111 | c = this.domNode.childNodes[idx]; |
---|
112 | // search for view-specific header or footer |
---|
113 | if(c === this.containerNode || this.checkFixedBar(c, true)){ |
---|
114 | idx++; |
---|
115 | continue; |
---|
116 | } |
---|
117 | this.containerNode.appendChild(this.domNode.removeChild(c)); |
---|
118 | } |
---|
119 | }, |
---|
120 | |
---|
121 | onAfterTransitionIn: function(moveTo, dir, transition, context, method){ |
---|
122 | this.flashScrollBar(); |
---|
123 | }, |
---|
124 | |
---|
125 | getChildren: function(){ |
---|
126 | // summary: |
---|
127 | // Overrides _WidgetBase#getChildren to add local fixed bars, |
---|
128 | // which are not under containerNode, to the children array. |
---|
129 | var children = this.inherited(arguments); |
---|
130 | if(this.fixedHeader && this.fixedHeader.parentNode === this.domNode){ |
---|
131 | children.push(registry.byNode(this.fixedHeader)); |
---|
132 | } |
---|
133 | if(this.fixedFooter && this.fixedFooter.parentNode === this.domNode){ |
---|
134 | children.push(registry.byNode(this.fixedFooter)); |
---|
135 | } |
---|
136 | return children; |
---|
137 | } |
---|
138 | }); |
---|
139 | }); |
---|