Added: ode/branches/APACHE_ODE_1.X/axis2-war/src/main/webapp/js/yui/button.js
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2-war/src/main/webapp/js/yui/button.js?rev=694856&view=auto
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2-war/src/main/webapp/js/yui/button.js (added)
+++ ode/branches/APACHE_ODE_1.X/axis2-war/src/main/webapp/js/yui/button.js Fri Sep 12 17:31:09 2008
@@ -0,0 +1,4696 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.5.2
+*/
+/**
+* @module button
+* @description <p>The Button Control enables the creation of rich, graphical
+* buttons that function like traditional HTML form buttons. <em>Unlike</em>
+* tradition HTML form buttons, buttons created with the Button Control can have
+* a label that is different from its value. With the inclusion of the optional
+* <a href="module_menu.html">Menu Control</a>, the Button Control can also be
+* used to create menu buttons and split buttons, controls that are not
+* available natively in HTML. The Button Control can also be thought of as a
+* way to create more visually engaging implementations of the browser's
+* default radio-button and check-box controls.</p>
+* <p>The Button Control supports the following types:</p>
+* <dl>
+* <dt>push</dt>
+* <dd>Basic push button that can execute a user-specified command when
+* pressed.</dd>
+* <dt>link</dt>
+* <dd>Navigates to a specified url when pressed.</dd>
+* <dt>submit</dt>
+* <dd>Submits the parent form when pressed.</dd>
+* <dt>reset</dt>
+* <dd>Resets the parent form when pressed.</dd>
+* <dt>checkbox</dt>
+* <dd>Maintains a "checked" state that can be toggled on and off.</dd>
+* <dt>radio</dt>
+* <dd>Maintains a "checked" state that can be toggled on and off. Use with
+* the ButtonGroup class to create a set of controls that are mutually
+* exclusive; checking one button in the set will uncheck all others in
+* the group.</dd>
+* <dt>menu</dt>
+* <dd>When pressed will show/hide a menu.</dd>
+* <dt>split</dt>
+* <dd>Can execute a user-specified command or display a menu when pressed.</dd>
+* </dl>
+* @title Button
+* @namespace YAHOO.widget
+* @requires yahoo, dom, element, event
+* @optional container, menu
+*/
+
+
+(function () {
+
+
+ /**
+ * The Button class creates a rich, graphical button.
+ * @param {String} p_oElement String specifying the id attribute of the
+ * <code><input></code>, <code><button></code>,
+ * <code><a></code>, or <code><span></code> element to
+ * be used to create the button.
+ * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-
+ * one-html.html#ID-6043025">HTMLInputElement</a>|<a href="http://www.w3.org
+ * /TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-34812697">
+ * HTMLButtonElement</a>|<a href="
+ * http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#
+ * ID-33759296">HTMLElement</a>} p_oElement Object reference for the
+ * <code><input></code>, <code><button></code>,
+ * <code><a></code>, or <code><span></code> element to be
+ * used to create the button.
+ * @param {Object} p_oElement Object literal specifying a set of
+ * configuration attributes used to create the button.
+ * @param {Object} p_oAttributes Optional. Object literal specifying a set
+ * of configuration attributes used to create the button.
+ * @namespace YAHOO.widget
+ * @class Button
+ * @constructor
+ * @extends YAHOO.util.Element
+ */
+
+
+
+ // Shorthard for utilities
+
+ var Dom = YAHOO.util.Dom,
+ Event = YAHOO.util.Event,
+ Lang = YAHOO.lang,
+ UA = YAHOO.env.ua,
+ Overlay = YAHOO.widget.Overlay,
+ Menu = YAHOO.widget.Menu,
+
+
+ // Private member variables
+
+ m_oButtons = {}, // Collection of all Button instances
+ m_oOverlayManager = null, // YAHOO.widget.OverlayManager instance
+ m_oSubmitTrigger = null, // The button that submitted the form
+ m_oFocusedButton = null; // The button that has focus
+
+
+
+ // Private methods
+
+
+
+ /**
+ * @method createInputElement
+ * @description Creates an <code><input></code> element of the
+ * specified type.
+ * @private
+ * @param {String} p_sType String specifying the type of
+ * <code><input></code> element to create.
+ * @param {String} p_sName String specifying the name of
+ * <code><input></code> element to create.
+ * @param {String} p_sValue String specifying the value of
+ * <code><input></code> element to create.
+ * @param {String} p_bChecked Boolean specifying if the
+ * <code><input></code> element is to be checked.
+ * @return {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-
+ * one-html.html#ID-6043025">HTMLInputElement</a>}
+ */
+ function createInputElement(p_sType, p_sName, p_sValue, p_bChecked) {
+
+ var oInput,
+ sInput;
+
+ if (Lang.isString(p_sType) && Lang.isString(p_sName)) {
+
+ if (UA.ie) {
+
+ /*
+ For IE it is necessary to create the element with the
+ "type," "name," "value," and "checked" properties set all
+ at once.
+ */
+
+ sInput = "<input type=\"" + p_sType + "\" name=\"" +
+ p_sName + "\"";
+
+ if (p_bChecked) {
+
+ sInput += " checked";
+
+ }
+
+ sInput += ">";
+
+ oInput = document.createElement(sInput);
+
+ }
+ else {
+
+ oInput = document.createElement("input");
+ oInput.name = p_sName;
+ oInput.type = p_sType;
+
+ if (p_bChecked) {
+
+ oInput.checked = true;
+
+ }
+
+ }
+
+ oInput.value = p_sValue;
+
+ return oInput;
+
+ }
+
+ }
+
+
+ /**
+ * @method setAttributesFromSrcElement
+ * @description Gets the values for all the attributes of the source element
+ * (either <code><input></code> or <code><a></code>) that
+ * map to Button configuration attributes and sets them into a collection
+ * that is passed to the Button constructor.
+ * @private
+ * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-
+ * one-html.html#ID-6043025">HTMLInputElement</a>|<a href="http://www.w3.org/
+ * TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-
+ * 48250443">HTMLAnchorElement</a>} p_oElement Object reference to the HTML
+ * element (either <code><input></code> or <code><span>
+ * </code>) used to create the button.
+ * @param {Object} p_oAttributes Object reference for the collection of
+ * configuration attributes used to create the button.
+ */
+ function setAttributesFromSrcElement(p_oElement, p_oAttributes) {
+
+ var sSrcElementNodeName = p_oElement.nodeName.toUpperCase(),
+ me = this,
+ oAttribute,
+ oRootNode,
+ sText;
+
+
+ /**
+ * @method setAttributeFromDOMAttribute
+ * @description Gets the value of the specified DOM attribute and sets it
+ * into the collection of configuration attributes used to configure
+ * the button.
+ * @private
+ * @param {String} p_sAttribute String representing the name of the
+ * attribute to retrieve from the DOM element.
+ */
+ function setAttributeFromDOMAttribute(p_sAttribute) {
+
+ if (!(p_sAttribute in p_oAttributes)) {
+
+ /*
+ Need to use "getAttributeNode" instead of "getAttribute"
+ because using "getAttribute," IE will return the innerText
+ of a <code><button></code> for the value attribute
+ rather than the value of the "value" attribute.
+ */
+
+ oAttribute = p_oElement.getAttributeNode(p_sAttribute);
+
+
+ if (oAttribute && ("value" in oAttribute)) {
+
+
+ p_oAttributes[p_sAttribute] = oAttribute.value;
+
+ }
+
+ }
+
+ }
+
+
+ /**
+ * @method setFormElementProperties
+ * @description Gets the value of the attributes from the form element
+ * and sets them into the collection of configuration attributes used to
+ * configure the button.
+ * @private
+ */
+ function setFormElementProperties() {
+
+ setAttributeFromDOMAttribute("type");
+
+ if (p_oAttributes.type == "button") {
+
+ p_oAttributes.type = "push";
+
+ }
+
+ if (!("disabled" in p_oAttributes)) {
+
+ p_oAttributes.disabled = p_oElement.disabled;
+
+ }
+
+ setAttributeFromDOMAttribute("name");
+ setAttributeFromDOMAttribute("value");
+ setAttributeFromDOMAttribute("title");
+
+ }
+
+
+ switch (sSrcElementNodeName) {
+
+ case "A":
+
+ p_oAttributes.type = "link";
+
+ setAttributeFromDOMAttribute("href");
+ setAttributeFromDOMAttribute("target");
+
+ break;
+
+ case "INPUT":
+
+ setFormElementProperties();
+
+ if (!("checked" in p_oAttributes)) {
+
+ p_oAttributes.checked = p_oElement.checked;
+
+ }
+
+ break;
+
+ case "BUTTON":
+
+ setFormElementProperties();
+
+ oRootNode = p_oElement.parentNode.parentNode;
+
+ if (Dom.hasClass(oRootNode, this.CSS_CLASS_NAME + "-checked")) {
+
+ p_oAttributes.checked = true;
+
+ }
+
+ if (Dom.hasClass(oRootNode, this.CSS_CLASS_NAME + "-disabled")) {
+
+ p_oAttributes.disabled = true;
+
+ }
+
+ p_oElement.removeAttribute("value");
+
+ p_oElement.setAttribute("type", "button");
+
+ break;
+
+ }
+
+ p_oElement.removeAttribute("id");
+ p_oElement.removeAttribute("name");
+
+ if (!("tabindex" in p_oAttributes)) {
+
+ p_oAttributes.tabindex = p_oElement.tabIndex;
+
+ }
+
+ if (!("label" in p_oAttributes)) {
+
+ // Set the "label" property
+
+ sText = sSrcElementNodeName == "INPUT" ?
+ p_oElement.value : p_oElement.innerHTML;
+
+
+ if (sText && sText.length > 0) {
+
+ p_oAttributes.label = sText;
+
+ }
+
+ }
+
+ }
+
+
+ /**
+ * @method initConfig
+ * @description Initializes the set of configuration attributes that are
+ * used to instantiate the button.
+ * @private
+ * @param {Object} Object representing the button's set of
+ * configuration attributes.
+ */
+ function initConfig(p_oConfig) {
+
+ var oAttributes = p_oConfig.attributes,
+ oSrcElement = oAttributes.srcelement,
+ sSrcElementNodeName = oSrcElement.nodeName.toUpperCase(),
+ me = this;
+
+
+ if (sSrcElementNodeName == this.NODE_NAME) {
+
+ p_oConfig.element = oSrcElement;
+ p_oConfig.id = oSrcElement.id;
+
+ Dom.getElementsBy(function (p_oElement) {
+
+ switch (p_oElement.nodeName.toUpperCase()) {
+
+ case "BUTTON":
+ case "A":
+ case "INPUT":
+
+ setAttributesFromSrcElement.call(me, p_oElement,
+ oAttributes);
+
+ break;
+
+ }
+
+ }, "*", oSrcElement);
+
+ }
+ else {
+
+ switch (sSrcElementNodeName) {
+
+ case "BUTTON":
+ case "A":
+ case "INPUT":
+
+ setAttributesFromSrcElement.call(this, oSrcElement,
+ oAttributes);
+
+ break;
+
+ }
+
+ }
+
+ }
+
+
+
+ // Constructor
+
+ YAHOO.widget.Button = function (p_oElement, p_oAttributes) {
+
+ if (!Overlay && YAHOO.widget.Overlay) {
+
+ Overlay = YAHOO.widget.Overlay;
+
+ }
+
+
+ if (!Menu && YAHOO.widget.Menu) {
+
+ Menu = YAHOO.widget.Menu;
+
+ }
+
+
+ var fnSuperClass = YAHOO.widget.Button.superclass.constructor,
+ oConfig,
+ oElement;
+
+ if (arguments.length == 1 && !Lang.isString(p_oElement) &&
+ !p_oElement.nodeName) {
+
+ if (!p_oElement.id) {
+
+ p_oElement.id = Dom.generateId();
+
+
+ }
+
+
+
+ fnSuperClass.call(this,
+ (this.createButtonElement(p_oElement.type)),
+ p_oElement);
+
+ }
+ else {
+
+ oConfig = { element: null, attributes: (p_oAttributes || {}) };
+
+
+ if (Lang.isString(p_oElement)) {
+
+ oElement = Dom.get(p_oElement);
+
+ if (oElement) {
+
+ if (!oConfig.attributes.id) {
+
+ oConfig.attributes.id = p_oElement;
+
+ }
+
+
+
+
+ oConfig.attributes.srcelement = oElement;
+
+ initConfig.call(this, oConfig);
+
+
+ if (!oConfig.element) {
+
+
+ oConfig.element =
+ this.createButtonElement(oConfig.attributes.type);
+
+ }
+
+ fnSuperClass.call(this, oConfig.element,
+ oConfig.attributes);
+
+ }
+
+ }
+ else if (p_oElement.nodeName) {
+
+ if (!oConfig.attributes.id) {
+
+ if (p_oElement.id) {
+
+ oConfig.attributes.id = p_oElement.id;
+
+ }
+ else {
+
+ oConfig.attributes.id = Dom.generateId();
+
+
+ }
+
+ }
+
+
+
+
+
+ oConfig.attributes.srcelement = p_oElement;
+
+ initConfig.call(this, oConfig);
+
+
+ if (!oConfig.element) {
+
+
+ oConfig.element =
+ this.createButtonElement(oConfig.attributes.type);
+
+ }
+
+ fnSuperClass.call(this, oConfig.element, oConfig.attributes);
+
+ }
+
+ }
+
+ };
+
+
+
+ YAHOO.extend(YAHOO.widget.Button, YAHOO.util.Element, {
+
+
+ // Protected properties
+
+
+ /**
+ * @property _button
+ * @description Object reference to the button's internal
+ * <code><a></code> or <code><button></code> element.
+ * @default null
+ * @protected
+ * @type <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
+ * level-one-html.html#ID-48250443">HTMLAnchorElement</a>|<a href="
+ * http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html
+ * #ID-34812697">HTMLButtonElement</a>
+ */
+ _button: null,
+
+
+ /**
+ * @property _menu
+ * @description Object reference to the button's menu.
+ * @default null
+ * @protected
+ * @type {<a href="YAHOO.widget.Overlay.html">YAHOO.widget.Overlay</a>|
+ * <a href="YAHOO.widget.Menu.html">YAHOO.widget.Menu</a>}
+ */
+ _menu: null,
+
+
+ /**
+ * @property _hiddenFields
+ * @description Object reference to the <code><input></code>
+ * element, or array of HTML form elements used to represent the button
+ * when its parent form is submitted.
+ * @default null
+ * @protected
+ * @type <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
+ * level-one-html.html#ID-6043025">HTMLInputElement</a>|Array
+ */
+ _hiddenFields: null,
+
+
+ /**
+ * @property _onclickAttributeValue
+ * @description Object reference to the button's current value for the
+ * "onclick" configuration attribute.
+ * @default null
+ * @protected
+ * @type Object
+ */
+ _onclickAttributeValue: null,
+
+
+ /**
+ * @property _activationKeyPressed
+ * @description Boolean indicating if the key(s) that toggle the button's
+ * "active" state have been pressed.
+ * @default false
+ * @protected
+ * @type Boolean
+ */
+ _activationKeyPressed: false,
+
+
+ /**
+ * @property _activationButtonPressed
+ * @description Boolean indicating if the mouse button that toggles
+ * the button's "active" state has been pressed.
+ * @default false
+ * @protected
+ * @type Boolean
+ */
+ _activationButtonPressed: false,
+
+
+ /**
+ * @property _hasKeyEventHandlers
+ * @description Boolean indicating if the button's "blur", "keydown" and
+ * "keyup" event handlers are assigned
+ * @default false
+ * @protected
+ * @type Boolean
+ */
+ _hasKeyEventHandlers: false,
+
+
+ /**
+ * @property _hasMouseEventHandlers
+ * @description Boolean indicating if the button's "mouseout,"
+ * "mousedown," and "mouseup" event handlers are assigned
+ * @default false
+ * @protected
+ * @type Boolean
+ */
+ _hasMouseEventHandlers: false,
+
+
+
+ // Constants
+
+
+ /**
+ * @property NODE_NAME
+ * @description The name of the node to be used for the button's
+ * root element.
+ * @default "SPAN"
+ * @final
+ * @type String
+ */
+ NODE_NAME: "SPAN",
+
+
+ /**
+ * @property CHECK_ACTIVATION_KEYS
+ * @description Array of numbers representing keys that (when pressed)
+ * toggle the button's "checked" attribute.
+ * @default [32]
+ * @final
+ * @type Array
+ */
+ CHECK_ACTIVATION_KEYS: [32],
+
+
+ /**
+ * @property ACTIVATION_KEYS
+ * @description Array of numbers representing keys that (when presed)
+ * toggle the button's "active" state.
+ * @default [13, 32]
+ * @final
+ * @type Array
+ */
+ ACTIVATION_KEYS: [13, 32],
+
+
+ /**
+ * @property OPTION_AREA_WIDTH
+ * @description Width (in pixels) of the area of a split button that
+ * when pressed will display a menu.
+ * @default 20
+ * @final
+ * @type Number
+ */
+ OPTION_AREA_WIDTH: 20,
+
+
+ /**
+ * @property CSS_CLASS_NAME
+ * @description String representing the CSS class(es) to be applied to
+ * the button's root element.
+ * @default "yui-button"
+ * @final
+ * @type String
+ */
+ CSS_CLASS_NAME: "yui-button",
+
+
+ /**
+ * @property RADIO_DEFAULT_TITLE
+ * @description String representing the default title applied to buttons
+ * of type "radio."
+ * @default "Unchecked. Click to check."
+ * @final
+ * @type String
+ */
+ RADIO_DEFAULT_TITLE: "Unchecked. Click to check.",
+
+
+ /**
+ * @property RADIO_CHECKED_TITLE
+ * @description String representing the title applied to buttons of
+ * type "radio" when checked.
+ * @default "Checked. Click another button to uncheck"
+ * @final
+ * @type String
+ */
+ RADIO_CHECKED_TITLE: "Checked. Click another button to uncheck",
+
+
+ /**
+ * @property CHECKBOX_DEFAULT_TITLE
+ * @description String representing the default title applied to
+ * buttons of type "checkbox."
+ * @default "Unchecked. Click to check."
+ * @final
+ * @type String
+ */
+ CHECKBOX_DEFAULT_TITLE: "Unchecked. Click to check.",
+
+
+ /**
+ * @property CHECKBOX_CHECKED_TITLE
+ * @description String representing the title applied to buttons of type
+ * "checkbox" when checked.
+ * @default "Checked. Click to uncheck."
+ * @final
+ * @type String
+ */
+ CHECKBOX_CHECKED_TITLE: "Checked. Click to uncheck.",
+
+
+ /**
+ * @property MENUBUTTON_DEFAULT_TITLE
+ * @description String representing the default title applied to
+ * buttons of type "menu."
+ * @default "Menu collapsed. Click to expand."
+ * @final
+ * @type String
+ */
+ MENUBUTTON_DEFAULT_TITLE: "Menu collapsed. Click to expand.",
+
+
+ /**
+ * @property MENUBUTTON_MENU_VISIBLE_TITLE
+ * @description String representing the title applied to buttons of type
+ * "menu" when the button's menu is visible.
+ * @default "Menu expanded. Click or press Esc to collapse."
+ * @final
+ * @type String
+ */
+ MENUBUTTON_MENU_VISIBLE_TITLE:
+ "Menu expanded. Click or press Esc to collapse.",
+
+
+ /**
+ * @property SPLITBUTTON_DEFAULT_TITLE
+ * @description String representing the default title applied to
+ * buttons of type "split."
+ * @default "Menu collapsed. Click inside option region or press
+ * Ctrl + Shift + M to show the menu."
+ * @final
+ * @type String
+ */
+ SPLITBUTTON_DEFAULT_TITLE: ("Menu collapsed. Click inside option " +
+ "region or press Ctrl + Shift + M to show the menu."),
+
+
+ /**
+ * @property SPLITBUTTON_OPTION_VISIBLE_TITLE
+ * @description String representing the title applied to buttons of type
+ * "split" when the button's menu is visible.
+ * @default "Menu expanded. Press Esc or Ctrl + Shift + M to hide
+ * the menu."
+ * @final
+ * @type String
+ */
+ SPLITBUTTON_OPTION_VISIBLE_TITLE:
+ "Menu expanded. Press Esc or Ctrl + Shift + M to hide the menu.",
+
+
+ /**
+ * @property SUBMIT_TITLE
+ * @description String representing the title applied to buttons of
+ * type "submit."
+ * @default "Click to submit form."
+ * @final
+ * @type String
+ */
+ SUBMIT_TITLE: "Click to submit form.",
+
+
+
+ // Protected attribute setter methods
+
+
+ /**
+ * @method _setType
+ * @description Sets the value of the button's "type" attribute.
+ * @protected
+ * @param {String} p_sType String indicating the value for the button's
+ * "type" attribute.
+ */
+ _setType: function (p_sType) {
+
+ if (p_sType == "split") {
+
+ this.on("option", this._onOption);
+
+ }
+
+ },
+
+
+ /**
+ * @method _setLabel
+ * @description Sets the value of the button's "label" attribute.
+ * @protected
+ * @param {String} p_sLabel String indicating the value for the button's
+ * "label" attribute.
+ */
+ _setLabel: function (p_sLabel) {
+
+ this._button.innerHTML = p_sLabel;
+
+
+ /*
+ Remove and add the default class name from the root element
+ for Gecko to ensure that the button shrinkwraps to the label.
+ Without this the button will not be rendered at the correct
+ width when the label changes. The most likely cause for this
+ bug is button's use of the Gecko-specific CSS display type of
+ "-moz-inline-box" to simulate "inline-block" supported by IE,
+ Safari and Opera.
+ */
+
+ var sClass,
+ nGeckoVersion = UA.gecko;
+
+
+ if (nGeckoVersion && nGeckoVersion < 1.9 && Dom.inDocument(this.get("element"))) {
+
+ sClass = this.CSS_CLASS_NAME;
+
+ this.removeClass(sClass);
+
+ Lang.later(0, this, this.addClass, sClass);
+
+ }
+
+ },
+
+
+ /**
+ * @method _setTabIndex
+ * @description Sets the value of the button's "tabindex" attribute.
+ * @protected
+ * @param {Number} p_nTabIndex Number indicating the value for the
+ * button's "tabindex" attribute.
+ */
+ _setTabIndex: function (p_nTabIndex) {
+
+ this._button.tabIndex = p_nTabIndex;
+
+ },
+
+
+ /**
+ * @method _setTitle
+ * @description Sets the value of the button's "title" attribute.
+ * @protected
+ * @param {String} p_nTabIndex Number indicating the value for
+ * the button's "title" attribute.
+ */
+ _setTitle: function (p_sTitle) {
+
+ var sTitle = p_sTitle;
+
+ if (this.get("type") != "link") {
+
+ if (!sTitle) {
+
+ switch (this.get("type")) {
+
+ case "radio":
+
+ sTitle = this.RADIO_DEFAULT_TITLE;
+
+ break;
+
+ case "checkbox":
+
+ sTitle = this.CHECKBOX_DEFAULT_TITLE;
+
+ break;
+
+ case "menu":
+
+ sTitle = this.MENUBUTTON_DEFAULT_TITLE;
+
+ break;
+
+ case "split":
+
+ sTitle = this.SPLITBUTTON_DEFAULT_TITLE;
+
+ break;
+
+ case "submit":
+
+ sTitle = this.SUBMIT_TITLE;
+
+ break;
+
+ }
+
+ }
+
+ this._button.title = sTitle;
+
+ }
+
+ },
+
+
+ /**
+ * @method _setDisabled
+ * @description Sets the value of the button's "disabled" attribute.
+ * @protected
+ * @param {Boolean} p_bDisabled Boolean indicating the value for
+ * the button's "disabled" attribute.
+ */
+ _setDisabled: function (p_bDisabled) {
+
+ if (this.get("type") != "link") {
+
+ if (p_bDisabled) {
+
+ if (this._menu) {
+
+ this._menu.hide();
+
+ }
+
+ if (this.hasFocus()) {
+
+ this.blur();
+
+ }
+
+ this._button.setAttribute("disabled", "disabled");
+
+ this.addStateCSSClasses("disabled");
+
+ this.removeStateCSSClasses("hover");
+ this.removeStateCSSClasses("active");
+ this.removeStateCSSClasses("focus");
+
+ }
+ else {
+
+ this._button.removeAttribute("disabled");
+
+ this.removeStateCSSClasses("disabled");
+
+ }
+
+ }
+
+ },
+
+
+ /**
+ * @method _setHref
+ * @description Sets the value of the button's "href" attribute.
+ * @protected
+ * @param {String} p_sHref String indicating the value for the button's
+ * "href" attribute.
+ */
+ _setHref: function (p_sHref) {
+
+ if (this.get("type") == "link") {
+
+ this._button.href = p_sHref;
+
+ }
+
+ },
+
+
+ /**
+ * @method _setTarget
+ * @description Sets the value of the button's "target" attribute.
+ * @protected
+ * @param {String} p_sTarget String indicating the value for the button's
+ * "target" attribute.
+ */
+ _setTarget: function (p_sTarget) {
+
+ if (this.get("type") == "link") {
+
+ this._button.setAttribute("target", p_sTarget);
+
+ }
+
+ },
+
+
+ /**
+ * @method _setChecked
+ * @description Sets the value of the button's "target" attribute.
+ * @protected
+ * @param {Boolean} p_bChecked Boolean indicating the value for
+ * the button's "checked" attribute.
+ */
+ _setChecked: function (p_bChecked) {
+
+ var sType = this.get("type"),
+ sTitle;
+
+ if (sType == "checkbox" || sType == "radio") {
+
+ if (p_bChecked) {
+
+ this.addStateCSSClasses("checked");
+
+ sTitle = (sType == "radio") ?
+ this.RADIO_CHECKED_TITLE :
+ this.CHECKBOX_CHECKED_TITLE;
+
+ }
+ else {
+
+ this.removeStateCSSClasses("checked");
+
+ sTitle = (sType == "radio") ?
+ this.RADIO_DEFAULT_TITLE :
+ this.CHECKBOX_DEFAULT_TITLE;
+
+ }
+
+ this.set("title", sTitle);
+
+ }
+
+ },
+
+
+ /**
+ * @method _setMenu
+ * @description Sets the value of the button's "menu" attribute.
+ * @protected
+ * @param {Object} p_oMenu Object indicating the value for the button's
+ * "menu" attribute.
+ */
+ _setMenu: function (p_oMenu) {
+
+ var bLazyLoad = this.get("lazyloadmenu"),
+ oButtonElement = this.get("element"),
+ sMenuCSSClassName,
+
+ /*
+ Boolean indicating if the value of p_oMenu is an instance
+ of YAHOO.widget.Menu or YAHOO.widget.Overlay.
+ */
+
+ bInstance = false,
+
+
+ oMenu,
+ oMenuElement,
+ oSrcElement,
+ aItems,
+ nItems,
+ oItem,
+ i;
+
+
+ if (!Overlay) {
+
+
+ return false;
+
+ }
+
+
+ if (Menu) {
+
+ sMenuCSSClassName = Menu.prototype.CSS_CLASS_NAME;
+
+ }
+
+
+ function onAppendTo() {
+
+ oMenu.render(oButtonElement.parentNode);
+
+ this.removeListener("appendTo", onAppendTo);
+
+ }
+
+
+ function initMenu() {
+
+ if (oMenu) {
+
+ Dom.addClass(oMenu.element, this.get("menuclassname"));
+ Dom.addClass(oMenu.element,
+ "yui-" + this.get("type") + "-button-menu");
+
+ oMenu.showEvent.subscribe(this._onMenuShow, null, this);
+ oMenu.hideEvent.subscribe(this._onMenuHide, null, this);
+ oMenu.renderEvent.subscribe(this._onMenuRender, null, this);
+
+
+ if (Menu && oMenu instanceof Menu) {
+
+ oMenu.keyDownEvent.subscribe(this._onMenuKeyDown,
+ this, true);
+
+ oMenu.subscribe("click", this._onMenuClick,
+ this, true);
+
+ oMenu.itemAddedEvent.subscribe(this._onMenuItemAdded,
+ this, true);
+
+ oSrcElement = oMenu.srcElement;
+
+ if (oSrcElement &&
+ oSrcElement.nodeName.toUpperCase() == "SELECT") {
+
+ oSrcElement.style.display = "none";
+ oSrcElement.parentNode.removeChild(oSrcElement);
+
+ }
+
+ }
+ else if (Overlay && oMenu instanceof Overlay) {
+
+ if (!m_oOverlayManager) {
+
+ m_oOverlayManager =
+ new YAHOO.widget.OverlayManager();
+
+ }
+
+ m_oOverlayManager.register(oMenu);
+
+ }
+
+
+ this._menu = oMenu;
+
+
+ if (!bInstance) {
+
+ if (bLazyLoad && Menu && !(oMenu instanceof Menu)) {
+
+ /*
+ Mimic Menu's "lazyload" functionality by adding
+ a "beforeshow" event listener that renders the
+ Overlay instance before it is made visible by
+ the button.
+ */
+
+ oMenu.beforeShowEvent.subscribe(
+ this._onOverlayBeforeShow, null, this);
+
+ }
+ else if (!bLazyLoad) {
+
+ if (Dom.inDocument(oButtonElement)) {
+
+ oMenu.render(oButtonElement.parentNode);
+
+ }
+ else {
+
+ this.on("appendTo", onAppendTo);
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+
+ if (p_oMenu && Menu && (p_oMenu instanceof Menu)) {
+
+ oMenu = p_oMenu;
+ aItems = oMenu.getItems();
+ nItems = aItems.length;
+ bInstance = true;
+
+
+ if (nItems > 0) {
+
+ i = nItems - 1;
+
+ do {
+
+ oItem = aItems[i];
+
+ if (oItem) {
+
+ oItem.cfg.subscribeToConfigEvent("selected",
+ this._onMenuItemSelected,
+ oItem,
+ this);
+
+ }
+
+ }
+ while (i--);
+
+ }
+
+ initMenu.call(this);
+
+ }
+ else if (Overlay && p_oMenu && (p_oMenu instanceof Overlay)) {
+
+ oMenu = p_oMenu;
+ bInstance = true;
+
+ oMenu.cfg.setProperty("visible", false);
+ oMenu.cfg.setProperty("context", [oButtonElement, "tl", "bl"]);
+
+ initMenu.call(this);
+
+ }
+ else if (Menu && Lang.isArray(p_oMenu)) {
+
+ this.on("appendTo", function () {
+
+ oMenu = new Menu(Dom.generateId(), { lazyload: bLazyLoad,
+ itemdata: p_oMenu });
+
+ initMenu.call(this);
+
+ });
+
+ }
+ else if (Lang.isString(p_oMenu)) {
+
+ oMenuElement = Dom.get(p_oMenu);
+
+ if (oMenuElement) {
+
+ if (Menu && Dom.hasClass(oMenuElement, sMenuCSSClassName) ||
+ oMenuElement.nodeName.toUpperCase() == "SELECT") {
+
+ oMenu = new Menu(p_oMenu, { lazyload: bLazyLoad });
+
+ initMenu.call(this);
+
+ }
+ else if (Overlay) {
+
+ oMenu = new Overlay(p_oMenu, { visible: false,
+ context: [oButtonElement, "tl", "bl"] });
+
+ initMenu.call(this);
+
+ }
+
+ }
+
+ }
+ else if (p_oMenu && p_oMenu.nodeName) {
+
+ if (Menu && Dom.hasClass(p_oMenu, sMenuCSSClassName) ||
+ p_oMenu.nodeName.toUpperCase() == "SELECT") {
+
+ oMenu = new Menu(p_oMenu, { lazyload: bLazyLoad });
+
+ initMenu.call(this);
+
+ }
+ else if (Overlay) {
+
+ if (!p_oMenu.id) {
+
+ Dom.generateId(p_oMenu);
+
+ }
+
+ oMenu = new Overlay(p_oMenu, { visible: false,
+ context: [oButtonElement, "tl", "bl"] });
+
+ initMenu.call(this);
+
+ }
+
+ }
+
+ },
+
+
+ /**
+ * @method _setOnClick
+ * @description Sets the value of the button's "onclick" attribute.
+ * @protected
+ * @param {Object} p_oObject Object indicating the value for the button's
+ * "onclick" attribute.
+ */
+ _setOnClick: function (p_oObject) {
+
+ /*
+ Remove any existing listeners if a "click" event handler
+ has already been specified.
+ */
+
+ if (this._onclickAttributeValue &&
+ (this._onclickAttributeValue != p_oObject)) {
+
+ this.removeListener("click", this._onclickAttributeValue.fn);
+
+ this._onclickAttributeValue = null;
+
+ }
+
+
+ if (!this._onclickAttributeValue &&
+ Lang.isObject(p_oObject) &&
+ Lang.isFunction(p_oObject.fn)) {
+
+ this.on("click", p_oObject.fn, p_oObject.obj, p_oObject.scope);
+
+ this._onclickAttributeValue = p_oObject;
+
+ }
+
+ },
+
+
+ /**
+ * @method _setSelectedMenuItem
+ * @description Sets the value of the button's
+ * "selectedMenuItem" attribute.
+ * @protected
+ * @param {Number} p_nIndex Number representing the index of the item
+ * in the button's menu that is currently selected.
+ */
+ _setSelectedMenuItem: function (p_nIndex) {
+
+ var oMenu = this._menu,
+ oMenuItem;
+
+
+ if (Menu && oMenu && oMenu instanceof Menu) {
+
+ oMenuItem = oMenu.getItem(p_nIndex);
+
+
+ if (oMenuItem && !oMenuItem.cfg.getProperty("selected")) {
+
+ oMenuItem.cfg.setProperty("selected", true);
+
+ }
+
+ }
+
+ },
+
+
+ // Protected methods
+
+
+
+ /**
+ * @method _isActivationKey
+ * @description Determines if the specified keycode is one that toggles
+ * the button's "active" state.
+ * @protected
+ * @param {Number} p_nKeyCode Number representing the keycode to
+ * be evaluated.
+ * @return {Boolean}
+ */
+ _isActivationKey: function (p_nKeyCode) {
+
+ var sType = this.get("type"),
+ aKeyCodes = (sType == "checkbox" || sType == "radio") ?
+ this.CHECK_ACTIVATION_KEYS : this.ACTIVATION_KEYS,
+
+ nKeyCodes = aKeyCodes.length,
+ i;
+
+ if (nKeyCodes > 0) {
+
+ i = nKeyCodes - 1;
+
+ do {
+
+ if (p_nKeyCode == aKeyCodes[i]) {
+
+ return true;
+
+ }
+
+ }
+ while (i--);
+
+ }
+
+ },
+
+
+ /**
+ * @method _isSplitButtonOptionKey
+ * @description Determines if the specified keycode is one that toggles
+ * the display of the split button's menu.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ * @return {Boolean}
+ */
+ _isSplitButtonOptionKey: function (p_oEvent) {
+
+ var bShowMenu = (p_oEvent.ctrlKey && p_oEvent.shiftKey &&
+ Event.getCharCode(p_oEvent) == 77);
+
+
+ function onKeyPress(p_oEvent) {
+
+ Event.preventDefault(p_oEvent);
+
+ this.removeListener("keypress", onKeyPress);
+
+ }
+
+
+ /*
+ It is necessary to add a "keypress" event listener to prevent Opera's default
+ browser context menu from appearing when the user presses Ctrl + Shift + M.
+ */
+
+ if (bShowMenu && UA.opera) {
+
+ this.on("keypress", onKeyPress);
+
+ }
+
+ return bShowMenu;
+
+ },
+
+
+ /**
+ * @method _addListenersToForm
+ * @description Adds event handlers to the button's form.
+ * @protected
+ */
+ _addListenersToForm: function () {
+
+ var oForm = this.getForm(),
+ onFormKeyPress = YAHOO.widget.Button.onFormKeyPress,
+ bHasKeyPressListener,
+ oSrcElement,
+ aListeners,
+ nListeners,
+ i;
+
+
+ if (oForm) {
+
+ Event.on(oForm, "reset", this._onFormReset, null, this);
+ Event.on(oForm, "submit", this.createHiddenFields, null, this);
+
+ oSrcElement = this.get("srcelement");
+
+
+ if (this.get("type") == "submit" ||
+ (oSrcElement && oSrcElement.type == "submit"))
+ {
+
+ aListeners = Event.getListeners(oForm, "keypress");
+ bHasKeyPressListener = false;
+
+ if (aListeners) {
+
+ nListeners = aListeners.length;
+
+ if (nListeners > 0) {
+
+ i = nListeners - 1;
+
+ do {
+
+ if (aListeners[i].fn == onFormKeyPress) {
+
+ bHasKeyPressListener = true;
+ break;
+
+ }
+
+ }
+ while (i--);
+
+ }
+
+ }
+
+
+ if (!bHasKeyPressListener) {
+
+ Event.on(oForm, "keypress", onFormKeyPress);
+
+ }
+
+ }
+
+ }
+
+ },
+
+
+
+ /**
+ * @method _showMenu
+ * @description Shows the button's menu.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event) that triggered
+ * the display of the menu.
+ */
+ _showMenu: function (p_oEvent) {
+
+ if (YAHOO.widget.MenuManager) {
+
+ YAHOO.widget.MenuManager.hideVisible();
+
+ }
+
+
+ if (m_oOverlayManager) {
+
+ m_oOverlayManager.hideAll();
+
+ }
+
+
+ var nViewportOffset = Overlay.VIEWPORT_OFFSET,
+
+ oMenu = this._menu,
+ oButton = this,
+ oButtonEL = oButton.get("element"),
+ bMenuFlipped = false,
+ nButtonY = Dom.getY(oButtonEL),
+ nScrollTop = Dom.getDocumentScrollTop(),
+ nMenuMinScrollHeight,
+ nMenuHeight,
+ oMenuShadow;
+
+
+ if (nScrollTop) {
+
+ nButtonY = nButtonY - nScrollTop;
+
+ }
+
+
+ var nTopRegion = nButtonY,
+ nBottomRegion = (Dom.getViewportHeight() -
+ (nButtonY + oButtonEL.offsetHeight));
+
+
+ /*
+ Uses the Button's position to calculate the availble height
+ above and below it to display its corresponding Menu.
+ */
+
+ function getMenuDisplayRegionHeight() {
+
+ if (bMenuFlipped) {
+
+ return (nTopRegion - nViewportOffset);
+
+ }
+ else {
+
+ return (nBottomRegion - nViewportOffset);
+
+ }
+
+ }
+
+
+
+ /*
+ Sets the Menu's "maxheight" configuration property and trys to
+ place the Menu in the best possible position (either above or
+ below its corresponding Button).
+ */
+
+ function sizeAndPositionMenu() {
+
+ var nDisplayRegionHeight = getMenuDisplayRegionHeight();
+
+
+ if (nMenuHeight > nDisplayRegionHeight) {
+
+ nMenuMinScrollHeight = oMenu.cfg.getProperty("minscrollheight");
+
+
+ if (nDisplayRegionHeight > nMenuMinScrollHeight) {
+
+ oMenu.cfg.setProperty("maxheight",
+ nDisplayRegionHeight);
+
+
+ if (bMenuFlipped) {
+
+ oMenu.align("bl", "tl");
+
+ }
+ else {
+
+ oMenu.align("tl", "bl");
+
+ }
+
+ }
+
+
+ if (nDisplayRegionHeight < nMenuMinScrollHeight) {
+
+ if (bMenuFlipped) {
+
+ /*
+ All possible positions and values for the
+ "maxheight" configuration property have been
+ tried, but none were successful, so fall back
+ to the original size and position.
+ */
+
+ oMenu.cfg.setProperty("context",
+ [oButtonEL, "tl", "bl"], true);
+
+ oMenu.align("tl", "bl");
+
+ }
+ else {
+
+ oMenu.cfg.setProperty("context",
+ [oButtonEL, "bl", "tl"], true);
+
+ oMenu.align("bl", "tl");
+
+ bMenuFlipped = true;
+
+ return sizeAndPositionMenu();
+
+ }
+
+ }
+
+ }
+
+ }
+
+
+ if (Menu && oMenu && (oMenu instanceof Menu)) {
+
+ oMenu.cfg.applyConfig({ context: [oButtonEL, "tl", "bl"], clicktohide: false });
+
+ oMenu.cfg.fireQueue();
+
+ oMenu.show();
+
+ oMenu.cfg.setProperty("maxheight", 0);
+
+ oMenu.align("tl", "bl");
+
+
+ /*
+ Stop the propagation of the event so that the MenuManager
+ doesn't blur the menu after it gets focus.
+ */
+
+ if (p_oEvent.type == "mousedown") {
+
+ Event.stopPropagation(p_oEvent);
+
+ }
+
+
+ nMenuHeight = oMenu.element.offsetHeight;
+
+ oMenuShadow = oMenu.element.lastChild;
+
+ sizeAndPositionMenu();
+
+ if (this.get("focusmenu")) {
+
+ this._menu.focus();
+
+ }
+
+ }
+ else if (Overlay && oMenu && (oMenu instanceof Overlay)) {
+
+ oMenu.show();
+ oMenu.align("tl", "bl");
+
+ var nDisplayRegionHeight = getMenuDisplayRegionHeight();
+
+ nMenuHeight = oMenu.element.offsetHeight;
+
+
+ if (nDisplayRegionHeight < nMenuHeight) {
+
+ oMenu.align("bl", "tl");
+
+ bMenuFlipped = true;
+
+ nDisplayRegionHeight = getMenuDisplayRegionHeight();
+
+ if (nDisplayRegionHeight < nMenuHeight) {
+
+ oMenu.align("tl", "bl");
+
+ }
+
+ }
+
+ }
+
+ },
+
+
+ /**
+ * @method _hideMenu
+ * @description Hides the button's menu.
+ * @protected
+ */
+ _hideMenu: function () {
+
+ var oMenu = this._menu;
+
+ if (oMenu) {
+
+ oMenu.hide();
+
+ }
+
+ },
+
+
+
+
+ // Protected event handlers
+
+
+ /**
+ * @method _onMouseOver
+ * @description "mouseover" event handler for the button.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onMouseOver: function (p_oEvent) {
+
+ if (!this._hasMouseEventHandlers) {
+
+ this.on("mouseout", this._onMouseOut);
+ this.on("mousedown", this._onMouseDown);
+ this.on("mouseup", this._onMouseUp);
+
+ this._hasMouseEventHandlers = true;
+
+ }
+
+ this.addStateCSSClasses("hover");
+
+ if (this._activationButtonPressed) {
+
+ this.addStateCSSClasses("active");
+
+ }
+
+
+ if (this._bOptionPressed) {
+
+ this.addStateCSSClasses("activeoption");
+
+ }
+
+
+ if (this._activationButtonPressed || this._bOptionPressed) {
+
+ Event.removeListener(document, "mouseup", this._onDocumentMouseUp);
+
+ }
+
+ },
+
+
+ /**
+ * @method _onMouseOut
+ * @description "mouseout" event handler for the button.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onMouseOut: function (p_oEvent) {
+
+ this.removeStateCSSClasses("hover");
+
+ if (this.get("type") != "menu") {
+
+ this.removeStateCSSClasses("active");
+
+ }
+
+ if (this._activationButtonPressed || this._bOptionPressed) {
+
+ Event.on(document, "mouseup", this._onDocumentMouseUp,
+ null, this);
+
+ }
+
+ },
+
+
+ /**
+ * @method _onDocumentMouseUp
+ * @description "mouseup" event handler for the button.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onDocumentMouseUp: function (p_oEvent) {
+
+ this._activationButtonPressed = false;
+ this._bOptionPressed = false;
+
+ var sType = this.get("type"),
+ oTarget,
+ oMenuElement;
+
+ if (sType == "menu" || sType == "split") {
+
+ oTarget = Event.getTarget(p_oEvent);
+ oMenuElement = this._menu.element;
+
+ if (oTarget != oMenuElement &&
+ !Dom.isAncestor(oMenuElement, oTarget)) {
+
+ this.removeStateCSSClasses((sType == "menu" ?
+ "active" : "activeoption"));
+
+ this._hideMenu();
+
+ }
+
+ }
+
+ Event.removeListener(document, "mouseup", this._onDocumentMouseUp);
+
+ },
+
+
+ /**
+ * @method _onMouseDown
+ * @description "mousedown" event handler for the button.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onMouseDown: function (p_oEvent) {
+
+ var sType,
+ oElement,
+ nX,
+ me;
+
+
+ function onMouseUp() {
+
+ this._hideMenu();
+ this.removeListener("mouseup", onMouseUp);
+
+ }
+
+
+ if ((p_oEvent.which || p_oEvent.button) == 1) {
+
+
+ if (!this.hasFocus()) {
+
+ this.focus();
+
+ }
+
+
+ sType = this.get("type");
+
+
+ if (sType == "split") {
+
+ oElement = this.get("element");
+ nX = Event.getPageX(p_oEvent) - Dom.getX(oElement);
+
+ if ((oElement.offsetWidth - this.OPTION_AREA_WIDTH) < nX) {
+
+ this.fireEvent("option", p_oEvent);
+
+ }
+ else {
+
+ this.addStateCSSClasses("active");
+
+ this._activationButtonPressed = true;
+
+ }
+
+ }
+ else if (sType == "menu") {
+
+ if (this.isActive()) {
+
+ this._hideMenu();
+
+ this._activationButtonPressed = false;
+
+ }
+ else {
+
+ this._showMenu(p_oEvent);
+
+ this._activationButtonPressed = true;
+
+ }
+
+ }
+ else {
+
+ this.addStateCSSClasses("active");
+
+ this._activationButtonPressed = true;
+
+ }
+
+
+
+ if (sType == "split" || sType == "menu") {
+
+ me = this;
+
+ this._hideMenuTimerId = window.setTimeout(function () {
+
+ me.on("mouseup", onMouseUp);
+
+ }, 250);
+
+ }
+
+ }
+
+ },
+
+
+ /**
+ * @method _onMouseUp
+ * @description "mouseup" event handler for the button.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onMouseUp: function (p_oEvent) {
+
+ var sType = this.get("type");
+
+
+ if (this._hideMenuTimerId) {
+
+ window.clearTimeout(this._hideMenuTimerId);
+
+ }
+
+
+ if (sType == "checkbox" || sType == "radio") {
+
+ this.set("checked", !(this.get("checked")));
+
+ }
+
+
+ this._activationButtonPressed = false;
+
+
+ if (this.get("type") != "menu") {
+
+ this.removeStateCSSClasses("active");
+
+ }
+
+ },
+
+
+ /**
+ * @method _onFocus
+ * @description "focus" event handler for the button.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onFocus: function (p_oEvent) {
+
+ var oElement;
+
+ this.addStateCSSClasses("focus");
+
+ if (this._activationKeyPressed) {
+
+ this.addStateCSSClasses("active");
+
+ }
+
+ m_oFocusedButton = this;
+
+
+ if (!this._hasKeyEventHandlers) {
+
+ oElement = this._button;
+
+ Event.on(oElement, "blur", this._onBlur, null, this);
+ Event.on(oElement, "keydown", this._onKeyDown, null, this);
+ Event.on(oElement, "keyup", this._onKeyUp, null, this);
+
+ this._hasKeyEventHandlers = true;
+
+ }
+
+
+ this.fireEvent("focus", p_oEvent);
+
+ },
+
+
+ /**
+ * @method _onBlur
+ * @description "blur" event handler for the button.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onBlur: function (p_oEvent) {
+
+ this.removeStateCSSClasses("focus");
+
+ if (this.get("type") != "menu") {
+
+ this.removeStateCSSClasses("active");
+
+ }
+
+ if (this._activationKeyPressed) {
+
+ Event.on(document, "keyup", this._onDocumentKeyUp, null, this);
+
+ }
+
+
+ m_oFocusedButton = null;
+
+ this.fireEvent("blur", p_oEvent);
+
+ },
+
+
+ /**
+ * @method _onDocumentKeyUp
+ * @description "keyup" event handler for the document.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onDocumentKeyUp: function (p_oEvent) {
+
+ if (this._isActivationKey(Event.getCharCode(p_oEvent))) {
+
+ this._activationKeyPressed = false;
+
+ Event.removeListener(document, "keyup", this._onDocumentKeyUp);
+
+ }
+
+ },
+
+
+ /**
+ * @method _onKeyDown
+ * @description "keydown" event handler for the button.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onKeyDown: function (p_oEvent) {
+
+ var oMenu = this._menu;
+
+
+ if (this.get("type") == "split" &&
+ this._isSplitButtonOptionKey(p_oEvent)) {
+
+ this.fireEvent("option", p_oEvent);
+
+ }
+ else if (this._isActivationKey(Event.getCharCode(p_oEvent))) {
+
+ if (this.get("type") == "menu") {
+
+ this._showMenu(p_oEvent);
+
+ }
+ else {
+
+ this._activationKeyPressed = true;
+
+ this.addStateCSSClasses("active");
+
+ }
+
+ }
+
+
+ if (oMenu && oMenu.cfg.getProperty("visible") &&
+ Event.getCharCode(p_oEvent) == 27) {
+
+ oMenu.hide();
+ this.focus();
+
+ }
+
+ },
+
+
+ /**
+ * @method _onKeyUp
+ * @description "keyup" event handler for the button.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onKeyUp: function (p_oEvent) {
+
+ var sType;
+
+ if (this._isActivationKey(Event.getCharCode(p_oEvent))) {
+
+ sType = this.get("type");
+
+ if (sType == "checkbox" || sType == "radio") {
+
+ this.set("checked", !(this.get("checked")));
+
+ }
+
+ this._activationKeyPressed = false;
+
+ if (this.get("type") != "menu") {
+
+ this.removeStateCSSClasses("active");
+
+ }
+
+ }
+
+ },
+
+
+ /**
+ * @method _onClick
+ * @description "click" event handler for the button.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onClick: function (p_oEvent) {
+
+ var sType = this.get("type"),
+ sTitle,
+ oForm,
+ oSrcElement,
+ oElement,
+ nX;
+
+
+ switch (sType) {
+
+ case "radio":
+ case "checkbox":
+
+ if (this.get("checked")) {
+
+ sTitle = (sType == "radio") ?
+ this.RADIO_CHECKED_TITLE :
+ this.CHECKBOX_CHECKED_TITLE;
+
+ }
+ else {
+
+ sTitle = (sType == "radio") ?
+ this.RADIO_DEFAULT_TITLE :
+ this.CHECKBOX_DEFAULT_TITLE;
+
+ }
+
+ this.set("title", sTitle);
+
+ break;
+
+ case "submit":
+
+ this.submitForm();
+
+ break;
+
+ case "reset":
+
+ oForm = this.getForm();
+
+ if (oForm) {
+
+ oForm.reset();
+
+ }
+
+ break;
+
+ case "menu":
+
+ sTitle = this._menu.cfg.getProperty("visible") ?
+ this.MENUBUTTON_MENU_VISIBLE_TITLE :
+ this.MENUBUTTON_DEFAULT_TITLE;
+
+ this.set("title", sTitle);
+
+ break;
+
+ case "split":
+
+ oElement = this.get("element");
+ nX = Event.getPageX(p_oEvent) - Dom.getX(oElement);
+
+ if ((oElement.offsetWidth - this.OPTION_AREA_WIDTH) < nX) {
+
+ return false;
+
+ }
+ else {
+
+ this._hideMenu();
+
+ oSrcElement = this.get("srcelement");
+
+ if (oSrcElement && oSrcElement.type == "submit") {
+
+ this.submitForm();
+
+ }
+
+ }
+
+ sTitle = this._menu.cfg.getProperty("visible") ?
+ this.SPLITBUTTON_OPTION_VISIBLE_TITLE :
+ this.SPLITBUTTON_DEFAULT_TITLE;
+
+ this.set("title", sTitle);
+
+ break;
+
+ }
+
+ },
+
+
+ /**
+ * @method _onAppendTo
+ * @description "appendTo" event handler for the button.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onAppendTo: function (p_oEvent) {
+
+ /*
+ It is necessary to call "_addListenersToForm" using
+ "setTimeout" to make sure that the button's "form" property
+ returns a node reference. Sometimes, if you try to get the
+ reference immediately after appending the field, it is null.
+ */
+
+ var me = this;
+
+ window.setTimeout(function () {
+
+ me._addListenersToForm();
+
+ }, 0);
+
+ },
+
+
+ /**
+ * @method _onFormReset
+ * @description "reset" event handler for the button's form.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event
+ * object passed back by the event utility (YAHOO.util.Event).
+ */
+ _onFormReset: function (p_oEvent) {
+
+ var sType = this.get("type"),
+ oMenu = this._menu;
+
+ if (sType == "checkbox" || sType == "radio") {
+
+ this.resetValue("checked");
+
+ }
+
+
+ if (Menu && oMenu && (oMenu instanceof Menu)) {
+
+ this.resetValue("selectedMenuItem");
+
+ }
+
+ },
+
+
+ /**
+ * @method _onDocumentMouseDown
+ * @description "mousedown" event handler for the document.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onDocumentMouseDown: function (p_oEvent) {
+
+ var oTarget = Event.getTarget(p_oEvent),
+ oButtonElement = this.get("element"),
+ oMenuElement = this._menu.element;
+
+
+ if (oTarget != oButtonElement &&
+ !Dom.isAncestor(oButtonElement, oTarget) &&
+ oTarget != oMenuElement &&
+ !Dom.isAncestor(oMenuElement, oTarget)) {
+
+ this._hideMenu();
+
+ Event.removeListener(document, "mousedown",
+ this._onDocumentMouseDown);
+
+ }
+
+ },
+
+
+ /**
+ * @method _onOption
+ * @description "option" event handler for the button.
+ * @protected
+ * @param {Event} p_oEvent Object representing the DOM event object
+ * passed back by the event utility (YAHOO.util.Event).
+ */
+ _onOption: function (p_oEvent) {
+
+ if (this.hasClass("yui-split-button-activeoption")) {
+
+ this._hideMenu();
+
+ this._bOptionPressed = false;
+
+ }
+ else {
+
+ this._showMenu(p_oEvent);
+
+ this._bOptionPressed = true;
+
+ }
+
+ },
+
+
+ /**
+ * @method _onOverlayBeforeShow
+ * @description "beforeshow" event handler for the
+ * <a href="YAHOO.widget.Overlay.html">YAHOO.widget.Overlay</a> instance
+ * serving as the button's menu.
+ * @private
+ * @param {String} p_sType String representing the name of the event
+ * that was fired.
+ */
+ _onOverlayBeforeShow: function (p_sType) {
+
+ var oMenu = this._menu;
+
+ oMenu.render(this.get("element").parentNode);
+
+ oMenu.beforeShowEvent.unsubscribe(this._onOverlayBeforeShow);
+
+ },
+
+
+ /**
+ * @method _onMenuShow
+ * @description "show" event handler for the button's menu.
+ * @private
+ * @param {String} p_sType String representing the name of the event
+ * that was fired.
+ */
+ _onMenuShow: function (p_sType) {
+
+ Event.on(document, "mousedown", this._onDocumentMouseDown,
+ null, this);
+
+ var sTitle,
+ sState;
+
+ if (this.get("type") == "split") {
+
+ sTitle = this.SPLITBUTTON_OPTION_VISIBLE_TITLE;
+ sState = "activeoption";
+
+ }
+ else {
+
+ sTitle = this.MENUBUTTON_MENU_VISIBLE_TITLE;
+ sState = "active";
+
+ }
+
+ this.addStateCSSClasses(sState);
+ this.set("title", sTitle);
+
+ },
+
+
+ /**
+ * @method _onMenuHide
+ * @description "hide" event handler for the button's menu.
+ * @private
+ * @param {String} p_sType String representing the name of the event
+ * that was fired.
+ */
+ _onMenuHide: function (p_sType) {
+
+ var oMenu = this._menu,
+ sTitle,
+ sState;
+
+
+ if (this.get("type") == "split") {
+
+ sTitle = this.SPLITBUTTON_DEFAULT_TITLE;
+ sState = "activeoption";
+
+ }
+ else {
+
+ sTitle = this.MENUBUTTON_DEFAULT_TITLE;
+ sState = "active";
+ }
+
+
+ this.removeStateCSSClasses(sState);
+ this.set("title", sTitle);
+
+
+ if (this.get("type") == "split") {
+
+ this._bOptionPressed = false;
+
+ }
+
+ },
+
+
+ /**
+ * @method _onMenuKeyDown
+ * @description "keydown" event handler for the button's menu.
+ * @private
+ * @param {String} p_sType String representing the name of the event
+ * that was fired.
+ * @param {Array} p_aArgs Array of arguments sent when the event
+ * was fired.
+ */
+ _onMenuKeyDown: function (p_sType, p_aArgs) {
+
+ var oEvent = p_aArgs[0];
+
+ if (Event.getCharCode(oEvent) == 27) {
+
+ this.focus();
+
+ if (this.get("type") == "split") {
+
+ this._bOptionPressed = false;
+
+ }
+
+ }
+
+ },
+
+
+ /**
+ * @method _onMenuRender
+ * @description "render" event handler for the button's menu.
+ * @private
+ * @param {String} p_sType String representing the name of the
+ * event thatwas fired.
+ */
+ _onMenuRender: function (p_sType) {
+
+ var oButtonElement = this.get("element"),
+ oButtonParent = oButtonElement.parentNode,
+ oMenuElement = this._menu.element;
+
+
+ if (oButtonParent != oMenuElement.parentNode) {
+
+ oButtonParent.appendChild(oMenuElement);
+
+ }
+
+ this.set("selectedMenuItem", this.get("selectedMenuItem"));
+
+ },
+
+
+ /**
+ * @method _onMenuItemSelected
+ * @description "selectedchange" event handler for each item in the
+ * button's menu.
+ * @private
+ * @param {String} p_sType String representing the name of the event
+ * that was fired.
+ * @param {Array} p_aArgs Array of arguments sent when the event
+ * was fired.
+ * @param {MenuItem} p_oItem Object representing the menu item that
+ * subscribed to the event.
+ */
+ _onMenuItemSelected: function (p_sType, p_aArgs, p_oItem) {
+
+ var bSelected = p_aArgs[0];
+
+ if (bSelected) {
+
+ this.set("selectedMenuItem", p_oItem);
+
+ }
+
+ },
+
+
+ /**
+ * @method _onMenuItemAdded
+ * @description "itemadded" event handler for the button's menu.
+ * @private
+ * @param {String} p_sType String representing the name of the event
+ * that was fired.
+ * @param {Array} p_aArgs Array of arguments sent when the event
+ * was fired.
+ * @param {<a href="YAHOO.widget.MenuItem.html">
+ * YAHOO.widget.MenuItem</a>} p_oItem Object representing the menu
+ * item that subscribed to the event.
+ */
+ _onMenuItemAdded: function (p_sType, p_aArgs, p_oItem) {
+
+ var oItem = p_aArgs[0];
+
+ oItem.cfg.subscribeToConfigEvent("selected",
+ this._onMenuItemSelected, oItem, this);
+
+ },
+
+
+ /**
+ * @method _onMenuClick
+ * @description "click" event handler for the button's menu.
+ * @private
+ * @param {String} p_sType String representing the name of the event
+ * that was fired.
+ * @param {Array} p_aArgs Array of arguments sent when the event
+ * was fired.
+ */
+ _onMenuClick: function (p_sType, p_aArgs) {
+
+ var oItem = p_aArgs[1],
+ oSrcElement;
+
+ if (oItem) {
+
+ oSrcElement = this.get("srcelement");
+
+ if (oSrcElement && oSrcElement.type == "submit") {
+
+ this.submitForm();
+
+ }
+
+ this._hideMenu();
+
+ }
+
+ },
+
+
+
+ // Public methods
+
+
+ /**
+ * @method createButtonElement
+ * @description Creates the button's HTML elements.
+ * @param {String} p_sType String indicating the type of element
+ * to create.
+ * @return {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
+ * level-one-html.html#ID-58190037">HTMLElement</a>}
+ */
+ createButtonElement: function (p_sType) {
+
+ var sNodeName = this.NODE_NAME,
+ oElement = document.createElement(sNodeName);
+
+ oElement.innerHTML = "<" + sNodeName + " class=\"first-child\">" +
+ (p_sType == "link" ? "<a></a>" :
+ "<button type=\"button\"></button>") + "</" + sNodeName + ">";
+
+ return oElement;
+
+ },
+
+
+ /**
+ * @method addStateCSSClasses
+ * @description Appends state-specific CSS classes to the button's root
+ * DOM element.
+ */
+ addStateCSSClasses: function (p_sState) {
+
+ var sType = this.get("type");
+
+ if (Lang.isString(p_sState)) {
+
+ if (p_sState != "activeoption") {
+
+ this.addClass(this.CSS_CLASS_NAME + ("-" + p_sState));
+
+ }
+
+ this.addClass("yui-" + sType + ("-button-" + p_sState));
+
+ }
+
+ },
+
+
+ /**
+ * @method removeStateCSSClasses
+ * @description Removes state-specific CSS classes to the button's root
+ * DOM element.
+ */
+ removeStateCSSClasses: function (p_sState) {
+
+ var sType = this.get("type");
+
+ if (Lang.isString(p_sState)) {
+
+ this.removeClass(this.CSS_CLASS_NAME + ("-" + p_sState));
+ this.removeClass("yui-" + sType + ("-button-" + p_sState));
+
+ }
+
+ },
+
+
+ /**
+ * @method createHiddenFields
+ * @description Creates the button's hidden form field and appends it
+ * to its parent form.
+ * @return {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
+ * level-one-html.html#ID-6043025">HTMLInputElement</a>|Array}
+ */
+ createHiddenFields: function () {
+
+ this.removeHiddenFields();
+
+ var oForm = this.getForm(),
+ oButtonField,
+ sType,
+ bCheckable,
+ oMenu,
+ oMenuItem,
+ sName,
+ oValue,
+ oMenuField;
+
+
+ if (oForm && !this.get("disabled")) {
+
+ sType = this.get("type");
+ bCheckable = (sType == "checkbox" || sType == "radio");
+
+
+ if (bCheckable || (m_oSubmitTrigger == this)) {
+
+
+ oButtonField = createInputElement(
+ (bCheckable ? sType : "hidden"),
+ this.get("name"),
+ this.get("value"),
+ this.get("checked"));
+
+
+ if (oButtonField) {
+
+ if (bCheckable) {
+
+ oButtonField.style.display = "none";
+
+ }
+
+ oForm.appendChild(oButtonField);
+
+ }
+
+ }
+
+
+ oMenu = this._menu;
+
+
+ if (Menu && oMenu && (oMenu instanceof Menu)) {
+
+
+ oMenuField = oMenu.srcElement;
+ oMenuItem = this.get("selectedMenuItem");
+
+ if (oMenuItem) {
+
+ if (oMenuField &&
+ oMenuField.nodeName.toUpperCase() == "SELECT") {
+
+ oForm.appendChild(oMenuField);
+ oMenuField.selectedIndex = oMenuItem.index;
+
+ }
+ else {
+
+ oValue = (oMenuItem.value === null ||
+ oMenuItem.value === "") ?
+ oMenuItem.cfg.getProperty("text") :
+ oMenuItem.value;
+
+ sName = this.get("name");
+
+ if (oValue && sName) {
+
+ oMenuField = createInputElement("hidden",
+ (sName + "_options"),
+ oValue);
+
+ oForm.appendChild(oMenuField);
+
+ }
+
+ }
+
+ }
+
+ }
+
+
+ if (oButtonField && oMenuField) {
+
+ this._hiddenFields = [oButtonField, oMenuField];
+
+ }
+ else if (!oButtonField && oMenuField) {
+
+ this._hiddenFields = oMenuField;
+
+ }
+ else if (oButtonField && !oMenuField) {
+
+ this._hiddenFields = oButtonField;
+
+ }
+
+
+ return this._hiddenFields;
+
+ }
+
+ },
+
+
+ /**
+ * @method removeHiddenFields
+ * @description Removes the button's hidden form field(s) from its
+ * parent form.
+ */
+ removeHiddenFields: function () {
+
+ var oField = this._hiddenFields,
+ nFields,
+ i;
+
+ function removeChild(p_oElement) {
+
+ if (Dom.inDocument(p_oElement)) {
+
+ p_oElement.parentNode.removeChild(p_oElement);
+
+ }
+
+ }
+
+
+ if (oField) {
+
+ if (Lang.isArray(oField)) {
+
+ nFields = oField.length;
+
+ if (nFields > 0) {
+
+ i = nFields - 1;
+
+ do {
+
+ removeChild(oField[i]);
+
+ }
+ while (i--);
+
+ }
+
+ }
+ else {
+
+ removeChild(oField);
+
+ }
+
+ this._hiddenFields = null;
+
+ }
+
+ },
+
+
+ /**
+ * @method submitForm
+ * @description Submits the form to which the button belongs. Returns
+ * true if the form was submitted successfully, false if the submission
+ * was cancelled.
+ * @protected
+ * @return {Boolean}
+ */
+ submitForm: function () {
+
+ var oForm = this.getForm(),
+
+ oSrcElement = this.get("srcelement"),
+
+ /*
+ Boolean indicating if the event fired successfully
+ (was not cancelled by any handlers)
+ */
+
+ bSubmitForm = false,
+
+ oEvent;
+
+
+ if (oForm) {
+
+ if (this.get("type") == "submit" ||
+ (oSrcElement && oSrcElement.type == "submit"))
+ {
+
+ m_oSubmitTrigger = this;
+
+ }
+
+
+ if (UA.ie) {
+
+ bSubmitForm = oForm.fireEvent("onsubmit");
+
+ }
+ else { // Gecko, Opera, and Safari
+
+ oEvent = document.createEvent("HTMLEvents");
+ oEvent.initEvent("submit", true, true);
+
+ bSubmitForm = oForm.dispatchEvent(oEvent);
+
+ }
+
+
+ /*
+ In IE and Safari, dispatching a "submit" event to a form
+ WILL cause the form's "submit" event to fire, but WILL NOT
+ submit the form. Therefore, we need to call the "submit"
+ method as well.
+ */
+
+ if ((UA.ie || UA.webkit) && bSubmitForm) {
+
+ oForm.submit();
+
+ }
+
+ }
+
+ return bSubmitForm;
+
+ },
+
+
+ /**
+ * @method init
+ * @description The Button class's initialization method.
+ * @param {String} p_oElement String specifying the id attribute of the
+ * <code><input></code>, <code><button></code>,
+ * <code><a></code>, or <code><span></code> element to
+ * be used to create the button.
+ * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/
+ * level-one-html.html#ID-6043025">HTMLInputElement</a>|<a href="http://
+ * www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html
+ * #ID-34812697">HTMLButtonElement</a>|<a href="http://www.w3.org/TR
+ * /2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-33759296">
+ * HTMLElement</a>} p_oElement Object reference for the
+ * <code><input></code>, <code><button></code>,
+ * <code><a></code>, or <code><span></code> element to be
+ * used to create the button.
+ * @param {Object} p_oElement Object literal specifying a set of
+ * configuration attributes used to create the button.
+ * @param {Object} p_oAttributes Optional. Object literal specifying a
+ * set of configuration attributes used to create the button.
+ */
+ init: function (p_oElement, p_oAttributes) {
+
+ var sNodeName = p_oAttributes.type == "link" ? "a" : "button",
+ oSrcElement = p_oAttributes.srcelement,
+ oButton = p_oElement.getElementsByTagName(sNodeName)[0],
+ oInput;
+
+
+ if (!oButton) {
+
+ oInput = p_oElement.getElementsByTagName("input")[0];
+
+
+ if (oInput) {
+
+ oButton = document.createElement("button");
+ oButton.setAttribute("type", "button");
+
+ oInput.parentNode.replaceChild(oButton, oInput);
+
+ }
+
+ }
+
+ this._button = oButton;
+
+
+ YAHOO.widget.Button.superclass.init.call(this, p_oElement,
+ p_oAttributes);
+
+
+ m_oButtons[this.get("id")] = this;
+
+
+ this.addClass(this.CSS_CLASS_NAME);
+
+ this.addClass("yui-" + this.get("type") + "-button");
+
+ Event.on(this._button, "focus", this._onFocus, null, this);
+ this.on("mouseover", this._onMouseOver);
+ this.on("click", this._onClick);
+ this.on("appendTo", this._onAppendTo);
+
+
+ var oContainer = this.get("container"),
+ oElement = this.get("element"),
+ bElInDoc = Dom.inDocument(oElement),
+ oParentNode;
+
+
+ if (oContainer) {
+
[... 1702 lines stripped ...]
|