source: Dev/branches/rest-dojo-ui/client/dojox/mobile/_ScrollableMixin.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 3.2 KB
Line 
1define([
2        "dojo/_base/kernel",
3        "dojo/_base/declare",
4        "dojo/_base/lang",
5        "dojo/_base/window",
6        "dojo/dom",
7        "dojo/dom-class",
8        "dijit/registry",       // registry.byNode
9        "./scrollable"
10], function(dojo, declare, lang, win, dom, domClass, registry, Scrollable){
11        // module:
12        //              dojox/mobile/_ScrollableMixin
13        // summary:
14        //              Mixin for widgets to have a touch scrolling capability.
15
16        var cls = declare("dojox.mobile._ScrollableMixin", null, {
17                // summary:
18                //              Mixin for widgets to have a touch scrolling capability.
19                // description:
20                //              Actual implementation is in scrollable.js.
21                //              scrollable.js is not a dojo class, but just a collection
22                //              of functions. This module makes scrollable.js a dojo class.
23
24                // fixedHeader: String
25                //              Id of the fixed header.
26                fixedHeader: "",
27
28                // fixedFooter: String
29                //              Id of the fixed footer.
30                fixedFooter: "",
31
32                // scrollableParams: Object
33                //              Parameters for dojox.mobile.scrollable.init().
34                scrollableParams: null,
35
36                // allowNestedScrolls: Boolean
37                //              e.g. Allow ScrollableView in a SwapView.
38                allowNestedScrolls: true,
39
40                constructor: function(){
41                        this.scrollableParams = {};
42                },
43
44                destroy: function(){
45                        this.cleanup();
46                        this.inherited(arguments);
47                },
48
49                startup: function(){
50                        if(this._started){ return; }
51                        var node;
52                        var params = this.scrollableParams;
53                        if(this.fixedHeader){
54                                node = dom.byId(this.fixedHeader);
55                                if(node.parentNode == this.domNode){ // local footer
56                                        this.isLocalHeader = true;
57                                }
58                                params.fixedHeaderHeight = node.offsetHeight;
59                        }
60                        if(this.fixedFooter){
61                                node = dom.byId(this.fixedFooter);
62                                if(node.parentNode == this.domNode){ // local footer
63                                        this.isLocalFooter = true;
64                                        node.style.bottom = "0px";
65                                }
66                                params.fixedFooterHeight = node.offsetHeight;
67                        }
68                        this.init(params);
69                        if(this.allowNestedScrolls){
70                                for(var p = this.getParent(); p; p = p.getParent()){
71                                        if(p && p.scrollableParams){
72                                                this.isNested = true;
73                                                this.dirLock = true;
74                                                p.dirLock = true;
75                                                break;
76                                        }
77                                }
78                        }
79                        this.inherited(arguments);
80                },
81
82                findAppBars: function(){
83                        // summary:
84                        //              Search for application-specific header or footer.
85                        var i, len, c;
86                        for(i = 0, len = win.body().childNodes.length; i < len; i++){
87                                c = win.body().childNodes[i];
88                                this.checkFixedBar(c, false);
89                        }
90                        if(this.domNode.parentNode){
91                                for(i = 0, len = this.domNode.parentNode.childNodes.length; i < len; i++){
92                                        c = this.domNode.parentNode.childNodes[i];
93                                        this.checkFixedBar(c, false);
94                                }
95                        }
96                        this.fixedFooterHeight = this.fixedFooter ? this.fixedFooter.offsetHeight : 0;
97                },
98
99                checkFixedBar: function(/*DomNode*/node, /*Boolean*/local){
100                        // summary:
101                        //              Checks if the given node is a fixed bar or not.
102                        if(node.nodeType === 1){
103                                var fixed = node.getAttribute("fixed")
104                                        || (registry.byNode(node) && registry.byNode(node).fixed);
105                                if(fixed === "top"){
106                                        domClass.add(node, "mblFixedHeaderBar");
107                                        if(local){
108                                                node.style.top = "0px";
109                                                this.fixedHeader = node;
110                                        }
111                                        return fixed;
112                                }else if(fixed === "bottom"){
113                                        domClass.add(node, "mblFixedBottomBar");
114                                        this.fixedFooter = node;
115                                        return fixed;
116                                }
117                        }
118                        return null;
119                }
120        });
121        lang.extend(cls, new Scrollable(dojo, dojox));
122        return cls;
123});
Note: See TracBrowser for help on using the repository browser.