Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
11
dojo.provide("dojo.widget.PageContainer");
12
dojo.require("dojo.lang.func");
13
dojo.require("dojo.widget.*");
14
dojo.require("dojo.event.*");
15
dojo.require("dojo.html.selection");
16
dojo.widget.defineWidget("dojo.widget.PageContainer", dojo.widget.HtmlWidget, {isContainer:true, doLayout:true, templateString:"<div dojoAttachPoint='containerNode'></div>", selectedChild:"", fillInTemplate:function (args, frag) {
17
	var source = this.getFragNodeRef(frag);
18
	dojo.html.copyStyle(this.domNode, source);
19
	dojo.widget.PageContainer.superclass.fillInTemplate.apply(this, arguments);
20
}, postCreate:function (args, frag) {
21
	if (this.children.length) {
22
		dojo.lang.forEach(this.children, this._setupChild, this);
23
		var initialChild;
24
		if (this.selectedChild) {
25
			this.selectChild(this.selectedChild);
26
		} else {
27
			for (var i = 0; i < this.children.length; i++) {
28
				if (this.children[i].selected) {
29
					this.selectChild(this.children[i]);
30
					break;
31
				}
32
			}
33
			if (!this.selectedChildWidget) {
34
				this.selectChild(this.children[0]);
35
			}
36
		}
37
	}
38
}, addChild:function (child) {
39
	dojo.widget.PageContainer.superclass.addChild.apply(this, arguments);
40
	this._setupChild(child);
41
	this.onResized();
42
	if (!this.selectedChildWidget) {
43
		this.selectChild(child);
44
	}
45
}, _setupChild:function (page) {
46
	page.hide();
47
	page.domNode.style.position = "relative";
48
	dojo.event.topic.publish(this.widgetId + "-addChild", page);
49
}, removeChild:function (page) {
50
	dojo.widget.PageContainer.superclass.removeChild.apply(this, arguments);
51
	if (this._beingDestroyed) {
52
		return;
53
	}
54
	dojo.event.topic.publish(this.widgetId + "-removeChild", page);
55
	this.onResized();
56
	if (this.selectedChildWidget === page) {
57
		this.selectedChildWidget = undefined;
58
		if (this.children.length > 0) {
59
			this.selectChild(this.children[0], true);
60
		}
61
	}
62
}, selectChild:function (page, callingWidget) {
63
	page = dojo.widget.byId(page);
64
	this.correspondingPageButton = callingWidget;
65
	if (this.selectedChildWidget) {
66
		this._hideChild(this.selectedChildWidget);
67
	}
68
	this.selectedChildWidget = page;
69
	this.selectedChild = page.widgetId;
70
	this._showChild(page);
71
	page.isFirstChild = (page == this.children[0]);
72
	page.isLastChild = (page == this.children[this.children.length - 1]);
73
	dojo.event.topic.publish(this.widgetId + "-selectChild", page);
74
}, forward:function () {
75
	var index = dojo.lang.find(this.children, this.selectedChildWidget);
76
	this.selectChild(this.children[index + 1]);
77
}, back:function () {
78
	var index = dojo.lang.find(this.children, this.selectedChildWidget);
79
	this.selectChild(this.children[index - 1]);
80
}, onResized:function () {
81
	if (this.doLayout && this.selectedChildWidget) {
82
		with (this.selectedChildWidget.domNode.style) {
83
			top = dojo.html.getPixelValue(this.containerNode, "padding-top", true);
84
			left = dojo.html.getPixelValue(this.containerNode, "padding-left", true);
85
		}
86
		var content = dojo.html.getContentBox(this.containerNode);
87
		this.selectedChildWidget.resizeTo(content.width, content.height);
88
	}
89
}, _showChild:function (page) {
90
	if (this.doLayout) {
91
		var content = dojo.html.getContentBox(this.containerNode);
92
		page.resizeTo(content.width, content.height);
93
	}
94
	page.selected = true;
95
	page.show();
96
}, _hideChild:function (page) {
97
	page.selected = false;
98
	page.hide();
99
}, closeChild:function (page) {
100
	var remove = page.onClose(this, page);
101
	if (remove) {
102
		this.removeChild(page);
103
		page.destroy();
104
	}
105
}, destroy:function () {
106
	this._beingDestroyed = true;
107
	dojo.event.topic.destroy(this.widgetId + "-addChild");
108
	dojo.event.topic.destroy(this.widgetId + "-removeChild");
109
	dojo.event.topic.destroy(this.widgetId + "-selectChild");
110
	dojo.widget.PageContainer.superclass.destroy.apply(this, arguments);
111
}});
112
dojo.widget.defineWidget("dojo.widget.PageController", dojo.widget.HtmlWidget, {templateString:"<span wairole='tablist' dojoAttachEvent='onKey'></span>", isContainer:true, containerId:"", buttonWidget:"PageButton", "class":"dojoPageController", fillInTemplate:function () {
113
	dojo.html.addClass(this.domNode, this["class"]);
114
	dojo.widget.wai.setAttr(this.domNode, "waiRole", "role", "tablist");
115
}, postCreate:function () {
116
	this.pane2button = {};
117
	var container = dojo.widget.byId(this.containerId);
118
	if (container) {
119
		dojo.lang.forEach(container.children, this.onAddChild, this);
120
	}
121
	dojo.event.topic.subscribe(this.containerId + "-addChild", this, "onAddChild");
122
	dojo.event.topic.subscribe(this.containerId + "-removeChild", this, "onRemoveChild");
123
	dojo.event.topic.subscribe(this.containerId + "-selectChild", this, "onSelectChild");
124
}, destroy:function () {
125
	dojo.event.topic.unsubscribe(this.containerId + "-addChild", this, "onAddChild");
126
	dojo.event.topic.unsubscribe(this.containerId + "-removeChild", this, "onRemoveChild");
127
	dojo.event.topic.unsubscribe(this.containerId + "-selectChild", this, "onSelectChild");
128
	dojo.widget.PageController.superclass.destroy.apply(this, arguments);
129
}, onAddChild:function (page) {
130
	var button = dojo.widget.createWidget(this.buttonWidget, {label:page.label, closeButton:page.closable});
131
	this.addChild(button);
132
	this.domNode.appendChild(button.domNode);
133
	this.pane2button[page] = button;
134
	page.controlButton = button;
135
	var _this = this;
136
	dojo.event.connect(button, "onClick", function () {
137
		_this.onButtonClick(page);
138
	});
139
	dojo.event.connect(button, "onCloseButtonClick", function () {
140
		_this.onCloseButtonClick(page);
141
	});
142
}, onRemoveChild:function (page) {
143
	if (this._currentChild == page) {
144
		this._currentChild = null;
145
	}
146
	var button = this.pane2button[page];
147
	if (button) {
148
		button.destroy();
149
	}
150
	this.pane2button[page] = null;
151
}, onSelectChild:function (page) {
152
	if (this._currentChild) {
153
		var oldButton = this.pane2button[this._currentChild];
154
		oldButton.clearSelected();
155
	}
156
	var newButton = this.pane2button[page];
157
	newButton.setSelected();
158
	this._currentChild = page;
159
}, onButtonClick:function (page) {
160
	var container = dojo.widget.byId(this.containerId);
161
	container.selectChild(page, false, this);
162
}, onCloseButtonClick:function (page) {
163
	var container = dojo.widget.byId(this.containerId);
164
	container.closeChild(page);
165
}, onKey:function (evt) {
166
	if ((evt.keyCode == evt.KEY_RIGHT_ARROW) || (evt.keyCode == evt.KEY_LEFT_ARROW)) {
167
		var current = 0;
168
		var next = null;
169
		var current = dojo.lang.find(this.children, this.pane2button[this._currentChild]);
170
		if (evt.keyCode == evt.KEY_RIGHT_ARROW) {
171
			next = this.children[(current + 1) % this.children.length];
172
		} else {
173
			next = this.children[(current + (this.children.length - 1)) % this.children.length];
174
		}
175
		dojo.event.browser.stopEvent(evt);
176
		next.onClick();
177
	}
178
}});
179
dojo.widget.defineWidget("dojo.widget.PageButton", dojo.widget.HtmlWidget, {templateString:"<span class='item'>" + "<span dojoAttachEvent='onClick' dojoAttachPoint='titleNode' class='selectButton'>${this.label}</span>" + "<span dojoAttachEvent='onClick:onCloseButtonClick' class='closeButton'>[X]</span>" + "</span>", label:"foo", closeButton:false, onClick:function () {
180
	this.focus();
181
}, onCloseButtonMouseOver:function () {
182
	dojo.html.addClass(this.closeButtonNode, "closeHover");
183
}, onCloseButtonMouseOut:function () {
184
	dojo.html.removeClass(this.closeButtonNode, "closeHover");
185
}, onCloseButtonClick:function (evt) {
186
}, setSelected:function () {
187
	dojo.html.addClass(this.domNode, "current");
188
	this.titleNode.setAttribute("tabIndex", "0");
189
}, clearSelected:function () {
190
	dojo.html.removeClass(this.domNode, "current");
191
	this.titleNode.setAttribute("tabIndex", "-1");
192
}, focus:function () {
193
	if (this.titleNode.focus) {
194
		this.titleNode.focus();
195
	}
196
}});
197
dojo.lang.extend(dojo.widget.Widget, {label:"", selected:false, closable:false, onClose:function () {
198
	return true;
199
}});
200