Subversion Repositories Applications.papyrus

Rev

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