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.Menu2");
12
dojo.require("dojo.widget.PopupContainer");
13
dojo.declare("dojo.widget.MenuBase", null, function () {
14
	this.eventNames = {open:""};
15
}, {isContainer:true, isMenu:true, eventNaming:"default", templateCssString:"\n.dojoPopupMenu2 {\n\tposition: absolute;\n\tborder: 1px solid #7298d0;\n\tbackground:#85aeec url(images/soriaMenuBg.gif) repeat-x bottom left !important;\n\tpadding: 1px;\n\tmargin-top: 1px;\n\tmargin-bottom: 1px;\n}\n\n.dojoMenuItem2{\n\twhite-space: nowrap;\n\tfont: menu;\n\tmargin: 0;\n}\n\n.dojoMenuItem2Hover {\n\tbackground-color: #D2E4FD;\n\tcursor:pointer;\n\tcursor:hand;\n}\n\n.dojoMenuItem2Icon {\n\tposition: relative;\n\tbackground-position: center center;\n\tbackground-repeat: no-repeat;\n\twidth: 16px;\n\theight: 16px;\n\tpadding-right: 3px;\n}\n\n.dojoMenuItem2Label {\n\tposition: relative;\n\tvertical-align: middle;\n}\n\n/* main label text */\n.dojoMenuItem2Label {\n\tposition: relative;\n\tvertical-align: middle;\n}\n\n.dojoMenuItem2Accel {\n\tposition: relative;\n\tvertical-align: middle;\n\tpadding-left: 3px;\n}\n\n.dojoMenuItem2Disabled .dojoMenuItem2Label,\n.dojoMenuItem2Disabled .dojoMenuItem2Accel {\n\tcolor: #607a9e;\n}\n\n.dojoMenuItem2Submenu {\n\tposition: relative;\n\tbackground-position: center center;\n\tbackground-repeat: no-repeat;\n\tbackground-image: url(images/submenu_off.gif);\n\twidth: 5px;\n\theight: 9px;\n\tpadding-left: 3px;\n}\n.dojoMenuItem2Hover .dojoMenuItem2Submenu {\n\tbackground-image: url(images/submenu_on.gif);\n}\n\n.dojoMenuItem2Disabled .dojoMenuItem2Submenu {\n\tbackground-image: url(images/submenu_disabled.gif);\n}\n\n.dojoMenuSeparator2 {\n\tfont-size: 1px;\n\tmargin: 0;\n}\n\n.dojoMenuSeparator2Top {\n\theight: 50%;\n\tborder-bottom: 1px solid #7a98c4;\n\tmargin: 0px 2px;\n\tfont-size: 1px;\n}\n\n.dojoMenuSeparator2Bottom {\n\theight: 50%;\n\tborder-top: 1px solid #c9deff;\n\tmargin: 0px 2px;\n\tfont-size: 1px;\n}\n\n.dojoMenuBar2 {\n\tbackground:#85aeec url(images/soriaBarBg.gif) repeat-x top left;\n\t/*border-bottom:1px solid #6b9fec;*/\n\tpadding: 1px;\n}\n\n.dojoMenuBar2 .dojoMenuItem2 {\n\twhite-space: nowrap;\n\tfont: menu;\n\tmargin: 0;\n\tposition: relative;\n\tvertical-align: middle;\n\tz-index: 1;\n\tpadding: 3px 8px;\n\tdisplay: inline;/* needed in khtml to display correctly */\n\tdisplay: -moz-inline-box;/* needed in firefox */\n\tcursor:pointer;\n\tcursor:hand;\n}\n\n.dojoMenuBar2 .dojoMenuItem2Hover {\n\tbackground-color:#d2e4fd;\n}\n\n.dojoMenuBar2 .dojoMenuItem2Disabled span {\n\tcolor: #4f6582;\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/Menu2.css"), submenuDelay:500, initialize:function (args, frag) {
16
	if (this.eventNaming == "default") {
17
		for (var eventName in this.eventNames) {
18
			this.eventNames[eventName] = this.widgetId + "/" + eventName;
19
		}
20
	}
21
}, _moveToNext:function (evt) {
22
	this._highlightOption(1);
23
	return true;
24
}, _moveToPrevious:function (evt) {
25
	this._highlightOption(-1);
26
	return true;
27
}, _moveToParentMenu:function (evt) {
28
	if (this._highlighted_option && this.parentMenu) {
29
		if (evt._menu2UpKeyProcessed) {
30
			return true;
31
		} else {
32
			this._highlighted_option.onUnhover();
33
			this.closeSubmenu();
34
			evt._menu2UpKeyProcessed = true;
35
		}
36
	}
37
	return false;
38
}, _moveToChildMenu:function (evt) {
39
	if (this._highlighted_option && this._highlighted_option.submenuId) {
40
		this._highlighted_option._onClick(true);
41
		return true;
42
	}
43
	return false;
44
}, _selectCurrentItem:function (evt) {
45
	if (this._highlighted_option) {
46
		this._highlighted_option._onClick();
47
		return true;
48
	}
49
	return false;
50
}, processKey:function (evt) {
51
	if (evt.ctrlKey || evt.altKey || !evt.key) {
52
		return false;
53
	}
54
	var rval = false;
55
	switch (evt.key) {
56
	  case evt.KEY_DOWN_ARROW:
57
		rval = this._moveToNext(evt);
58
		break;
59
	  case evt.KEY_UP_ARROW:
60
		rval = this._moveToPrevious(evt);
61
		break;
62
	  case evt.KEY_RIGHT_ARROW:
63
		rval = this._moveToChildMenu(evt);
64
		break;
65
	  case evt.KEY_LEFT_ARROW:
66
		rval = this._moveToParentMenu(evt);
67
		break;
68
	  case " ":
69
	  case evt.KEY_ENTER:
70
		if (rval = this._selectCurrentItem(evt)) {
71
			break;
72
		}
73
	  case evt.KEY_ESCAPE:
74
	  case evt.KEY_TAB:
75
		this.close(true);
76
		rval = true;
77
		break;
78
	}
79
	return rval;
80
}, _findValidItem:function (dir, curItem) {
81
	if (curItem) {
82
		curItem = dir > 0 ? curItem.getNextSibling() : curItem.getPreviousSibling();
83
	}
84
	for (var i = 0; i < this.children.length; ++i) {
85
		if (!curItem) {
86
			curItem = dir > 0 ? this.children[0] : this.children[this.children.length - 1];
87
		}
88
		if (curItem.onHover && curItem.isShowing()) {
89
			return curItem;
90
		}
91
		curItem = dir > 0 ? curItem.getNextSibling() : curItem.getPreviousSibling();
92
	}
93
}, _highlightOption:function (dir) {
94
	var item;
95
	if ((!this._highlighted_option)) {
96
		item = this._findValidItem(dir);
97
	} else {
98
		item = this._findValidItem(dir, this._highlighted_option);
99
	}
100
	if (item) {
101
		if (this._highlighted_option) {
102
			this._highlighted_option.onUnhover();
103
		}
104
		item.onHover();
105
		dojo.html.scrollIntoView(item.domNode);
106
		try {
107
			var node = dojo.html.getElementsByClass("dojoMenuItem2Label", item.domNode)[0];
108
			node.focus();
109
		}
110
		catch (e) {
111
		}
112
	}
113
}, onItemClick:function (item) {
114
}, closeSubmenu:function (force) {
115
	if (this.currentSubmenu == null) {
116
		return;
117
	}
118
	this.currentSubmenu.close(force);
119
	this.currentSubmenu = null;
120
	this.currentSubmenuTrigger.is_open = false;
121
	this.currentSubmenuTrigger._closedSubmenu(force);
122
	this.currentSubmenuTrigger = null;
123
}});
124
dojo.widget.defineWidget("dojo.widget.PopupMenu2", [dojo.widget.HtmlWidget, dojo.widget.PopupContainerBase, dojo.widget.MenuBase], function () {
125
	this.targetNodeIds = [];
126
}, {templateString:"<table class=\"dojoPopupMenu2\" border=0 cellspacing=0 cellpadding=0 style=\"display: none; position: absolute;\">" + "<tbody dojoAttachPoint=\"containerNode\"></tbody>" + "</table>", submenuOverlap:5, contextMenuForWindow:false, parentMenu:null, postCreate:function () {
127
	if (this.contextMenuForWindow) {
128
		var doc = dojo.body();
129
		this.bindDomNode(doc);
130
	} else {
131
		if (this.targetNodeIds.length > 0) {
132
			dojo.lang.forEach(this.targetNodeIds, this.bindDomNode, this);
133
		}
134
	}
135
	this._subscribeSubitemsOnOpen();
136
}, _subscribeSubitemsOnOpen:function () {
137
	var subItems = this.getChildrenOfType(dojo.widget.MenuItem2);
138
	for (var i = 0; i < subItems.length; i++) {
139
		dojo.event.topic.subscribe(this.eventNames.open, subItems[i], "menuOpen");
140
	}
141
}, getTopOpenEvent:function () {
142
	var menu = this;
143
	while (menu.parentMenu) {
144
		menu = menu.parentMenu;
145
	}
146
	return menu.openEvent;
147
}, bindDomNode:function (node) {
148
	node = dojo.byId(node);
149
	var win = dojo.html.getElementWindow(node);
150
	if (dojo.html.isTag(node, "iframe") == "iframe") {
151
		win = dojo.html.iframeContentWindow(node);
152
		node = dojo.withGlobal(win, dojo.body);
153
	}
154
	dojo.widget.Menu2.OperaAndKonqFixer.fixNode(node);
155
	dojo.event.kwConnect({srcObj:node, srcFunc:"oncontextmenu", targetObj:this, targetFunc:"onOpen", once:true});
156
	if (dojo.render.html.moz && win.document.designMode.toLowerCase() == "on") {
157
		dojo.event.browser.addListener(node, "contextmenu", dojo.lang.hitch(this, "onOpen"));
158
	}
159
	dojo.widget.PopupManager.registerWin(win);
160
}, unBindDomNode:function (nodeName) {
161
	var node = dojo.byId(nodeName);
162
	dojo.event.kwDisconnect({srcObj:node, srcFunc:"oncontextmenu", targetObj:this, targetFunc:"onOpen", once:true});
163
	dojo.widget.Menu2.OperaAndKonqFixer.cleanNode(node);
164
}, _openAsSubmenu:function (parent, explodeSrc, orient) {
165
	if (this.isShowingNow) {
166
		return;
167
	}
168
	this.parentMenu = parent;
169
	this.open(explodeSrc, parent, explodeSrc, orient);
170
}, close:function (force) {
171
	if (this.animationInProgress) {
172
		dojo.widget.PopupContainerBase.prototype.close.call(this, force);
173
		return;
174
	}
175
	if (this._highlighted_option) {
176
		this._highlighted_option.onUnhover();
177
	}
178
	dojo.widget.PopupContainerBase.prototype.close.call(this, force);
179
	this.parentMenu = null;
180
}, closeAll:function (force) {
181
	if (this.parentMenu) {
182
		this.parentMenu.closeAll(force);
183
	} else {
184
		this.close(force);
185
	}
186
}, _openSubmenu:function (submenu, from_item) {
187
	submenu._openAsSubmenu(this, from_item.arrow, {"TR":"TL", "TL":"TR"});
188
	this.currentSubmenu = submenu;
189
	this.currentSubmenuTrigger = from_item;
190
	this.currentSubmenuTrigger.is_open = true;
191
}, focus:function () {
192
	if (this.currentSubmenuTrigger) {
193
		if (this.currentSubmenuTrigger.caption) {
194
			try {
195
				this.currentSubmenuTrigger.caption.focus();
196
			}
197
			catch (e) {
198
			}
199
		} else {
200
			try {
201
				this.currentSubmenuTrigger.domNode.focus();
202
			}
203
			catch (e) {
204
			}
205
		}
206
	}
207
}, onOpen:function (e) {
208
	this.openEvent = e;
209
	if (e["target"]) {
210
		this.openedForWindow = dojo.html.getElementWindow(e.target);
211
	} else {
212
		this.openedForWindow = null;
213
	}
214
	var x = e.pageX, y = e.pageY;
215
	var win = dojo.html.getElementWindow(e.target);
216
	var iframe = win._frameElement || win.frameElement;
217
	if (iframe) {
218
		var cood = dojo.html.abs(iframe, true);
219
		x += cood.x - dojo.withGlobal(win, dojo.html.getScroll).left;
220
		y += cood.y - dojo.withGlobal(win, dojo.html.getScroll).top;
221
	}
222
	this.open(x, y, null, [x, y]);
223
	dojo.event.browser.stopEvent(e);
224
}});
225
dojo.widget.defineWidget("dojo.widget.MenuItem2", dojo.widget.HtmlWidget, function () {
226
	this.eventNames = {engage:""};
227
}, {templateString:"<tr class=\"dojoMenuItem2\" dojoAttachEvent=\"onMouseOver: onHover; onMouseOut: onUnhover; onClick: _onClick; onKey:onKey;\">" + "<td><div class=\"${this.iconClass}\" style=\"${this.iconStyle}\"></div></td>" + "<td tabIndex=\"-1\" class=\"dojoMenuItem2Label\" dojoAttachPoint=\"caption\">${this.caption}</td>" + "<td class=\"dojoMenuItem2Accel\">${this.accelKey}</td>" + "<td><div class=\"dojoMenuItem2Submenu\" style=\"display:${this.arrowDisplay};\" dojoAttachPoint=\"arrow\"></div></td>" + "</tr>", is_hovering:false, hover_timer:null, is_open:false, topPosition:0, caption:"Untitled", accelKey:"", iconSrc:"", disabledClass:"dojoMenuItem2Disabled", iconClass:"dojoMenuItem2Icon", submenuId:"", eventNaming:"default", highlightClass:"dojoMenuItem2Hover", postMixInProperties:function () {
228
	this.iconStyle = "";
229
	if (this.iconSrc) {
230
		if ((this.iconSrc.toLowerCase().substring(this.iconSrc.length - 4) == ".png") && (dojo.render.html.ie55 || dojo.render.html.ie60)) {
231
			this.iconStyle = "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.iconSrc + "', sizingMethod='image')";
232
		} else {
233
			this.iconStyle = "background-image: url(" + this.iconSrc + ")";
234
		}
235
	}
236
	this.arrowDisplay = this.submenuId ? "block" : "none";
237
	dojo.widget.MenuItem2.superclass.postMixInProperties.apply(this, arguments);
238
}, fillInTemplate:function () {
239
	dojo.html.disableSelection(this.domNode);
240
	if (this.disabled) {
241
		this.setDisabled(true);
242
	}
243
	if (this.eventNaming == "default") {
244
		for (var eventName in this.eventNames) {
245
			this.eventNames[eventName] = this.widgetId + "/" + eventName;
246
		}
247
	}
248
}, onHover:function () {
249
	this.onUnhover();
250
	if (this.is_hovering) {
251
		return;
252
	}
253
	if (this.is_open) {
254
		return;
255
	}
256
	if (this.parent._highlighted_option) {
257
		this.parent._highlighted_option.onUnhover();
258
	}
259
	this.parent.closeSubmenu();
260
	this.parent._highlighted_option = this;
261
	dojo.widget.PopupManager.setFocusedMenu(this.parent);
262
	this._highlightItem();
263
	if (this.is_hovering) {
264
		this._stopSubmenuTimer();
265
	}
266
	this.is_hovering = true;
267
	this._startSubmenuTimer();
268
}, onUnhover:function () {
269
	if (!this.is_open) {
270
		this._unhighlightItem();
271
	}
272
	this.is_hovering = false;
273
	this.parent._highlighted_option = null;
274
	if (this.parent.parentMenu) {
275
		dojo.widget.PopupManager.setFocusedMenu(this.parent.parentMenu);
276
	}
277
	this._stopSubmenuTimer();
278
}, _onClick:function (focus) {
279
	var displayingSubMenu = false;
280
	if (this.disabled) {
281
		return false;
282
	}
283
	if (this.submenuId) {
284
		if (!this.is_open) {
285
			this._stopSubmenuTimer();
286
			this._openSubmenu();
287
		}
288
		displayingSubMenu = true;
289
	} else {
290
		this.onUnhover();
291
		this.parent.closeAll(true);
292
	}
293
	this.onClick();
294
	dojo.event.topic.publish(this.eventNames.engage, this);
295
	if (displayingSubMenu && focus) {
296
		dojo.widget.getWidgetById(this.submenuId)._highlightOption(1);
297
	}
298
	return;
299
}, onClick:function () {
300
	this.parent.onItemClick(this);
301
}, _highlightItem:function () {
302
	dojo.html.addClass(this.domNode, this.highlightClass);
303
}, _unhighlightItem:function () {
304
	dojo.html.removeClass(this.domNode, this.highlightClass);
305
}, _startSubmenuTimer:function () {
306
	this._stopSubmenuTimer();
307
	if (this.disabled) {
308
		return;
309
	}
310
	var self = this;
311
	var closure = function () {
312
		return function () {
313
			self._openSubmenu();
314
		};
315
	}();
316
	this.hover_timer = dojo.lang.setTimeout(closure, this.parent.submenuDelay);
317
}, _stopSubmenuTimer:function () {
318
	if (this.hover_timer) {
319
		dojo.lang.clearTimeout(this.hover_timer);
320
		this.hover_timer = null;
321
	}
322
}, _openSubmenu:function () {
323
	if (this.disabled) {
324
		return;
325
	}
326
	this.parent.closeSubmenu();
327
	var submenu = dojo.widget.getWidgetById(this.submenuId);
328
	if (submenu) {
329
		this.parent._openSubmenu(submenu, this);
330
	}
331
}, _closedSubmenu:function () {
332
	this.onUnhover();
333
}, setDisabled:function (value) {
334
	this.disabled = value;
335
	if (this.disabled) {
336
		dojo.html.addClass(this.domNode, this.disabledClass);
337
	} else {
338
		dojo.html.removeClass(this.domNode, this.disabledClass);
339
	}
340
}, enable:function () {
341
	this.setDisabled(false);
342
}, disable:function () {
343
	this.setDisabled(true);
344
}, menuOpen:function (message) {
345
}});
346
dojo.widget.defineWidget("dojo.widget.MenuSeparator2", dojo.widget.HtmlWidget, {templateString:"<tr class=\"dojoMenuSeparator2\"><td colspan=4>" + "<div class=\"dojoMenuSeparator2Top\"></div>" + "<div class=\"dojoMenuSeparator2Bottom\"></div>" + "</td></tr>", postCreate:function () {
347
	dojo.html.disableSelection(this.domNode);
348
}});
349
dojo.widget.defineWidget("dojo.widget.MenuBar2", [dojo.widget.HtmlWidget, dojo.widget.MenuBase], {menuOverlap:2, templateString:"<div class=\"dojoMenuBar2\" dojoAttachPoint=\"containerNode\" tabIndex=\"0\"></div>", close:function (force) {
350
	if (this._highlighted_option) {
351
		this._highlighted_option.onUnhover();
352
	}
353
	this.closeSubmenu(force);
354
}, closeAll:function (force) {
355
	this.close(force);
356
}, processKey:function (evt) {
357
	if (evt.ctrlKey || evt.altKey) {
358
		return false;
359
	}
360
	var rval = false;
361
	switch (evt.key) {
362
	  case evt.KEY_DOWN_ARROW:
363
		rval = this._moveToChildMenu(evt);
364
		break;
365
	  case evt.KEY_UP_ARROW:
366
		rval = this._moveToParentMenu(evt);
367
		break;
368
	  case evt.KEY_RIGHT_ARROW:
369
		rval = this._moveToNext(evt);
370
		break;
371
	  case evt.KEY_LEFT_ARROW:
372
		rval = this._moveToPrevious(evt);
373
		break;
374
	  default:
375
		rval = dojo.widget.MenuBar2.superclass.processKey.apply(this, arguments);
376
		break;
377
	}
378
	return rval;
379
}, postCreate:function () {
380
	dojo.widget.MenuBar2.superclass.postCreate.apply(this, arguments);
381
	this.isShowingNow = true;
382
}, _openSubmenu:function (submenu, from_item) {
383
	submenu._openAsSubmenu(this, from_item.domNode, {"BL":"TL", "TL":"BL"});
384
	this.currentSubmenu = submenu;
385
	this.currentSubmenuTrigger = from_item;
386
	this.currentSubmenuTrigger.is_open = true;
387
}});
388
dojo.widget.defineWidget("dojo.widget.MenuBarItem2", dojo.widget.MenuItem2, {templateString:"<span class=\"dojoMenuItem2\" dojoAttachEvent=\"onMouseOver: onHover; onMouseOut: onUnhover; onClick: _onClick;\">${this.caption}</span>"});
389
dojo.widget.Menu2.OperaAndKonqFixer = new function () {
390
	var implement = true;
391
	var delfunc = false;
392
	if (!dojo.lang.isFunction(dojo.doc().oncontextmenu)) {
393
		dojo.doc().oncontextmenu = function () {
394
			implement = false;
395
			delfunc = true;
396
		};
397
	}
398
	if (dojo.doc().createEvent) {
399
		try {
400
			var e = dojo.doc().createEvent("MouseEvents");
401
			e.initMouseEvent("contextmenu", 1, 1, dojo.global(), 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, null);
402
			dojo.doc().dispatchEvent(e);
403
		}
404
		catch (e) {
405
		}
406
	} else {
407
		implement = false;
408
	}
409
	if (delfunc) {
410
		delete dojo.doc().oncontextmenu;
411
	}
412
	this.fixNode = function (node) {
413
		if (implement) {
414
			if (!dojo.lang.isFunction(node.oncontextmenu)) {
415
				node.oncontextmenu = function (e) {
416
				};
417
			}
418
			if (dojo.render.html.opera) {
419
				node._menufixer_opera = function (e) {
420
					if (e.ctrlKey) {
421
						this.oncontextmenu(e);
422
					}
423
				};
424
				dojo.event.connect(node, "onclick", node, "_menufixer_opera");
425
			} else {
426
				node._menufixer_konq = function (e) {
427
					if (e.button == 2) {
428
						e.preventDefault();
429
						this.oncontextmenu(e);
430
					}
431
				};
432
				dojo.event.connect(node, "onmousedown", node, "_menufixer_konq");
433
			}
434
		}
435
	};
436
	this.cleanNode = function (node) {
437
		if (implement) {
438
			if (node._menufixer_opera) {
439
				dojo.event.disconnect(node, "onclick", node, "_menufixer_opera");
440
				delete node._menufixer_opera;
441
			} else {
442
				if (node._menufixer_konq) {
443
					dojo.event.disconnect(node, "onmousedown", node, "_menufixer_konq");
444
					delete node._menufixer_konq;
445
				}
446
			}
447
			if (node.oncontextmenu) {
448
				delete node.oncontextmenu;
449
			}
450
		}
451
	};
452
};
453