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 | "./FixedSplitterPane" |
---|
11 | ], function(array, declare, win, domClass, domGeometry, Contained, Container, WidgetBase, FixedSplitterPane){ |
---|
12 | |
---|
13 | /*===== |
---|
14 | var Contained = dijit._Contained; |
---|
15 | var Container = dijit._Container; |
---|
16 | var WidgetBase = dijit._WidgetBase; |
---|
17 | =====*/ |
---|
18 | |
---|
19 | // module: |
---|
20 | // dojox/mobile/FixedSplitter |
---|
21 | // summary: |
---|
22 | // A layout container that splits the window horizontally or vertically. |
---|
23 | |
---|
24 | return declare("dojox.mobile.FixedSplitter", [WidgetBase, Container, Contained], { |
---|
25 | // summary: |
---|
26 | // A layout container that splits the window horizontally or |
---|
27 | // vertically. |
---|
28 | // description: |
---|
29 | // FixedSplitter is a very simple container widget that layouts its |
---|
30 | // child dom nodes side by side either horizontally or |
---|
31 | // vertically. An example usage of this widget would be to realize |
---|
32 | // the split view on iPad. There is no visual splitter between the |
---|
33 | // children, and there is no function to resize the child panes |
---|
34 | // with drag-and-drop. If you need a visual splitter, you can |
---|
35 | // specify a border of a child dom node with CSS. |
---|
36 | // A child of the widget should be FixedSplitterPane. |
---|
37 | // |
---|
38 | // example: |
---|
39 | // | <div dojoType="dojox.mobile.FixedSplitter" orientation="H"> |
---|
40 | // | <div dojoType="dojox.mobile.FixedSplitterPane" |
---|
41 | // | style="width:200px;border-right:1px solid black;"> |
---|
42 | // | pane #1 (width=200px) |
---|
43 | // | </div> |
---|
44 | // | <div dojoType="dojox.mobile.FixedSplitterPane"> |
---|
45 | // | pane #2 |
---|
46 | // | </div> |
---|
47 | // | </div> |
---|
48 | |
---|
49 | // orientation: String |
---|
50 | // The direction of split. If "H" is specified, panes are split |
---|
51 | // horizontally. If "V" is specified, panes are split vertically. |
---|
52 | orientation: "H", |
---|
53 | |
---|
54 | |
---|
55 | buildRendering: function(){ |
---|
56 | this.domNode = this.containerNode = this.srcNodeRef ? this.srcNodeRef : win.doc.createElement("DIV"); |
---|
57 | domClass.add(this.domNode, "mblFixedSpliter"); |
---|
58 | }, |
---|
59 | |
---|
60 | startup: function(){ |
---|
61 | if(this._started){ return; } |
---|
62 | var children = array.filter(this.domNode.childNodes, function(node){ return node.nodeType == 1; }); |
---|
63 | array.forEach(children, function(node){ |
---|
64 | domClass.add(node, "mblFixedSplitterPane"+this.orientation); |
---|
65 | }, this); |
---|
66 | this.inherited(arguments); |
---|
67 | |
---|
68 | var _this = this; |
---|
69 | setTimeout(function(){ |
---|
70 | var parent = _this.getParent && _this.getParent(); |
---|
71 | if(!parent || !parent.resize){ // top level widget |
---|
72 | _this.resize(); |
---|
73 | } |
---|
74 | }, 0); |
---|
75 | }, |
---|
76 | |
---|
77 | resize: function(){ |
---|
78 | this.layout(); |
---|
79 | }, |
---|
80 | |
---|
81 | layout: function(){ |
---|
82 | var sz = this.orientation == "H" ? "w" : "h"; |
---|
83 | var children = array.filter(this.domNode.childNodes, function(node){ return node.nodeType == 1; }); |
---|
84 | var offset = 0; |
---|
85 | for(var i = 0; i < children.length; i++){ |
---|
86 | domGeometry.setMarginBox(children[i], this.orientation == "H" ? {l:offset} : {t:offset}); |
---|
87 | if(i < children.length - 1){ |
---|
88 | offset += domGeometry.getMarginBox(children[i])[sz]; |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | var h; |
---|
93 | if(this.orientation == "V"){ |
---|
94 | if(this.domNode.parentNode.tagName == "BODY"){ |
---|
95 | if(array.filter(win.body().childNodes, function(node){ return node.nodeType == 1; }).length == 1){ |
---|
96 | h = (win.global.innerHeight||win.doc.documentElement.clientHeight); |
---|
97 | } |
---|
98 | } |
---|
99 | } |
---|
100 | var l = (h || domGeometry.getMarginBox(this.domNode)[sz]) - offset; |
---|
101 | var props = {}; |
---|
102 | props[sz] = l; |
---|
103 | domGeometry.setMarginBox(children[children.length - 1], props); |
---|
104 | |
---|
105 | array.forEach(this.getChildren(), function(child){ |
---|
106 | if(child.resize){ child.resize(); } |
---|
107 | }); |
---|
108 | }, |
---|
109 | |
---|
110 | addChild: function(widget, /*Number?*/insertIndex){ |
---|
111 | domClass.add(widget.domNode, "mblFixedSplitterPane"+this.orientation); |
---|
112 | this.inherited(arguments); |
---|
113 | } |
---|
114 | }); |
---|
115 | }); |
---|