Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | 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.Button");
14
dojo.require("dojo.lang.extras");
15
dojo.require("dojo.html.*");
16
dojo.require("dojo.html.selection");
17
dojo.require("dojo.widget.*");
18
dojo.widget.defineWidget("dojo.widget.Button", dojo.widget.HtmlWidget, {isContainer:true, caption:"", templateString:"<div dojoAttachPoint=\"buttonNode\" class=\"dojoButton\" style=\"position:relative;\" dojoAttachEvent=\"onMouseOver; onMouseOut; onMouseDown; onMouseUp; onClick:buttonClick; onKey:onKey; onFocus;\">\n  <div class=\"dojoButtonContents\" align=center dojoAttachPoint=\"containerNode\" style=\"position:absolute;z-index:2;\"></div>\n  <img dojoAttachPoint=\"leftImage\" style=\"position:absolute;left:0px;\">\n  <img dojoAttachPoint=\"centerImage\" style=\"position:absolute;z-index:1;\">\n  <img dojoAttachPoint=\"rightImage\" style=\"position:absolute;top:0px;right:0px;\">\n</div>\n", templateCssString:"/* ---- button --- */\n.dojoButton {\n\tpadding: 0 0 0 0;\n\tfont-size: 8pt;\n\twhite-space: nowrap;\n\tcursor: pointer;\n\tfont-family: Myriad, Tahoma, Verdana, sans-serif;\n}\n\n.dojoButton .dojoButtonContents {\n\tpadding: 2px 2px 2px 2px;\n\ttext-align: center;\t\t/* if icon and label are split across two lines, center icon */\n\tcolor: white;\n}\n\n.dojoButtonLeftPart .dojoButtonContents {\n\tpadding-right: 8px;\n}\n\n.dojoButtonDisabled {\n\tcursor: url(\"images/no.gif\"), default;\n}\n\n\n.dojoButtonContents img {\n\tvertical-align: middle;\t/* if icon and label are on same line, center them */\n}\n\n/* -------- colors ------------ */\n\n.dojoButtonHover .dojoButtonContents {\n}\n\n.dojoButtonDepressed .dojoButtonContents {\n\tcolor: #293a4b;\n}\n\n.dojoButtonDisabled .dojoButtonContents {\n\tcolor: #aaa;\n}\n\n\n/* ---------- drop down button specific ---------- */\n\n/* border between label and arrow (for drop down buttons */\n.dojoButton .border {\n\twidth: 1px;\n\tbackground: gray;\n}\n\n/* button arrow */\n.dojoButton .downArrow {\n\tpadding-left: 10px;\n\ttext-align: center;\n}\n\n.dojoButton.disabled .downArrow {\n\tcursor : default;\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/ButtonTemplate.css"), inactiveImg:"templates/images/soriaButton-", activeImg:"templates/images/soriaActive-", pressedImg:"templates/images/soriaPressed-", disabledImg:"templates/images/soriaDisabled-", width2height:1 / 3, fillInTemplate:function () {
19
	if (this.caption) {
20
		this.containerNode.appendChild(document.createTextNode(this.caption));
21
	}
22
	dojo.html.disableSelection(this.containerNode);
23
}, postCreate:function () {
24
	this._sizeMyself();
25
}, _sizeMyself:function () {
26
	if (this.domNode.parentNode) {
27
		var placeHolder = document.createElement("span");
28
		dojo.html.insertBefore(placeHolder, this.domNode);
29
	}
30
	dojo.body().appendChild(this.domNode);
31
	this._sizeMyselfHelper();
32
	if (placeHolder) {
33
		dojo.html.insertBefore(this.domNode, placeHolder);
34
		dojo.html.removeNode(placeHolder);
35
	}
36
}, _sizeMyselfHelper:function () {
37
	var mb = dojo.html.getMarginBox(this.containerNode);
38
	this.height = mb.height;
39
	this.containerWidth = mb.width;
40
	var endWidth = this.height * this.width2height;
41
	this.containerNode.style.left = endWidth + "px";
42
	this.leftImage.height = this.rightImage.height = this.centerImage.height = this.height;
43
	this.leftImage.width = this.rightImage.width = endWidth + 1;
44
	this.centerImage.width = this.containerWidth;
45
	this.centerImage.style.left = endWidth + "px";
46
	this._setImage(this.disabled ? this.disabledImg : this.inactiveImg);
47
	if (this.disabled) {
48
		dojo.html.prependClass(this.domNode, "dojoButtonDisabled");
49
		this.domNode.removeAttribute("tabIndex");
50
		dojo.widget.wai.setAttr(this.domNode, "waiState", "disabled", true);
51
	} else {
52
		dojo.html.removeClass(this.domNode, "dojoButtonDisabled");
53
		this.domNode.setAttribute("tabIndex", "0");
54
		dojo.widget.wai.setAttr(this.domNode, "waiState", "disabled", false);
55
	}
56
	this.domNode.style.height = this.height + "px";
57
	this.domNode.style.width = (this.containerWidth + 2 * endWidth) + "px";
58
}, onMouseOver:function (e) {
59
	if (this.disabled) {
60
		return;
61
	}
62
	if (!dojo.html.hasClass(this.buttonNode, "dojoButtonHover")) {
63
		dojo.html.prependClass(this.buttonNode, "dojoButtonHover");
64
	}
65
	this._setImage(this.activeImg);
66
}, onMouseDown:function (e) {
67
	if (this.disabled) {
68
		return;
69
	}
70
	dojo.html.prependClass(this.buttonNode, "dojoButtonDepressed");
71
	dojo.html.removeClass(this.buttonNode, "dojoButtonHover");
72
	this._setImage(this.pressedImg);
73
}, onMouseUp:function (e) {
74
	if (this.disabled) {
75
		return;
76
	}
77
	dojo.html.prependClass(this.buttonNode, "dojoButtonHover");
78
	dojo.html.removeClass(this.buttonNode, "dojoButtonDepressed");
79
	this._setImage(this.activeImg);
80
}, onMouseOut:function (e) {
81
	if (this.disabled) {
82
		return;
83
	}
84
	if (e.toElement && dojo.html.isDescendantOf(e.toElement, this.buttonNode)) {
85
		return;
86
	}
87
	dojo.html.removeClass(this.buttonNode, "dojoButtonHover");
88
	dojo.html.removeClass(this.buttonNode, "dojoButtonDepressed");
89
	this._setImage(this.inactiveImg);
90
}, onKey:function (e) {
91
	if (!e.key) {
92
		return;
93
	}
94
	var menu = dojo.widget.getWidgetById(this.menuId);
95
	if (e.key == e.KEY_ENTER || e.key == " ") {
96
		this.onMouseDown(e);
97
		this.buttonClick(e);
98
		dojo.lang.setTimeout(this, "onMouseUp", 75, e);
99
		dojo.event.browser.stopEvent(e);
100
	}
101
	if (menu && menu.isShowingNow && e.key == e.KEY_DOWN_ARROW) {
102
		dojo.event.disconnect(this.domNode, "onblur", this, "onBlur");
103
	}
104
}, onFocus:function (e) {
105
	var menu = dojo.widget.getWidgetById(this.menuId);
106
	if (menu) {
107
		dojo.event.connectOnce(this.domNode, "onblur", this, "onBlur");
108
	}
109
}, onBlur:function (e) {
110
	var menu = dojo.widget.getWidgetById(this.menuId);
111
	if (!menu) {
112
		return;
113
	}
114
	if (menu.close && menu.isShowingNow) {
115
		menu.close();
116
	}
117
}, buttonClick:function (e) {
118
	if (!this.disabled) {
119
		try {
120
			this.domNode.focus();
121
		}
122
		catch (e2) {
123
		}
124
		this.onClick(e);
125
	}
126
}, onClick:function (e) {
127
}, _setImage:function (prefix) {
128
	this.leftImage.src = dojo.uri.moduleUri("dojo.widget", prefix + "l.gif");
129
	this.centerImage.src = dojo.uri.moduleUri("dojo.widget", prefix + "c.gif");
130
	this.rightImage.src = dojo.uri.moduleUri("dojo.widget", prefix + "r.gif");
131
}, _toggleMenu:function (menuId) {
132
	var menu = dojo.widget.getWidgetById(menuId);
133
	if (!menu) {
134
		return;
135
	}
136
	if (menu.open && !menu.isShowingNow) {
137
		var pos = dojo.html.getAbsolutePosition(this.domNode, false);
138
		menu.open(pos.x, pos.y + this.height, this);
139
		dojo.event.disconnect(this.domNode, "onblur", this, "onBlur");
140
	} else {
141
		if (menu.close && menu.isShowingNow) {
142
			menu.close();
143
		} else {
144
			menu.toggle();
145
		}
146
	}
147
}, setCaption:function (content) {
148
	this.caption = content;
149
	this.containerNode.innerHTML = content;
150
	this._sizeMyself();
151
}, setDisabled:function (disabled) {
152
	this.disabled = disabled;
153
	this._sizeMyself();
154
}});
155
dojo.widget.defineWidget("dojo.widget.DropDownButton", dojo.widget.Button, {menuId:"", downArrow:"templates/images/whiteDownArrow.gif", disabledDownArrow:"templates/images/whiteDownArrow.gif", fillInTemplate:function () {
156
	dojo.widget.DropDownButton.superclass.fillInTemplate.apply(this, arguments);
157
	this.arrow = document.createElement("img");
158
	dojo.html.setClass(this.arrow, "downArrow");
159
	dojo.widget.wai.setAttr(this.domNode, "waiState", "haspopup", this.menuId);
160
}, _sizeMyselfHelper:function () {
161
	this.arrow.src = dojo.uri.moduleUri("dojo.widget", this.disabled ? this.disabledDownArrow : this.downArrow);
162
	this.containerNode.appendChild(this.arrow);
163
	dojo.widget.DropDownButton.superclass._sizeMyselfHelper.call(this);
164
}, onClick:function (e) {
165
	this._toggleMenu(this.menuId);
166
}});
167
dojo.widget.defineWidget("dojo.widget.ComboButton", dojo.widget.Button, {menuId:"", templateString:"<div class=\"dojoButton\" style=\"position:relative;top:0px;left:0px; text-align:none;\" dojoAttachEvent=\"onKey;onFocus\">\n\n\t<div dojoAttachPoint=\"buttonNode\" class=\"dojoButtonLeftPart\" style=\"position:absolute;left:0px;top:0px;\"\n\t\tdojoAttachEvent=\"onMouseOver; onMouseOut; onMouseDown; onMouseUp; onClick:buttonClick;\">\n\t\t<div class=\"dojoButtonContents\" dojoAttachPoint=\"containerNode\" style=\"position:absolute;top:0px;right:0px;z-index:2;\"></div>\n\t\t<img dojoAttachPoint=\"leftImage\" style=\"position:absolute;left:0px;top:0px;\">\n\t\t<img dojoAttachPoint=\"centerImage\" style=\"position:absolute;right:0px;top:0px;z-index:1;\">\n\t</div>\n\n\t<div dojoAttachPoint=\"rightPart\" class=\"dojoButtonRightPart\" style=\"position:absolute;top:0px;right:0px;\"\n\t\tdojoAttachEvent=\"onMouseOver:rightOver; onMouseOut:rightOut; onMouseDown:rightDown; onMouseUp:rightUp; onClick:rightClick;\">\n\t\t<img dojoAttachPoint=\"arrowBackgroundImage\" style=\"position:absolute;top:0px;left:0px;z-index:1;\">\n\t\t<img src=\"${dojoWidgetModuleUri}templates/images/whiteDownArrow.gif\"\n\t\t  \t\tstyle=\"z-index:2;position:absolute;left:3px;top:50%;\">\n\t\t<img dojoAttachPoint=\"rightImage\" style=\"position:absolute;top:0px;right:0px;\">\n\t</div>\n\n</div>\n", splitWidth:2, arrowWidth:5, _sizeMyselfHelper:function (e) {
168
	var mb = dojo.html.getMarginBox(this.containerNode);
169
	this.height = mb.height;
170
	this.containerWidth = mb.width;
171
	var endWidth = this.height / 3;
172
	if (this.disabled) {
173
		dojo.widget.wai.setAttr(this.domNode, "waiState", "disabled", true);
174
		this.domNode.removeAttribute("tabIndex");
175
	} else {
176
		dojo.widget.wai.setAttr(this.domNode, "waiState", "disabled", false);
177
		this.domNode.setAttribute("tabIndex", "0");
178
	}
179
	this.leftImage.height = this.rightImage.height = this.centerImage.height = this.arrowBackgroundImage.height = this.height;
180
	this.leftImage.width = endWidth + 1;
181
	this.centerImage.width = this.containerWidth;
182
	this.buttonNode.style.height = this.height + "px";
183
	this.buttonNode.style.width = endWidth + this.containerWidth + "px";
184
	this._setImage(this.disabled ? this.disabledImg : this.inactiveImg);
185
	this.arrowBackgroundImage.width = this.arrowWidth;
186
	this.rightImage.width = endWidth + 1;
187
	this.rightPart.style.height = this.height + "px";
188
	this.rightPart.style.width = this.arrowWidth + endWidth + "px";
189
	this._setImageR(this.disabled ? this.disabledImg : this.inactiveImg);
190
	this.domNode.style.height = this.height + "px";
191
	var totalWidth = this.containerWidth + this.splitWidth + this.arrowWidth + 2 * endWidth;
192
	this.domNode.style.width = totalWidth + "px";
193
}, _setImage:function (prefix) {
194
	this.leftImage.src = dojo.uri.moduleUri("dojo.widget", prefix + "l.gif");
195
	this.centerImage.src = dojo.uri.moduleUri("dojo.widget", prefix + "c.gif");
196
}, rightOver:function (e) {
197
	if (this.disabled) {
198
		return;
199
	}
200
	dojo.html.prependClass(this.rightPart, "dojoButtonHover");
201
	this._setImageR(this.activeImg);
202
}, rightDown:function (e) {
203
	if (this.disabled) {
204
		return;
205
	}
206
	dojo.html.prependClass(this.rightPart, "dojoButtonDepressed");
207
	dojo.html.removeClass(this.rightPart, "dojoButtonHover");
208
	this._setImageR(this.pressedImg);
209
}, rightUp:function (e) {
210
	if (this.disabled) {
211
		return;
212
	}
213
	dojo.html.prependClass(this.rightPart, "dojoButtonHover");
214
	dojo.html.removeClass(this.rightPart, "dojoButtonDepressed");
215
	this._setImageR(this.activeImg);
216
}, rightOut:function (e) {
217
	if (this.disabled) {
218
		return;
219
	}
220
	dojo.html.removeClass(this.rightPart, "dojoButtonHover");
221
	dojo.html.removeClass(this.rightPart, "dojoButtonDepressed");
222
	this._setImageR(this.inactiveImg);
223
}, rightClick:function (e) {
224
	if (this.disabled) {
225
		return;
226
	}
227
	try {
228
		this.domNode.focus();
229
	}
230
	catch (e2) {
231
	}
232
	this._toggleMenu(this.menuId);
233
}, _setImageR:function (prefix) {
234
	this.arrowBackgroundImage.src = dojo.uri.moduleUri("dojo.widget", prefix + "c.gif");
235
	this.rightImage.src = dojo.uri.moduleUri("dojo.widget", prefix + "r.gif");
236
}, onKey:function (e) {
237
	if (!e.key) {
238
		return;
239
	}
240
	var menu = dojo.widget.getWidgetById(this.menuId);
241
	if (e.key == e.KEY_ENTER || e.key == " ") {
242
		this.onMouseDown(e);
243
		this.buttonClick(e);
244
		dojo.lang.setTimeout(this, "onMouseUp", 75, e);
245
		dojo.event.browser.stopEvent(e);
246
	} else {
247
		if (e.key == e.KEY_DOWN_ARROW && e.altKey) {
248
			this.rightDown(e);
249
			this.rightClick(e);
250
			dojo.lang.setTimeout(this, "rightUp", 75, e);
251
			dojo.event.browser.stopEvent(e);
252
		} else {
253
			if (menu && menu.isShowingNow && e.key == e.KEY_DOWN_ARROW) {
254
				dojo.event.disconnect(this.domNode, "onblur", this, "onBlur");
255
			}
256
		}
257
	}
258
}});
259