Debian Codegraph @

dojox/mobile/FixedSplitter.js

raw symbols SCIP
1 define([
2 "dojo/_base/array",
3 "dojo/_base/declare",
4 "dojo/_base/window",
5 "dojo/dom-class",
6 "dojo/dom-geometry",
7 "dijit/_Contained",
8 "dijit/_Container",
9 "dijit/_WidgetBase",
10 "dojo/has",
11 "./common" // to ensure proper relayout when resizing/switching orientation (#18684)
12 ], function(array, declare, win, domClass, domGeometry, Contained, Container, WidgetBase, has){
13
14 // module:
15 // dojox/mobile/FixedSplitter
16
17 return declare("dojox.mobile.FixedSplitter", [WidgetBase, Container, Contained], {
18 // summary:
19 // A layout container that splits the window horizontally or
20 // vertically.
21 // description:
22 // FixedSplitter is a very simple container widget that layouts its
23 // child DOM nodes side by side either horizontally or
24 // vertically. An example usage of this widget would be to realize
25 // the split view on iPad. There is no visual splitter between the
26 // children, and there is no function to resize the child panes
27 // with drag-and-drop. If you need a visual splitter, you can
28 // specify a border of a child DOM node with CSS.
29 //
30 // FixedSplitter has no knowledge of its child widgets.
31 // dojox/mobile/Container, dojox/mobile/Pane, or dojox/mobile/ContentPane
32 // can be used as a child widget of FixedSplitter.
33 //
34 // - Use dojox/mobile/Container if your content consists of ONLY
35 // Dojo widgets.
36 // - Use dojox/mobile/Pane if your content is an inline HTML
37 // fragment (may or may not include Dojo widgets).
38 // - Use dojox/mobile/ContentPane if your content is an external
39 // HTML fragment (may or may not include Dojo widgets).
40 //
41 // example:
42 // | <div data-dojo-type="dojox.mobile.FixedSplitter" orientation="H">
43 // | <div data-dojo-type="dojox.mobile.Pane"
44 // | style="width:200px;border-right:1px solid black;">
45 // | pane #1 (width=200px)
46 // | </div>
47 // | <div data-dojo-type="dojox.mobile.Pane">
48 // | pane #2
49 // | </div>
50 // | </div>
51
52 // orientation: String
53 // The direction of split. If "H" is specified, panes are split
54 // horizontally. If "V" is specified, panes are split vertically.
55 orientation: "H",
56
57 // variablePane: Number
58 // The index of a pane that fills the remainig space.
59 // If -1, the last child pane fills the remaining space.
60 variablePane: -1,
61
62 // screenSizeAware: Boolean
63 // If true, dynamically load a screen-size-aware module.
64 screenSizeAware: false,
65
66 // screenSizeAwareClass: String
67 // A screen-size-aware module to load.
68 screenSizeAwareClass: "dojox/mobile/ScreenSizeAware",
69
70 /* internal properties */
71
72 // baseClass: String
73 // The name of the CSS class of this widget.
74 baseClass: "mblFixedSplitter",
75
76 startup: function(){
77 if(this._started){ return; }
78 domClass.add(this.domNode, this.baseClass + this.orientation);
79
80 var parent = this.getParent(), f;
81 if(!parent || !parent.resize){ // top level widget
82 var _this = this;
83 f = function(){
84 _this.defer(function(){
85 _this.resize();
86 });
87 };
88 }
89
90 if(this.screenSizeAware){
91 require([this.screenSizeAwareClass], function(module){
92 module.getInstance();
93 f && f();
94 });
95 }else{
96 f && f();
97 }
98
99 this.inherited(arguments);
100 },
101
102 resize: function(){
103 var paddingTop = domGeometry.getPadExtents(this.domNode).t;
104 var wh = this.orientation === "H" ? "w" : "h", // width/height
105 tl = this.orientation === "H" ? "l" : "t", // top/left
106 props1 = {}, props2 = {},
107 i, c, h,
108 a = [], offset = 0, total = 0,
109 children = array.filter(this.domNode.childNodes, function(node){ return node.nodeType == 1; }),
110 idx = this.variablePane == -1 ? children.length - 1 : this.variablePane;
111 for(i = 0; i < children.length; i++){
112 if(i != idx){
113 a[i] = domGeometry.getMarginBox(children[i])[wh];
114 total += a[i];
115 }
116 }
117
118 if(this.orientation == "V"){
119 if(this.domNode.parentNode.tagName == "BODY"){
120 if(array.filter(win.body().childNodes, function(node){ return node.nodeType == 1; }).length == 1){
121 h = (win.global.innerHeight||win.doc.documentElement.clientHeight);
122 }
123 }
124 }
125 var l = (h || domGeometry.getMarginBox(this.domNode)[wh]) - total;
126 if(this.orientation === "V"){
127 l -= paddingTop;
128 }
129 props2[wh] = a[idx] = l;
130 c = children[idx];
131 domGeometry.setMarginBox(c, props2);
132 c.style[this.orientation === "H" ? "height" : "width"] = "";
133 // dojox.mobile mirroring support
134 if(has("dojo-bidi") && (this.orientation=="H" && !this.isLeftToRight())){
135 offset = l;
136 for(i = children.length - 1; i >= 0; i--){
137 c = children[i];
138 props1[tl] = l - offset;
139 domGeometry.setMarginBox(c, props1);
140 if(this.orientation === "H"){
141 c.style.top = paddingTop +"px";
142 }else{
143 c.style.left = "";
144 }
145 offset -= a[i];
146 }
147 }else{
148 if(this.orientation === "V"){
149 offset = offset ? offset + paddingTop : paddingTop;
150 }
151
152 for(i = 0; i < children.length; i++){
153 c = children[i];
154 props1[tl] = offset;
155
156 domGeometry.setMarginBox(c, props1);
157 if(this.orientation === "H"){
158 c.style.top = paddingTop +"px";
159 }else{
160 c.style.left = "";
161 }
162 offset += a[i];
163 }
164 }
165
166 array.forEach(this.getChildren(), function(child){
167 if(child.resize){ child.resize(); }
168 });
169 },
170
171 _setOrientationAttr: function(/*String*/orientation){
172 // summary:
173 // Sets the direction of split.
174 // description:
175 // The value must be either "H" or "V".
176 // If "H" is specified, panes are split horizontally.
177 // If "V" is specified, panes are split vertically.
178 // tags:
179 // private
180 var s = this.baseClass;
181 domClass.replace(this.domNode, s + orientation, s + this.orientation);
182 this.orientation = orientation;
183 if(this._started){
184 this.resize();
185 }
186 }
187 });
188 });