Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('yui2-button', function(Y) {
2
    var YAHOO    = Y.YUI2;
3
    /*
4
Copyright (c) 2011, Yahoo! Inc. All rights reserved.
5
Code licensed under the BSD License:
6
http://developer.yahoo.com/yui/license.html
7
version: 2.9.0
8
*/
9
/**
10
* @module button
11
* @description <p>The Button Control enables the creation of rich, graphical
12
* buttons that function like traditional HTML form buttons.  <em>Unlike</em>
13
* traditional HTML form buttons, buttons created with the Button Control can have
14
* a label that is different from its value.  With the inclusion of the optional
15
* <a href="module_menu.html">Menu Control</a>, the Button Control can also be
16
* used to create menu buttons and split buttons, controls that are not
17
* available natively in HTML.  The Button Control can also be thought of as a
18
* way to create more visually engaging implementations of the browser's
19
* default radio-button and check-box controls.</p>
20
* <p>The Button Control supports the following types:</p>
21
* <dl>
22
* <dt>push</dt>
23
* <dd>Basic push button that can execute a user-specified command when
24
* pressed.</dd>
25
* <dt>link</dt>
26
* <dd>Navigates to a specified url when pressed.</dd>
27
* <dt>submit</dt>
28
* <dd>Submits the parent form when pressed.</dd>
29
* <dt>reset</dt>
30
* <dd>Resets the parent form when pressed.</dd>
31
* <dt>checkbox</dt>
32
* <dd>Maintains a "checked" state that can be toggled on and off.</dd>
33
* <dt>radio</dt>
34
* <dd>Maintains a "checked" state that can be toggled on and off.  Use with
35
* the ButtonGroup class to create a set of controls that are mutually
36
* exclusive; checking one button in the set will uncheck all others in
37
* the group.</dd>
38
* <dt>menu</dt>
39
* <dd>When pressed will show/hide a menu.</dd>
40
* <dt>split</dt>
41
* <dd>Can execute a user-specified command or display a menu when pressed.</dd>
42
* </dl>
43
* @title Button
44
* @namespace YAHOO.widget
45
* @requires yahoo, dom, element, event
46
* @optional container, menu
47
*/
48
 
49
 
50
(function () {
51
 
52
 
53
    /**
54
    * The Button class creates a rich, graphical button.
55
    * @param {String} p_oElement String specifying the id attribute of the
56
    * <code>&#60;input&#62;</code>, <code>&#60;button&#62;</code>,
57
    * <code>&#60;a&#62;</code>, or <code>&#60;span&#62;</code> element to
58
    * be used to create the button.
59
    * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-
60
    * one-html.html#ID-6043025">HTMLInputElement</a>|<a href="http://www.w3.org
61
    * /TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-34812697">
62
    * HTMLButtonElement</a>|<a href="
63
    * http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#
64
    * ID-33759296">HTMLElement</a>} p_oElement Object reference for the
65
    * <code>&#60;input&#62;</code>, <code>&#60;button&#62;</code>,
66
    * <code>&#60;a&#62;</code>, or <code>&#60;span&#62;</code> element to be
67
    * used to create the button.
68
    * @param {Object} p_oElement Object literal specifying a set of
69
    * configuration attributes used to create the button.
70
    * @param {Object} p_oAttributes Optional. Object literal specifying a set
71
    * of configuration attributes used to create the button.
72
    * @namespace YAHOO.widget
73
    * @class Button
74
    * @constructor
75
    * @extends YAHOO.util.Element
76
    */
77
 
78
 
79
 
80
    // Shorthard for utilities
81
 
82
    var Dom = YAHOO.util.Dom,
83
        Event = YAHOO.util.Event,
84
        Lang = YAHOO.lang,
85
        UA = YAHOO.env.ua,
86
        Overlay = YAHOO.widget.Overlay,
87
        Menu = YAHOO.widget.Menu,
88
 
89
 
90
        // Private member variables
91
 
92
        m_oButtons = {},    // Collection of all Button instances
93
        m_oOverlayManager = null,   // YAHOO.widget.OverlayManager instance
94
        m_oSubmitTrigger = null,    // The button that submitted the form
95
        m_oFocusedButton = null;    // The button that has focus
96
 
97
 
98
 
99
    // Private methods
100
 
101
 
102
 
103
    /**
104
    * @method createInputElement
105
    * @description Creates an <code>&#60;input&#62;</code> element of the
106
    * specified type.
107
    * @private
108
    * @param {String} p_sType String specifying the type of
109
    * <code>&#60;input&#62;</code> element to create.
110
    * @param {String} p_sName String specifying the name of
111
    * <code>&#60;input&#62;</code> element to create.
112
    * @param {String} p_sValue String specifying the value of
113
    * <code>&#60;input&#62;</code> element to create.
114
    * @param {String} p_bChecked Boolean specifying if the
115
    * <code>&#60;input&#62;</code> element is to be checked.
116
    * @return {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-
117
    * one-html.html#ID-6043025">HTMLInputElement</a>}
118
    */
119
    function createInputElement(p_sType, p_sName, p_sValue, p_bChecked) {
120
 
121
        var oInput,
122
            sInput;
123
 
124
        if (Lang.isString(p_sType) && Lang.isString(p_sName)) {
125
 
126
            if (UA.ie && (UA.ie < 9)) {
127
 
128
                /*
129
                    For IE it is necessary to create the element with the
130
                    "type," "name," "value," and "checked" properties set all
131
                    at once.
132
                */
133
 
134
                sInput = "<input type=\"" + p_sType + "\" name=\"" +
135
                    p_sName + "\"";
136
 
137
                if (p_bChecked) {
138
 
139
                    sInput += " checked";
140
 
141
                }
142
 
143
                sInput += ">";
144
 
145
                oInput = document.createElement(sInput);
146
 
147
                oInput.value = p_sValue;
148
 
149
            } else {
150
 
151
                oInput = document.createElement("input");
152
                oInput.name = p_sName;
153
                oInput.type = p_sType;
154
                oInput.value = p_sValue;
155
 
156
                if (p_bChecked) {
157
 
158
                    oInput.checked = true;
159
 
160
                }
161
 
162
            }
163
 
164
 
165
        }
166
 
167
		return oInput;
168
 
169
    }
170
 
171
 
172
    /**
173
    * @method setAttributesFromSrcElement
174
    * @description Gets the values for all the attributes of the source element
175
    * (either <code>&#60;input&#62;</code> or <code>&#60;a&#62;</code>) that
176
    * map to Button configuration attributes and sets them into a collection
177
    * that is passed to the Button constructor.
178
    * @private
179
    * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-
180
    * one-html.html#ID-6043025">HTMLInputElement</a>|<a href="http://www.w3.org/
181
    * TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-
182
    * 48250443">HTMLAnchorElement</a>} p_oElement Object reference to the HTML
183
    * element (either <code>&#60;input&#62;</code> or <code>&#60;span&#62;
184
    * </code>) used to create the button.
185
    * @param {Object} p_oAttributes Object reference for the collection of
186
    * configuration attributes used to create the button.
187
    */
188
    function setAttributesFromSrcElement(p_oElement, p_oAttributes) {
189
 
190
        var sSrcElementNodeName = p_oElement.nodeName.toUpperCase(),
191
			sClass = (this.CLASS_NAME_PREFIX + this.CSS_CLASS_NAME),
192
            me = this,
193
            oAttribute,
194
            oRootNode,
195
            sText;
196
 
197
 
198
        /**
199
        * @method setAttributeFromDOMAttribute
200
        * @description Gets the value of the specified DOM attribute and sets it
201
        * into the collection of configuration attributes used to configure
202
        * the button.
203
        * @private
204
        * @param {String} p_sAttribute String representing the name of the
205
        * attribute to retrieve from the DOM element.
206
        */
207
        function setAttributeFromDOMAttribute(p_sAttribute) {
208
 
209
            if (!(p_sAttribute in p_oAttributes)) {
210
 
211
                /*
212
                    Need to use "getAttributeNode" instead of "getAttribute"
213
                    because using "getAttribute," IE will return the innerText
214
                    of a <code>&#60;button&#62;</code> for the value attribute
215
                    rather than the value of the "value" attribute.
216
                */
217
 
218
                oAttribute = p_oElement.getAttributeNode(p_sAttribute);
219
 
220
 
221
                if (oAttribute && ("value" in oAttribute)) {
222
 
223
 
224
                    p_oAttributes[p_sAttribute] = oAttribute.value;
225
 
226
                }
227
 
228
            }
229
 
230
        }
231
 
232
 
233
        /**
234
        * @method setFormElementProperties
235
        * @description Gets the value of the attributes from the form element
236
        * and sets them into the collection of configuration attributes used to
237
        * configure the button.
238
        * @private
239
        */
240
        function setFormElementProperties() {
241
 
242
            setAttributeFromDOMAttribute("type");
243
 
244
            if (p_oAttributes.type == "button") {
245
 
246
                p_oAttributes.type = "push";
247
 
248
            }
249
 
250
            if (!("disabled" in p_oAttributes)) {
251
 
252
                p_oAttributes.disabled = p_oElement.disabled;
253
 
254
            }
255
 
256
            setAttributeFromDOMAttribute("name");
257
            setAttributeFromDOMAttribute("value");
258
            setAttributeFromDOMAttribute("title");
259
 
260
        }
261
 
262
 
263
        switch (sSrcElementNodeName) {
264
 
265
        case "A":
266
 
267
            p_oAttributes.type = "link";
268
 
269
            setAttributeFromDOMAttribute("href");
270
            setAttributeFromDOMAttribute("target");
271
 
272
            break;
273
 
274
        case "INPUT":
275
 
276
            setFormElementProperties();
277
 
278
            if (!("checked" in p_oAttributes)) {
279
 
280
                p_oAttributes.checked = p_oElement.checked;
281
 
282
            }
283
 
284
            break;
285
 
286
        case "BUTTON":
287
 
288
            setFormElementProperties();
289
 
290
            oRootNode = p_oElement.parentNode.parentNode;
291
 
292
            if (Dom.hasClass(oRootNode, sClass + "-checked")) {
293
 
294
                p_oAttributes.checked = true;
295
 
296
            }
297
 
298
            if (Dom.hasClass(oRootNode, sClass + "-disabled")) {
299
 
300
                p_oAttributes.disabled = true;
301
 
302
            }
303
 
304
            p_oElement.removeAttribute("value");
305
 
306
            p_oElement.setAttribute("type", "button");
307
 
308
            break;
309
 
310
        }
311
 
312
        p_oElement.removeAttribute("id");
313
        p_oElement.removeAttribute("name");
314
 
315
        if (!("tabindex" in p_oAttributes)) {
316
 
317
            p_oAttributes.tabindex = p_oElement.tabIndex;
318
 
319
        }
320
 
321
        if (!("label" in p_oAttributes)) {
322
 
323
            // Set the "label" property
324
 
325
            sText = sSrcElementNodeName == "INPUT" ?
326
                            p_oElement.value : p_oElement.innerHTML;
327
 
328
 
329
            if (sText && sText.length > 0) {
330
 
331
                p_oAttributes.label = sText;
332
 
333
            }
334
 
335
        }
336
 
337
    }
338
 
339
 
340
    /**
341
    * @method initConfig
342
    * @description Initializes the set of configuration attributes that are
343
    * used to instantiate the button.
344
    * @private
345
    * @param {Object} Object representing the button's set of
346
    * configuration attributes.
347
    */
348
    function initConfig(p_oConfig) {
349
 
350
        var oAttributes = p_oConfig.attributes,
351
            oSrcElement = oAttributes.srcelement,
352
            sSrcElementNodeName = oSrcElement.nodeName.toUpperCase(),
353
            me = this;
354
 
355
 
356
        if (sSrcElementNodeName == this.NODE_NAME) {
357
 
358
            p_oConfig.element = oSrcElement;
359
            p_oConfig.id = oSrcElement.id;
360
 
361
            Dom.getElementsBy(function (p_oElement) {
362
 
363
                switch (p_oElement.nodeName.toUpperCase()) {
364
 
365
                case "BUTTON":
366
                case "A":
367
                case "INPUT":
368
 
369
                    setAttributesFromSrcElement.call(me, p_oElement,
370
                        oAttributes);
371
 
372
                    break;
373
 
374
                }
375
 
376
            }, "*", oSrcElement);
377
 
378
        }
379
        else {
380
 
381
            switch (sSrcElementNodeName) {
382
 
383
            case "BUTTON":
384
            case "A":
385
            case "INPUT":
386
 
387
                setAttributesFromSrcElement.call(this, oSrcElement,
388
                    oAttributes);
389
 
390
                break;
391
 
392
            }
393
 
394
        }
395
 
396
    }
397
 
398
 
399
 
400
    //  Constructor
401
 
402
    YAHOO.widget.Button = function (p_oElement, p_oAttributes) {
403
 
404
		if (!Overlay && YAHOO.widget.Overlay) {
405
 
406
			Overlay = YAHOO.widget.Overlay;
407
 
408
		}
409
 
410
 
411
		if (!Menu && YAHOO.widget.Menu) {
412
 
413
			Menu = YAHOO.widget.Menu;
414
 
415
		}
416
 
417
 
418
        var fnSuperClass = YAHOO.widget.Button.superclass.constructor,
419
            oConfig,
420
            oElement;
421
 
422
 
423
        if (arguments.length == 1 && !Lang.isString(p_oElement) && !p_oElement.nodeName) {
424
 
425
            if (!p_oElement.id) {
426
 
427
                p_oElement.id = Dom.generateId();
428
 
429
 
430
            }
431
 
432
 
433
            fnSuperClass.call(this, (this.createButtonElement(p_oElement.type)), p_oElement);
434
 
435
        }
436
        else {
437
 
438
            oConfig = { element: null, attributes: (p_oAttributes || {}) };
439
 
440
 
441
            if (Lang.isString(p_oElement)) {
442
 
443
                oElement = Dom.get(p_oElement);
444
 
445
                if (oElement) {
446
 
447
                    if (!oConfig.attributes.id) {
448
 
449
                        oConfig.attributes.id = p_oElement;
450
 
451
                    }
452
 
453
 
454
 
455
                    oConfig.attributes.srcelement = oElement;
456
 
457
                    initConfig.call(this, oConfig);
458
 
459
 
460
                    if (!oConfig.element) {
461
 
462
 
463
                        oConfig.element = this.createButtonElement(oConfig.attributes.type);
464
 
465
                    }
466
 
467
                    fnSuperClass.call(this, oConfig.element, oConfig.attributes);
468
 
469
                }
470
 
471
            }
472
            else if (p_oElement.nodeName) {
473
 
474
                if (!oConfig.attributes.id) {
475
 
476
                    if (p_oElement.id) {
477
 
478
                        oConfig.attributes.id = p_oElement.id;
479
 
480
                    }
481
                    else {
482
 
483
                        oConfig.attributes.id = Dom.generateId();
484
 
485
 
486
                    }
487
 
488
                }
489
 
490
 
491
 
492
                oConfig.attributes.srcelement = p_oElement;
493
 
494
                initConfig.call(this, oConfig);
495
 
496
 
497
                if (!oConfig.element) {
498
 
499
 
500
                    oConfig.element = this.createButtonElement(oConfig.attributes.type);
501
 
502
                }
503
 
504
                fnSuperClass.call(this, oConfig.element, oConfig.attributes);
505
 
506
            }
507
 
508
        }
509
 
510
    };
511
 
512
 
513
 
514
    YAHOO.extend(YAHOO.widget.Button, YAHOO.util.Element, {
515
 
516
 
517
        // Protected properties
518
 
519
 
520
        /**
521
        * @property _button
522
        * @description Object reference to the button's internal
523
        * <code>&#60;a&#62;</code> or <code>&#60;button&#62;</code> element.
524
        * @default null
525
        * @protected
526
        * @type <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
527
        * level-one-html.html#ID-48250443">HTMLAnchorElement</a>|<a href="
528
        * http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html
529
        * #ID-34812697">HTMLButtonElement</a>
530
        */
531
        _button: null,
532
 
533
 
534
        /**
535
        * @property _menu
536
        * @description Object reference to the button's menu.
537
        * @default null
538
        * @protected
539
        * @type {<a href="YAHOO.widget.Overlay.html">YAHOO.widget.Overlay</a>|
540
        * <a href="YAHOO.widget.Menu.html">YAHOO.widget.Menu</a>}
541
        */
542
        _menu: null,
543
 
544
 
545
        /**
546
        * @property _hiddenFields
547
        * @description Object reference to the <code>&#60;input&#62;</code>
548
        * element, or array of HTML form elements used to represent the button
549
        *  when its parent form is submitted.
550
        * @default null
551
        * @protected
552
        * @type <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
553
        * level-one-html.html#ID-6043025">HTMLInputElement</a>|Array
554
        */
555
        _hiddenFields: null,
556
 
557
 
558
        /**
559
        * @property _onclickAttributeValue
560
        * @description Object reference to the button's current value for the
561
        * "onclick" configuration attribute.
562
        * @default null
563
        * @protected
564
        * @type Object
565
        */
566
        _onclickAttributeValue: null,
567
 
568
 
569
        /**
570
        * @property _activationKeyPressed
571
        * @description Boolean indicating if the key(s) that toggle the button's
572
        * "active" state have been pressed.
573
        * @default false
574
        * @protected
575
        * @type Boolean
576
        */
577
        _activationKeyPressed: false,
578
 
579
 
580
        /**
581
        * @property _activationButtonPressed
582
        * @description Boolean indicating if the mouse button that toggles
583
        * the button's "active" state has been pressed.
584
        * @default false
585
        * @protected
586
        * @type Boolean
587
        */
588
        _activationButtonPressed: false,
589
 
590
 
591
        /**
592
        * @property _hasKeyEventHandlers
593
        * @description Boolean indicating if the button's "blur", "keydown" and
594
        * "keyup" event handlers are assigned
595
        * @default false
596
        * @protected
597
        * @type Boolean
598
        */
599
        _hasKeyEventHandlers: false,
600
 
601
 
602
        /**
603
        * @property _hasMouseEventHandlers
604
        * @description Boolean indicating if the button's "mouseout,"
605
        * "mousedown," and "mouseup" event handlers are assigned
606
        * @default false
607
        * @protected
608
        * @type Boolean
609
        */
610
        _hasMouseEventHandlers: false,
611
 
612
 
613
        /**
614
        * @property _nOptionRegionX
615
        * @description Number representing the X coordinate of the leftmost edge of the Button's
616
        * option region.  Applies only to Buttons of type "split".
617
        * @default 0
618
        * @protected
619
        * @type Number
620
        */
621
        _nOptionRegionX: 0,
622
 
623
 
624
 
625
        // Constants
626
 
627
        /**
628
        * @property CLASS_NAME_PREFIX
629
        * @description Prefix used for all class names applied to a Button.
630
        * @default "yui-"
631
        * @final
632
        * @type String
633
        */
634
        CLASS_NAME_PREFIX: "yui-",
635
 
636
 
637
        /**
638
        * @property NODE_NAME
639
        * @description The name of the node to be used for the button's
640
        * root element.
641
        * @default "SPAN"
642
        * @final
643
        * @type String
644
        */
645
        NODE_NAME: "SPAN",
646
 
647
 
648
        /**
649
        * @property CHECK_ACTIVATION_KEYS
650
        * @description Array of numbers representing keys that (when pressed)
651
        * toggle the button's "checked" attribute.
652
        * @default [32]
653
        * @final
654
        * @type Array
655
        */
656
        CHECK_ACTIVATION_KEYS: [32],
657
 
658
 
659
        /**
660
        * @property ACTIVATION_KEYS
661
        * @description Array of numbers representing keys that (when presed)
662
        * toggle the button's "active" state.
663
        * @default [13, 32]
664
        * @final
665
        * @type Array
666
        */
667
        ACTIVATION_KEYS: [13, 32],
668
 
669
 
670
        /**
671
        * @property OPTION_AREA_WIDTH
672
        * @description Width (in pixels) of the area of a split button that
673
        * when pressed will display a menu.
674
        * @default 20
675
        * @final
676
        * @type Number
677
        */
678
        OPTION_AREA_WIDTH: 20,
679
 
680
 
681
        /**
682
        * @property CSS_CLASS_NAME
683
        * @description String representing the CSS class(es) to be applied to
684
        * the button's root element.
685
        * @default "button"
686
        * @final
687
        * @type String
688
        */
689
        CSS_CLASS_NAME: "button",
690
 
691
 
692
 
693
        // Protected attribute setter methods
694
 
695
 
696
        /**
697
        * @method _setType
698
        * @description Sets the value of the button's "type" attribute.
699
        * @protected
700
        * @param {String} p_sType String indicating the value for the button's
701
        * "type" attribute.
702
        */
703
        _setType: function (p_sType) {
704
 
705
            if (p_sType == "split") {
706
 
707
                this.on("option", this._onOption);
708
 
709
            }
710
 
711
        },
712
 
713
 
714
        /**
715
        * @method _setLabel
716
        * @description Sets the value of the button's "label" attribute.
717
        * @protected
718
        * @param {HTML} p_sLabel String indicating the value for the button's
719
        * "label" attribute.
720
        */
721
        _setLabel: function (p_sLabel) {
722
 
723
            this._button.innerHTML = p_sLabel;
724
 
725
 
726
            /*
727
                Remove and add the default class name from the root element
728
                for Gecko to ensure that the button shrinkwraps to the label.
729
                Without this the button will not be rendered at the correct
730
                width when the label changes.  The most likely cause for this
731
                bug is button's use of the Gecko-specific CSS display type of
732
                "-moz-inline-box" to simulate "inline-block" supported by IE,
733
                Safari and Opera.
734
            */
735
 
736
            var sClass,
737
                nGeckoVersion = UA.gecko;
738
 
739
 
740
            if (nGeckoVersion && nGeckoVersion < 1.9 && Dom.inDocument(this.get("element"))) {
741
 
742
                sClass = (this.CLASS_NAME_PREFIX + this.CSS_CLASS_NAME);
743
 
744
                this.removeClass(sClass);
745
 
746
                Lang.later(0, this, this.addClass, sClass);
747
 
748
            }
749
 
750
        },
751
 
752
 
753
        /**
754
        * @method _setTabIndex
755
        * @description Sets the value of the button's "tabindex" attribute.
756
        * @protected
757
        * @param {Number} p_nTabIndex Number indicating the value for the
758
        * button's "tabindex" attribute.
759
        */
760
        _setTabIndex: function (p_nTabIndex) {
761
 
762
            this._button.tabIndex = p_nTabIndex;
763
 
764
        },
765
 
766
 
767
        /**
768
        * @method _setTitle
769
        * @description Sets the value of the button's "title" attribute.
770
        * @protected
771
        * @param {String} p_nTabIndex Number indicating the value for
772
        * the button's "title" attribute.
773
        */
774
        _setTitle: function (p_sTitle) {
775
 
776
            if (this.get("type") != "link") {
777
 
778
                this._button.title = p_sTitle;
779
 
780
            }
781
 
782
        },
783
 
784
 
785
        /**
786
        * @method _setDisabled
787
        * @description Sets the value of the button's "disabled" attribute.
788
        * @protected
789
        * @param {Boolean} p_bDisabled Boolean indicating the value for
790
        * the button's "disabled" attribute.
791
        */
792
        _setDisabled: function (p_bDisabled) {
793
 
794
            if (this.get("type") != "link") {
795
 
796
                if (p_bDisabled) {
797
 
798
                    if (this._menu) {
799
 
800
                        this._menu.hide();
801
 
802
                    }
803
 
804
                    if (this.hasFocus()) {
805
 
806
                        this.blur();
807
 
808
                    }
809
 
810
                    this._button.setAttribute("disabled", "disabled");
811
 
812
                    this.addStateCSSClasses("disabled");
813
 
814
                    this.removeStateCSSClasses("hover");
815
                    this.removeStateCSSClasses("active");
816
                    this.removeStateCSSClasses("focus");
817
 
818
                }
819
                else {
820
 
821
                    this._button.removeAttribute("disabled");
822
 
823
                    this.removeStateCSSClasses("disabled");
824
 
825
                }
826
 
827
            }
828
 
829
        },
830
 
831
 
832
        /**
833
        * @method _setHref
834
        * @description Sets the value of the button's "href" attribute.
835
        * @protected
836
        * @param {String} p_sHref String indicating the value for the button's
837
        * "href" attribute.
838
        */
839
        _setHref: function (p_sHref) {
840
 
841
            if (this.get("type") == "link") {
842
 
843
                this._button.href = p_sHref;
844
 
845
            }
846
 
847
        },
848
 
849
 
850
        /**
851
        * @method _setTarget
852
        * @description Sets the value of the button's "target" attribute.
853
        * @protected
854
        * @param {String} p_sTarget String indicating the value for the button's
855
        * "target" attribute.
856
        */
857
        _setTarget: function (p_sTarget) {
858
 
859
            if (this.get("type") == "link") {
860
 
861
                this._button.setAttribute("target", p_sTarget);
862
 
863
            }
864
 
865
        },
866
 
867
 
868
        /**
869
        * @method _setChecked
870
        * @description Sets the value of the button's "target" attribute.
871
        * @protected
872
        * @param {Boolean} p_bChecked Boolean indicating the value for
873
        * the button's "checked" attribute.
874
        */
875
        _setChecked: function (p_bChecked) {
876
 
877
            var sType = this.get("type");
878
 
879
            if (sType == "checkbox" || sType == "radio") {
880
 
881
                if (p_bChecked) {
882
                    this.addStateCSSClasses("checked");
883
                }
884
                else {
885
                    this.removeStateCSSClasses("checked");
886
                }
887
 
888
            }
889
 
890
        },
891
 
892
 
893
        /**
894
        * @method _setMenu
895
        * @description Sets the value of the button's "menu" attribute.
896
        * @protected
897
        * @param {Object} p_oMenu Object indicating the value for the button's
898
        * "menu" attribute.
899
        */
900
        _setMenu: function (p_oMenu) {
901
 
902
            var bLazyLoad = this.get("lazyloadmenu"),
903
                oButtonElement = this.get("element"),
904
                sMenuCSSClassName,
905
 
906
                /*
907
                    Boolean indicating if the value of p_oMenu is an instance
908
                    of YAHOO.widget.Menu or YAHOO.widget.Overlay.
909
                */
910
 
911
                bInstance = false,
912
                oMenu,
913
                oMenuElement,
914
                oSrcElement;
915
 
916
 
917
			function onAppendTo() {
918
 
919
				oMenu.render(oButtonElement.parentNode);
920
 
921
				this.removeListener("appendTo", onAppendTo);
922
 
923
			}
924
 
925
 
926
			function setMenuContainer() {
927
 
928
				oMenu.cfg.queueProperty("container", oButtonElement.parentNode);
929
 
930
				this.removeListener("appendTo", setMenuContainer);
931
 
932
			}
933
 
934
 
935
			function initMenu() {
936
 
937
				var oContainer;
938
 
939
				if (oMenu) {
940
 
941
					Dom.addClass(oMenu.element, this.get("menuclassname"));
942
					Dom.addClass(oMenu.element, this.CLASS_NAME_PREFIX + this.get("type") + "-button-menu");
943
 
944
					oMenu.showEvent.subscribe(this._onMenuShow, null, this);
945
					oMenu.hideEvent.subscribe(this._onMenuHide, null, this);
946
					oMenu.renderEvent.subscribe(this._onMenuRender, null, this);
947
 
948
 
949
					if (Menu && oMenu instanceof Menu) {
950
 
951
						if (bLazyLoad) {
952
 
953
							oContainer = this.get("container");
954
 
955
							if (oContainer) {
956
 
957
								oMenu.cfg.queueProperty("container", oContainer);
958
 
959
							}
960
							else {
961
 
962
								this.on("appendTo", setMenuContainer);
963
 
964
							}
965
 
966
						}
967
 
968
						oMenu.cfg.queueProperty("clicktohide", false);
969
 
970
						oMenu.keyDownEvent.subscribe(this._onMenuKeyDown, this, true);
971
						oMenu.subscribe("click", this._onMenuClick, this, true);
972
 
973
						this.on("selectedMenuItemChange", this._onSelectedMenuItemChange);
974
 
975
						oSrcElement = oMenu.srcElement;
976
 
977
						if (oSrcElement && oSrcElement.nodeName.toUpperCase() == "SELECT") {
978
 
979
							oSrcElement.style.display = "none";
980
							oSrcElement.parentNode.removeChild(oSrcElement);
981
 
982
						}
983
 
984
					}
985
					else if (Overlay && oMenu instanceof Overlay) {
986
 
987
						if (!m_oOverlayManager) {
988
 
989
							m_oOverlayManager = new YAHOO.widget.OverlayManager();
990
 
991
						}
992
 
993
						m_oOverlayManager.register(oMenu);
994
 
995
					}
996
 
997
 
998
					this._menu = oMenu;
999
 
1000
 
1001
					if (!bInstance && !bLazyLoad) {
1002
 
1003
						if (Dom.inDocument(oButtonElement)) {
1004
 
1005
							oMenu.render(oButtonElement.parentNode);
1006
 
1007
						}
1008
						else {
1009
 
1010
							this.on("appendTo", onAppendTo);
1011
 
1012
						}
1013
 
1014
					}
1015
 
1016
				}
1017
 
1018
			}
1019
 
1020
 
1021
            if (Overlay) {
1022
 
1023
				if (Menu) {
1024
 
1025
					sMenuCSSClassName = Menu.prototype.CSS_CLASS_NAME;
1026
 
1027
				}
1028
 
1029
				if (p_oMenu && Menu && (p_oMenu instanceof Menu)) {
1030
 
1031
					oMenu = p_oMenu;
1032
					bInstance = true;
1033
 
1034
					initMenu.call(this);
1035
 
1036
				}
1037
				else if (Overlay && p_oMenu && (p_oMenu instanceof Overlay)) {
1038
 
1039
					oMenu = p_oMenu;
1040
					bInstance = true;
1041
 
1042
					oMenu.cfg.queueProperty("visible", false);
1043
 
1044
					initMenu.call(this);
1045
 
1046
				}
1047
				else if (Menu && Lang.isArray(p_oMenu)) {
1048
 
1049
					oMenu = new Menu(Dom.generateId(), { lazyload: bLazyLoad, itemdata: p_oMenu });
1050
 
1051
					this._menu = oMenu;
1052
 
1053
					this.on("appendTo", initMenu);
1054
 
1055
				}
1056
				else if (Lang.isString(p_oMenu)) {
1057
 
1058
					oMenuElement = Dom.get(p_oMenu);
1059
 
1060
					if (oMenuElement) {
1061
 
1062
						if (Menu && Dom.hasClass(oMenuElement, sMenuCSSClassName) ||
1063
							oMenuElement.nodeName.toUpperCase() == "SELECT") {
1064
 
1065
							oMenu = new Menu(p_oMenu, { lazyload: bLazyLoad });
1066
 
1067
							initMenu.call(this);
1068
 
1069
						}
1070
						else if (Overlay) {
1071
 
1072
							oMenu = new Overlay(p_oMenu, { visible: false });
1073
 
1074
							initMenu.call(this);
1075
 
1076
						}
1077
 
1078
					}
1079
 
1080
				}
1081
				else if (p_oMenu && p_oMenu.nodeName) {
1082
 
1083
					if (Menu && Dom.hasClass(p_oMenu, sMenuCSSClassName) ||
1084
							p_oMenu.nodeName.toUpperCase() == "SELECT") {
1085
 
1086
						oMenu = new Menu(p_oMenu, { lazyload: bLazyLoad });
1087
 
1088
						initMenu.call(this);
1089
 
1090
					}
1091
					else if (Overlay) {
1092
 
1093
						if (!p_oMenu.id) {
1094
 
1095
							Dom.generateId(p_oMenu);
1096
 
1097
						}
1098
 
1099
						oMenu = new Overlay(p_oMenu, { visible: false });
1100
 
1101
						initMenu.call(this);
1102
 
1103
					}
1104
 
1105
				}
1106
 
1107
            }
1108
 
1109
        },
1110
 
1111
 
1112
        /**
1113
        * @method _setOnClick
1114
        * @description Sets the value of the button's "onclick" attribute.
1115
        * @protected
1116
        * @param {Object} p_oObject Object indicating the value for the button's
1117
        * "onclick" attribute.
1118
        */
1119
        _setOnClick: function (p_oObject) {
1120
 
1121
            /*
1122
                Remove any existing listeners if a "click" event handler
1123
                has already been specified.
1124
            */
1125
 
1126
            if (this._onclickAttributeValue &&
1127
                (this._onclickAttributeValue != p_oObject)) {
1128
 
1129
                this.removeListener("click", this._onclickAttributeValue.fn);
1130
 
1131
                this._onclickAttributeValue = null;
1132
 
1133
            }
1134
 
1135
 
1136
            if (!this._onclickAttributeValue &&
1137
                Lang.isObject(p_oObject) &&
1138
                Lang.isFunction(p_oObject.fn)) {
1139
 
1140
                this.on("click", p_oObject.fn, p_oObject.obj, p_oObject.scope);
1141
 
1142
                this._onclickAttributeValue = p_oObject;
1143
 
1144
            }
1145
 
1146
        },
1147
 
1148
 
1149
 
1150
        // Protected methods
1151
 
1152
 
1153
 
1154
        /**
1155
        * @method _isActivationKey
1156
        * @description Determines if the specified keycode is one that toggles
1157
        * the button's "active" state.
1158
        * @protected
1159
        * @param {Number} p_nKeyCode Number representing the keycode to
1160
        * be evaluated.
1161
        * @return {Boolean}
1162
        */
1163
        _isActivationKey: function (p_nKeyCode) {
1164
 
1165
            var sType = this.get("type"),
1166
                aKeyCodes = (sType == "checkbox" || sType == "radio") ?
1167
                    this.CHECK_ACTIVATION_KEYS : this.ACTIVATION_KEYS,
1168
 
1169
                nKeyCodes = aKeyCodes.length,
1170
                bReturnVal = false,
1171
                i;
1172
 
1173
 
1174
            if (nKeyCodes > 0) {
1175
 
1176
                i = nKeyCodes - 1;
1177
 
1178
                do {
1179
 
1180
                    if (p_nKeyCode == aKeyCodes[i]) {
1181
 
1182
                        bReturnVal = true;
1183
                        break;
1184
 
1185
                    }
1186
 
1187
                }
1188
                while (i--);
1189
 
1190
            }
1191
 
1192
            return bReturnVal;
1193
 
1194
        },
1195
 
1196
 
1197
        /**
1198
        * @method _isSplitButtonOptionKey
1199
        * @description Determines if the specified keycode is one that toggles
1200
        * the display of the split button's menu.
1201
        * @protected
1202
        * @param {Event} p_oEvent Object representing the DOM event object
1203
        * passed back by the event utility (YAHOO.util.Event).
1204
        * @return {Boolean}
1205
        */
1206
        _isSplitButtonOptionKey: function (p_oEvent) {
1207
 
1208
			var bShowMenu = (Event.getCharCode(p_oEvent) == 40);
1209
 
1210
 
1211
			var onKeyPress = function (p_oEvent) {
1212
 
1213
				Event.preventDefault(p_oEvent);
1214
 
1215
				this.removeListener("keypress", onKeyPress);
1216
 
1217
			};
1218
 
1219
 
1220
			// Prevent the browser from scrolling the window
1221
			if (bShowMenu) {
1222
 
1223
				if (UA.opera) {
1224
 
1225
					this.on("keypress", onKeyPress);
1226
 
1227
				}
1228
 
1229
				Event.preventDefault(p_oEvent);
1230
			}
1231
 
1232
            return bShowMenu;
1233
 
1234
        },
1235
 
1236
 
1237
        /**
1238
        * @method _addListenersToForm
1239
        * @description Adds event handlers to the button's form.
1240
        * @protected
1241
        */
1242
        _addListenersToForm: function () {
1243
 
1244
            var oForm = this.getForm(),
1245
                onFormKeyPress = YAHOO.widget.Button.onFormKeyPress,
1246
                bHasKeyPressListener,
1247
                oSrcElement,
1248
                aListeners,
1249
                nListeners,
1250
                i;
1251
 
1252
 
1253
            if (oForm) {
1254
 
1255
                Event.on(oForm, "reset", this._onFormReset, null, this);
1256
                Event.on(oForm, "submit", this._onFormSubmit, null, this);
1257
 
1258
                oSrcElement = this.get("srcelement");
1259
 
1260
 
1261
                if (this.get("type") == "submit" ||
1262
                    (oSrcElement && oSrcElement.type == "submit"))
1263
                {
1264
 
1265
                    aListeners = Event.getListeners(oForm, "keypress");
1266
                    bHasKeyPressListener = false;
1267
 
1268
                    if (aListeners) {
1269
 
1270
                        nListeners = aListeners.length;
1271
 
1272
                        if (nListeners > 0) {
1273
 
1274
                            i = nListeners - 1;
1275
 
1276
                            do {
1277
 
1278
                                if (aListeners[i].fn == onFormKeyPress) {
1279
 
1280
                                    bHasKeyPressListener = true;
1281
                                    break;
1282
 
1283
                                }
1284
 
1285
                            }
1286
                            while (i--);
1287
 
1288
                        }
1289
 
1290
                    }
1291
 
1292
 
1293
                    if (!bHasKeyPressListener) {
1294
 
1295
                        Event.on(oForm, "keypress", onFormKeyPress);
1296
 
1297
                    }
1298
 
1299
                }
1300
 
1301
            }
1302
 
1303
        },
1304
 
1305
 
1306
 
1307
        /**
1308
        * @method _showMenu
1309
        * @description Shows the button's menu.
1310
        * @protected
1311
        * @param {Event} p_oEvent Object representing the DOM event object
1312
        * passed back by the event utility (YAHOO.util.Event) that triggered
1313
        * the display of the menu.
1314
        */
1315
        _showMenu: function (p_oEvent) {
1316
 
1317
            if (YAHOO.widget.MenuManager) {
1318
                YAHOO.widget.MenuManager.hideVisible();
1319
            }
1320
 
1321
 
1322
            if (m_oOverlayManager) {
1323
                m_oOverlayManager.hideAll();
1324
            }
1325
 
1326
 
1327
            var oMenu = this._menu,
1328
            	aMenuAlignment = this.get("menualignment"),
1329
            	bFocusMenu = this.get("focusmenu"),
1330
				fnFocusMethod;
1331
 
1332
 
1333
			if (this._renderedMenu) {
1334
 
1335
				oMenu.cfg.setProperty("context",
1336
								[this.get("element"), aMenuAlignment[0], aMenuAlignment[1]]);
1337
 
1338
				oMenu.cfg.setProperty("preventcontextoverlap", true);
1339
				oMenu.cfg.setProperty("constraintoviewport", true);
1340
 
1341
			}
1342
			else {
1343
 
1344
				oMenu.cfg.queueProperty("context",
1345
								[this.get("element"), aMenuAlignment[0], aMenuAlignment[1]]);
1346
 
1347
				oMenu.cfg.queueProperty("preventcontextoverlap", true);
1348
				oMenu.cfg.queueProperty("constraintoviewport", true);
1349
 
1350
			}
1351
 
1352
 
1353
			/*
1354
				 Refocus the Button before showing its Menu in case the call to
1355
				 YAHOO.widget.MenuManager.hideVisible() resulted in another element in the
1356
				 DOM being focused after another Menu was hidden.
1357
			*/
1358
 
1359
			this.focus();
1360
 
1361
 
1362
            if (Menu && oMenu && (oMenu instanceof Menu)) {
1363
 
1364
				// Since Menus automatically focus themselves when made visible, temporarily
1365
				// replace the Menu focus method so that the value of the Button's "focusmenu"
1366
				// attribute determines if the Menu should be focus when made visible.
1367
 
1368
				fnFocusMethod = oMenu.focus;
1369
 
1370
				oMenu.focus = function () {};
1371
 
1372
				if (this._renderedMenu) {
1373
 
1374
					oMenu.cfg.setProperty("minscrollheight", this.get("menuminscrollheight"));
1375
					oMenu.cfg.setProperty("maxheight", this.get("menumaxheight"));
1376
 
1377
				}
1378
				else {
1379
 
1380
					oMenu.cfg.queueProperty("minscrollheight", this.get("menuminscrollheight"));
1381
					oMenu.cfg.queueProperty("maxheight", this.get("menumaxheight"));
1382
 
1383
				}
1384
 
1385
 
1386
                oMenu.show();
1387
 
1388
        		oMenu.focus = fnFocusMethod;
1389
 
1390
				oMenu.align();
1391
 
1392
 
1393
                /*
1394
                    Stop the propagation of the event so that the MenuManager
1395
                    doesn't blur the menu after it gets focus.
1396
                */
1397
 
1398
                if (p_oEvent.type == "mousedown") {
1399
                    Event.stopPropagation(p_oEvent);
1400
                }
1401
 
1402
 
1403
                if (bFocusMenu) {
1404
                    oMenu.focus();
1405
                }
1406
 
1407
            }
1408
            else if (Overlay && oMenu && (oMenu instanceof Overlay)) {
1409
 
1410
				if (!this._renderedMenu) {
1411
		            oMenu.render(this.get("element").parentNode);
1412
				}
1413
 
1414
                oMenu.show();
1415
				oMenu.align();
1416
 
1417
            }
1418
 
1419
        },
1420
 
1421
 
1422
        /**
1423
        * @method _hideMenu
1424
        * @description Hides the button's menu.
1425
        * @protected
1426
        */
1427
        _hideMenu: function () {
1428
 
1429
            var oMenu = this._menu;
1430
 
1431
            if (oMenu) {
1432
 
1433
                oMenu.hide();
1434
 
1435
            }
1436
 
1437
        },
1438
 
1439
 
1440
 
1441
 
1442
        // Protected event handlers
1443
 
1444
 
1445
        /**
1446
        * @method _onMouseOver
1447
        * @description "mouseover" event handler for the button.
1448
        * @protected
1449
        * @param {Event} p_oEvent Object representing the DOM event object
1450
        * passed back by the event utility (YAHOO.util.Event).
1451
        */
1452
        _onMouseOver: function (p_oEvent) {
1453
 
1454
        	var sType = this.get("type"),
1455
        		oElement,
1456
				nOptionRegionX;
1457
 
1458
 
1459
			if (sType === "split") {
1460
 
1461
				oElement = this.get("element");
1462
				nOptionRegionX =
1463
					(Dom.getX(oElement) + (oElement.offsetWidth - this.OPTION_AREA_WIDTH));
1464
 
1465
				this._nOptionRegionX = nOptionRegionX;
1466
 
1467
			}
1468
 
1469
 
1470
            if (!this._hasMouseEventHandlers) {
1471
 
1472
				if (sType === "split") {
1473
 
1474
	        		this.on("mousemove", this._onMouseMove);
1475
 
1476
        		}
1477
 
1478
                this.on("mouseout", this._onMouseOut);
1479
 
1480
                this._hasMouseEventHandlers = true;
1481
 
1482
            }
1483
 
1484
 
1485
            this.addStateCSSClasses("hover");
1486
 
1487
 
1488
			if (sType === "split" && (Event.getPageX(p_oEvent) > nOptionRegionX)) {
1489
 
1490
				this.addStateCSSClasses("hoveroption");
1491
 
1492
			}
1493
 
1494
 
1495
            if (this._activationButtonPressed) {
1496
 
1497
                this.addStateCSSClasses("active");
1498
 
1499
            }
1500
 
1501
 
1502
            if (this._bOptionPressed) {
1503
 
1504
                this.addStateCSSClasses("activeoption");
1505
 
1506
            }
1507
 
1508
 
1509
            if (this._activationButtonPressed || this._bOptionPressed) {
1510
 
1511
                Event.removeListener(document, "mouseup", this._onDocumentMouseUp);
1512
 
1513
            }
1514
 
1515
        },
1516
 
1517
 
1518
        /**
1519
        * @method _onMouseMove
1520
        * @description "mousemove" event handler for the button.
1521
        * @protected
1522
        * @param {Event} p_oEvent Object representing the DOM event object
1523
        * passed back by the event utility (YAHOO.util.Event).
1524
        */
1525
        _onMouseMove: function (p_oEvent) {
1526
 
1527
        	var nOptionRegionX = this._nOptionRegionX;
1528
 
1529
        	if (nOptionRegionX) {
1530
 
1531
				if (Event.getPageX(p_oEvent) > nOptionRegionX) {
1532
 
1533
					this.addStateCSSClasses("hoveroption");
1534
 
1535
				}
1536
				else {
1537
 
1538
					this.removeStateCSSClasses("hoveroption");
1539
 
1540
				}
1541
 
1542
        	}
1543
 
1544
        },
1545
 
1546
        /**
1547
        * @method _onMouseOut
1548
        * @description "mouseout" event handler for the button.
1549
        * @protected
1550
        * @param {Event} p_oEvent Object representing the DOM event object
1551
        * passed back by the event utility (YAHOO.util.Event).
1552
        */
1553
        _onMouseOut: function (p_oEvent) {
1554
 
1555
			var sType = this.get("type");
1556
 
1557
            this.removeStateCSSClasses("hover");
1558
 
1559
 
1560
            if (sType != "menu") {
1561
 
1562
                this.removeStateCSSClasses("active");
1563
 
1564
            }
1565
 
1566
 
1567
            if (this._activationButtonPressed || this._bOptionPressed) {
1568
 
1569
                Event.on(document, "mouseup", this._onDocumentMouseUp, null, this);
1570
 
1571
            }
1572
 
1573
 
1574
			if (sType === "split" && (Event.getPageX(p_oEvent) > this._nOptionRegionX)) {
1575
 
1576
				this.removeStateCSSClasses("hoveroption");
1577
 
1578
			}
1579
 
1580
        },
1581
 
1582
 
1583
        /**
1584
        * @method _onDocumentMouseUp
1585
        * @description "mouseup" event handler for the button.
1586
        * @protected
1587
        * @param {Event} p_oEvent Object representing the DOM event object
1588
        * passed back by the event utility (YAHOO.util.Event).
1589
        */
1590
        _onDocumentMouseUp: function (p_oEvent) {
1591
 
1592
            this._activationButtonPressed = false;
1593
            this._bOptionPressed = false;
1594
 
1595
            var sType = this.get("type"),
1596
                oTarget,
1597
                oMenuElement;
1598
 
1599
            if (sType == "menu" || sType == "split") {
1600
 
1601
                oTarget = Event.getTarget(p_oEvent);
1602
                oMenuElement = this._menu.element;
1603
 
1604
                if (oTarget != oMenuElement &&
1605
                    !Dom.isAncestor(oMenuElement, oTarget)) {
1606
 
1607
                    this.removeStateCSSClasses((sType == "menu" ?
1608
                        "active" : "activeoption"));
1609
 
1610
                    this._hideMenu();
1611
 
1612
                }
1613
 
1614
            }
1615
 
1616
            Event.removeListener(document, "mouseup", this._onDocumentMouseUp);
1617
 
1618
        },
1619
 
1620
 
1621
        /**
1622
        * @method _onMouseDown
1623
        * @description "mousedown" event handler for the button.
1624
        * @protected
1625
        * @param {Event} p_oEvent Object representing the DOM event object
1626
        * passed back by the event utility (YAHOO.util.Event).
1627
        */
1628
        _onMouseDown: function (p_oEvent) {
1629
 
1630
            var sType,
1631
            	bReturnVal = true;
1632
 
1633
 
1634
            function onMouseUp() {
1635
 
1636
                this._hideMenu();
1637
                this.removeListener("mouseup", onMouseUp);
1638
 
1639
            }
1640
 
1641
 
1642
            if ((p_oEvent.which || p_oEvent.button) == 1) {
1643
 
1644
 
1645
                if (!this.hasFocus()) {
1646
                    Lang.later(0, this, this.focus);
1647
                    //this.focus();
1648
                }
1649
 
1650
 
1651
                sType = this.get("type");
1652
 
1653
 
1654
                if (sType == "split") {
1655
 
1656
                    if (Event.getPageX(p_oEvent) > this._nOptionRegionX) {
1657
 
1658
                        this.fireEvent("option", p_oEvent);
1659
						bReturnVal = false;
1660
 
1661
                    }
1662
                    else {
1663
 
1664
                        this.addStateCSSClasses("active");
1665
 
1666
                        this._activationButtonPressed = true;
1667
 
1668
                    }
1669
 
1670
                }
1671
                else if (sType == "menu") {
1672
 
1673
                    if (this.isActive()) {
1674
 
1675
                        this._hideMenu();
1676
 
1677
                        this._activationButtonPressed = false;
1678
 
1679
                    }
1680
                    else {
1681
 
1682
                        this._showMenu(p_oEvent);
1683
 
1684
                        this._activationButtonPressed = true;
1685
 
1686
                    }
1687
 
1688
                }
1689
                else {
1690
 
1691
                    this.addStateCSSClasses("active");
1692
 
1693
                    this._activationButtonPressed = true;
1694
 
1695
                }
1696
 
1697
 
1698
 
1699
                if (sType == "split" || sType == "menu") {
1700
 
1701
                    this._hideMenuTimer = Lang.later(250, this, this.on, ["mouseup", onMouseUp]);
1702
 
1703
                }
1704
 
1705
            }
1706
 
1707
            return bReturnVal;
1708
 
1709
        },
1710
 
1711
 
1712
        /**
1713
        * @method _onMouseUp
1714
        * @description "mouseup" event handler for the button.
1715
        * @protected
1716
        * @param {Event} p_oEvent Object representing the DOM event object
1717
        * passed back by the event utility (YAHOO.util.Event).
1718
        */
1719
        _onMouseUp: function (p_oEvent) {
1720
            this.inMouseDown = false;
1721
 
1722
            var sType = this.get("type"),
1723
            	oHideMenuTimer = this._hideMenuTimer,
1724
            	bReturnVal = true;
1725
 
1726
 
1727
            if (oHideMenuTimer) {
1728
 
1729
  				oHideMenuTimer.cancel();
1730
 
1731
            }
1732
 
1733
 
1734
            if (sType == "checkbox" || sType == "radio") {
1735
                if ((p_oEvent.which || p_oEvent.button) != 1) {
1736
                    return;
1737
                }
1738
 
1739
                this.set("checked", !(this.get("checked")));
1740
 
1741
            }
1742
 
1743
 
1744
            this._activationButtonPressed = false;
1745
 
1746
 
1747
            if (sType != "menu") {
1748
 
1749
                this.removeStateCSSClasses("active");
1750
 
1751
            }
1752
 
1753
 
1754
			if (sType == "split" && Event.getPageX(p_oEvent) > this._nOptionRegionX) {
1755
 
1756
				bReturnVal = false;
1757
 
1758
			}
1759
 
1760
			return bReturnVal;
1761
 
1762
        },
1763
 
1764
 
1765
        /**
1766
        * @method _onFocus
1767
        * @description "focus" event handler for the button.
1768
        * @protected
1769
        * @param {Event} p_oEvent Object representing the DOM event object
1770
        * passed back by the event utility (YAHOO.util.Event).
1771
        */
1772
        _onFocus: function (p_oEvent) {
1773
 
1774
            var oElement;
1775
 
1776
            this.addStateCSSClasses("focus");
1777
 
1778
            if (this._activationKeyPressed) {
1779
 
1780
                this.addStateCSSClasses("active");
1781
 
1782
            }
1783
 
1784
            m_oFocusedButton = this;
1785
 
1786
 
1787
            if (!this._hasKeyEventHandlers) {
1788
 
1789
                oElement = this._button;
1790
 
1791
                Event.on(oElement, "blur", this._onBlur, null, this);
1792
                Event.on(oElement, "keydown", this._onKeyDown, null, this);
1793
                Event.on(oElement, "keyup", this._onKeyUp, null, this);
1794
 
1795
                this._hasKeyEventHandlers = true;
1796
 
1797
            }
1798
 
1799
 
1800
            this.fireEvent("focus", p_oEvent);
1801
 
1802
        },
1803
 
1804
 
1805
        /**
1806
        * @method _onBlur
1807
        * @description "blur" event handler for the button.
1808
        * @protected
1809
        * @param {Event} p_oEvent Object representing the DOM event object
1810
        * passed back by the event utility (YAHOO.util.Event).
1811
        */
1812
        _onBlur: function (p_oEvent) {
1813
 
1814
            this.removeStateCSSClasses("focus");
1815
 
1816
            if (this.get("type") != "menu") {
1817
 
1818
                this.removeStateCSSClasses("active");
1819
 
1820
            }
1821
 
1822
            if (this._activationKeyPressed) {
1823
 
1824
                Event.on(document, "keyup", this._onDocumentKeyUp, null, this);
1825
 
1826
            }
1827
 
1828
 
1829
            m_oFocusedButton = null;
1830
 
1831
            this.fireEvent("blur", p_oEvent);
1832
 
1833
        },
1834
 
1835
 
1836
        /**
1837
        * @method _onDocumentKeyUp
1838
        * @description "keyup" event handler for the document.
1839
        * @protected
1840
        * @param {Event} p_oEvent Object representing the DOM event object
1841
        * passed back by the event utility (YAHOO.util.Event).
1842
        */
1843
        _onDocumentKeyUp: function (p_oEvent) {
1844
 
1845
            if (this._isActivationKey(Event.getCharCode(p_oEvent))) {
1846
 
1847
                this._activationKeyPressed = false;
1848
 
1849
                Event.removeListener(document, "keyup", this._onDocumentKeyUp);
1850
 
1851
            }
1852
 
1853
        },
1854
 
1855
 
1856
        /**
1857
        * @method _onKeyDown
1858
        * @description "keydown" event handler for the button.
1859
        * @protected
1860
        * @param {Event} p_oEvent Object representing the DOM event object
1861
        * passed back by the event utility (YAHOO.util.Event).
1862
        */
1863
        _onKeyDown: function (p_oEvent) {
1864
 
1865
            var oMenu = this._menu;
1866
 
1867
 
1868
            if (this.get("type") == "split" &&
1869
                this._isSplitButtonOptionKey(p_oEvent)) {
1870
 
1871
                this.fireEvent("option", p_oEvent);
1872
 
1873
            }
1874
            else if (this._isActivationKey(Event.getCharCode(p_oEvent))) {
1875
 
1876
                if (this.get("type") == "menu") {
1877
 
1878
                    this._showMenu(p_oEvent);
1879
 
1880
                }
1881
                else {
1882
 
1883
                    this._activationKeyPressed = true;
1884
 
1885
                    this.addStateCSSClasses("active");
1886
 
1887
                }
1888
 
1889
            }
1890
 
1891
 
1892
            if (oMenu && oMenu.cfg.getProperty("visible") &&
1893
                Event.getCharCode(p_oEvent) == 27) {
1894
 
1895
                oMenu.hide();
1896
                this.focus();
1897
 
1898
            }
1899
 
1900
        },
1901
 
1902
 
1903
        /**
1904
        * @method _onKeyUp
1905
        * @description "keyup" event handler for the button.
1906
        * @protected
1907
        * @param {Event} p_oEvent Object representing the DOM event object
1908
        * passed back by the event utility (YAHOO.util.Event).
1909
        */
1910
        _onKeyUp: function (p_oEvent) {
1911
 
1912
            var sType;
1913
 
1914
            if (this._isActivationKey(Event.getCharCode(p_oEvent))) {
1915
 
1916
                sType = this.get("type");
1917
 
1918
                if (sType == "checkbox" || sType == "radio") {
1919
 
1920
                    this.set("checked", !(this.get("checked")));
1921
 
1922
                }
1923
 
1924
                this._activationKeyPressed = false;
1925
 
1926
                if (this.get("type") != "menu") {
1927
 
1928
                    this.removeStateCSSClasses("active");
1929
 
1930
                }
1931
 
1932
            }
1933
 
1934
        },
1935
 
1936
 
1937
        /**
1938
        * @method _onClick
1939
        * @description "click" event handler for the button.
1940
        * @protected
1941
        * @param {Event} p_oEvent Object representing the DOM event object
1942
        * passed back by the event utility (YAHOO.util.Event).
1943
        */
1944
        _onClick: function (p_oEvent) {
1945
 
1946
            var sType = this.get("type"),
1947
                oForm,
1948
                oSrcElement,
1949
                bReturnVal;
1950
 
1951
 
1952
			switch (sType) {
1953
 
1954
			case "submit":
1955
 
1956
				if (p_oEvent.returnValue !== false) {
1957
 
1958
					this.submitForm();
1959
 
1960
				}
1961
 
1962
				break;
1963
 
1964
			case "reset":
1965
 
1966
				oForm = this.getForm();
1967
 
1968
				if (oForm) {
1969
 
1970
					oForm.reset();
1971
 
1972
				}
1973
 
1974
				break;
1975
 
1976
 
1977
			case "split":
1978
 
1979
				if (this._nOptionRegionX > 0 &&
1980
						(Event.getPageX(p_oEvent) > this._nOptionRegionX)) {
1981
 
1982
					bReturnVal = false;
1983
 
1984
				}
1985
				else {
1986
 
1987
					this._hideMenu();
1988
 
1989
					oSrcElement = this.get("srcelement");
1990
 
1991
					if (oSrcElement && oSrcElement.type == "submit" &&
1992
							p_oEvent.returnValue !== false) {
1993
 
1994
						this.submitForm();
1995
 
1996
					}
1997
 
1998
				}
1999
 
2000
				break;
2001
 
2002
			}
2003
 
2004
			return bReturnVal;
2005
 
2006
        },
2007
 
2008
 
2009
        /**
2010
        * @method _onDblClick
2011
        * @description "dblclick" event handler for the button.
2012
        * @protected
2013
        * @param {Event} p_oEvent Object representing the DOM event object
2014
        * passed back by the event utility (YAHOO.util.Event).
2015
        */
2016
        _onDblClick: function (p_oEvent) {
2017
 
2018
            var bReturnVal = true;
2019
 
2020
			if (this.get("type") == "split" && Event.getPageX(p_oEvent) > this._nOptionRegionX) {
2021
 
2022
				bReturnVal = false;
2023
 
2024
			}
2025
 
2026
        	return bReturnVal;
2027
 
2028
        },
2029
 
2030
 
2031
        /**
2032
        * @method _onAppendTo
2033
        * @description "appendTo" event handler for the button.
2034
        * @protected
2035
        * @param {Event} p_oEvent Object representing the DOM event object
2036
        * passed back by the event utility (YAHOO.util.Event).
2037
        */
2038
        _onAppendTo: function (p_oEvent) {
2039
 
2040
            /*
2041
                It is necessary to call "_addListenersToForm" using
2042
                "setTimeout" to make sure that the button's "form" property
2043
                returns a node reference.  Sometimes, if you try to get the
2044
                reference immediately after appending the field, it is null.
2045
            */
2046
 
2047
            Lang.later(0, this, this._addListenersToForm);
2048
 
2049
        },
2050
 
2051
 
2052
        /**
2053
        * @method _onFormReset
2054
        * @description "reset" event handler for the button's form.
2055
        * @protected
2056
        * @param {Event} p_oEvent Object representing the DOM event
2057
        * object passed back by the event utility (YAHOO.util.Event).
2058
        */
2059
        _onFormReset: function (p_oEvent) {
2060
 
2061
            var sType = this.get("type"),
2062
                oMenu = this._menu;
2063
 
2064
            if (sType == "checkbox" || sType == "radio") {
2065
 
2066
                this.resetValue("checked");
2067
 
2068
            }
2069
 
2070
 
2071
            if (Menu && oMenu && (oMenu instanceof Menu)) {
2072
 
2073
                this.resetValue("selectedMenuItem");
2074
 
2075
            }
2076
 
2077
        },
2078
 
2079
 
2080
        /**
2081
        * @method _onFormSubmit
2082
        * @description "submit" event handler for the button's form.
2083
        * @protected
2084
        * @param {Event} p_oEvent Object representing the DOM event
2085
        * object passed back by the event utility (YAHOO.util.Event).
2086
        */
2087
        _onFormSubmit: function (p_oEvent) {
2088
 
2089
        	this.createHiddenFields();
2090
 
2091
        },
2092
 
2093
 
2094
        /**
2095
        * @method _onDocumentMouseDown
2096
        * @description "mousedown" event handler for the document.
2097
        * @protected
2098
        * @param {Event} p_oEvent Object representing the DOM event object
2099
        * passed back by the event utility (YAHOO.util.Event).
2100
        */
2101
        _onDocumentMouseDown: function (p_oEvent) {
2102
 
2103
            var oTarget = Event.getTarget(p_oEvent),
2104
                oButtonElement = this.get("element"),
2105
                oMenuElement = this._menu.element;
2106
 
2107
            function findTargetInSubmenus(aSubmenus) {
2108
                var i, iMax, oSubmenuElement;
2109
                if (!aSubmenus) {
2110
                    return true;
2111
                }
2112
                for (i = 0, iMax = aSubmenus.length; i < iMax; i++) {
2113
                    oSubmenuElement = aSubmenus[i].element;
2114
                    if (oTarget == oSubmenuElement || Dom.isAncestor(oSubmenuElement, oTarget)) {
2115
                        return true;
2116
                    }
2117
                    if (aSubmenus[i] && aSubmenus[i].getSubmenus) {
2118
                        if (findTargetInSubmenus(aSubmenus[i].getSubmenus())) {
2119
                            return true;
2120
                        }
2121
                    }
2122
                }
2123
 
2124
                return false;
2125
            }
2126
 
2127
            if (oTarget != oButtonElement &&
2128
                !Dom.isAncestor(oButtonElement, oTarget) &&
2129
                oTarget != oMenuElement &&
2130
                !Dom.isAncestor(oMenuElement, oTarget)) {
2131
 
2132
 
2133
                if (this._menu  && this._menu.getSubmenus) {
2134
                    if (!findTargetInSubmenus(this._menu.getSubmenus())) {
2135
                        return;
2136
                    }
2137
                }
2138
 
2139
 
2140
                this._hideMenu();
2141
 
2142
				//	In IE when the user mouses down on a focusable element
2143
				//	that element will be focused and become the "activeElement".
2144
				//	(http://msdn.microsoft.com/en-us/library/ms533065(VS.85).aspx)
2145
				//	However, there is a bug in IE where if there is a
2146
				//	positioned element with a focused descendant that is
2147
				//	hidden in response to the mousedown event, the target of
2148
				//	the mousedown event will appear to have focus, but will
2149
				//	not be set as the activeElement.  This will result
2150
				//	in the element not firing key events, even though it
2151
				//	appears to have focus.	The following call to "setActive"
2152
				//	fixes this bug.
2153
 
2154
                if (UA.ie && (UA.ie < 9) && oTarget.focus) {
2155
					oTarget.setActive();
2156
				}
2157
 
2158
                Event.removeListener(document, "mousedown",
2159
                    this._onDocumentMouseDown);
2160
 
2161
            }
2162
 
2163
        },
2164
 
2165
 
2166
        /**
2167
        * @method _onOption
2168
        * @description "option" event handler for the button.
2169
        * @protected
2170
        * @param {Event} p_oEvent Object representing the DOM event object
2171
        * passed back by the event utility (YAHOO.util.Event).
2172
        */
2173
        _onOption: function (p_oEvent) {
2174
 
2175
            if (this.hasClass(this.CLASS_NAME_PREFIX + "split-button-activeoption")) {
2176
 
2177
                this._hideMenu();
2178
 
2179
                this._bOptionPressed = false;
2180
 
2181
            }
2182
            else {
2183
 
2184
                this._showMenu(p_oEvent);
2185
 
2186
                this._bOptionPressed = true;
2187
 
2188
            }
2189
 
2190
        },
2191
 
2192
 
2193
        /**
2194
        * @method _onMenuShow
2195
        * @description "show" event handler for the button's menu.
2196
        * @private
2197
        * @param {String} p_sType String representing the name of the event
2198
        * that was fired.
2199
        */
2200
        _onMenuShow: function (p_sType) {
2201
 
2202
            Event.on(document, "mousedown", this._onDocumentMouseDown,
2203
                null, this);
2204
 
2205
            var sState = (this.get("type") == "split") ? "activeoption" : "active";
2206
 
2207
            this.addStateCSSClasses(sState);
2208
 
2209
        },
2210
 
2211
 
2212
        /**
2213
        * @method _onMenuHide
2214
        * @description "hide" event handler for the button's menu.
2215
        * @private
2216
        * @param {String} p_sType String representing the name of the event
2217
        * that was fired.
2218
        */
2219
        _onMenuHide: function (p_sType) {
2220
 
2221
            var sState = (this.get("type") == "split") ? "activeoption" : "active";
2222
 
2223
            this.removeStateCSSClasses(sState);
2224
 
2225
 
2226
            if (this.get("type") == "split") {
2227
 
2228
                this._bOptionPressed = false;
2229
 
2230
            }
2231
 
2232
        },
2233
 
2234
 
2235
        /**
2236
        * @method _onMenuKeyDown
2237
        * @description "keydown" event handler for the button's menu.
2238
        * @private
2239
        * @param {String} p_sType String representing the name of the event
2240
        * that was fired.
2241
        * @param {Array} p_aArgs Array of arguments sent when the event
2242
        * was fired.
2243
        */
2244
        _onMenuKeyDown: function (p_sType, p_aArgs) {
2245
 
2246
            var oEvent = p_aArgs[0];
2247
 
2248
            if (Event.getCharCode(oEvent) == 27) {
2249
 
2250
                this.focus();
2251
 
2252
                if (this.get("type") == "split") {
2253
 
2254
                    this._bOptionPressed = false;
2255
 
2256
                }
2257
 
2258
            }
2259
 
2260
        },
2261
 
2262
 
2263
        /**
2264
        * @method _onMenuRender
2265
        * @description "render" event handler for the button's menu.
2266
        * @private
2267
        * @param {String} p_sType String representing the name of the
2268
        * event thatwas fired.
2269
        */
2270
        _onMenuRender: function (p_sType) {
2271
 
2272
            var oButtonElement = this.get("element"),
2273
                oButtonParent = oButtonElement.parentNode,
2274
				oMenu = this._menu,
2275
                oMenuElement = oMenu.element,
2276
				oSrcElement = oMenu.srcElement,
2277
				oItem;
2278
 
2279
 
2280
            if (oButtonParent != oMenuElement.parentNode) {
2281
 
2282
                oButtonParent.appendChild(oMenuElement);
2283
 
2284
            }
2285
 
2286
			this._renderedMenu = true;
2287
 
2288
			//	If the user has designated an <option> of the Menu's source
2289
			//	<select> element to be selected, sync the selectedIndex with
2290
			//	the "selectedMenuItem" Attribute.
2291
 
2292
			if (oSrcElement &&
2293
					oSrcElement.nodeName.toLowerCase() === "select" &&
2294
					oSrcElement.value) {
2295
 
2296
 
2297
				oItem = oMenu.getItem(oSrcElement.selectedIndex);
2298
 
2299
				//	Set the value of the "selectedMenuItem" attribute
2300
				//	silently since this is the initial set--synchronizing
2301
				//	the value of the source <SELECT> element in the DOM with
2302
				//	its corresponding Menu instance.
2303
 
2304
				this.set("selectedMenuItem", oItem, true);
2305
 
2306
				//	Call the "_onSelectedMenuItemChange" method since the
2307
				//	attribute was set silently.
2308
 
2309
				this._onSelectedMenuItemChange({ newValue: oItem });
2310
 
2311
			}
2312
 
2313
        },
2314
 
2315
 
2316
 
2317
        /**
2318
        * @method _onMenuClick
2319
        * @description "click" event handler for the button's menu.
2320
        * @private
2321
        * @param {String} p_sType String representing the name of the event
2322
        * that was fired.
2323
        * @param {Array} p_aArgs Array of arguments sent when the event
2324
        * was fired.
2325
        */
2326
        _onMenuClick: function (p_sType, p_aArgs) {
2327
 
2328
            var oItem = p_aArgs[1],
2329
                oSrcElement;
2330
 
2331
            if (oItem) {
2332
 
2333
				this.set("selectedMenuItem", oItem);
2334
 
2335
                oSrcElement = this.get("srcelement");
2336
 
2337
                if (oSrcElement && oSrcElement.type == "submit") {
2338
 
2339
                    this.submitForm();
2340
 
2341
                }
2342
 
2343
                this._hideMenu();
2344
 
2345
            }
2346
 
2347
        },
2348
 
2349
 
2350
        /**
2351
        * @method _onSelectedMenuItemChange
2352
        * @description "selectedMenuItemChange" event handler for the Button's
2353
		* "selectedMenuItem" attribute.
2354
        * @param {Event} event Object representing the DOM event object
2355
        * passed back by the event utility (YAHOO.util.Event).
2356
        */
2357
		_onSelectedMenuItemChange: function (event) {
2358
 
2359
			var oSelected = event.prevValue,
2360
				oItem = event.newValue,
2361
				sPrefix = this.CLASS_NAME_PREFIX;
2362
 
2363
			if (oSelected) {
2364
				Dom.removeClass(oSelected.element, (sPrefix + "button-selectedmenuitem"));
2365
			}
2366
 
2367
			if (oItem) {
2368
				Dom.addClass(oItem.element, (sPrefix + "button-selectedmenuitem"));
2369
			}
2370
 
2371
		},
2372
 
2373
 
2374
        /**
2375
        * @method _onLabelClick
2376
        * @description "click" event handler for the Button's
2377
		* <code>&#60;label&#62;</code> element.
2378
        * @param {Event} event Object representing the DOM event object
2379
        * passed back by the event utility (YAHOO.util.Event).
2380
        */
2381
		_onLabelClick: function (event) {
2382
 
2383
			this.focus();
2384
 
2385
			var sType = this.get("type");
2386
 
2387
			if (sType == "radio" || sType == "checkbox") {
2388
				this.set("checked", (!this.get("checked")));
2389
			}
2390
 
2391
		},
2392
 
2393
 
2394
        // Public methods
2395
 
2396
 
2397
        /**
2398
        * @method createButtonElement
2399
        * @description Creates the button's HTML elements.
2400
        * @param {String} p_sType String indicating the type of element
2401
        * to create.
2402
        * @return {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
2403
        * level-one-html.html#ID-58190037">HTMLElement</a>}
2404
        */
2405
        createButtonElement: function (p_sType) {
2406
 
2407
            var sNodeName = this.NODE_NAME,
2408
                oElement = document.createElement(sNodeName);
2409
 
2410
            oElement.innerHTML =  "<" + sNodeName + " class=\"first-child\">" +
2411
                (p_sType == "link" ? "<a></a>" :
2412
                "<button type=\"button\"></button>") + "</" + sNodeName + ">";
2413
 
2414
            return oElement;
2415
 
2416
        },
2417
 
2418
 
2419
        /**
2420
        * @method addStateCSSClasses
2421
        * @description Appends state-specific CSS classes to the button's root
2422
        * DOM element.
2423
        */
2424
        addStateCSSClasses: function (p_sState) {
2425
 
2426
            var sType = this.get("type"),
2427
				sPrefix = this.CLASS_NAME_PREFIX;
2428
 
2429
            if (Lang.isString(p_sState)) {
2430
 
2431
                if (p_sState != "activeoption" && p_sState != "hoveroption") {
2432
 
2433
                    this.addClass(sPrefix + this.CSS_CLASS_NAME + ("-" + p_sState));
2434
 
2435
                }
2436
 
2437
                this.addClass(sPrefix + sType + ("-button-" + p_sState));
2438
 
2439
            }
2440
 
2441
        },
2442
 
2443
 
2444
        /**
2445
        * @method removeStateCSSClasses
2446
        * @description Removes state-specific CSS classes to the button's root
2447
        * DOM element.
2448
        */
2449
        removeStateCSSClasses: function (p_sState) {
2450
 
2451
            var sType = this.get("type"),
2452
				sPrefix = this.CLASS_NAME_PREFIX;
2453
 
2454
            if (Lang.isString(p_sState)) {
2455
 
2456
                this.removeClass(sPrefix + this.CSS_CLASS_NAME + ("-" + p_sState));
2457
                this.removeClass(sPrefix + sType + ("-button-" + p_sState));
2458
 
2459
            }
2460
 
2461
        },
2462
 
2463
 
2464
        /**
2465
        * @method createHiddenFields
2466
        * @description Creates the button's hidden form field and appends it
2467
        * to its parent form.
2468
        * @return {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
2469
        * level-one-html.html#ID-6043025">HTMLInputElement</a>|Array}
2470
        */
2471
        createHiddenFields: function () {
2472
 
2473
            this.removeHiddenFields();
2474
 
2475
            var oForm = this.getForm(),
2476
                oButtonField,
2477
                sType,
2478
                bCheckable,
2479
                oMenu,
2480
                oMenuItem,
2481
                sButtonName,
2482
                oValue,
2483
                oMenuField,
2484
                oReturnVal,
2485
				sMenuFieldName,
2486
				oMenuSrcElement,
2487
				bMenuSrcElementIsSelect = false;
2488
 
2489
 
2490
            if (oForm && !this.get("disabled")) {
2491
 
2492
                sType = this.get("type");
2493
                bCheckable = (sType == "checkbox" || sType == "radio");
2494
 
2495
 
2496
                if ((bCheckable && this.get("checked")) || (m_oSubmitTrigger == this)) {
2497
 
2498
 
2499
                    oButtonField = createInputElement((bCheckable ? sType : "hidden"),
2500
                                    this.get("name"), this.get("value"), this.get("checked"));
2501
 
2502
 
2503
                    if (oButtonField) {
2504
 
2505
                        if (bCheckable) {
2506
 
2507
                            oButtonField.style.display = "none";
2508
 
2509
                        }
2510
 
2511
                        oForm.appendChild(oButtonField);
2512
 
2513
                    }
2514
 
2515
                }
2516
 
2517
 
2518
                oMenu = this._menu;
2519
 
2520
 
2521
                if (Menu && oMenu && (oMenu instanceof Menu)) {
2522
 
2523
 
2524
                    oMenuItem = this.get("selectedMenuItem");
2525
					oMenuSrcElement = oMenu.srcElement;
2526
					bMenuSrcElementIsSelect = (oMenuSrcElement &&
2527
												oMenuSrcElement.nodeName.toUpperCase() == "SELECT");
2528
 
2529
                    if (oMenuItem) {
2530
 
2531
						oValue = (oMenuItem.value === null || oMenuItem.value === "") ?
2532
									oMenuItem.cfg.getProperty("text") : oMenuItem.value;
2533
 
2534
						sButtonName = this.get("name");
2535
 
2536
 
2537
						if (bMenuSrcElementIsSelect) {
2538
 
2539
							sMenuFieldName = oMenuSrcElement.name;
2540
 
2541
						}
2542
						else if (sButtonName) {
2543
 
2544
							sMenuFieldName = (sButtonName + "_options");
2545
 
2546
						}
2547
 
2548
 
2549
						if (oValue && sMenuFieldName) {
2550
 
2551
							oMenuField = createInputElement("hidden", sMenuFieldName, oValue);
2552
							oForm.appendChild(oMenuField);
2553
 
2554
						}
2555
 
2556
                    }
2557
                    else if (bMenuSrcElementIsSelect) {
2558
 
2559
						oMenuField = oForm.appendChild(oMenuSrcElement);
2560
 
2561
                    }
2562
 
2563
                }
2564
 
2565
 
2566
                if (oButtonField && oMenuField) {
2567
 
2568
                    this._hiddenFields = [oButtonField, oMenuField];
2569
 
2570
                }
2571
                else if (!oButtonField && oMenuField) {
2572
 
2573
                    this._hiddenFields = oMenuField;
2574
 
2575
                }
2576
                else if (oButtonField && !oMenuField) {
2577
 
2578
                    this._hiddenFields = oButtonField;
2579
 
2580
                }
2581
 
2582
        		oReturnVal = this._hiddenFields;
2583
 
2584
            }
2585
 
2586
			return oReturnVal;
2587
 
2588
        },
2589
 
2590
 
2591
        /**
2592
        * @method removeHiddenFields
2593
        * @description Removes the button's hidden form field(s) from its
2594
        * parent form.
2595
        */
2596
        removeHiddenFields: function () {
2597
 
2598
            var oField = this._hiddenFields,
2599
                nFields,
2600
                i;
2601
 
2602
            function removeChild(p_oElement) {
2603
 
2604
                if (Dom.inDocument(p_oElement)) {
2605
 
2606
                    p_oElement.parentNode.removeChild(p_oElement);
2607
 
2608
                }
2609
 
2610
            }
2611
 
2612
 
2613
            if (oField) {
2614
 
2615
                if (Lang.isArray(oField)) {
2616
 
2617
                    nFields = oField.length;
2618
 
2619
                    if (nFields > 0) {
2620
 
2621
                        i = nFields - 1;
2622
 
2623
                        do {
2624
 
2625
                            removeChild(oField[i]);
2626
 
2627
                        }
2628
                        while (i--);
2629
 
2630
                    }
2631
 
2632
                }
2633
                else {
2634
 
2635
                    removeChild(oField);
2636
 
2637
                }
2638
 
2639
                this._hiddenFields = null;
2640
 
2641
            }
2642
 
2643
        },
2644
 
2645
 
2646
        /**
2647
        * @method submitForm
2648
        * @description Submits the form to which the button belongs.  Returns
2649
        * true if the form was submitted successfully, false if the submission
2650
        * was cancelled.
2651
        * @protected
2652
        * @return {Boolean}
2653
        */
2654
        submitForm: function () {
2655
 
2656
            var oForm = this.getForm(),
2657
 
2658
                oSrcElement = this.get("srcelement"),
2659
 
2660
                /*
2661
                    Boolean indicating if the event fired successfully
2662
                    (was not cancelled by any handlers)
2663
                */
2664
 
2665
                bSubmitForm = false,
2666
 
2667
                oEvent;
2668
 
2669
 
2670
            if (oForm) {
2671
 
2672
                if (this.get("type") == "submit" || (oSrcElement && oSrcElement.type == "submit")) {
2673
 
2674
                    m_oSubmitTrigger = this;
2675
 
2676
                }
2677
 
2678
 
2679
                if (UA.ie && (UA.ie < 9)) {
2680
 
2681
                    bSubmitForm = oForm.fireEvent("onsubmit");
2682
 
2683
                }
2684
                else {  // Gecko, Opera, and Safari
2685
 
2686
                    oEvent = document.createEvent("HTMLEvents");
2687
                    oEvent.initEvent("submit", true, true);
2688
 
2689
                    bSubmitForm = oForm.dispatchEvent(oEvent);
2690
 
2691
                }
2692
 
2693
 
2694
                /*
2695
                    In IE and Safari, dispatching a "submit" event to a form
2696
                    WILL cause the form's "submit" event to fire, but WILL NOT
2697
                    submit the form.  Therefore, we need to call the "submit"
2698
                    method as well.
2699
                */
2700
 
2701
                if ((UA.ie || UA.webkit) && bSubmitForm) {
2702
 
2703
                    oForm.submit();
2704
 
2705
                }
2706
 
2707
            }
2708
 
2709
            return bSubmitForm;
2710
 
2711
        },
2712
 
2713
 
2714
        /**
2715
        * @method init
2716
        * @description The Button class's initialization method.
2717
        * @param {String} p_oElement String specifying the id attribute of the
2718
        * <code>&#60;input&#62;</code>, <code>&#60;button&#62;</code>,
2719
        * <code>&#60;a&#62;</code>, or <code>&#60;span&#62;</code> element to
2720
        * be used to create the button.
2721
        * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
2722
        * level-one-html.html#ID-6043025">HTMLInputElement</a>|<a href="http://
2723
        * www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html
2724
        * #ID-34812697">HTMLButtonElement</a>|<a href="http://www.w3.org/TR
2725
        * /2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-33759296">
2726
        * HTMLElement</a>} p_oElement Object reference for the
2727
        * <code>&#60;input&#62;</code>, <code>&#60;button&#62;</code>,
2728
        * <code>&#60;a&#62;</code>, or <code>&#60;span&#62;</code> element to be
2729
        * used to create the button.
2730
        * @param {Object} p_oElement Object literal specifying a set of
2731
        * configuration attributes used to create the button.
2732
        * @param {Object} p_oAttributes Optional. Object literal specifying a
2733
        * set of configuration attributes used to create the button.
2734
        */
2735
        init: function (p_oElement, p_oAttributes) {
2736
 
2737
            var sNodeName = p_oAttributes.type == "link" ? "a" : "button",
2738
                oSrcElement = p_oAttributes.srcelement,
2739
                oButton = p_oElement.getElementsByTagName(sNodeName)[0],
2740
                oInput;
2741
 
2742
 
2743
            if (!oButton) {
2744
 
2745
                oInput = p_oElement.getElementsByTagName("input")[0];
2746
 
2747
 
2748
                if (oInput) {
2749
 
2750
                    oButton = document.createElement("button");
2751
                    oButton.setAttribute("type", "button");
2752
 
2753
                    oInput.parentNode.replaceChild(oButton, oInput);
2754
 
2755
                }
2756
 
2757
            }
2758
 
2759
            this._button = oButton;
2760
 
2761
 
2762
            YAHOO.widget.Button.superclass.init.call(this, p_oElement, p_oAttributes);
2763
 
2764
 
2765
			var sId = this.get("id"),
2766
				sButtonId = sId + "-button";
2767
 
2768
 
2769
        	oButton.id = sButtonId;
2770
 
2771
 
2772
			var aLabels,
2773
				oLabel;
2774
 
2775
 
2776
        	var hasLabel = function (element) {
2777
 
2778
				return (element.htmlFor === sId);
2779
 
2780
        	};
2781
 
2782
 
2783
			var setLabel = function () {
2784
 
2785
				oLabel.setAttribute((UA.ie ? "htmlFor" : "for"), sButtonId);
2786
 
2787
			};
2788
 
2789
 
2790
			if (oSrcElement && this.get("type") != "link") {
2791
 
2792
				aLabels = Dom.getElementsBy(hasLabel, "label");
2793
 
2794
				if (Lang.isArray(aLabels) && aLabels.length > 0) {
2795
 
2796
					oLabel = aLabels[0];
2797
 
2798
				}
2799
 
2800
			}
2801
 
2802
 
2803
            m_oButtons[sId] = this;
2804
 
2805
        	var sPrefix = this.CLASS_NAME_PREFIX;
2806
 
2807
            this.addClass(sPrefix + this.CSS_CLASS_NAME);
2808
            this.addClass(sPrefix + this.get("type") + "-button");
2809
 
2810
            Event.on(this._button, "focus", this._onFocus, null, this);
2811
            this.on("mouseover", this._onMouseOver);
2812
			this.on("mousedown", this._onMouseDown);
2813
			this.on("mouseup", this._onMouseUp);
2814
            this.on("click", this._onClick);
2815
 
2816
			//	Need to reset the value of the "onclick" Attribute so that any
2817
			//	handlers registered via the "onclick" Attribute are fired after
2818
			//	Button's default "_onClick" listener.
2819
 
2820
			var fnOnClick = this.get("onclick");
2821
 
2822
			this.set("onclick", null);
2823
			this.set("onclick", fnOnClick);
2824
 
2825
            this.on("dblclick", this._onDblClick);
2826
 
2827
 
2828
			var oParentNode;
2829
 
2830
            if (oLabel) {
2831
 
2832
				if (this.get("replaceLabel")) {
2833
 
2834
					this.set("label", oLabel.innerHTML);
2835
 
2836
					oParentNode = oLabel.parentNode;
2837
 
2838
					oParentNode.removeChild(oLabel);
2839
 
2840
				}
2841
				else {
2842
 
2843
					this.on("appendTo", setLabel);
2844
 
2845
					Event.on(oLabel, "click", this._onLabelClick, null, this);
2846
 
2847
					this._label = oLabel;
2848
 
2849
				}
2850
 
2851
            }
2852
 
2853
            this.on("appendTo", this._onAppendTo);
2854
 
2855
 
2856
 
2857
            var oContainer = this.get("container"),
2858
                oElement = this.get("element"),
2859
                bElInDoc = Dom.inDocument(oElement);
2860
 
2861
 
2862
            if (oContainer) {
2863
 
2864
                if (oSrcElement && oSrcElement != oElement) {
2865
 
2866
                    oParentNode = oSrcElement.parentNode;
2867
 
2868
                    if (oParentNode) {
2869
 
2870
                        oParentNode.removeChild(oSrcElement);
2871
 
2872
                    }
2873
 
2874
                }
2875
 
2876
                if (Lang.isString(oContainer)) {
2877
 
2878
                    Event.onContentReady(oContainer, this.appendTo, oContainer, this);
2879
 
2880
                }
2881
                else {
2882
 
2883
        			this.on("init", function () {
2884
 
2885
        				Lang.later(0, this, this.appendTo, oContainer);
2886
 
2887
        			});
2888
 
2889
                }
2890
 
2891
            }
2892
            else if (!bElInDoc && oSrcElement && oSrcElement != oElement) {
2893
 
2894
                oParentNode = oSrcElement.parentNode;
2895
 
2896
                if (oParentNode) {
2897
 
2898
                    this.fireEvent("beforeAppendTo", {
2899
                        type: "beforeAppendTo",
2900
                        target: oParentNode
2901
                    });
2902
 
2903
                    oParentNode.replaceChild(oElement, oSrcElement);
2904
 
2905
                    this.fireEvent("appendTo", {
2906
                        type: "appendTo",
2907
                        target: oParentNode
2908
                    });
2909
 
2910
                }
2911
 
2912
            }
2913
            else if (this.get("type") != "link" && bElInDoc && oSrcElement &&
2914
                oSrcElement == oElement) {
2915
 
2916
                this._addListenersToForm();
2917
 
2918
            }
2919
 
2920
 
2921
 
2922
			this.fireEvent("init", {
2923
				type: "init",
2924
				target: this
2925
			});
2926
 
2927
        },
2928
 
2929
 
2930
        /**
2931
        * @method initAttributes
2932
        * @description Initializes all of the configuration attributes used to
2933
        * create the button.
2934
        * @param {Object} p_oAttributes Object literal specifying a set of
2935
        * configuration attributes used to create the button.
2936
        */
2937
        initAttributes: function (p_oAttributes) {
2938
 
2939
            var oAttributes = p_oAttributes || {};
2940
 
2941
            YAHOO.widget.Button.superclass.initAttributes.call(this,
2942
                oAttributes);
2943
 
2944
 
2945
            /**
2946
            * @attribute type
2947
            * @description String specifying the button's type.  Possible
2948
            * values are: "push," "link," "submit," "reset," "checkbox,"
2949
            * "radio," "menu," and "split."
2950
            * @default "push"
2951
            * @type String
2952
			* @writeonce
2953
            */
2954
            this.setAttributeConfig("type", {
2955
 
2956
                value: (oAttributes.type || "push"),
2957
                validator: Lang.isString,
2958
                writeOnce: true,
2959
                method: this._setType
2960
 
2961
            });
2962
 
2963
 
2964
            /**
2965
            * @attribute label
2966
            * @description {HTML} specifying the button's text label
2967
            * or innerHTML.
2968
            * @default null
2969
            * @type String
2970
            */
2971
            this.setAttributeConfig("label", {
2972
 
2973
                value: oAttributes.label,
2974
                validator: Lang.isString,
2975
                method: this._setLabel
2976
 
2977
            });
2978
 
2979
 
2980
            /**
2981
            * @attribute value
2982
            * @description Object specifying the value for the button.
2983
            * @default null
2984
            * @type Object
2985
            */
2986
            this.setAttributeConfig("value", {
2987
 
2988
                value: oAttributes.value
2989
 
2990
            });
2991
 
2992
 
2993
            /**
2994
            * @attribute name
2995
            * @description String specifying the name for the button.
2996
            * @default null
2997
            * @type String
2998
            */
2999
            this.setAttributeConfig("name", {
3000
 
3001
                value: oAttributes.name,
3002
                validator: Lang.isString
3003
 
3004
            });
3005
 
3006
 
3007
            /**
3008
            * @attribute tabindex
3009
            * @description Number specifying the tabindex for the button.
3010
            * @default null
3011
            * @type Number
3012
            */
3013
            this.setAttributeConfig("tabindex", {
3014
 
3015
                value: oAttributes.tabindex,
3016
                validator: Lang.isNumber,
3017
                method: this._setTabIndex
3018
 
3019
            });
3020
 
3021
 
3022
            /**
3023
            * @attribute title
3024
            * @description String specifying the title for the button.
3025
            * @default null
3026
            * @type String
3027
            */
3028
            this.configureAttribute("title", {
3029
 
3030
                value: oAttributes.title,
3031
                validator: Lang.isString,
3032
                method: this._setTitle
3033
 
3034
            });
3035
 
3036
 
3037
            /**
3038
            * @attribute disabled
3039
            * @description Boolean indicating if the button should be disabled.
3040
            * (Disabled buttons are dimmed and will not respond to user input
3041
            * or fire events.  Does not apply to button's of type "link.")
3042
            * @default false
3043
            * @type Boolean
3044
            */
3045
            this.setAttributeConfig("disabled", {
3046
 
3047
                value: (oAttributes.disabled || false),
3048
                validator: Lang.isBoolean,
3049
                method: this._setDisabled
3050
 
3051
            });
3052
 
3053
 
3054
            /**
3055
            * @attribute href
3056
            * @description String specifying the href for the button.  Applies
3057
            * only to buttons of type "link."
3058
            * @type String
3059
            */
3060
            this.setAttributeConfig("href", {
3061
 
3062
                value: oAttributes.href,
3063
                validator: Lang.isString,
3064
                method: this._setHref
3065
 
3066
            });
3067
 
3068
 
3069
            /**
3070
            * @attribute target
3071
            * @description String specifying the target for the button.
3072
            * Applies only to buttons of type "link."
3073
            * @type String
3074
            */
3075
            this.setAttributeConfig("target", {
3076
 
3077
                value: oAttributes.target,
3078
                validator: Lang.isString,
3079
                method: this._setTarget
3080
 
3081
            });
3082
 
3083
 
3084
            /**
3085
            * @attribute checked
3086
            * @description Boolean indicating if the button is checked.
3087
            * Applies only to buttons of type "radio" and "checkbox."
3088
            * @default false
3089
            * @type Boolean
3090
            */
3091
            this.setAttributeConfig("checked", {
3092
 
3093
                value: (oAttributes.checked || false),
3094
                validator: Lang.isBoolean,
3095
                method: this._setChecked
3096
 
3097
            });
3098
 
3099
 
3100
            /**
3101
            * @attribute container
3102
            * @description HTML element reference or string specifying the id
3103
            * attribute of the HTML element that the button's markup should be
3104
            * rendered into.
3105
            * @type <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
3106
            * level-one-html.html#ID-58190037">HTMLElement</a>|String
3107
            * @default null
3108
			* @writeonce
3109
            */
3110
            this.setAttributeConfig("container", {
3111
 
3112
                value: oAttributes.container,
3113
                writeOnce: true
3114
 
3115
            });
3116
 
3117
 
3118
            /**
3119
            * @attribute srcelement
3120
            * @description Object reference to the HTML element (either
3121
            * <code>&#60;input&#62;</code> or <code>&#60;span&#62;</code>)
3122
            * used to create the button.
3123
            * @type <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
3124
            * level-one-html.html#ID-58190037">HTMLElement</a>|String
3125
            * @default null
3126
			* @writeonce
3127
            */
3128
            this.setAttributeConfig("srcelement", {
3129
 
3130
                value: oAttributes.srcelement,
3131
                writeOnce: true
3132
 
3133
            });
3134
 
3135
 
3136
            /**
3137
            * @attribute menu
3138
            * @description Object specifying the menu for the button.
3139
            * The value can be one of the following:
3140
            * <ul>
3141
            * <li>Object specifying a rendered <a href="YAHOO.widget.Menu.html">
3142
            * YAHOO.widget.Menu</a> instance.</li>
3143
            * <li>Object specifying a rendered <a href="YAHOO.widget.Overlay.html">
3144
            * YAHOO.widget.Overlay</a> instance.</li>
3145
            * <li>String specifying the id attribute of the <code>&#60;div&#62;
3146
            * </code> element used to create the menu.  By default the menu
3147
            * will be created as an instance of
3148
            * <a href="YAHOO.widget.Overlay.html">YAHOO.widget.Overlay</a>.
3149
            * If the <a href="YAHOO.widget.Menu.html#CSS_CLASS_NAME">
3150
            * default CSS class name for YAHOO.widget.Menu</a> is applied to
3151
            * the <code>&#60;div&#62;</code> element, it will be created as an
3152
            * instance of <a href="YAHOO.widget.Menu.html">YAHOO.widget.Menu
3153
            * </a>.</li><li>String specifying the id attribute of the
3154
            * <code>&#60;select&#62;</code> element used to create the menu.
3155
            * </li><li>Object specifying the <code>&#60;div&#62;</code> element
3156
            * used to create the menu.</li>
3157
            * <li>Object specifying the <code>&#60;select&#62;</code> element
3158
            * used to create the menu.</li>
3159
            * <li>Array of object literals, each representing a set of
3160
            * <a href="YAHOO.widget.MenuItem.html">YAHOO.widget.MenuItem</a>
3161
            * configuration attributes.</li>
3162
            * <li>Array of strings representing the text labels for each menu
3163
            * item in the menu.</li>
3164
            * </ul>
3165
            * @type <a href="YAHOO.widget.Menu.html">YAHOO.widget.Menu</a>|<a
3166
            * href="YAHOO.widget.Overlay.html">YAHOO.widget.Overlay</a>|<a
3167
            * href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-
3168
            * one-html.html#ID-58190037">HTMLElement</a>|String|Array
3169
            * @default null
3170
			* @writeonce
3171
            */
3172
            this.setAttributeConfig("menu", {
3173
 
3174
                value: null,
3175
                method: this._setMenu,
3176
                writeOnce: true
3177
 
3178
            });
3179
 
3180
 
3181
            /**
3182
            * @attribute lazyloadmenu
3183
            * @description Boolean indicating the value to set for the
3184
            * <a href="YAHOO.widget.Menu.html#lazyLoad">"lazyload"</a>
3185
            * configuration property of the button's menu.  Setting
3186
            * "lazyloadmenu" to <code>true </code> will defer rendering of
3187
            * the button's menu until the first time it is made visible.
3188
            * If "lazyloadmenu" is set to <code>false</code>, the button's
3189
            * menu will be rendered immediately if the button is in the
3190
            * document, or in response to the button's "appendTo" event if
3191
            * the button is not yet in the document.  In either case, the
3192
            * menu is rendered into the button's parent HTML element.
3193
            * <em>This attribute does not apply if a
3194
            * <a href="YAHOO.widget.Menu.html">YAHOO.widget.Menu</a> or
3195
            * <a href="YAHOO.widget.Overlay.html">YAHOO.widget.Overlay</a>
3196
            * instance is passed as the value of the button's "menu"
3197
            * configuration attribute. <a href="YAHOO.widget.Menu.html">
3198
            * YAHOO.widget.Menu</a> or <a href="YAHOO.widget.Overlay.html">
3199
            * YAHOO.widget.Overlay</a> instances should be rendered before
3200
            * being set as the value for the "menu" configuration
3201
            * attribute.</em>
3202
            * @default true
3203
            * @type Boolean
3204
			* @writeonce
3205
            */
3206
            this.setAttributeConfig("lazyloadmenu", {
3207
 
3208
                value: (oAttributes.lazyloadmenu === false ? false : true),
3209
                validator: Lang.isBoolean,
3210
                writeOnce: true
3211
 
3212
            });
3213
 
3214
 
3215
            /**
3216
            * @attribute menuclassname
3217
            * @description String representing the CSS class name to be
3218
            * applied to the root element of the button's menu.
3219
            * @type String
3220
            * @default "yui-button-menu"
3221
			* @writeonce
3222
            */
3223
            this.setAttributeConfig("menuclassname", {
3224
 
3225
                value: (oAttributes.menuclassname || (this.CLASS_NAME_PREFIX + "button-menu")),
3226
                validator: Lang.isString,
3227
                method: this._setMenuClassName,
3228
                writeOnce: true
3229
 
3230
            });
3231
 
3232
 
3233
			/**
3234
			* @attribute menuminscrollheight
3235
			* @description Number defining the minimum threshold for the "menumaxheight"
3236
			* configuration attribute.  When set this attribute is automatically applied
3237
			* to all submenus.
3238
			* @default 90
3239
			* @type Number
3240
			*/
3241
            this.setAttributeConfig("menuminscrollheight", {
3242
 
3243
                value: (oAttributes.menuminscrollheight || 90),
3244
                validator: Lang.isNumber
3245
 
3246
            });
3247
 
3248
 
3249
            /**
3250
            * @attribute menumaxheight
3251
			* @description Number defining the maximum height (in pixels) for a menu's
3252
			* body element (<code>&#60;div class="bd"&#60;</code>).  Once a menu's body
3253
			* exceeds this height, the contents of the body are scrolled to maintain
3254
			* this value.  This value cannot be set lower than the value of the
3255
			* "minscrollheight" configuration property.
3256
            * @type Number
3257
            * @default 0
3258
            */
3259
            this.setAttributeConfig("menumaxheight", {
3260
 
3261
                value: (oAttributes.menumaxheight || 0),
3262
                validator: Lang.isNumber
3263
 
3264
            });
3265
 
3266
 
3267
            /**
3268
            * @attribute menualignment
3269
			* @description Array defining how the Button's Menu is aligned to the Button.
3270
            * The default value of ["tl", "bl"] aligns the Menu's top left corner to the Button's
3271
            * bottom left corner.
3272
            * @type Array
3273
            * @default ["tl", "bl"]
3274
            */
3275
            this.setAttributeConfig("menualignment", {
3276
 
3277
                value: (oAttributes.menualignment || ["tl", "bl"]),
3278
                validator: Lang.isArray
3279
 
3280
            });
3281
 
3282
 
3283
            /**
3284
            * @attribute selectedMenuItem
3285
            * @description Object representing the item in the button's menu
3286
            * that is currently selected.
3287
            * @type YAHOO.widget.MenuItem
3288
            * @default null
3289
            */
3290
            this.setAttributeConfig("selectedMenuItem", {
3291
 
3292
                value: null
3293
 
3294
            });
3295
 
3296
 
3297
            /**
3298
            * @attribute onclick
3299
            * @description Object literal representing the code to be executed
3300
            * when the button is clicked.  Format:<br> <code> {<br>
3301
            * <strong>fn:</strong> Function,   &#47;&#47; The handler to call
3302
            * when the event fires.<br> <strong>obj:</strong> Object,
3303
            * &#47;&#47; An object to pass back to the handler.<br>
3304
            * <strong>scope:</strong> Object &#47;&#47;  The object to use
3305
            * for the scope of the handler.<br> } </code>
3306
            * @type Object
3307
            * @default null
3308
            */
3309
            this.setAttributeConfig("onclick", {
3310
 
3311
                value: oAttributes.onclick,
3312
                method: this._setOnClick
3313
 
3314
            });
3315
 
3316
 
3317
            /**
3318
            * @attribute focusmenu
3319
            * @description Boolean indicating whether or not the button's menu
3320
            * should be focused when it is made visible.
3321
            * @type Boolean
3322
            * @default true
3323
            */
3324
            this.setAttributeConfig("focusmenu", {
3325
 
3326
                value: (oAttributes.focusmenu === false ? false : true),
3327
                validator: Lang.isBoolean
3328
 
3329
            });
3330
 
3331
 
3332
            /**
3333
            * @attribute replaceLabel
3334
            * @description Boolean indicating whether or not the text of the
3335
			* button's <code>&#60;label&#62;</code> element should be used as
3336
			* the source for the button's label configuration attribute and
3337
			* removed from the DOM.
3338
            * @type Boolean
3339
            * @default false
3340
            */
3341
            this.setAttributeConfig("replaceLabel", {
3342
 
3343
                value: false,
3344
                validator: Lang.isBoolean,
3345
                writeOnce: true
3346
 
3347
            });
3348
 
3349
        },
3350
 
3351
 
3352
        /**
3353
        * @method focus
3354
        * @description Causes the button to receive the focus and fires the
3355
        * button's "focus" event.
3356
        */
3357
        focus: function () {
3358
 
3359
            if (!this.get("disabled")) {
3360
                //Adding a try/catch in case the element is not
3361
                //  visible by the time it's focus is being called.
3362
                //  for example, on a dialog that closes on button click
3363
                try {
3364
                    this._button.focus();
3365
                } catch (e) {}
3366
 
3367
            }
3368
 
3369
        },
3370
 
3371
 
3372
        /**
3373
        * @method blur
3374
        * @description Causes the button to lose focus and fires the button's
3375
        * "blur" event.
3376
        */
3377
        blur: function () {
3378
 
3379
            if (!this.get("disabled")) {
3380
                //Adding a try/catch in case the element is not
3381
                //  visible by the time it's focus is being called.
3382
                //  for example, on a dialog that closes on button click
3383
                try {
3384
                    this._button.blur();
3385
                } catch (e) {}
3386
 
3387
            }
3388
 
3389
        },
3390
 
3391
 
3392
        /**
3393
        * @method hasFocus
3394
        * @description Returns a boolean indicating whether or not the button
3395
        * has focus.
3396
        * @return {Boolean}
3397
        */
3398
        hasFocus: function () {
3399
 
3400
            return (m_oFocusedButton == this);
3401
 
3402
        },
3403
 
3404
 
3405
        /**
3406
        * @method isActive
3407
        * @description Returns a boolean indicating whether or not the button
3408
        * is active.
3409
        * @return {Boolean}
3410
        */
3411
        isActive: function () {
3412
 
3413
            return this.hasClass(this.CLASS_NAME_PREFIX + this.CSS_CLASS_NAME + "-active");
3414
 
3415
        },
3416
 
3417
 
3418
        /**
3419
        * @method getMenu
3420
        * @description Returns a reference to the button's menu.
3421
        * @return {<a href="YAHOO.widget.Overlay.html">
3422
        * YAHOO.widget.Overlay</a>|<a
3423
        * href="YAHOO.widget.Menu.html">YAHOO.widget.Menu</a>}
3424
        */
3425
        getMenu: function () {
3426
 
3427
            return this._menu;
3428
 
3429
        },
3430
 
3431
 
3432
        /**
3433
        * @method getForm
3434
        * @description Returns a reference to the button's parent form.
3435
        * @return {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-
3436
        * 20000929/level-one-html.html#ID-40002357">HTMLFormElement</a>}
3437
        */
3438
        getForm: function () {
3439
 
3440
        	var oButton = this._button,
3441
        		oForm;
3442
 
3443
            if (oButton) {
3444
 
3445
            	oForm = oButton.form;
3446
 
3447
            }
3448
 
3449
        	return oForm;
3450
 
3451
        },
3452
 
3453
 
3454
        /**
3455
        * @method getHiddenFields
3456
        * @description Returns an <code>&#60;input&#62;</code> element or
3457
        * array of form elements used to represent the button when its parent
3458
        * form is submitted.
3459
        * @return {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
3460
        * level-one-html.html#ID-6043025">HTMLInputElement</a>|Array}
3461
        */
3462
        getHiddenFields: function () {
3463
 
3464
            return this._hiddenFields;
3465
 
3466
        },
3467
 
3468
 
3469
        /**
3470
        * @method destroy
3471
        * @description Removes the button's element from its parent element and
3472
        * removes all event handlers.
3473
        */
3474
        destroy: function () {
3475
 
3476
 
3477
            var oElement = this.get("element"),
3478
                oMenu = this._menu,
3479
				oLabel = this._label,
3480
                oParentNode,
3481
                aButtons;
3482
 
3483
            if (oMenu) {
3484
 
3485
 
3486
                if (m_oOverlayManager && m_oOverlayManager.find(oMenu)) {
3487
 
3488
                    m_oOverlayManager.remove(oMenu);
3489
 
3490
                }
3491
 
3492
                oMenu.destroy();
3493
 
3494
            }
3495
 
3496
 
3497
            Event.purgeElement(oElement);
3498
            Event.purgeElement(this._button);
3499
            Event.removeListener(document, "mouseup", this._onDocumentMouseUp);
3500
            Event.removeListener(document, "keyup", this._onDocumentKeyUp);
3501
            Event.removeListener(document, "mousedown", this._onDocumentMouseDown);
3502
 
3503
 
3504
			if (oLabel) {
3505
 
3506
            	Event.removeListener(oLabel, "click", this._onLabelClick);
3507
 
3508
				oParentNode = oLabel.parentNode;
3509
				oParentNode.removeChild(oLabel);
3510
 
3511
			}
3512
 
3513
 
3514
            var oForm = this.getForm();
3515
 
3516
            if (oForm) {
3517
 
3518
                Event.removeListener(oForm, "reset", this._onFormReset);
3519
                Event.removeListener(oForm, "submit", this._onFormSubmit);
3520
 
3521
            }
3522
 
3523
 
3524
            this.unsubscribeAll();
3525
 
3526
			oParentNode = oElement.parentNode;
3527
 
3528
            if (oParentNode) {
3529
 
3530
                oParentNode.removeChild(oElement);
3531
 
3532
            }
3533
 
3534
 
3535
            delete m_oButtons[this.get("id")];
3536
 
3537
			var sClass = (this.CLASS_NAME_PREFIX + this.CSS_CLASS_NAME);
3538
 
3539
            aButtons = Dom.getElementsByClassName(sClass,
3540
                                this.NODE_NAME, oForm);
3541
 
3542
            if (Lang.isArray(aButtons) && aButtons.length === 0) {
3543
 
3544
                Event.removeListener(oForm, "keypress",
3545
                        YAHOO.widget.Button.onFormKeyPress);
3546
 
3547
            }
3548
 
3549
 
3550
        },
3551
 
3552
 
3553
        fireEvent: function (p_sType , p_aArgs) {
3554
 
3555
			var sType = arguments[0];
3556
 
3557
			//  Disabled buttons should not respond to DOM events
3558
 
3559
			if (this.DOM_EVENTS[sType] && this.get("disabled")) {
3560
 
3561
				return false;
3562
 
3563
			}
3564
 
3565
			return YAHOO.widget.Button.superclass.fireEvent.apply(this, arguments);
3566
 
3567
        },
3568
 
3569
 
3570
        /**
3571
        * @method toString
3572
        * @description Returns a string representing the button.
3573
        * @return {String}
3574
        */
3575
        toString: function () {
3576
 
3577
            return ("Button " + this.get("id"));
3578
 
3579
        }
3580
 
3581
    });
3582
 
3583
 
3584
    /**
3585
    * @method YAHOO.widget.Button.onFormKeyPress
3586
    * @description "keypress" event handler for the button's form.
3587
    * @param {Event} p_oEvent Object representing the DOM event object passed
3588
    * back by the event utility (YAHOO.util.Event).
3589
    */
3590
    YAHOO.widget.Button.onFormKeyPress = function (p_oEvent) {
3591
 
3592
        var oTarget = Event.getTarget(p_oEvent),
3593
            nCharCode = Event.getCharCode(p_oEvent),
3594
            sNodeName = oTarget.nodeName && oTarget.nodeName.toUpperCase(),
3595
            sType = oTarget.type,
3596
 
3597
            /*
3598
                Boolean indicating if the form contains any enabled or
3599
                disabled YUI submit buttons
3600
            */
3601
 
3602
            bFormContainsYUIButtons = false,
3603
 
3604
            oButton,
3605
 
3606
            oYUISubmitButton,   // The form's first, enabled YUI submit button
3607
 
3608
            /*
3609
                 The form's first, enabled HTML submit button that precedes any
3610
                 YUI submit button
3611
            */
3612
 
3613
            oPrecedingSubmitButton,
3614
 
3615
            oEvent;
3616
 
3617
 
3618
        function isSubmitButton(p_oElement) {
3619
 
3620
            var sId,
3621
                oSrcElement;
3622
 
3623
            switch (p_oElement.nodeName.toUpperCase()) {
3624
 
3625
            case "INPUT":
3626
            case "BUTTON":
3627
 
3628
                if (p_oElement.type == "submit" && !p_oElement.disabled) {
3629
 
3630
                    if (!bFormContainsYUIButtons && !oPrecedingSubmitButton) {
3631
 
3632
                        oPrecedingSubmitButton = p_oElement;
3633
 
3634
                    }
3635
 
3636
                }
3637
 
3638
                break;
3639
 
3640
 
3641
            default:
3642
 
3643
                sId = p_oElement.id;
3644
 
3645
                if (sId) {
3646
 
3647
                    oButton = m_oButtons[sId];
3648
 
3649
                    if (oButton) {
3650
 
3651
                        bFormContainsYUIButtons = true;
3652
 
3653
                        if (!oButton.get("disabled")) {
3654
 
3655
                            oSrcElement = oButton.get("srcelement");
3656
 
3657
                            if (!oYUISubmitButton && (oButton.get("type") == "submit" ||
3658
                                (oSrcElement && oSrcElement.type == "submit"))) {
3659
 
3660
                                oYUISubmitButton = oButton;
3661
 
3662
                            }
3663
 
3664
                        }
3665
 
3666
                    }
3667
 
3668
                }
3669
 
3670
                break;
3671
 
3672
            }
3673
 
3674
        }
3675
 
3676
 
3677
        if (nCharCode == 13 && ((sNodeName == "INPUT" && (sType == "text" ||
3678
            sType == "password" || sType == "checkbox" || sType == "radio" ||
3679
            sType == "file")) || sNodeName == "SELECT")) {
3680
 
3681
            Dom.getElementsBy(isSubmitButton, "*", this);
3682
 
3683
 
3684
            if (oPrecedingSubmitButton) {
3685
 
3686
                /*
3687
                     Need to set focus to the first enabled submit button
3688
                     to make sure that IE includes its name and value
3689
                     in the form's data set.
3690
                */
3691
 
3692
                oPrecedingSubmitButton.focus();
3693
 
3694
            }
3695
            else if (!oPrecedingSubmitButton && oYUISubmitButton) {
3696
 
3697
				/*
3698
					Need to call "preventDefault" to ensure that the form doesn't end up getting
3699
					submitted twice.
3700
				*/
3701
 
3702
    			Event.preventDefault(p_oEvent);
3703
 
3704
 
3705
				if (UA.ie) {
3706
 
3707
					oYUISubmitButton.get("element").fireEvent("onclick");
3708
 
3709
				}
3710
				else {
3711
 
3712
					oEvent = document.createEvent("HTMLEvents");
3713
					oEvent.initEvent("click", true, true);
3714
 
3715
 
3716
					if (UA.gecko < 1.9) {
3717
 
3718
						oYUISubmitButton.fireEvent("click", oEvent);
3719
 
3720
					}
3721
					else {
3722
 
3723
						oYUISubmitButton.get("element").dispatchEvent(oEvent);
3724
 
3725
					}
3726
 
3727
                }
3728
 
3729
            }
3730
 
3731
        }
3732
 
3733
    };
3734
 
3735
 
3736
    /**
3737
    * @method YAHOO.widget.Button.addHiddenFieldsToForm
3738
    * @description Searches the specified form and adds hidden fields for
3739
    * instances of YAHOO.widget.Button that are of type "radio," "checkbox,"
3740
    * "menu," and "split."
3741
    * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-
3742
    * one-html.html#ID-40002357">HTMLFormElement</a>} p_oForm Object reference
3743
    * for the form to search.
3744
    */
3745
    YAHOO.widget.Button.addHiddenFieldsToForm = function (p_oForm) {
3746
 
3747
        var proto = YAHOO.widget.Button.prototype,
3748
			aButtons = Dom.getElementsByClassName(
3749
							(proto.CLASS_NAME_PREFIX + proto.CSS_CLASS_NAME),
3750
                            "*",
3751
                            p_oForm),
3752
 
3753
            nButtons = aButtons.length,
3754
            oButton,
3755
            sId,
3756
            i;
3757
 
3758
        if (nButtons > 0) {
3759
 
3760
 
3761
            for (i = 0; i < nButtons; i++) {
3762
 
3763
                sId = aButtons[i].id;
3764
 
3765
                if (sId) {
3766
 
3767
                    oButton = m_oButtons[sId];
3768
 
3769
                    if (oButton) {
3770
 
3771
                        oButton.createHiddenFields();
3772
 
3773
                    }
3774
 
3775
                }
3776
 
3777
            }
3778
 
3779
        }
3780
 
3781
    };
3782
 
3783
 
3784
    /**
3785
    * @method YAHOO.widget.Button.getButton
3786
    * @description Returns a button with the specified id.
3787
    * @param {String} p_sId String specifying the id of the root node of the
3788
    * HTML element representing the button to be retrieved.
3789
    * @return {YAHOO.widget.Button}
3790
    */
3791
    YAHOO.widget.Button.getButton = function (p_sId) {
3792
 
3793
		return m_oButtons[p_sId];
3794
 
3795
    };
3796
 
3797
 
3798
    // Events
3799
 
3800
 
3801
    /**
3802
    * @event focus
3803
    * @description Fires when the menu item receives focus.  Passes back a
3804
    * single object representing the original DOM event object passed back by
3805
    * the event utility (YAHOO.util.Event) when the event was fired.  See
3806
    * <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
3807
    * for more information on listening for this event.
3808
    * @type YAHOO.util.CustomEvent
3809
    */
3810
 
3811
 
3812
    /**
3813
    * @event blur
3814
    * @description Fires when the menu item loses the input focus.  Passes back
3815
    * a single object representing the original DOM event object passed back by
3816
    * the event utility (YAHOO.util.Event) when the event was fired.  See
3817
    * <a href="YAHOO.util.Element.html#addListener">Element.addListener</a> for
3818
    * more information on listening for this event.
3819
    * @type YAHOO.util.CustomEvent
3820
    */
3821
 
3822
 
3823
    /**
3824
    * @event option
3825
    * @description Fires when the user invokes the button's option.  Passes
3826
    * back a single object representing the original DOM event (either
3827
    * "mousedown" or "keydown") that caused the "option" event to fire.  See
3828
    * <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
3829
    * for more information on listening for this event.
3830
    * @type YAHOO.util.CustomEvent
3831
    */
3832
 
3833
})();
3834
(function () {
3835
 
3836
    // Shorthard for utilities
3837
 
3838
    var Dom = YAHOO.util.Dom,
3839
        Event = YAHOO.util.Event,
3840
        Lang = YAHOO.lang,
3841
        Button = YAHOO.widget.Button,
3842
 
3843
        // Private collection of radio buttons
3844
 
3845
        m_oButtons = {};
3846
 
3847
 
3848
 
3849
    /**
3850
    * The ButtonGroup class creates a set of buttons that are mutually
3851
    * exclusive; checking one button in the set will uncheck all others in the
3852
    * button group.
3853
    * @param {String} p_oElement String specifying the id attribute of the
3854
    * <code>&#60;div&#62;</code> element of the button group.
3855
    * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
3856
    * level-one-html.html#ID-22445964">HTMLDivElement</a>} p_oElement Object
3857
    * specifying the <code>&#60;div&#62;</code> element of the button group.
3858
    * @param {Object} p_oElement Object literal specifying a set of
3859
    * configuration attributes used to create the button group.
3860
    * @param {Object} p_oAttributes Optional. Object literal specifying a set
3861
    * of configuration attributes used to create the button group.
3862
    * @namespace YAHOO.widget
3863
    * @class ButtonGroup
3864
    * @constructor
3865
    * @extends YAHOO.util.Element
3866
    */
3867
    YAHOO.widget.ButtonGroup = function (p_oElement, p_oAttributes) {
3868
 
3869
        var fnSuperClass = YAHOO.widget.ButtonGroup.superclass.constructor,
3870
            sNodeName,
3871
            oElement,
3872
            sId;
3873
 
3874
        if (arguments.length == 1 && !Lang.isString(p_oElement) &&
3875
            !p_oElement.nodeName) {
3876
 
3877
            if (!p_oElement.id) {
3878
 
3879
                sId = Dom.generateId();
3880
 
3881
                p_oElement.id = sId;
3882
 
3883
 
3884
            }
3885
 
3886
 
3887
 
3888
            fnSuperClass.call(this, (this._createGroupElement()), p_oElement);
3889
 
3890
        }
3891
        else if (Lang.isString(p_oElement)) {
3892
 
3893
            oElement = Dom.get(p_oElement);
3894
 
3895
            if (oElement) {
3896
 
3897
                if (oElement.nodeName.toUpperCase() == this.NODE_NAME) {
3898
 
3899
 
3900
                    fnSuperClass.call(this, oElement, p_oAttributes);
3901
 
3902
                }
3903
 
3904
            }
3905
 
3906
        }
3907
        else {
3908
 
3909
            sNodeName = p_oElement.nodeName.toUpperCase();
3910
 
3911
            if (sNodeName && sNodeName == this.NODE_NAME) {
3912
 
3913
                if (!p_oElement.id) {
3914
 
3915
                    p_oElement.id = Dom.generateId();
3916
 
3917
 
3918
                }
3919
 
3920
 
3921
                fnSuperClass.call(this, p_oElement, p_oAttributes);
3922
 
3923
            }
3924
 
3925
        }
3926
 
3927
    };
3928
 
3929
 
3930
    YAHOO.extend(YAHOO.widget.ButtonGroup, YAHOO.util.Element, {
3931
 
3932
 
3933
        // Protected properties
3934
 
3935
 
3936
        /**
3937
        * @property _buttons
3938
        * @description Array of buttons in the button group.
3939
        * @default null
3940
        * @protected
3941
        * @type Array
3942
        */
3943
        _buttons: null,
3944
 
3945
 
3946
 
3947
        // Constants
3948
 
3949
 
3950
        /**
3951
        * @property NODE_NAME
3952
        * @description The name of the tag to be used for the button
3953
        * group's element.
3954
        * @default "DIV"
3955
        * @final
3956
        * @type String
3957
        */
3958
        NODE_NAME: "DIV",
3959
 
3960
 
3961
        /**
3962
        * @property CLASS_NAME_PREFIX
3963
        * @description Prefix used for all class names applied to a ButtonGroup.
3964
        * @default "yui-"
3965
        * @final
3966
        * @type String
3967
        */
3968
        CLASS_NAME_PREFIX: "yui-",
3969
 
3970
 
3971
        /**
3972
        * @property CSS_CLASS_NAME
3973
        * @description String representing the CSS class(es) to be applied
3974
        * to the button group's element.
3975
        * @default "buttongroup"
3976
        * @final
3977
        * @type String
3978
        */
3979
        CSS_CLASS_NAME: "buttongroup",
3980
 
3981
 
3982
 
3983
        // Protected methods
3984
 
3985
 
3986
        /**
3987
        * @method _createGroupElement
3988
        * @description Creates the button group's element.
3989
        * @protected
3990
        * @return {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
3991
        * level-one-html.html#ID-22445964">HTMLDivElement</a>}
3992
        */
3993
        _createGroupElement: function () {
3994
 
3995
            var oElement = document.createElement(this.NODE_NAME);
3996
 
3997
            return oElement;
3998
 
3999
        },
4000
 
4001
 
4002
 
4003
        // Protected attribute setter methods
4004
 
4005
 
4006
        /**
4007
        * @method _setDisabled
4008
        * @description Sets the value of the button groups's
4009
        * "disabled" attribute.
4010
        * @protected
4011
        * @param {Boolean} p_bDisabled Boolean indicating the value for
4012
        * the button group's "disabled" attribute.
4013
        */
4014
        _setDisabled: function (p_bDisabled) {
4015
 
4016
            var nButtons = this.getCount(),
4017
                i;
4018
 
4019
            if (nButtons > 0) {
4020
 
4021
                i = nButtons - 1;
4022
 
4023
                do {
4024
 
4025
                    this._buttons[i].set("disabled", p_bDisabled);
4026
 
4027
                }
4028
                while (i--);
4029
 
4030
            }
4031
 
4032
        },
4033
 
4034
 
4035
 
4036
        // Protected event handlers
4037
 
4038
 
4039
        /**
4040
        * @method _onKeyDown
4041
        * @description "keydown" event handler for the button group.
4042
        * @protected
4043
        * @param {Event} p_oEvent Object representing the DOM event object
4044
        * passed back by the event utility (YAHOO.util.Event).
4045
        */
4046
        _onKeyDown: function (p_oEvent) {
4047
 
4048
            var oTarget = Event.getTarget(p_oEvent),
4049
                nCharCode = Event.getCharCode(p_oEvent),
4050
                sId = oTarget.parentNode.parentNode.id,
4051
                oButton = m_oButtons[sId],
4052
                nIndex = -1;
4053
 
4054
 
4055
            if (nCharCode == 37 || nCharCode == 38) {
4056
 
4057
                nIndex = (oButton.index === 0) ?
4058
                            (this._buttons.length - 1) : (oButton.index - 1);
4059
 
4060
            }
4061
            else if (nCharCode == 39 || nCharCode == 40) {
4062
 
4063
                nIndex = (oButton.index === (this._buttons.length - 1)) ?
4064
 
4065
 
4066
            }
4067
 
4068
 
4069
            if (nIndex > -1) {
4070
 
4071
                this.check(nIndex);
4072
                this.getButton(nIndex).focus();
4073
 
4074
            }
4075
 
4076
        },
4077
 
4078
 
4079
        /**
4080
        * @method _onAppendTo
4081
        * @description "appendTo" event handler for the button group.
4082
        * @protected
4083
        * @param {Event} p_oEvent Object representing the event that was fired.
4084
        */
4085
        _onAppendTo: function (p_oEvent) {
4086
 
4087
            var aButtons = this._buttons,
4088
                nButtons = aButtons.length,
4089
                i;
4090
 
4091
            for (i = 0; i < nButtons; i++) {
4092
 
4093
                aButtons[i].appendTo(this.get("element"));
4094
 
4095
            }
4096
 
4097
        },
4098
 
4099
 
4100
        /**
4101
        * @method _onButtonCheckedChange
4102
        * @description "checkedChange" event handler for each button in the
4103
        * button group.
4104
        * @protected
4105
        * @param {Event} p_oEvent Object representing the event that was fired.
4106
        * @param {<a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a>}
4107
        * p_oButton Object representing the button that fired the event.
4108
        */
4109
        _onButtonCheckedChange: function (p_oEvent, p_oButton) {
4110
 
4111
            var bChecked = p_oEvent.newValue,
4112
                oCheckedButton = this.get("checkedButton");
4113
 
4114
            if (bChecked && oCheckedButton != p_oButton) {
4115
 
4116
                if (oCheckedButton) {
4117
 
4118
                    oCheckedButton.set("checked", false, true);
4119
 
4120
                }
4121
 
4122
                this.set("checkedButton", p_oButton);
4123
                this.set("value", p_oButton.get("value"));
4124
 
4125
            }
4126
            else if (oCheckedButton && !oCheckedButton.set("checked")) {
4127
 
4128
                oCheckedButton.set("checked", true, true);
4129
 
4130
            }
4131
 
4132
        },
4133
 
4134
 
4135
 
4136
        // Public methods
4137
 
4138
 
4139
        /**
4140
        * @method init
4141
        * @description The ButtonGroup class's initialization method.
4142
        * @param {String} p_oElement String specifying the id attribute of the
4143
        * <code>&#60;div&#62;</code> element of the button group.
4144
        * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
4145
        * level-one-html.html#ID-22445964">HTMLDivElement</a>} p_oElement Object
4146
        * specifying the <code>&#60;div&#62;</code> element of the button group.
4147
        * @param {Object} p_oElement Object literal specifying a set of
4148
        * configuration attributes used to create the button group.
4149
        * @param {Object} p_oAttributes Optional. Object literal specifying a
4150
        * set of configuration attributes used to create the button group.
4151
        */
4152
        init: function (p_oElement, p_oAttributes) {
4153
 
4154
            this._buttons = [];
4155
 
4156
            YAHOO.widget.ButtonGroup.superclass.init.call(this, p_oElement,
4157
                    p_oAttributes);
4158
 
4159
            this.addClass(this.CLASS_NAME_PREFIX + this.CSS_CLASS_NAME);
4160
 
4161
 
4162
            var sClass = (YAHOO.widget.Button.prototype.CLASS_NAME_PREFIX + "radio-button"),
4163
				aButtons = this.getElementsByClassName(sClass);
4164
 
4165
 
4166
 
4167
            if (aButtons.length > 0) {
4168
 
4169
 
4170
                this.addButtons(aButtons);
4171
 
4172
            }
4173
 
4174
 
4175
 
4176
            function isRadioButton(p_oElement) {
4177
 
4178
                return (p_oElement.type == "radio");
4179
 
4180
            }
4181
 
4182
            aButtons =
4183
                Dom.getElementsBy(isRadioButton, "input", this.get("element"));
4184
 
4185
 
4186
            if (aButtons.length > 0) {
4187
 
4188
 
4189
                this.addButtons(aButtons);
4190
 
4191
            }
4192
 
4193
            this.on("keydown", this._onKeyDown);
4194
            this.on("appendTo", this._onAppendTo);
4195
 
4196
 
4197
            var oContainer = this.get("container");
4198
 
4199
            if (oContainer) {
4200
 
4201
                if (Lang.isString(oContainer)) {
4202
 
4203
                    Event.onContentReady(oContainer, function () {
4204
 
4205
                        this.appendTo(oContainer);
4206
 
4207
                    }, null, this);
4208
 
4209
                }
4210
                else {
4211
 
4212
                    this.appendTo(oContainer);
4213
 
4214
                }
4215
 
4216
            }
4217
 
4218
 
4219
 
4220
        },
4221
 
4222
 
4223
        /**
4224
        * @method initAttributes
4225
        * @description Initializes all of the configuration attributes used to
4226
        * create the button group.
4227
        * @param {Object} p_oAttributes Object literal specifying a set of
4228
        * configuration attributes used to create the button group.
4229
        */
4230
        initAttributes: function (p_oAttributes) {
4231
 
4232
            var oAttributes = p_oAttributes || {};
4233
 
4234
            YAHOO.widget.ButtonGroup.superclass.initAttributes.call(
4235
                this, oAttributes);
4236
 
4237
 
4238
            /**
4239
            * @attribute name
4240
            * @description String specifying the name for the button group.
4241
            * This name will be applied to each button in the button group.
4242
            * @default null
4243
            * @type String
4244
            */
4245
            this.setAttributeConfig("name", {
4246
 
4247
                value: oAttributes.name,
4248
                validator: Lang.isString
4249
 
4250
            });
4251
 
4252
 
4253
            /**
4254
            * @attribute disabled
4255
            * @description Boolean indicating if the button group should be
4256
            * disabled.  Disabling the button group will disable each button
4257
            * in the button group.  Disabled buttons are dimmed and will not
4258
            * respond to user input or fire events.
4259
            * @default false
4260
            * @type Boolean
4261
            */
4262
            this.setAttributeConfig("disabled", {
4263
 
4264
                value: (oAttributes.disabled || false),
4265
                validator: Lang.isBoolean,
4266
                method: this._setDisabled
4267
 
4268
            });
4269
 
4270
 
4271
            /**
4272
            * @attribute value
4273
            * @description Object specifying the value for the button group.
4274
            * @default null
4275
            * @type Object
4276
            */
4277
            this.setAttributeConfig("value", {
4278
 
4279
                value: oAttributes.value
4280
 
4281
            });
4282
 
4283
 
4284
            /**
4285
            * @attribute container
4286
            * @description HTML element reference or string specifying the id
4287
            * attribute of the HTML element that the button group's markup
4288
            * should be rendered into.
4289
            * @type <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
4290
            * level-one-html.html#ID-58190037">HTMLElement</a>|String
4291
            * @default null
4292
			* @writeonce
4293
            */
4294
            this.setAttributeConfig("container", {
4295
 
4296
                value: oAttributes.container,
4297
                writeOnce: true
4298
 
4299
            });
4300
 
4301
 
4302
            /**
4303
            * @attribute checkedButton
4304
            * @description Reference for the button in the button group that
4305
            * is checked.
4306
            * @type {<a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a>}
4307
            * @default null
4308
            */
4309
            this.setAttributeConfig("checkedButton", {
4310
 
4311
                value: null
4312
 
4313
            });
4314
 
4315
        },
4316
 
4317
 
4318
        /**
4319
        * @method addButton
4320
        * @description Adds the button to the button group.
4321
        * @param {<a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a>}
4322
        * p_oButton Object reference for the <a href="YAHOO.widget.Button.html">
4323
        * YAHOO.widget.Button</a> instance to be added to the button group.
4324
        * @param {String} p_oButton String specifying the id attribute of the
4325
        * <code>&#60;input&#62;</code> or <code>&#60;span&#62;</code> element
4326
        * to be used to create the button to be added to the button group.
4327
        * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
4328
        * level-one-html.html#ID-6043025">HTMLInputElement</a>|<a href="
4329
        * http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#
4330
        * ID-33759296">HTMLElement</a>} p_oButton Object reference for the
4331
        * <code>&#60;input&#62;</code> or <code>&#60;span&#62;</code> element
4332
        * to be used to create the button to be added to the button group.
4333
        * @param {Object} p_oButton Object literal specifying a set of
4334
        * <a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a>
4335
        * configuration attributes used to configure the button to be added to
4336
        * the button group.
4337
        * @return {<a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a>}
4338
        */
4339
        addButton: function (p_oButton) {
4340
 
4341
            var oButton,
4342
                oButtonElement,
4343
                oGroupElement,
4344
                nIndex,
4345
                sButtonName,
4346
                sGroupName;
4347
 
4348
 
4349
            if (p_oButton instanceof Button &&
4350
                p_oButton.get("type") == "radio") {
4351
 
4352
                oButton = p_oButton;
4353
 
4354
            }
4355
            else if (!Lang.isString(p_oButton) && !p_oButton.nodeName) {
4356
 
4357
                p_oButton.type = "radio";
4358
 
4359
                oButton = new Button(p_oButton);
4360
 
4361
            }
4362
            else {
4363
 
4364
                oButton = new Button(p_oButton, { type: "radio" });
4365
 
4366
            }
4367
 
4368
 
4369
            if (oButton) {
4370
 
4371
                nIndex = this._buttons.length;
4372
                sButtonName = oButton.get("name");
4373
                sGroupName = this.get("name");
4374
 
4375
                oButton.index = nIndex;
4376
 
4377
                this._buttons[nIndex] = oButton;
4378
                m_oButtons[oButton.get("id")] = oButton;
4379
 
4380
 
4381
                if (sButtonName != sGroupName) {
4382
 
4383
                    oButton.set("name", sGroupName);
4384
 
4385
                }
4386
 
4387
 
4388
                if (this.get("disabled")) {
4389
 
4390
                    oButton.set("disabled", true);
4391
 
4392
                }
4393
 
4394
 
4395
                if (oButton.get("checked")) {
4396
 
4397
                    this.set("checkedButton", oButton);
4398
 
4399
                }
4400
 
4401
 
4402
                oButtonElement = oButton.get("element");
4403
                oGroupElement = this.get("element");
4404
 
4405
                if (oButtonElement.parentNode != oGroupElement) {
4406
 
4407
                    oGroupElement.appendChild(oButtonElement);
4408
 
4409
                }
4410
 
4411
 
4412
                oButton.on("checkedChange",
4413
                    this._onButtonCheckedChange, oButton, this);
4414
 
4415
 
4416
            }
4417
 
4418
			return oButton;
4419
 
4420
        },
4421
 
4422
 
4423
        /**
4424
        * @method addButtons
4425
        * @description Adds the array of buttons to the button group.
4426
        * @param {Array} p_aButtons Array of <a href="YAHOO.widget.Button.html">
4427
        * YAHOO.widget.Button</a> instances to be added
4428
        * to the button group.
4429
        * @param {Array} p_aButtons Array of strings specifying the id
4430
        * attribute of the <code>&#60;input&#62;</code> or <code>&#60;span&#62;
4431
        * </code> elements to be used to create the buttons to be added to the
4432
        * button group.
4433
        * @param {Array} p_aButtons Array of object references for the
4434
        * <code>&#60;input&#62;</code> or <code>&#60;span&#62;</code> elements
4435
        * to be used to create the buttons to be added to the button group.
4436
        * @param {Array} p_aButtons Array of object literals, each containing
4437
        * a set of <a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a>
4438
        * configuration attributes used to configure each button to be added
4439
        * to the button group.
4440
        * @return {Array}
4441
        */
4442
        addButtons: function (p_aButtons) {
4443
 
4444
            var nButtons,
4445
                oButton,
4446
                aButtons,
4447
                i;
4448
 
4449
            if (Lang.isArray(p_aButtons)) {
4450
 
4451
                nButtons = p_aButtons.length;
4452
                aButtons = [];
4453
 
4454
                if (nButtons > 0) {
4455
 
4456
                    for (i = 0; i < nButtons; i++) {
4457
 
4458
                        oButton = this.addButton(p_aButtons[i]);
4459
 
4460
                        if (oButton) {
4461
 
4462
                            aButtons[aButtons.length] = oButton;
4463
 
4464
                        }
4465
 
4466
                    }
4467
 
4468
                }
4469
 
4470
            }
4471
 
4472
			return aButtons;
4473
 
4474
        },
4475
 
4476
 
4477
        /**
4478
        * @method removeButton
4479
        * @description Removes the button at the specified index from the
4480
        * button group.
4481
        * @param {Number} p_nIndex Number specifying the index of the button
4482
        * to be removed from the button group.
4483
        */
4484
        removeButton: function (p_nIndex) {
4485
 
4486
            var oButton = this.getButton(p_nIndex),
4487
                nButtons,
4488
                i;
4489
 
4490
            if (oButton) {
4491
 
4492
 
4493
                this._buttons.splice(p_nIndex, 1);
4494
                delete m_oButtons[oButton.get("id")];
4495
 
4496
                oButton.removeListener("checkedChange",
4497
                    this._onButtonCheckedChange);
4498
 
4499
                oButton.destroy();
4500
 
4501
 
4502
                nButtons = this._buttons.length;
4503
 
4504
                if (nButtons > 0) {
4505
 
4506
                    i = this._buttons.length - 1;
4507
 
4508
                    do {
4509
 
4510
                        this._buttons[i].index = i;
4511
 
4512
                    }
4513
                    while (i--);
4514
 
4515
                }
4516
 
4517
 
4518
            }
4519
 
4520
        },
4521
 
4522
 
4523
        /**
4524
        * @method getButton
4525
        * @description Returns the button at the specified index.
4526
        * @param {Number} p_nIndex The index of the button to retrieve from the
4527
        * button group.
4528
        * @return {<a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a>}
4529
        */
4530
        getButton: function (p_nIndex) {
4531
 
4532
            return this._buttons[p_nIndex];
4533
 
4534
        },
4535
 
4536
 
4537
        /**
4538
        * @method getButtons
4539
        * @description Returns an array of the buttons in the button group.
4540
        * @return {Array}
4541
        */
4542
        getButtons: function () {
4543
 
4544
            return this._buttons;
4545
 
4546
        },
4547
 
4548
 
4549
        /**
4550
        * @method getCount
4551
        * @description Returns the number of buttons in the button group.
4552
        * @return {Number}
4553
        */
4554
        getCount: function () {
4555
 
4556
            return this._buttons.length;
4557
 
4558
        },
4559
 
4560
 
4561
        /**
4562
        * @method focus
4563
        * @description Sets focus to the button at the specified index.
4564
        * @param {Number} p_nIndex Number indicating the index of the button
4565
        * to focus.
4566
        */
4567
        focus: function (p_nIndex) {
4568
 
4569
            var oButton,
4570
                nButtons,
4571
                i;
4572
 
4573
            if (Lang.isNumber(p_nIndex)) {
4574
 
4575
                oButton = this._buttons[p_nIndex];
4576
 
4577
                if (oButton) {
4578
 
4579
                    oButton.focus();
4580
 
4581
                }
4582
 
4583
            }
4584
            else {
4585
 
4586
                nButtons = this.getCount();
4587
 
4588
                for (i = 0; i < nButtons; i++) {
4589
 
4590
                    oButton = this._buttons[i];
4591
 
4592
                    if (!oButton.get("disabled")) {
4593
 
4594
                        oButton.focus();
4595
                        break;
4596
 
4597
                    }
4598
 
4599
                }
4600
 
4601
            }
4602
 
4603
        },
4604
 
4605
 
4606
        /**
4607
        * @method check
4608
        * @description Checks the button at the specified index.
4609
        * @param {Number} p_nIndex Number indicating the index of the button
4610
        * to check.
4611
        */
4612
        check: function (p_nIndex) {
4613
 
4614
            var oButton = this.getButton(p_nIndex);
4615
 
4616
            if (oButton) {
4617
 
4618
                oButton.set("checked", true);
4619
 
4620
            }
4621
 
4622
        },
4623
 
4624
 
4625
        /**
4626
        * @method destroy
4627
        * @description Removes the button group's element from its parent
4628
        * element and removes all event handlers.
4629
        */
4630
        destroy: function () {
4631
 
4632
 
4633
            var nButtons = this._buttons.length,
4634
                oElement = this.get("element"),
4635
                oParentNode = oElement.parentNode,
4636
                i;
4637
 
4638
            if (nButtons > 0) {
4639
 
4640
                i = this._buttons.length - 1;
4641
 
4642
                do {
4643
 
4644
                    this._buttons[i].destroy();
4645
 
4646
                }
4647
                while (i--);
4648
 
4649
            }
4650
 
4651
 
4652
            Event.purgeElement(oElement);
4653
 
4654
 
4655
            oParentNode.removeChild(oElement);
4656
 
4657
        },
4658
 
4659
 
4660
        /**
4661
        * @method toString
4662
        * @description Returns a string representing the button group.
4663
        * @return {String}
4664
        */
4665
        toString: function () {
4666
 
4667
            return ("ButtonGroup " + this.get("id"));
4668
 
4669
        }
4670
 
4671
    });
4672
 
4673
})();
4674
YAHOO.register("button", YAHOO.widget.Button, {version: "2.9.0", build: "2800"});
4675
 
4676
}, '2.9.0' ,{"requires": ["yui2-yahoo", "yui2-dom", "yui2-event", "yui2-skin-sam-button", "yui2-element"], "optional": ["yui2-containercore", "yui2-skin-sam-menu", "yui2-menu"]});