Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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