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