Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
Copyright (c) 2007, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.2.0
*/
/**
* @module button
* @description <p>The Button Control enables the creation of rich, graphical
* buttons that function like traditional HTML form buttons. <em>Unlike</em>
* tradition HTML form buttons, buttons created with the Button Control can have
* a label that is different from its value. With the inclusion of the optional
* <a href="module_menu.html">Menu Control</a>, the Button Control can also be
* used to create menu buttons and split buttons, controls that are not
* available natively in HTML. The Button Control can also be thought of as a
* way to create more visually engaging implementations of the browser's
* default radio-button and check-box controls.</p>
* <p>The Button Control supports the following types:</p>
* <dl>
* <dt>button</dt>
* <dd>Basic push button that can execute a user-specified command when
* pressed.</dd>
* <dt>link</dt>
* <dd>Navigates to a specified url when pressed.</dd>
* <dt>submit</dt>
* <dd>Submits the parent form when pressed.</dd>
* <dt>reset</dt>
* <dd>Resets the parent form when pressed.</dd>
* <dt>checkbox</dt>
* <dd>Maintains a "checked" state that can be toggled on and off.</dd>
* <dt>radio</dt>
* <dd>Maintains a "checked" state that can be toggled on and off. Use with
* the ButtonGroup class to create a set of controls that are mutually
* exclusive; checking one button in the set will uncheck all others in
* the group.</dd>
* <dt>menubutton</dt>
* <dd>When pressed will show/hide a menu.</dd>
* <dt>splitbutton</dt>
* <dd>Can execute a user-specified command or display a menu when pressed.</dd>
* </dl>
* @title Button
* @namespace YAHOO.widget
* @requires yahoo, dom, element, event
* @optional container, menu
* @beta
*/
(function() {
// Shorthard for utilities
var Dom = YAHOO.util.Dom,
Event = YAHOO.util.Event,
Lang = YAHOO.lang,
// Private member variables
m_oButtons = {},
m_oFocusedButton = null;
// Constructor
/**
* The Button class creates a rich, graphical button.
* @param {String} p_oElement String specifying the id attribute of the
* <code><input></code>, <code><a></code> or
* <code><span></code> element to be used to create the button.
* @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-
* one-html.html#ID-6043025">HTMLInputElement</a>|<a href="
* http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#
* ID-33759296">HTMLElement</a>} p_oElement Object reference for the
* <code><input></code>, <code><a></code> or
* <code><span></code> element to be used to create the button.
* @param {Object} p_oElement Object literal specifying a set of configuration
* attributes used to create the button.
* @param {Object} p_oAttributes Optional. Object literal specifying a set of
* configuration attributes used to create the button.
* @namespace YAHOO.widget
* @class Button
* @constructor
* @extends YAHOO.util.Element
*/
YAHOO.widget.Button = function(p_oElement, p_oAttributes) {
var fnSuperClass = YAHOO.widget.Button.superclass.constructor;
if(
arguments.length == 1 &&
!Lang.isString(p_oElement) &&
!p_oElement.nodeName
) {
if(!p_oElement.id) {
p_oElement.id = Dom.generateId();
}
fnSuperClass.call(
this,
(this._createButtonElement(p_oElement.type)),
p_oElement
);
}
else {
var oConfig = {
element: null,
attributes: (p_oAttributes || {})
};
if(Lang.isString(p_oElement)) {
var me = this;
Event.onAvailable(p_oElement, function() {
var sTagName = this.tagName.toUpperCase();
if(sTagName == me.TAG_NAME) {
oConfig.attributes.id = this.id;
}
else if(sTagName == "INPUT" && !oConfig.attributes.id) {
oConfig.attributes.id = Dom.generateId();
}
oConfig.attributes.srcelement = this;
initConfig.call(me, oConfig);
if(!oConfig.element) {
oConfig.element =
me._createButtonElement(oConfig.attributes.type);
}
fnSuperClass.call(me, oConfig.element, oConfig.attributes);
});
}
else {
var sTagName = p_oElement.tagName.toUpperCase();
if(sTagName == this.TAG_NAME) {
if(p_oElement.id) {
oConfig.attributes.id = p_oElement.id;
}
else {
oConfig.attributes.id = Dom.generateId();
}
}
else if(sTagName == "INPUT" && !oConfig.attributes.id) {
oConfig.attributes.id = Dom.generateId();
}
oConfig.attributes.srcelement = p_oElement;
initConfig.call(this, oConfig);
if(!oConfig.element) {
Loading full blame...