Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | 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.Dialog");
12
dojo.require("dojo.widget.*");
13
dojo.require("dojo.widget.ContentPane");
14
dojo.require("dojo.event.*");
15
dojo.require("dojo.gfx.color");
16
dojo.require("dojo.html.layout");
17
dojo.require("dojo.html.display");
18
dojo.require("dojo.html.iframe");
19
dojo.declare("dojo.widget.ModalDialogBase", null, {isContainer:true, focusElement:"", bgColor:"black", bgOpacity:0.4, followScroll:true, closeOnBackgroundClick:false, trapTabs:function (e) {
20
	if (e.target == this.tabStartOuter) {
21
		if (this._fromTrap) {
22
			this.tabStart.focus();
23
			this._fromTrap = false;
24
		} else {
25
			this._fromTrap = true;
26
			this.tabEnd.focus();
27
		}
28
	} else {
29
		if (e.target == this.tabStart) {
30
			if (this._fromTrap) {
31
				this._fromTrap = false;
32
			} else {
33
				this._fromTrap = true;
34
				this.tabEnd.focus();
35
			}
36
		} else {
37
			if (e.target == this.tabEndOuter) {
38
				if (this._fromTrap) {
39
					this.tabEnd.focus();
40
					this._fromTrap = false;
41
				} else {
42
					this._fromTrap = true;
43
					this.tabStart.focus();
44
				}
45
			} else {
46
				if (e.target == this.tabEnd) {
47
					if (this._fromTrap) {
48
						this._fromTrap = false;
49
					} else {
50
						this._fromTrap = true;
51
						this.tabStart.focus();
52
					}
53
				}
54
			}
55
		}
56
	}
57
}, clearTrap:function (e) {
58
	var _this = this;
59
	setTimeout(function () {
60
		_this._fromTrap = false;
61
	}, 100);
62
}, postCreate:function () {
63
	with (this.domNode.style) {
64
		position = "absolute";
65
		zIndex = 999;
66
		display = "none";
67
		overflow = "visible";
68
	}
69
	var b = dojo.body();
70
	b.appendChild(this.domNode);
71
	this.bg = document.createElement("div");
72
	this.bg.className = "dialogUnderlay";
73
	with (this.bg.style) {
74
		position = "absolute";
75
		left = top = "0px";
76
		zIndex = 998;
77
		display = "none";
78
	}
79
	b.appendChild(this.bg);
80
	this.setBackgroundColor(this.bgColor);
81
	this.bgIframe = new dojo.html.BackgroundIframe();
82
	if (this.bgIframe.iframe) {
83
		with (this.bgIframe.iframe.style) {
84
			position = "absolute";
85
			left = top = "0px";
86
			zIndex = 90;
87
			display = "none";
88
		}
89
	}
90
	if (this.closeOnBackgroundClick) {
91
		dojo.event.kwConnect({srcObj:this.bg, srcFunc:"onclick", adviceObj:this, adviceFunc:"onBackgroundClick", once:true});
92
	}
93
}, uninitialize:function () {
94
	this.bgIframe.remove();
95
	dojo.html.removeNode(this.bg, true);
96
}, setBackgroundColor:function (color) {
97
	if (arguments.length >= 3) {
98
		color = new dojo.gfx.color.Color(arguments[0], arguments[1], arguments[2]);
99
	} else {
100
		color = new dojo.gfx.color.Color(color);
101
	}
102
	this.bg.style.backgroundColor = color.toString();
103
	return this.bgColor = color;
104
}, setBackgroundOpacity:function (op) {
105
	if (arguments.length == 0) {
106
		op = this.bgOpacity;
107
	}
108
	dojo.html.setOpacity(this.bg, op);
109
	try {
110
		this.bgOpacity = dojo.html.getOpacity(this.bg);
111
	}
112
	catch (e) {
113
		this.bgOpacity = op;
114
	}
115
	return this.bgOpacity;
116
}, _sizeBackground:function () {
117
	if (this.bgOpacity > 0) {
118
		var viewport = dojo.html.getViewport();
119
		var h = viewport.height;
120
		var w = viewport.width;
121
		with (this.bg.style) {
122
			width = w + "px";
123
			height = h + "px";
124
		}
125
		var scroll_offset = dojo.html.getScroll().offset;
126
		this.bg.style.top = scroll_offset.y + "px";
127
		this.bg.style.left = scroll_offset.x + "px";
128
		var viewport = dojo.html.getViewport();
129
		if (viewport.width != w) {
130
			this.bg.style.width = viewport.width + "px";
131
		}
132
		if (viewport.height != h) {
133
			this.bg.style.height = viewport.height + "px";
134
		}
135
	}
136
	this.bgIframe.size(this.bg);
137
}, _showBackground:function () {
138
	if (this.bgOpacity > 0) {
139
		this.bg.style.display = "block";
140
	}
141
	if (this.bgIframe.iframe) {
142
		this.bgIframe.iframe.style.display = "block";
143
	}
144
}, placeModalDialog:function () {
145
	var scroll_offset = dojo.html.getScroll().offset;
146
	var viewport_size = dojo.html.getViewport();
147
	var mb;
148
	if (this.isShowing()) {
149
		mb = dojo.html.getMarginBox(this.domNode);
150
	} else {
151
		dojo.html.setVisibility(this.domNode, false);
152
		dojo.html.show(this.domNode);
153
		mb = dojo.html.getMarginBox(this.domNode);
154
		dojo.html.hide(this.domNode);
155
		dojo.html.setVisibility(this.domNode, true);
156
	}
157
	var x = scroll_offset.x + (viewport_size.width - mb.width) / 2;
158
	var y = scroll_offset.y + (viewport_size.height - mb.height) / 2;
159
	with (this.domNode.style) {
160
		left = x + "px";
161
		top = y + "px";
162
	}
163
}, _onKey:function (evt) {
164
	if (evt.key) {
165
		var node = evt.target;
166
		while (node != null) {
167
			if (node == this.domNode) {
168
				return;
169
			}
170
			node = node.parentNode;
171
		}
172
		if (evt.key != evt.KEY_TAB) {
173
			dojo.event.browser.stopEvent(evt);
174
		} else {
175
			if (!dojo.render.html.opera) {
176
				try {
177
					this.tabStart.focus();
178
				}
179
				catch (e) {
180
				}
181
			}
182
		}
183
	}
184
}, showModalDialog:function () {
185
	if (this.followScroll && !this._scrollConnected) {
186
		this._scrollConnected = true;
187
		dojo.event.connect(window, "onscroll", this, "_onScroll");
188
	}
189
	dojo.event.connect(document.documentElement, "onkey", this, "_onKey");
190
	this.placeModalDialog();
191
	this.setBackgroundOpacity();
192
	this._sizeBackground();
193
	this._showBackground();
194
	this._fromTrap = true;
195
	setTimeout(dojo.lang.hitch(this, function () {
196
		try {
197
			this.tabStart.focus();
198
		}
199
		catch (e) {
200
		}
201
	}), 50);
202
}, hideModalDialog:function () {
203
	if (this.focusElement) {
204
		dojo.byId(this.focusElement).focus();
205
		dojo.byId(this.focusElement).blur();
206
	}
207
	this.bg.style.display = "none";
208
	this.bg.style.width = this.bg.style.height = "1px";
209
	if (this.bgIframe.iframe) {
210
		this.bgIframe.iframe.style.display = "none";
211
	}
212
	dojo.event.disconnect(document.documentElement, "onkey", this, "_onKey");
213
	if (this._scrollConnected) {
214
		this._scrollConnected = false;
215
		dojo.event.disconnect(window, "onscroll", this, "_onScroll");
216
	}
217
}, _onScroll:function () {
218
	var scroll_offset = dojo.html.getScroll().offset;
219
	this.bg.style.top = scroll_offset.y + "px";
220
	this.bg.style.left = scroll_offset.x + "px";
221
	this.placeModalDialog();
222
}, checkSize:function () {
223
	if (this.isShowing()) {
224
		this._sizeBackground();
225
		this.placeModalDialog();
226
		this.onResized();
227
	}
228
}, onBackgroundClick:function () {
229
	if (this.lifetime - this.timeRemaining >= this.blockDuration) {
230
		return;
231
	}
232
	this.hide();
233
}});
234
dojo.widget.defineWidget("dojo.widget.Dialog", [dojo.widget.ContentPane, dojo.widget.ModalDialogBase], {templateString:"<div id=\"${this.widgetId}\" class=\"dojoDialog\" dojoattachpoint=\"wrapper\">\n\t<span dojoattachpoint=\"tabStartOuter\" dojoonfocus=\"trapTabs\" dojoonblur=\"clearTrap\"\ttabindex=\"0\"></span>\n\t<span dojoattachpoint=\"tabStart\" dojoonfocus=\"trapTabs\" dojoonblur=\"clearTrap\" tabindex=\"0\"></span>\n\t<div dojoattachpoint=\"containerNode\" style=\"position: relative; z-index: 2;\"></div>\n\t<span dojoattachpoint=\"tabEnd\" dojoonfocus=\"trapTabs\" dojoonblur=\"clearTrap\" tabindex=\"0\"></span>\n\t<span dojoattachpoint=\"tabEndOuter\" dojoonfocus=\"trapTabs\" dojoonblur=\"clearTrap\" tabindex=\"0\"></span>\n</div>\n", blockDuration:0, lifetime:0, closeNode:"", postMixInProperties:function () {
235
	dojo.widget.Dialog.superclass.postMixInProperties.apply(this, arguments);
236
	if (this.closeNode) {
237
		this.setCloseControl(this.closeNode);
238
	}
239
}, postCreate:function () {
240
	dojo.widget.Dialog.superclass.postCreate.apply(this, arguments);
241
	dojo.widget.ModalDialogBase.prototype.postCreate.apply(this, arguments);
242
}, show:function () {
243
	if (this.lifetime) {
244
		this.timeRemaining = this.lifetime;
245
		if (this.timerNode) {
246
			this.timerNode.innerHTML = Math.ceil(this.timeRemaining / 1000);
247
		}
248
		if (this.blockDuration && this.closeNode) {
249
			if (this.lifetime > this.blockDuration) {
250
				this.closeNode.style.visibility = "hidden";
251
			} else {
252
				this.closeNode.style.display = "none";
253
			}
254
		}
255
		if (this.timer) {
256
			clearInterval(this.timer);
257
		}
258
		this.timer = setInterval(dojo.lang.hitch(this, "_onTick"), 100);
259
	}
260
	this.showModalDialog();
261
	dojo.widget.Dialog.superclass.show.call(this);
262
}, onLoad:function () {
263
	this.placeModalDialog();
264
	dojo.widget.Dialog.superclass.onLoad.call(this);
265
}, fillInTemplate:function () {
266
}, hide:function () {
267
	this.hideModalDialog();
268
	dojo.widget.Dialog.superclass.hide.call(this);
269
	if (this.timer) {
270
		clearInterval(this.timer);
271
	}
272
}, setTimerNode:function (node) {
273
	this.timerNode = node;
274
}, setCloseControl:function (node) {
275
	this.closeNode = dojo.byId(node);
276
	dojo.event.connect(this.closeNode, "onclick", this, "hide");
277
}, setShowControl:function (node) {
278
	node = dojo.byId(node);
279
	dojo.event.connect(node, "onclick", this, "show");
280
}, _onTick:function () {
281
	if (this.timer) {
282
		this.timeRemaining -= 100;
283
		if (this.lifetime - this.timeRemaining >= this.blockDuration) {
284
			if (this.closeNode) {
285
				this.closeNode.style.visibility = "visible";
286
			}
287
		}
288
		if (!this.timeRemaining) {
289
			clearInterval(this.timer);
290
			this.hide();
291
		} else {
292
			if (this.timerNode) {
293
				this.timerNode.innerHTML = Math.ceil(this.timeRemaining / 1000);
294
			}
295
		}
296
	}
297
}});
298