source: Dev/trunk/src/client/dojox/mobile/ScrollablePane.js @ 529

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

Added Dojo 1.9.3 release.

File size: 3.4 KB
Line 
1define([
2        "dojo/_base/array",
3        "dojo/_base/declare",
4        "dojo/sniff",
5        "dojo/_base/window",
6        "dojo/dom",
7        "dojo/dom-construct",
8        "dojo/dom-style",
9        "./_ScrollableMixin",
10        "./Pane",
11        "./_maskUtils"
12], function(array, declare, has, win, dom, domConstruct, domStyle, ScrollableMixin, Pane, maskUtils){
13
14        // module:
15        //              dojox/mobile/ScrollablePane
16
17        return declare("dojox.mobile.ScrollablePane", [Pane, ScrollableMixin], {
18                // summary:
19                //              A pane that has the touch-scrolling capability.
20
21                // roundCornerMask: Boolean
22                //              If true, creates a rounded corner mask to clip corners of a
23                //              child widget or DOM node. Works only on WebKit-based browsers.
24                roundCornerMask: false,
25
26                // radius: Number
27                //              Radius of the rounded corner mask.
28                radius: 0,
29
30                // baseClass: String
31                //              The name of the CSS class of this widget.
32                baseClass: "mblScrollablePane",
33
34                buildRendering: function(){
35                        var c = this.containerNode = domConstruct.create("div", {
36                                className: "mblScrollableViewContainer",
37                                style: {
38                                        width: this.scrollDir === "v" ? "100%" : ""
39                                }
40                        });
41                        this.inherited(arguments);
42
43                        if(this.srcNodeRef){
44                                // reparent
45                                for(var i = 0, len = this.srcNodeRef.childNodes.length; i < len; i++){
46                                        this.containerNode.appendChild(this.srcNodeRef.firstChild);
47                                }
48                        }
49
50                        if(this.roundCornerMask && (has("webkit")||has("svg"))){
51                                var node = this.containerNode;
52                                var mask = this.maskNode = domConstruct.create("div", {
53                                        className: "mblScrollablePaneMask"
54                                });
55                                mask.appendChild(node);
56                                c = mask;
57                        }
58
59                        this.domNode.appendChild(c);
60                        dom.setSelectable(this.containerNode, false);
61                },
62
63                resize: function(){
64                        // summary:
65                        //              Calls resize() of each child widget.
66                        this.inherited(arguments); // scrollable#resize() will be called
67                        if(this.roundCornerMask){
68                                this.createRoundMask();
69                        }
70                        array.forEach(this.getChildren(), function(child){
71                                if(child.resize){ child.resize(); }
72                        });
73                },
74
75                isTopLevel: function(e){
76                        // summary:
77                        //              Returns true if this is a top-level widget.
78                        //              Overrides dojox/mobile/scrollable.
79                        var parent = this.getParent && this.getParent();
80                        return (!parent || !parent.resize); // top level widget
81                },
82
83                createRoundMask: function(){
84                        // summary:
85                        //              Creates a rounded corner rectangle mask.
86                        // description:
87                        //              Creates a rounded corner rectangle mask.
88                        //              This function works only on WebKit-based browsers.
89                        if(has("webkit")||has("svg")){
90                                if(this.domNode.offsetHeight == 0){ return; } // in a hidden view
91                                this.maskNode.style.height = this.domNode.offsetHeight + "px";
92                                var child = this.getChildren()[0],
93                                        c = this.containerNode,
94                                        node = child ? child.domNode :
95                                                (c.childNodes.length > 0 && (c.childNodes[0].nodeType === 1 ? c.childNodes[0] : c.childNodes[1]));
96
97                                var r = this.radius;
98                                if(!r){
99                                        var getRadius = function(n){ return parseInt(domStyle.get(n, "borderTopLeftRadius")); };
100                                        if(child){
101                                                r = getRadius(child.domNode);
102                                                if(!r){
103                                                        var item = child.getChildren()[0];
104                                                        r = item ? getRadius(item.domNode) : 0;
105                                                }
106                                        }else{
107                                                r = getRadius(node);
108                                        }
109                                }
110
111                                var pw = this.domNode.offsetWidth, // pane width
112                                        w = node.offsetWidth,
113                                        h = this.domNode.offsetHeight,
114                                        t = domStyle.get(node, "marginTop"),
115                                        b = domStyle.get(node, "marginBottom"),
116                                        l = domStyle.get(node, "marginLeft");
117                               
118                                maskUtils.createRoundMask(this.maskNode, l, t, 0, b, w, h - b - t, r, r);
119                        }
120                }
121        });
122});
Note: See TracBrowser for help on using the repository browser.