source: Dev/trunk/src/client/dojox/app/widgets/_ScrollableMixin.js

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 4.7 KB
Line 
1// This module is modified from dojox/mobile/_ScrollableMixin and dojox/mobile/ScrollableView
2define([
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.parentNode == this.domNode){ // local footer
61                                        this.isLocalFooter = true;
62                                        node.style.bottom = "0px";
63                                }
64                                params.fixedFooterHeight = node.offsetHeight;
65                        }
66                       
67                        this.init(params);
68                        this.inherited(arguments);
69                        this.reparent();
70                },
71
72                // build scrollable container domNode. This method from dojox/mobile/ScrollableView
73                buildRendering: function(){
74                        this.inherited(arguments);
75                        domClass.add(this.domNode, "mblScrollableView");
76                        this.domNode.style.overflow = "hidden";
77                        this.domNode.style.top = "0px";
78                        this.containerNode = domConstruct.create("div", {className:"mblScrollableViewContainer"}, this.domNode);
79                        this.containerNode.style.position = "absolute";
80                        this.containerNode.style.top = "0px"; // view bar is relative
81                        if(this.scrollDir === "v"){
82                                this.containerNode.style.width = "100%";
83                        }
84                },
85
86                // This method from dojox/mobile/ScrollableView
87                reparent: function(){
88                        // summary:
89                        //              Moves all the children to containerNode.
90                        var i, idx, len, c;
91                        for(i = 0, idx = 0, len = this.domNode.childNodes.length; i < len; i++){
92                                c = this.domNode.childNodes[idx];
93                                // search for view-specific header or footer
94                //              if(c === this.containerNode){
95                                if(c === this.containerNode || this.checkFixedBar(c, true)){
96                                        idx++;
97                                        continue;
98                                }
99                                this.containerNode.appendChild(this.domNode.removeChild(c));
100                        }
101                },
102
103                // This method from dojox/mobile/ScrollableView
104                resize: function(){
105                        // summary:
106                        //              Calls resize() of each child widget.
107                        this.inherited(arguments); // scrollable#resize() will be called
108                        array.forEach(this.getChildren(), function(child){
109                                if(child.resize){ child.resize(); }
110                        });
111                },
112
113
114                findAppBars: function(){
115                        // summary:
116                        //              Search for application-specific header or footer.
117                        if(!this.appBars){ return; }
118                        var i, len, c;
119                        for(i = 0, len = win.body().childNodes.length; i < len; i++){
120                                c = win.body().childNodes[i];
121                                this.checkFixedBar(c, false);
122                        }
123                        if(this.domNode.parentNode){
124                                for(i = 0, len = this.domNode.parentNode.childNodes.length; i < len; i++){
125                                        c = this.domNode.parentNode.childNodes[i];
126                                        this.checkFixedBar(c, false);
127                                }
128                        }
129                        this.fixedFooterHeight = this.fixedFooter ? this.fixedFooter.offsetHeight : 0;
130                },
131
132       
133                checkFixedBar: function(/*DomNode*/node, /*Boolean*/local){
134                        // summary:
135                        //              Checks if the given node is a fixed bar or not.
136                        if(node.nodeType === 1){
137                                var fixed = node.getAttribute("data-app-constraint")
138                                        || (registry.byNode(node) && registry.byNode(node)["data-app-constraint"]);
139                        /*      if(fixed === "top"){
140                                        domClass.add(node, "mblFixedHeaderBar");
141                                        if(local){
142                                                node.style.top = "0px";
143                                                this.fixedHeader = node;
144                                        }
145                                        return fixed;
146                                }else
147                        */       
148                                if(fixed === "bottom"){
149                                        domClass.add(node, "mblFixedBottomBar");
150                                        if(local){
151                                                this.fixedFooter = node;
152                                        }else{
153                                                this._fixedAppFooter = node;
154                                        }
155                                        return fixed;
156                                }
157                        }
158                        return null;
159                }
160                       
161        });
162});
Note: See TracBrowser for help on using the repository browser.