Debian Codegraph @

dojox/mobile/ScrollablePane.js

raw symbols SCIP
1 define([
2 "dojo/_base/array",
3 "dojo/_base/declare",
4 "dojo/sniff",
5 "dojo/_base/window",
6 "dojo/dom-construct",
7 "dojo/dom-style",
8 "./common",
9 "./_ScrollableMixin",
10 "./Pane",
11 "./_maskUtils"
12 ], function(array, declare, has, win, domConstruct, domStyle, common, 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("mask-image"))){
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 common.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("mask-image")){
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 });