summaryrefslogtreecommitdiff
path: root/js/dojo-1.6/dojox/mobile/FixedSplitter.xd.js
blob: 1436f4c1d878fc3dd5482f21f88fb73397bd3a53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


dojo._xdResourceLoaded(function(dojo, dijit, dojox){
return {depends: [["provide", "dojox.mobile.FixedSplitter"],
["require", "dijit._WidgetBase"]],
defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.mobile.FixedSplitter"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.mobile.FixedSplitter"] = true;
dojo.provide("dojox.mobile.FixedSplitter");

dojo.require("dijit._WidgetBase");

// summary:
//		A layout container that splits the window horizontally or vertically.
// description:
//		FixedSplitter is a very simple container widget that layouts its child
//		dom nodes side by side either horizontally or vertically.
//		An example usage of this widget would be to realize the split view on iPad.
//		There is no visual splitter between the children, and there is no
//		function to resize the child panes with drag-and-drop.
//		If you need a visual splitter, you can specify a border of a child
//		dom node with CSS.
//		A child of the widget can be a plain <div> or dojox.mobile.FixedSplitterPane.
// example:
// |	<div dojoType="dojox.mobile.FixedSplitter" orientation="H">
// |		<div style="width:200px;border-right:1px solid black;">
// |			pane #1 (width=200px)
// |		</div>
// |		<div>
// |			pane #2
// |		</div>
// |	</div>

dojo.declare(
	"dojox.mobile.FixedSplitter",
	dijit._WidgetBase,
{
	orientation: "H", // "H" or "V"

	isContainer: true,

	buildRendering: function(){
		this.domNode = this.containerNode = this.srcNodeRef ? this.srcNodeRef : dojo.doc.createElement("DIV");
		dojo.addClass(this.domNode, "mblFixedSpliter");
	},

	startup: function(){
		var children = dojo.filter(this.domNode.childNodes, function(node){ return node.nodeType == 1; });
		dojo.forEach(children, function(node){
			dojo.addClass(node, "mblFixedSplitterPane"+this.orientation);
		}, this);

		dojo.forEach(this.getChildren(), function(child){if(child.startup){child.startup();}});
		this._started = true;

		var _this = this;
		setTimeout(function(){
			_this.resize();
		}, 0);

		var parent = dijit.getEnclosingWidget(this.domNode.parentNode);
		if(!parent){
			if(dojo.global.onorientationchange !== undefined){
				this.connect(dojo.global, "onorientationchange", "resize");
			}else{
				this.connect(dojo.global, "onresize", "resize");
			}
		}
	},

	resize: function(changeSize, resultSize){
		this.layout();
	},

	layout: function(){
		var sz = this.orientation == "H" ? "w" : "h";
		var children = dojo.filter(this.domNode.childNodes, function(node){ return node.nodeType == 1; });
		var offset = 0;
		for(var i = 0; i < children.length; i++){
			dojo.marginBox(children[i], this.orientation == "H" ? {l:offset} : {t:offset});
			if(i < children.length - 1){
				offset += dojo.marginBox(children[i])[sz];
			}
		}

		var l = dojo.marginBox(this.domNode)[sz] - offset;
		var props = {};
		props[sz] = l;
		dojo.marginBox(children[children.length - 1], props);

		dojo.forEach(this.getChildren(), function(child){
			if(child.resize){ child.resize(); }
		});
	}
});

dojo.declare(
	"dojox.mobile.FixedSplitterPane",
	dijit._WidgetBase,
{
	buildRendering: function(){
		this.inherited(arguments);
		dojo.addClass(this.domNode, "mblFixedSplitterPane");
	}
});

}

}};});