Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1372 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.PopupContainer");
13
dojo.provide("dojo.widget.PopupContainer");
12
dojo.require("dojo.html.style");
14
dojo.require("dojo.html.style");
13
dojo.require("dojo.html.layout");
15
dojo.require("dojo.html.layout");
14
dojo.require("dojo.html.selection");
16
dojo.require("dojo.html.selection");
15
dojo.require("dojo.html.iframe");
17
dojo.require("dojo.html.iframe");
16
dojo.require("dojo.event.*");
18
dojo.require("dojo.event.*");
17
dojo.require("dojo.widget.*");
19
dojo.require("dojo.widget.*");
18
dojo.require("dojo.widget.HtmlWidget");
20
dojo.require("dojo.widget.HtmlWidget");
19
dojo.declare("dojo.widget.PopupContainerBase", null, function () {
21
dojo.declare("dojo.widget.PopupContainerBase", null, function () {
20
	this.queueOnAnimationFinish = [];
22
	this.queueOnAnimationFinish = [];
21
}, {isShowingNow:false, currentSubpopup:null, beginZIndex:1000, parentPopup:null, parent:null, popupIndex:0, aroundBox:dojo.html.boxSizing.BORDER_BOX, openedForWindow:null, processKey:function (evt) {
23
}, {isShowingNow:false, currentSubpopup:null, beginZIndex:1000, parentPopup:null, parent:null, popupIndex:0, aroundBox:dojo.html.boxSizing.BORDER_BOX, openedForWindow:null, processKey:function (evt) {
22
	return false;
24
	return false;
23
}, applyPopupBasicStyle:function () {
25
}, applyPopupBasicStyle:function () {
24
	with (this.domNode.style) {
26
	with (this.domNode.style) {
25
		display = "none";
27
		display = "none";
26
		position = "absolute";
28
		position = "absolute";
27
	}
29
	}
28
}, aboutToShow:function () {
30
}, aboutToShow:function () {
29
}, open:function (x, y, parent, explodeSrc, orient, padding) {
31
}, open:function (x, y, parent, explodeSrc, orient, padding) {
30
	if (this.isShowingNow) {
32
	if (this.isShowingNow) {
31
		return;
33
		return;
32
	}
34
	}
33
	if (this.animationInProgress) {
35
	if (this.animationInProgress) {
34
		this.queueOnAnimationFinish.push(this.open, arguments);
36
		this.queueOnAnimationFinish.push(this.open, arguments);
35
		return;
37
		return;
36
	}
38
	}
37
	this.aboutToShow();
39
	this.aboutToShow();
38
	var around = false, node, aroundOrient;
40
	var around = false, node, aroundOrient;
39
	if (typeof x == "object") {
41
	if (typeof x == "object") {
40
		node = x;
42
		node = x;
41
		aroundOrient = explodeSrc;
43
		aroundOrient = explodeSrc;
42
		explodeSrc = parent;
44
		explodeSrc = parent;
43
		parent = y;
45
		parent = y;
44
		around = true;
46
		around = true;
45
	}
47
	}
46
	this.parent = parent;
48
	this.parent = parent;
47
	dojo.body().appendChild(this.domNode);
49
	dojo.body().appendChild(this.domNode);
48
	explodeSrc = explodeSrc || parent["domNode"] || [];
50
	explodeSrc = explodeSrc || parent["domNode"] || [];
49
	var parentPopup = null;
51
	var parentPopup = null;
50
	this.isTopLevel = true;
52
	this.isTopLevel = true;
51
	while (parent) {
53
	while (parent) {
52
		if (parent !== this && (parent.setOpenedSubpopup != undefined && parent.applyPopupBasicStyle != undefined)) {
54
		if (parent !== this && (parent.setOpenedSubpopup != undefined && parent.applyPopupBasicStyle != undefined)) {
53
			parentPopup = parent;
55
			parentPopup = parent;
54
			this.isTopLevel = false;
56
			this.isTopLevel = false;
55
			parentPopup.setOpenedSubpopup(this);
57
			parentPopup.setOpenedSubpopup(this);
56
			break;
58
			break;
57
		}
59
		}
58
		parent = parent.parent;
60
		parent = parent.parent;
59
	}
61
	}
60
	this.parentPopup = parentPopup;
62
	this.parentPopup = parentPopup;
61
	this.popupIndex = parentPopup ? parentPopup.popupIndex + 1 : 1;
63
	this.popupIndex = parentPopup ? parentPopup.popupIndex + 1 : 1;
62
	if (this.isTopLevel) {
64
	if (this.isTopLevel) {
63
		var button = dojo.html.isNode(explodeSrc) ? explodeSrc : null;
65
		var button = dojo.html.isNode(explodeSrc) ? explodeSrc : null;
64
		dojo.widget.PopupManager.opened(this, button);
66
		dojo.widget.PopupManager.opened(this, button);
65
	}
67
	}
66
	if (this.isTopLevel && !dojo.withGlobal(this.openedForWindow || dojo.global(), dojo.html.selection.isCollapsed)) {
68
	if (this.isTopLevel && !dojo.withGlobal(this.openedForWindow || dojo.global(), dojo.html.selection.isCollapsed)) {
67
		this._bookmark = dojo.withGlobal(this.openedForWindow || dojo.global(), dojo.html.selection.getBookmark);
69
		this._bookmark = dojo.withGlobal(this.openedForWindow || dojo.global(), dojo.html.selection.getBookmark);
68
	} else {
70
	} else {
69
		this._bookmark = null;
71
		this._bookmark = null;
70
	}
72
	}
71
	if (explodeSrc instanceof Array) {
73
	if (explodeSrc instanceof Array) {
72
		explodeSrc = {left:explodeSrc[0], top:explodeSrc[1], width:0, height:0};
74
		explodeSrc = {left:explodeSrc[0], top:explodeSrc[1], width:0, height:0};
73
	}
75
	}
74
	with (this.domNode.style) {
76
	with (this.domNode.style) {
75
		display = "";
77
		display = "";
76
		zIndex = this.beginZIndex + this.popupIndex;
78
		zIndex = this.beginZIndex + this.popupIndex;
77
	}
79
	}
78
	if (around) {
80
	if (around) {
79
		this.move(node, padding, aroundOrient);
81
		this.move(node, padding, aroundOrient);
80
	} else {
82
	} else {
81
		this.move(x, y, padding, orient);
83
		this.move(x, y, padding, orient);
82
	}
84
	}
83
	this.domNode.style.display = "none";
85
	this.domNode.style.display = "none";
84
	this.explodeSrc = explodeSrc;
86
	this.explodeSrc = explodeSrc;
85
	this.show();
87
	this.show();
86
	this.isShowingNow = true;
88
	this.isShowingNow = true;
87
}, move:function (x, y, padding, orient) {
89
}, move:function (x, y, padding, orient) {
88
	var around = (typeof x == "object");
90
	var around = (typeof x == "object");
89
	if (around) {
91
	if (around) {
90
		var aroundOrient = padding;
92
		var aroundOrient = padding;
91
		var node = x;
93
		var node = x;
92
		padding = y;
94
		padding = y;
93
		if (!aroundOrient) {
95
		if (!aroundOrient) {
94
			aroundOrient = {"BL":"TL", "TL":"BL"};
96
			aroundOrient = {"BL":"TL", "TL":"BL"};
95
		}
97
		}
96
		dojo.html.placeOnScreenAroundElement(this.domNode, node, padding, this.aroundBox, aroundOrient);
98
		dojo.html.placeOnScreenAroundElement(this.domNode, node, padding, this.aroundBox, aroundOrient);
97
	} else {
99
	} else {
98
		if (!orient) {
100
		if (!orient) {
99
			orient = "TL,TR,BL,BR";
101
			orient = "TL,TR,BL,BR";
100
		}
102
		}
101
		dojo.html.placeOnScreen(this.domNode, x, y, padding, true, orient);
103
		dojo.html.placeOnScreen(this.domNode, x, y, padding, true, orient);
102
	}
104
	}
103
}, close:function (force) {
105
}, close:function (force) {
104
	if (force) {
106
	if (force) {
105
		this.domNode.style.display = "none";
107
		this.domNode.style.display = "none";
106
	}
108
	}
107
	if (this.animationInProgress) {
109
	if (this.animationInProgress) {
108
		this.queueOnAnimationFinish.push(this.close, []);
110
		this.queueOnAnimationFinish.push(this.close, []);
109
		return;
111
		return;
110
	}
112
	}
111
	this.closeSubpopup(force);
113
	this.closeSubpopup(force);
112
	this.hide();
114
	this.hide();
113
	if (this.bgIframe) {
115
	if (this.bgIframe) {
114
		this.bgIframe.hide();
116
		this.bgIframe.hide();
115
		this.bgIframe.size({left:0, top:0, width:0, height:0});
117
		this.bgIframe.size({left:0, top:0, width:0, height:0});
116
	}
118
	}
117
	if (this.isTopLevel) {
119
	if (this.isTopLevel) {
118
		dojo.widget.PopupManager.closed(this);
120
		dojo.widget.PopupManager.closed(this);
119
	}
121
	}
120
	this.isShowingNow = false;
122
	this.isShowingNow = false;
121
	if (this.parent) {
123
	if (this.parent) {
122
		setTimeout(dojo.lang.hitch(this, function () {
124
		setTimeout(dojo.lang.hitch(this, function () {
123
			try {
125
			try {
124
				if (this.parent["focus"]) {
126
				if (this.parent["focus"]) {
125
					this.parent.focus();
127
					this.parent.focus();
126
				} else {
128
				} else {
127
					this.parent.domNode.focus();
129
					this.parent.domNode.focus();
128
				}
130
				}
129
			}
131
			}
130
			catch (e) {
132
			catch (e) {
131
				dojo.debug("No idea how to focus to parent", e);
133
				dojo.debug("No idea how to focus to parent", e);
132
			}
134
			}
133
		}), 10);
135
		}), 10);
134
	}
136
	}
135
	if (this._bookmark && dojo.withGlobal(this.openedForWindow || dojo.global(), dojo.html.selection.isCollapsed)) {
137
	if (this._bookmark && dojo.withGlobal(this.openedForWindow || dojo.global(), dojo.html.selection.isCollapsed)) {
136
		if (this.openedForWindow) {
138
		if (this.openedForWindow) {
137
			this.openedForWindow.focus();
139
			this.openedForWindow.focus();
138
		}
140
		}
139
		try {
141
		try {
140
			dojo.withGlobal(this.openedForWindow || dojo.global(), "moveToBookmark", dojo.html.selection, [this._bookmark]);
142
			dojo.withGlobal(this.openedForWindow || dojo.global(), "moveToBookmark", dojo.html.selection, [this._bookmark]);
141
		}
143
		}
142
		catch (e) {
144
		catch (e) {
143
		}
145
		}
144
	}
146
	}
145
	this._bookmark = null;
147
	this._bookmark = null;
146
}, closeAll:function (force) {
148
}, closeAll:function (force) {
147
	if (this.parentPopup) {
149
	if (this.parentPopup) {
148
		this.parentPopup.closeAll(force);
150
		this.parentPopup.closeAll(force);
149
	} else {
151
	} else {
150
		this.close(force);
152
		this.close(force);
151
	}
153
	}
152
}, setOpenedSubpopup:function (popup) {
154
}, setOpenedSubpopup:function (popup) {
153
	this.currentSubpopup = popup;
155
	this.currentSubpopup = popup;
154
}, closeSubpopup:function (force) {
156
}, closeSubpopup:function (force) {
155
	if (this.currentSubpopup == null) {
157
	if (this.currentSubpopup == null) {
156
		return;
158
		return;
157
	}
159
	}
158
	this.currentSubpopup.close(force);
160
	this.currentSubpopup.close(force);
159
	this.currentSubpopup = null;
161
	this.currentSubpopup = null;
160
}, onShow:function () {
162
}, onShow:function () {
161
	dojo.widget.PopupContainer.superclass.onShow.apply(this, arguments);
163
	dojo.widget.PopupContainer.superclass.onShow.apply(this, arguments);
162
	this.openedSize = {w:this.domNode.style.width, h:this.domNode.style.height};
164
	this.openedSize = {w:this.domNode.style.width, h:this.domNode.style.height};
163
	if (dojo.render.html.ie) {
165
	if (dojo.render.html.ie) {
164
		if (!this.bgIframe) {
166
		if (!this.bgIframe) {
165
			this.bgIframe = new dojo.html.BackgroundIframe();
167
			this.bgIframe = new dojo.html.BackgroundIframe();
166
			this.bgIframe.setZIndex(this.domNode);
168
			this.bgIframe.setZIndex(this.domNode);
167
		}
169
		}
168
		this.bgIframe.size(this.domNode);
170
		this.bgIframe.size(this.domNode);
169
		this.bgIframe.show();
171
		this.bgIframe.show();
170
	}
172
	}
171
	this.processQueue();
173
	this.processQueue();
172
}, processQueue:function () {
174
}, processQueue:function () {
173
	if (!this.queueOnAnimationFinish.length) {
175
	if (!this.queueOnAnimationFinish.length) {
174
		return;
176
		return;
175
	}
177
	}
176
	var func = this.queueOnAnimationFinish.shift();
178
	var func = this.queueOnAnimationFinish.shift();
177
	var args = this.queueOnAnimationFinish.shift();
179
	var args = this.queueOnAnimationFinish.shift();
178
	func.apply(this, args);
180
	func.apply(this, args);
179
}, onHide:function () {
181
}, onHide:function () {
180
	dojo.widget.HtmlWidget.prototype.onHide.call(this);
182
	dojo.widget.HtmlWidget.prototype.onHide.call(this);
181
	if (this.openedSize) {
183
	if (this.openedSize) {
182
		with (this.domNode.style) {
184
		with (this.domNode.style) {
183
			width = this.openedSize.w;
185
			width = this.openedSize.w;
184
			height = this.openedSize.h;
186
			height = this.openedSize.h;
185
		}
187
		}
186
	}
188
	}
187
	this.processQueue();
189
	this.processQueue();
188
}});
190
}});
189
dojo.widget.defineWidget("dojo.widget.PopupContainer", [dojo.widget.HtmlWidget, dojo.widget.PopupContainerBase], {isContainer:true, fillInTemplate:function () {
191
dojo.widget.defineWidget("dojo.widget.PopupContainer", [dojo.widget.HtmlWidget, dojo.widget.PopupContainerBase], {isContainer:true, fillInTemplate:function () {
190
	this.applyPopupBasicStyle();
192
	this.applyPopupBasicStyle();
191
	dojo.widget.PopupContainer.superclass.fillInTemplate.apply(this, arguments);
193
	dojo.widget.PopupContainer.superclass.fillInTemplate.apply(this, arguments);
192
}});
194
}});
193
dojo.widget.PopupManager = new function () {
195
dojo.widget.PopupManager = new function () {
194
	this.currentMenu = null;
196
	this.currentMenu = null;
195
	this.currentButton = null;
197
	this.currentButton = null;
196
	this.currentFocusMenu = null;
198
	this.currentFocusMenu = null;
197
	this.focusNode = null;
199
	this.focusNode = null;
198
	this.registeredWindows = [];
200
	this.registeredWindows = [];
199
	this.registerWin = function (win) {
201
	this.registerWin = function (win) {
200
		if (!win.__PopupManagerRegistered) {
202
		if (!win.__PopupManagerRegistered) {
201
			dojo.event.connect(win.document, "onmousedown", this, "onClick");
203
			dojo.event.connect(win.document, "onmousedown", this, "onClick");
202
			dojo.event.connect(win, "onscroll", this, "onClick");
204
			dojo.event.connect(win, "onscroll", this, "onClick");
203
			dojo.event.connect(win.document, "onkey", this, "onKey");
205
			dojo.event.connect(win.document, "onkey", this, "onKey");
204
			win.__PopupManagerRegistered = true;
206
			win.__PopupManagerRegistered = true;
205
			this.registeredWindows.push(win);
207
			this.registeredWindows.push(win);
206
		}
208
		}
207
	};
209
	};
208
	this.registerAllWindows = function (targetWindow) {
210
	this.registerAllWindows = function (targetWindow) {
209
		if (!targetWindow) {
211
		if (!targetWindow) {
210
			targetWindow = dojo.html.getDocumentWindow(window.top && window.top.document || window.document);
212
			targetWindow = dojo.html.getDocumentWindow(window.top && window.top.document || window.document);
211
		}
213
		}
212
		this.registerWin(targetWindow);
214
		this.registerWin(targetWindow);
213
		for (var i = 0; i < targetWindow.frames.length; i++) {
215
		for (var i = 0; i < targetWindow.frames.length; i++) {
214
			try {
216
			try {
215
				var win = dojo.html.getDocumentWindow(targetWindow.frames[i].document);
217
				var win = dojo.html.getDocumentWindow(targetWindow.frames[i].document);
216
				if (win) {
218
				if (win) {
217
					this.registerAllWindows(win);
219
					this.registerAllWindows(win);
218
				}
220
				}
219
			}
221
			}
220
			catch (e) {
222
			catch (e) {
221
			}
223
			}
222
		}
224
		}
223
	};
225
	};
224
	this.unRegisterWin = function (win) {
226
	this.unRegisterWin = function (win) {
225
		if (win.__PopupManagerRegistered) {
227
		if (win.__PopupManagerRegistered) {
226
			dojo.event.disconnect(win.document, "onmousedown", this, "onClick");
228
			dojo.event.disconnect(win.document, "onmousedown", this, "onClick");
227
			dojo.event.disconnect(win, "onscroll", this, "onClick");
229
			dojo.event.disconnect(win, "onscroll", this, "onClick");
228
			dojo.event.disconnect(win.document, "onkey", this, "onKey");
230
			dojo.event.disconnect(win.document, "onkey", this, "onKey");
229
			win.__PopupManagerRegistered = false;
231
			win.__PopupManagerRegistered = false;
230
		}
232
		}
231
	};
233
	};
232
	this.unRegisterAllWindows = function () {
234
	this.unRegisterAllWindows = function () {
233
		for (var i = 0; i < this.registeredWindows.length; ++i) {
235
		for (var i = 0; i < this.registeredWindows.length; ++i) {
234
			this.unRegisterWin(this.registeredWindows[i]);
236
			this.unRegisterWin(this.registeredWindows[i]);
235
		}
237
		}
236
		this.registeredWindows = [];
238
		this.registeredWindows = [];
237
	};
239
	};
238
	dojo.addOnLoad(this, "registerAllWindows");
240
	dojo.addOnLoad(this, "registerAllWindows");
239
	dojo.addOnUnload(this, "unRegisterAllWindows");
241
	dojo.addOnUnload(this, "unRegisterAllWindows");
240
	this.closed = function (menu) {
242
	this.closed = function (menu) {
241
		if (this.currentMenu == menu) {
243
		if (this.currentMenu == menu) {
242
			this.currentMenu = null;
244
			this.currentMenu = null;
243
			this.currentButton = null;
245
			this.currentButton = null;
244
			this.currentFocusMenu = null;
246
			this.currentFocusMenu = null;
245
		}
247
		}
246
	};
248
	};
247
	this.opened = function (menu, button) {
249
	this.opened = function (menu, button) {
248
		if (menu == this.currentMenu) {
250
		if (menu == this.currentMenu) {
249
			return;
251
			return;
250
		}
252
		}
251
		if (this.currentMenu) {
253
		if (this.currentMenu) {
252
			this.currentMenu.close();
254
			this.currentMenu.close();
253
		}
255
		}
254
		this.currentMenu = menu;
256
		this.currentMenu = menu;
255
		this.currentFocusMenu = menu;
257
		this.currentFocusMenu = menu;
256
		this.currentButton = button;
258
		this.currentButton = button;
257
	};
259
	};
258
	this.setFocusedMenu = function (menu) {
260
	this.setFocusedMenu = function (menu) {
259
		this.currentFocusMenu = menu;
261
		this.currentFocusMenu = menu;
260
	};
262
	};
261
	this.onKey = function (e) {
263
	this.onKey = function (e) {
262
		if (!e.key) {
264
		if (!e.key) {
263
			return;
265
			return;
264
		}
266
		}
265
		if (!this.currentMenu || !this.currentMenu.isShowingNow) {
267
		if (!this.currentMenu || !this.currentMenu.isShowingNow) {
266
			return;
268
			return;
267
		}
269
		}
268
		var m = this.currentFocusMenu;
270
		var m = this.currentFocusMenu;
269
		while (m) {
271
		while (m) {
270
			if (m.processKey(e)) {
272
			if (m.processKey(e)) {
271
				e.preventDefault();
273
				e.preventDefault();
272
				e.stopPropagation();
274
				e.stopPropagation();
273
				break;
275
				break;
274
			}
276
			}
275
			m = m.parentPopup || m.parentMenu;
277
			m = m.parentPopup || m.parentMenu;
276
		}
278
		}
277
	}, this.onClick = function (e) {
279
	}, this.onClick = function (e) {
278
		if (!this.currentMenu) {
280
		if (!this.currentMenu) {
279
			return;
281
			return;
280
		}
282
		}
281
		var scrolloffset = dojo.html.getScroll().offset;
283
		var scrolloffset = dojo.html.getScroll().offset;
282
		var m = this.currentMenu;
284
		var m = this.currentMenu;
283
		while (m) {
285
		while (m) {
284
			if (dojo.html.overElement(m.domNode, e) || dojo.html.isDescendantOf(e.target, m.domNode)) {
286
			if (dojo.html.overElement(m.domNode, e) || dojo.html.isDescendantOf(e.target, m.domNode)) {
285
				return;
287
				return;
286
			}
288
			}
287
			m = m.currentSubpopup;
289
			m = m.currentSubpopup;
288
		}
290
		}
289
		if (this.currentButton && dojo.html.overElement(this.currentButton, e)) {
291
		if (this.currentButton && dojo.html.overElement(this.currentButton, e)) {
290
			return;
292
			return;
291
		}
293
		}
292
		this.currentMenu.closeAll(true);
294
		this.currentMenu.closeAll(true);
293
	};
295
	};
294
};
296
};
295
 
297