diff --git a/lib/yui/animation/animation-debug.js b/lib/yui/animation/animation-debug.js deleted file mode 100644 index 7bcb96d6..00000000 --- a/lib/yui/animation/animation-debug.js +++ /dev/null @@ -1,1394 +0,0 @@ -/* -Copyright (c) 2009, Yahoo! Inc. All rights reserved. -Code licensed under the BSD License: -http://developer.yahoo.net/yui/license.txt -version: 2.7.0 -*/ -(function() { - -var Y = YAHOO.util; - -/* -Copyright (c) 2006, Yahoo! Inc. All rights reserved. -Code licensed under the BSD License: -http://developer.yahoo.net/yui/license.txt -*/ - -/** - * The animation module provides allows effects to be added to HTMLElements. - * @module animation - * @requires yahoo, event, dom - */ - -/** - * - * Base animation class that provides the interface for building animated effects. - *
Usage: var myAnim = new YAHOO.util.Anim(el, { width: { from: 10, to: 100 } }, 1, YAHOO.util.Easing.easeOut);
- * @class Anim - * @namespace YAHOO.util - * @requires YAHOO.util.AnimMgr - * @requires YAHOO.util.Easing - * @requires YAHOO.util.Dom - * @requires YAHOO.util.Event - * @requires YAHOO.util.CustomEvent - * @constructor - * @param {String | HTMLElement} el Reference to the element that will be animated - * @param {Object} attributes The attribute(s) to be animated. - * Each attribute is an object with at minimum a "to" or "by" member defined. - * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). - * All attribute names use camelCase. - * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based - * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) - */ - -var Anim = function(el, attributes, duration, method) { - if (!el) { - YAHOO.log('element required to create Anim instance', 'error', 'Anim'); - } - this.init(el, attributes, duration, method); -}; - -Anim.NAME = 'Anim'; - -Anim.prototype = { - /** - * Provides a readable name for the Anim instance. - * @method toString - * @return {String} - */ - toString: function() { - var el = this.getEl() || {}; - var id = el.id || el.tagName; - return (this.constructor.NAME + ': ' + id); - }, - - patterns: { // cached for performance - noNegatives: /width|height|opacity|padding/i, // keep at zero or above - offsetAttribute: /^((width|height)|(top|left))$/, // use offsetValue as default - defaultUnit: /width|height|top$|bottom$|left$|right$/i, // use 'px' by default - offsetUnit: /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i // IE may return these, so convert these to offset - }, - - /** - * Returns the value computed by the animation's "method". - * @method doMethod - * @param {String} attr The name of the attribute. - * @param {Number} start The value this attribute should start from for this animation. - * @param {Number} end The value this attribute should end at for this animation. - * @return {Number} The Value to be applied to the attribute. - */ - doMethod: function(attr, start, end) { - return this.method(this.currentFrame, start, end - start, this.totalFrames); - }, - - /** - * Applies a value to an attribute. - * @method setAttribute - * @param {String} attr The name of the attribute. - * @param {Number} val The value to be applied to the attribute. - * @param {String} unit The unit ('px', '%', etc.) of the value. - */ - setAttribute: function(attr, val, unit) { - var el = this.getEl(); - if ( this.patterns.noNegatives.test(attr) ) { - val = (val > 0) ? val : 0; - } - - if ('style' in el) { - Y.Dom.setStyle(el, attr, val + unit); - } else if (attr in el) { - el[attr] = val; - } - }, - - /** - * Returns current value of the attribute. - * @method getAttribute - * @param {String} attr The name of the attribute. - * @return {Number} val The current value of the attribute. - */ - getAttribute: function(attr) { - var el = this.getEl(); - var val = Y.Dom.getStyle(el, attr); - - if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) { - return parseFloat(val); - } - - var a = this.patterns.offsetAttribute.exec(attr) || []; - var pos = !!( a[3] ); // top or left - var box = !!( a[2] ); // width or height - - if ('style' in el) { - // use offsets for width/height and abs pos top/left - if ( box || (Y.Dom.getStyle(el, 'position') == 'absolute' && pos) ) { - val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)]; - } else { // default to zero for other 'auto' - val = 0; - } - } else if (attr in el) { - val = el[attr]; - } - - return val; - }, - - /** - * Returns the unit to use when none is supplied. - * @method getDefaultUnit - * @param {attr} attr The name of the attribute. - * @return {String} The default unit to be used. - */ - getDefaultUnit: function(attr) { - if ( this.patterns.defaultUnit.test(attr) ) { - return 'px'; - } - - return ''; - }, - - /** - * Sets the actual values to be used during the animation. Should only be needed for subclass use. - * @method setRuntimeAttribute - * @param {Object} attr The attribute object - * @private - */ - setRuntimeAttribute: function(attr) { - var start; - var end; - var attributes = this.attributes; - - this.runtimeAttributes[attr] = {}; - - var isset = function(prop) { - return (typeof prop !== 'undefined'); - }; - - if ( !isset(attributes[attr]['to']) && !isset(attributes[attr]['by']) ) { - return false; // note return; nothing to animate to - } - - start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr); - - // To beats by, per SMIL 2.1 spec - if ( isset(attributes[attr]['to']) ) { - end = attributes[attr]['to']; - } else if ( isset(attributes[attr]['by']) ) { - if (start.constructor == Array) { - end = []; - for (var i = 0, len = start.length; i < len; ++i) { - end[i] = start[i] + attributes[attr]['by'][i] * 1; // times 1 to cast "by" - } - } else { - end = start + attributes[attr]['by'] * 1; - } - } - - this.runtimeAttributes[attr].start = start; - this.runtimeAttributes[attr].end = end; - - // set units if needed - this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? - attributes[attr]['unit'] : this.getDefaultUnit(attr); - return true; - }, - - /** - * Constructor for Anim instance. - * @method init - * @param {String | HTMLElement} el Reference to the element that will be animated - * @param {Object} attributes The attribute(s) to be animated. - * Each attribute is an object with at minimum a "to" or "by" member defined. - * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). - * All attribute names use camelCase. - * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based - * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) - */ - init: function(el, attributes, duration, method) { - /** - * Whether or not the animation is running. - * @property isAnimated - * @private - * @type Boolean - */ - var isAnimated = false; - - /** - * A Date object that is created when the animation begins. - * @property startTime - * @private - * @type Date - */ - var startTime = null; - - /** - * The number of frames this animation was able to execute. - * @property actualFrames - * @private - * @type Int - */ - var actualFrames = 0; - - /** - * The element to be animated. - * @property el - * @private - * @type HTMLElement - */ - el = Y.Dom.get(el); - - /** - * The collection of attributes to be animated. - * Each attribute must have at least a "to" or "by" defined in order to animate. - * If "to" is supplied, the animation will end with the attribute at that value. - * If "by" is supplied, the animation will end at that value plus its starting value. - * If both are supplied, "to" is used, and "by" is ignored. - * Optional additional member include "from" (the value the attribute should start animating from, defaults to current value), and "unit" (the units to apply to the values). - * @property attributes - * @type Object - */ - this.attributes = attributes || {}; - - /** - * The length of the animation. Defaults to "1" (second). - * @property duration - * @type Number - */ - this.duration = !YAHOO.lang.isUndefined(duration) ? duration : 1; - - /** - * The method that will provide values to the attribute(s) during the animation. - * Defaults to "YAHOO.util.Easing.easeNone". - * @property method - * @type Function - */ - this.method = method || Y.Easing.easeNone; - - /** - * Whether or not the duration should be treated as seconds. - * Defaults to true. - * @property useSeconds - * @type Boolean - */ - this.useSeconds = true; // default to seconds - - /** - * The location of the current animation on the timeline. - * In time-based animations, this is used by AnimMgr to ensure the animation finishes on time. - * @property currentFrame - * @type Int - */ - this.currentFrame = 0; - - /** - * The total number of frames to be executed. - * In time-based animations, this is used by AnimMgr to ensure the animation finishes on time. - * @property totalFrames - * @type Int - */ - this.totalFrames = Y.AnimMgr.fps; - - /** - * Changes the animated element - * @method setEl - */ - this.setEl = function(element) { - el = Y.Dom.get(element); - }; - - /** - * Returns a reference to the animated element. - * @method getEl - * @return {HTMLElement} - */ - this.getEl = function() { return el; }; - - /** - * Checks whether the element is currently animated. - * @method isAnimated - * @return {Boolean} current value of isAnimated. - */ - this.isAnimated = function() { - return isAnimated; - }; - - /** - * Returns the animation start time. - * @method getStartTime - * @return {Date} current value of startTime. - */ - this.getStartTime = function() { - return startTime; - }; - - this.runtimeAttributes = {}; - - var logger = {}; - logger.log = function() {YAHOO.log.apply(window, arguments)}; - - logger.log('creating new instance of ' + this); - - /** - * Starts the animation by registering it with the animation manager. - * @method animate - */ - this.animate = function() { - if ( this.isAnimated() ) { - return false; - } - - this.currentFrame = 0; - - this.totalFrames = ( this.useSeconds ) ? Math.ceil(Y.AnimMgr.fps * this.duration) : this.duration; - - if (this.duration === 0 && this.useSeconds) { // jump to last frame if zero second duration - this.totalFrames = 1; - } - Y.AnimMgr.registerElement(this); - return true; - }; - - /** - * Stops the animation. Normally called by AnimMgr when animation completes. - * @method stop - * @param {Boolean} finish (optional) If true, animation will jump to final frame. - */ - this.stop = function(finish) { - if (!this.isAnimated()) { // nothing to stop - return false; - } - - if (finish) { - this.currentFrame = this.totalFrames; - this._onTween.fire(); - } - Y.AnimMgr.stop(this); - }; - - var onStart = function() { - this.onStart.fire(); - - this.runtimeAttributes = {}; - for (var attr in this.attributes) { - this.setRuntimeAttribute(attr); - } - - isAnimated = true; - actualFrames = 0; - startTime = new Date(); - }; - - /** - * Feeds the starting and ending values for each animated attribute to doMethod once per frame, then applies the resulting value to the attribute(s). - * @private - */ - - var onTween = function() { - var data = { - duration: new Date() - this.getStartTime(), - currentFrame: this.currentFrame - }; - - data.toString = function() { - return ( - 'duration: ' + data.duration + - ', currentFrame: ' + data.currentFrame - ); - }; - - this.onTween.fire(data); - - var runtimeAttributes = this.runtimeAttributes; - - for (var attr in runtimeAttributes) { - this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit); - } - - actualFrames += 1; - }; - - var onComplete = function() { - var actual_duration = (new Date() - startTime) / 1000 ; - - var data = { - duration: actual_duration, - frames: actualFrames, - fps: actualFrames / actual_duration - }; - - data.toString = function() { - return ( - 'duration: ' + data.duration + - ', frames: ' + data.frames + - ', fps: ' + data.fps - ); - }; - - isAnimated = false; - actualFrames = 0; - this.onComplete.fire(data); - }; - - /** - * Custom event that fires after onStart, useful in subclassing - * @private - */ - this._onStart = new Y.CustomEvent('_start', this, true); - - /** - * Custom event that fires when animation begins - * Listen via subscribe method (e.g. myAnim.onStart.subscribe(someFunction) - * @event onStart - */ - this.onStart = new Y.CustomEvent('start', this); - - /** - * Custom event that fires between each frame - * Listen via subscribe method (e.g. myAnim.onTween.subscribe(someFunction) - * @event onTween - */ - this.onTween = new Y.CustomEvent('tween', this); - - /** - * Custom event that fires after onTween - * @private - */ - this._onTween = new Y.CustomEvent('_tween', this, true); - - /** - * Custom event that fires when animation ends - * Listen via subscribe method (e.g. myAnim.onComplete.subscribe(someFunction) - * @event onComplete - */ - this.onComplete = new Y.CustomEvent('complete', this); - /** - * Custom event that fires after onComplete - * @private - */ - this._onComplete = new Y.CustomEvent('_complete', this, true); - - this._onStart.subscribe(onStart); - this._onTween.subscribe(onTween); - this._onComplete.subscribe(onComplete); - } -}; - - Y.Anim = Anim; -})(); -/** - * Handles animation queueing and threading. - * Used by Anim and subclasses. - * @class AnimMgr - * @namespace YAHOO.util - */ -YAHOO.util.AnimMgr = new function() { - /** - * Reference to the animation Interval. - * @property thread - * @private - * @type Int - */ - var thread = null; - - /** - * The current queue of registered animation objects. - * @property queue - * @private - * @type Array - */ - var queue = []; - - /** - * The number of active animations. - * @property tweenCount - * @private - * @type Int - */ - var tweenCount = 0; - - /** - * Base frame rate (frames per second). - * Arbitrarily high for better x-browser calibration (slower browsers drop more frames). - * @property fps - * @type Int - * - */ - this.fps = 1000; - - /** - * Interval delay in milliseconds, defaults to fastest possible. - * @property delay - * @type Int - * - */ - this.delay = 1; - - /** - * Adds an animation instance to the animation queue. - * All animation instances must be registered in order to animate. - * @method registerElement - * @param {object} tween The Anim instance to be be registered - */ - this.registerElement = function(tween) { - queue[queue.length] = tween; - tweenCount += 1; - tween._onStart.fire(); - this.start(); - }; - - /** - * removes an animation instance from the animation queue. - * All animation instances must be registered in order to animate. - * @method unRegister - * @param {object} tween The Anim instance to be be registered - * @param {Int} index The index of the Anim instance - * @private - */ - this.unRegister = function(tween, index) { - index = index || getIndex(tween); - if (!tween.isAnimated() || index == -1) { - return false; - } - - tween._onComplete.fire(); - queue.splice(index, 1); - - tweenCount -= 1; - if (tweenCount <= 0) { - this.stop(); - } - - return true; - }; - - /** - * Starts the animation thread. - * Only one thread can run at a time. - * @method start - */ - this.start = function() { - if (thread === null) { - thread = setInterval(this.run, this.delay); - } - }; - - /** - * Stops the animation thread or a specific animation instance. - * @method stop - * @param {object} tween A specific Anim instance to stop (optional) - * If no instance given, Manager stops thread and all animations. - */ - this.stop = function(tween) { - if (!tween) { - clearInterval(thread); - - for (var i = 0, len = queue.length; i < len; ++i) { - this.unRegister(queue[0], 0); - } - - queue = []; - thread = null; - tweenCount = 0; - } - else { - this.unRegister(tween); - } - }; - - /** - * Called per Interval to handle each animation frame. - * @method run - */ - this.run = function() { - for (var i = 0, len = queue.length; i < len; ++i) { - var tween = queue[i]; - if ( !tween || !tween.isAnimated() ) { continue; } - - if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null) - { - tween.currentFrame += 1; - - if (tween.useSeconds) { - correctFrame(tween); - } - tween._onTween.fire(); - } - else { YAHOO.util.AnimMgr.stop(tween, i); } - } - }; - - var getIndex = function(anim) { - for (var i = 0, len = queue.length; i < len; ++i) { - if (queue[i] == anim) { - return i; // note return; - } - } - return -1; - }; - - /** - * On the fly frame correction to keep animation on time. - * @method correctFrame - * @private - * @param {Object} tween The Anim instance being corrected. - */ - var correctFrame = function(tween) { - var frames = tween.totalFrames; - var frame = tween.currentFrame; - var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames); - var elapsed = (new Date() - tween.getStartTime()); - var tweak = 0; - - if (elapsed < tween.duration * 1000) { // check if falling behind - tweak = Math.round((elapsed / expected - 1) * tween.currentFrame); - } else { // went over duration, so jump to end - tweak = frames - (frame + 1); - } - if (tweak > 0 && isFinite(tweak)) { // adjust if needed - if (tween.currentFrame + tweak >= frames) {// dont go past last frame - tweak = frames - (frame + 1); - } - - tween.currentFrame += tweak; - } - }; -}; -/** - * Used to calculate Bezier splines for any number of control points. - * @class Bezier - * @namespace YAHOO.util - * - */ -YAHOO.util.Bezier = new function() { - /** - * Get the current position of the animated element based on t. - * Each point is an array of "x" and "y" values (0 = x, 1 = y) - * At least 2 points are required (start and end). - * First point is start. Last point is end. - * Additional control points are optional. - * @method getPosition - * @param {Array} points An array containing Bezier points - * @param {Number} t A number between 0 and 1 which is the basis for determining current position - * @return {Array} An array containing int x and y member data - */ - this.getPosition = function(points, t) { - var n = points.length; - var tmp = []; - - for (var i = 0; i < n; ++i){ - tmp[i] = [points[i][0], points[i][1]]; // save input - } - - for (var j = 1; j < n; ++j) { - for (i = 0; i < n - j; ++i) { - tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0]; - tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1]; - } - } - - return [ tmp[0][0], tmp[0][1] ]; - - }; -}; -(function() { -/** - * Anim subclass for color transitions. - *Usage: var myAnim = new Y.ColorAnim(el, { backgroundColor: { from: '#FF0000', to: '#FFFFFF' } }, 1, Y.Easing.easeOut);
Color values can be specified with either 112233, #112233,
- * [255,255,255], or rgb(255,255,255)
Usage: var myAnim = new YAHOO.util.Motion(el, { points: { to: [800, 800] } }, 1, YAHOO.util.Easing.easeOut);
Usage: var myAnim = new YAHOO.util.Scroll(el, { scroll: { to: [0, 800] } }, 1, YAHOO.util.Easing.easeOut);
Usage: var myAnim = new YAHOO.util.Anim(el, { width: { from: 10, to: 100 } }, 1, YAHOO.util.Easing.easeOut);
- * @class Anim - * @namespace YAHOO.util - * @requires YAHOO.util.AnimMgr - * @requires YAHOO.util.Easing - * @requires YAHOO.util.Dom - * @requires YAHOO.util.Event - * @requires YAHOO.util.CustomEvent - * @constructor - * @param {String | HTMLElement} el Reference to the element that will be animated - * @param {Object} attributes The attribute(s) to be animated. - * Each attribute is an object with at minimum a "to" or "by" member defined. - * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). - * All attribute names use camelCase. - * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based - * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) - */ - -var Anim = function(el, attributes, duration, method) { - if (!el) { - } - this.init(el, attributes, duration, method); -}; - -Anim.NAME = 'Anim'; - -Anim.prototype = { - /** - * Provides a readable name for the Anim instance. - * @method toString - * @return {String} - */ - toString: function() { - var el = this.getEl() || {}; - var id = el.id || el.tagName; - return (this.constructor.NAME + ': ' + id); - }, - - patterns: { // cached for performance - noNegatives: /width|height|opacity|padding/i, // keep at zero or above - offsetAttribute: /^((width|height)|(top|left))$/, // use offsetValue as default - defaultUnit: /width|height|top$|bottom$|left$|right$/i, // use 'px' by default - offsetUnit: /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i // IE may return these, so convert these to offset - }, - - /** - * Returns the value computed by the animation's "method". - * @method doMethod - * @param {String} attr The name of the attribute. - * @param {Number} start The value this attribute should start from for this animation. - * @param {Number} end The value this attribute should end at for this animation. - * @return {Number} The Value to be applied to the attribute. - */ - doMethod: function(attr, start, end) { - return this.method(this.currentFrame, start, end - start, this.totalFrames); - }, - - /** - * Applies a value to an attribute. - * @method setAttribute - * @param {String} attr The name of the attribute. - * @param {Number} val The value to be applied to the attribute. - * @param {String} unit The unit ('px', '%', etc.) of the value. - */ - setAttribute: function(attr, val, unit) { - var el = this.getEl(); - if ( this.patterns.noNegatives.test(attr) ) { - val = (val > 0) ? val : 0; - } - - if ('style' in el) { - Y.Dom.setStyle(el, attr, val + unit); - } else if (attr in el) { - el[attr] = val; - } - }, - - /** - * Returns current value of the attribute. - * @method getAttribute - * @param {String} attr The name of the attribute. - * @return {Number} val The current value of the attribute. - */ - getAttribute: function(attr) { - var el = this.getEl(); - var val = Y.Dom.getStyle(el, attr); - - if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) { - return parseFloat(val); - } - - var a = this.patterns.offsetAttribute.exec(attr) || []; - var pos = !!( a[3] ); // top or left - var box = !!( a[2] ); // width or height - - if ('style' in el) { - // use offsets for width/height and abs pos top/left - if ( box || (Y.Dom.getStyle(el, 'position') == 'absolute' && pos) ) { - val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)]; - } else { // default to zero for other 'auto' - val = 0; - } - } else if (attr in el) { - val = el[attr]; - } - - return val; - }, - - /** - * Returns the unit to use when none is supplied. - * @method getDefaultUnit - * @param {attr} attr The name of the attribute. - * @return {String} The default unit to be used. - */ - getDefaultUnit: function(attr) { - if ( this.patterns.defaultUnit.test(attr) ) { - return 'px'; - } - - return ''; - }, - - /** - * Sets the actual values to be used during the animation. Should only be needed for subclass use. - * @method setRuntimeAttribute - * @param {Object} attr The attribute object - * @private - */ - setRuntimeAttribute: function(attr) { - var start; - var end; - var attributes = this.attributes; - - this.runtimeAttributes[attr] = {}; - - var isset = function(prop) { - return (typeof prop !== 'undefined'); - }; - - if ( !isset(attributes[attr]['to']) && !isset(attributes[attr]['by']) ) { - return false; // note return; nothing to animate to - } - - start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr); - - // To beats by, per SMIL 2.1 spec - if ( isset(attributes[attr]['to']) ) { - end = attributes[attr]['to']; - } else if ( isset(attributes[attr]['by']) ) { - if (start.constructor == Array) { - end = []; - for (var i = 0, len = start.length; i < len; ++i) { - end[i] = start[i] + attributes[attr]['by'][i] * 1; // times 1 to cast "by" - } - } else { - end = start + attributes[attr]['by'] * 1; - } - } - - this.runtimeAttributes[attr].start = start; - this.runtimeAttributes[attr].end = end; - - // set units if needed - this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? - attributes[attr]['unit'] : this.getDefaultUnit(attr); - return true; - }, - - /** - * Constructor for Anim instance. - * @method init - * @param {String | HTMLElement} el Reference to the element that will be animated - * @param {Object} attributes The attribute(s) to be animated. - * Each attribute is an object with at minimum a "to" or "by" member defined. - * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). - * All attribute names use camelCase. - * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based - * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) - */ - init: function(el, attributes, duration, method) { - /** - * Whether or not the animation is running. - * @property isAnimated - * @private - * @type Boolean - */ - var isAnimated = false; - - /** - * A Date object that is created when the animation begins. - * @property startTime - * @private - * @type Date - */ - var startTime = null; - - /** - * The number of frames this animation was able to execute. - * @property actualFrames - * @private - * @type Int - */ - var actualFrames = 0; - - /** - * The element to be animated. - * @property el - * @private - * @type HTMLElement - */ - el = Y.Dom.get(el); - - /** - * The collection of attributes to be animated. - * Each attribute must have at least a "to" or "by" defined in order to animate. - * If "to" is supplied, the animation will end with the attribute at that value. - * If "by" is supplied, the animation will end at that value plus its starting value. - * If both are supplied, "to" is used, and "by" is ignored. - * Optional additional member include "from" (the value the attribute should start animating from, defaults to current value), and "unit" (the units to apply to the values). - * @property attributes - * @type Object - */ - this.attributes = attributes || {}; - - /** - * The length of the animation. Defaults to "1" (second). - * @property duration - * @type Number - */ - this.duration = !YAHOO.lang.isUndefined(duration) ? duration : 1; - - /** - * The method that will provide values to the attribute(s) during the animation. - * Defaults to "YAHOO.util.Easing.easeNone". - * @property method - * @type Function - */ - this.method = method || Y.Easing.easeNone; - - /** - * Whether or not the duration should be treated as seconds. - * Defaults to true. - * @property useSeconds - * @type Boolean - */ - this.useSeconds = true; // default to seconds - - /** - * The location of the current animation on the timeline. - * In time-based animations, this is used by AnimMgr to ensure the animation finishes on time. - * @property currentFrame - * @type Int - */ - this.currentFrame = 0; - - /** - * The total number of frames to be executed. - * In time-based animations, this is used by AnimMgr to ensure the animation finishes on time. - * @property totalFrames - * @type Int - */ - this.totalFrames = Y.AnimMgr.fps; - - /** - * Changes the animated element - * @method setEl - */ - this.setEl = function(element) { - el = Y.Dom.get(element); - }; - - /** - * Returns a reference to the animated element. - * @method getEl - * @return {HTMLElement} - */ - this.getEl = function() { return el; }; - - /** - * Checks whether the element is currently animated. - * @method isAnimated - * @return {Boolean} current value of isAnimated. - */ - this.isAnimated = function() { - return isAnimated; - }; - - /** - * Returns the animation start time. - * @method getStartTime - * @return {Date} current value of startTime. - */ - this.getStartTime = function() { - return startTime; - }; - - this.runtimeAttributes = {}; - - - - /** - * Starts the animation by registering it with the animation manager. - * @method animate - */ - this.animate = function() { - if ( this.isAnimated() ) { - return false; - } - - this.currentFrame = 0; - - this.totalFrames = ( this.useSeconds ) ? Math.ceil(Y.AnimMgr.fps * this.duration) : this.duration; - - if (this.duration === 0 && this.useSeconds) { // jump to last frame if zero second duration - this.totalFrames = 1; - } - Y.AnimMgr.registerElement(this); - return true; - }; - - /** - * Stops the animation. Normally called by AnimMgr when animation completes. - * @method stop - * @param {Boolean} finish (optional) If true, animation will jump to final frame. - */ - this.stop = function(finish) { - if (!this.isAnimated()) { // nothing to stop - return false; - } - - if (finish) { - this.currentFrame = this.totalFrames; - this._onTween.fire(); - } - Y.AnimMgr.stop(this); - }; - - var onStart = function() { - this.onStart.fire(); - - this.runtimeAttributes = {}; - for (var attr in this.attributes) { - this.setRuntimeAttribute(attr); - } - - isAnimated = true; - actualFrames = 0; - startTime = new Date(); - }; - - /** - * Feeds the starting and ending values for each animated attribute to doMethod once per frame, then applies the resulting value to the attribute(s). - * @private - */ - - var onTween = function() { - var data = { - duration: new Date() - this.getStartTime(), - currentFrame: this.currentFrame - }; - - data.toString = function() { - return ( - 'duration: ' + data.duration + - ', currentFrame: ' + data.currentFrame - ); - }; - - this.onTween.fire(data); - - var runtimeAttributes = this.runtimeAttributes; - - for (var attr in runtimeAttributes) { - this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit); - } - - actualFrames += 1; - }; - - var onComplete = function() { - var actual_duration = (new Date() - startTime) / 1000 ; - - var data = { - duration: actual_duration, - frames: actualFrames, - fps: actualFrames / actual_duration - }; - - data.toString = function() { - return ( - 'duration: ' + data.duration + - ', frames: ' + data.frames + - ', fps: ' + data.fps - ); - }; - - isAnimated = false; - actualFrames = 0; - this.onComplete.fire(data); - }; - - /** - * Custom event that fires after onStart, useful in subclassing - * @private - */ - this._onStart = new Y.CustomEvent('_start', this, true); - - /** - * Custom event that fires when animation begins - * Listen via subscribe method (e.g. myAnim.onStart.subscribe(someFunction) - * @event onStart - */ - this.onStart = new Y.CustomEvent('start', this); - - /** - * Custom event that fires between each frame - * Listen via subscribe method (e.g. myAnim.onTween.subscribe(someFunction) - * @event onTween - */ - this.onTween = new Y.CustomEvent('tween', this); - - /** - * Custom event that fires after onTween - * @private - */ - this._onTween = new Y.CustomEvent('_tween', this, true); - - /** - * Custom event that fires when animation ends - * Listen via subscribe method (e.g. myAnim.onComplete.subscribe(someFunction) - * @event onComplete - */ - this.onComplete = new Y.CustomEvent('complete', this); - /** - * Custom event that fires after onComplete - * @private - */ - this._onComplete = new Y.CustomEvent('_complete', this, true); - - this._onStart.subscribe(onStart); - this._onTween.subscribe(onTween); - this._onComplete.subscribe(onComplete); - } -}; - - Y.Anim = Anim; -})(); -/** - * Handles animation queueing and threading. - * Used by Anim and subclasses. - * @class AnimMgr - * @namespace YAHOO.util - */ -YAHOO.util.AnimMgr = new function() { - /** - * Reference to the animation Interval. - * @property thread - * @private - * @type Int - */ - var thread = null; - - /** - * The current queue of registered animation objects. - * @property queue - * @private - * @type Array - */ - var queue = []; - - /** - * The number of active animations. - * @property tweenCount - * @private - * @type Int - */ - var tweenCount = 0; - - /** - * Base frame rate (frames per second). - * Arbitrarily high for better x-browser calibration (slower browsers drop more frames). - * @property fps - * @type Int - * - */ - this.fps = 1000; - - /** - * Interval delay in milliseconds, defaults to fastest possible. - * @property delay - * @type Int - * - */ - this.delay = 1; - - /** - * Adds an animation instance to the animation queue. - * All animation instances must be registered in order to animate. - * @method registerElement - * @param {object} tween The Anim instance to be be registered - */ - this.registerElement = function(tween) { - queue[queue.length] = tween; - tweenCount += 1; - tween._onStart.fire(); - this.start(); - }; - - /** - * removes an animation instance from the animation queue. - * All animation instances must be registered in order to animate. - * @method unRegister - * @param {object} tween The Anim instance to be be registered - * @param {Int} index The index of the Anim instance - * @private - */ - this.unRegister = function(tween, index) { - index = index || getIndex(tween); - if (!tween.isAnimated() || index == -1) { - return false; - } - - tween._onComplete.fire(); - queue.splice(index, 1); - - tweenCount -= 1; - if (tweenCount <= 0) { - this.stop(); - } - - return true; - }; - - /** - * Starts the animation thread. - * Only one thread can run at a time. - * @method start - */ - this.start = function() { - if (thread === null) { - thread = setInterval(this.run, this.delay); - } - }; - - /** - * Stops the animation thread or a specific animation instance. - * @method stop - * @param {object} tween A specific Anim instance to stop (optional) - * If no instance given, Manager stops thread and all animations. - */ - this.stop = function(tween) { - if (!tween) { - clearInterval(thread); - - for (var i = 0, len = queue.length; i < len; ++i) { - this.unRegister(queue[0], 0); - } - - queue = []; - thread = null; - tweenCount = 0; - } - else { - this.unRegister(tween); - } - }; - - /** - * Called per Interval to handle each animation frame. - * @method run - */ - this.run = function() { - for (var i = 0, len = queue.length; i < len; ++i) { - var tween = queue[i]; - if ( !tween || !tween.isAnimated() ) { continue; } - - if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null) - { - tween.currentFrame += 1; - - if (tween.useSeconds) { - correctFrame(tween); - } - tween._onTween.fire(); - } - else { YAHOO.util.AnimMgr.stop(tween, i); } - } - }; - - var getIndex = function(anim) { - for (var i = 0, len = queue.length; i < len; ++i) { - if (queue[i] == anim) { - return i; // note return; - } - } - return -1; - }; - - /** - * On the fly frame correction to keep animation on time. - * @method correctFrame - * @private - * @param {Object} tween The Anim instance being corrected. - */ - var correctFrame = function(tween) { - var frames = tween.totalFrames; - var frame = tween.currentFrame; - var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames); - var elapsed = (new Date() - tween.getStartTime()); - var tweak = 0; - - if (elapsed < tween.duration * 1000) { // check if falling behind - tweak = Math.round((elapsed / expected - 1) * tween.currentFrame); - } else { // went over duration, so jump to end - tweak = frames - (frame + 1); - } - if (tweak > 0 && isFinite(tweak)) { // adjust if needed - if (tween.currentFrame + tweak >= frames) {// dont go past last frame - tweak = frames - (frame + 1); - } - - tween.currentFrame += tweak; - } - }; -}; -/** - * Used to calculate Bezier splines for any number of control points. - * @class Bezier - * @namespace YAHOO.util - * - */ -YAHOO.util.Bezier = new function() { - /** - * Get the current position of the animated element based on t. - * Each point is an array of "x" and "y" values (0 = x, 1 = y) - * At least 2 points are required (start and end). - * First point is start. Last point is end. - * Additional control points are optional. - * @method getPosition - * @param {Array} points An array containing Bezier points - * @param {Number} t A number between 0 and 1 which is the basis for determining current position - * @return {Array} An array containing int x and y member data - */ - this.getPosition = function(points, t) { - var n = points.length; - var tmp = []; - - for (var i = 0; i < n; ++i){ - tmp[i] = [points[i][0], points[i][1]]; // save input - } - - for (var j = 1; j < n; ++j) { - for (i = 0; i < n - j; ++i) { - tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0]; - tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1]; - } - } - - return [ tmp[0][0], tmp[0][1] ]; - - }; -}; -(function() { -/** - * Anim subclass for color transitions. - *Usage: var myAnim = new Y.ColorAnim(el, { backgroundColor: { from: '#FF0000', to: '#FFFFFF' } }, 1, Y.Easing.easeOut);
Color values can be specified with either 112233, #112233,
- * [255,255,255], or rgb(255,255,255)
Usage: var myAnim = new YAHOO.util.Motion(el, { points: { to: [800, 800] } }, 1, YAHOO.util.Easing.easeOut);
Usage: var myAnim = new YAHOO.util.Scroll(el, { scroll: { to: [0, 800] } }, 1, YAHOO.util.Easing.easeOut);
The Button Control supports the following types:
-*<input>
, <button>
,
- * <a>
, or <span>
element to
- * be used to create the button.
- * @param {HTMLInputElement|
- * HTMLButtonElement|HTMLElement} p_oElement Object reference for the
- * <input>
, <button>
,
- * <a>
, or <span>
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 <input>
element of the
- * specified type.
- * @private
- * @param {String} p_sType String specifying the type of
- * <input>
element to create.
- * @param {String} p_sName String specifying the name of
- * <input>
element to create.
- * @param {String} p_sValue String specifying the value of
- * <input>
element to create.
- * @param {String} p_bChecked Boolean specifying if the
- * <input>
element is to be checked.
- * @return {HTMLInputElement}
- */
- 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 = "";
-
- 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 <input>
or <a>
) that
- * map to Button configuration attributes and sets them into a collection
- * that is passed to the Button constructor.
- * @private
- * @param {HTMLInputElement|HTMLAnchorElement} p_oElement Object reference to the HTML
- * element (either <input>
or <span>
- *
) 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 <button>
for the value attribute
- rather than the value of the "value" attribute.
- */
-
- oAttribute = p_oElement.getAttributeNode(p_sAttribute);
-
-
- if (oAttribute && ("value" in oAttribute)) {
-
- YAHOO.log("Setting attribute \"" + p_sAttribute +
- "\" using source element's attribute value of \"" +
- oAttribute.value + "\"", "info", me.toString());
-
- 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();
-
- YAHOO.log("No value specified for the button's \"id\" " +
- "attribute. Setting button id to \"" + p_oElement.id +
- "\".", "info", this.toString());
-
- }
-
- YAHOO.log("No source HTML element. Building the button " +
- "using the set of configuration attributes.", "info", this.toString());
-
- 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;
-
- }
-
- YAHOO.log("Building the button using an existing " +
- "HTML element as a source element.", "info", this.toString());
-
-
- oConfig.attributes.srcelement = oElement;
-
- initConfig.call(this, oConfig);
-
-
- if (!oConfig.element) {
-
- YAHOO.log("Source element could not be used " +
- "as is. Creating a new HTML element for " +
- "the button.", "info", this.toString());
-
- 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();
-
- YAHOO.log("No value specified for the button's " +
- "\"id\" attribute. Setting button id to \"" +
- oConfig.attributes.id + "\".", "info", this.toString());
-
- }
-
- }
-
- YAHOO.log("Building the button using an existing HTML " +
- "element as a source element.", "info", this.toString());
-
-
- oConfig.attributes.srcelement = p_oElement;
-
- initConfig.call(this, oConfig);
-
-
- if (!oConfig.element) {
-
- YAHOO.log("Source element could not be used as is." +
- " Creating a new HTML element for the button.",
- "info", this.toString());
-
- 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
- * <a>
or <button>
element.
- * @default null
- * @protected
- * @type HTMLAnchorElement|HTMLButtonElement
- */
- _button: null,
-
-
- /**
- * @property _menu
- * @description Object reference to the button's menu.
- * @default null
- * @protected
- * @type {YAHOO.widget.Overlay|
- * YAHOO.widget.Menu}
- */
- _menu: null,
-
-
- /**
- * @property _hiddenFields
- * @description Object reference to the <input>
- * element, or array of HTML form elements used to represent the button
- * when its parent form is submitted.
- * @default null
- * @protected
- * @type HTMLInputElement|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,
-
-
- /**
- * @property _nOptionRegionX
- * @description Number representing the X coordinate of the leftmost edge of the Button's
- * option region. Applies only to Buttons of type "split".
- * @default 0
- * @protected
- * @type Number
- */
- _nOptionRegionX: 0,
-
-
-
- // 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 down arrow key 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 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;
-
- }
-
-
- if (!this._hasDefaultTitle) {
-
- 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;
-
-
- function onAppendTo() {
-
- oMenu.render(oButtonElement.parentNode);
-
- this.removeListener("appendTo", onAppendTo);
-
- }
-
-
- function setMenuContainer() {
-
- oMenu.cfg.queueProperty("container", oButtonElement.parentNode);
-
- this.removeListener("appendTo", setMenuContainer);
-
- }
-
-
- function initMenu() {
-
- var oContainer;
-
- 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) {
-
- if (bLazyLoad) {
-
- oContainer = this.get("container");
-
- if (oContainer) {
-
- oMenu.cfg.queueProperty("container", oContainer);
-
- }
- else {
-
- this.on("appendTo", setMenuContainer);
-
- }
-
- }
-
- oMenu.cfg.queueProperty("clicktohide", false);
-
- oMenu.keyDownEvent.subscribe(this._onMenuKeyDown, this, true);
- oMenu.subscribe("click", this._onMenuClick, this, true);
-
- this.on("selectedMenuItemChange", this._onSelectedMenuItemChange);
-
- 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 && !bLazyLoad) {
-
- if (Dom.inDocument(oButtonElement)) {
-
- oMenu.render(oButtonElement.parentNode);
-
- }
- else {
-
- this.on("appendTo", onAppendTo);
-
- }
-
- }
-
- }
-
- }
-
-
- if (Overlay) {
-
- if (Menu) {
-
- sMenuCSSClassName = Menu.prototype.CSS_CLASS_NAME;
-
- }
-
- if (p_oMenu && Menu && (p_oMenu instanceof Menu)) {
-
- oMenu = p_oMenu;
- bInstance = true;
-
- initMenu.call(this);
-
- }
- else if (Overlay && p_oMenu && (p_oMenu instanceof Overlay)) {
-
- oMenu = p_oMenu;
- bInstance = true;
-
- oMenu.cfg.queueProperty("visible", false);
-
- initMenu.call(this);
-
- }
- else if (Menu && Lang.isArray(p_oMenu)) {
-
- oMenu = new Menu(Dom.generateId(), { lazyload: bLazyLoad, itemdata: p_oMenu });
-
- this._menu = oMenu;
-
- this.on("appendTo", initMenu);
-
- }
- 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 });
-
- 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 });
-
- 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;
-
- }
-
- },
-
-
-
- // 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,
- bReturnVal = false,
- i;
-
-
- if (nKeyCodes > 0) {
-
- i = nKeyCodes - 1;
-
- do {
-
- if (p_nKeyCode == aKeyCodes[i]) {
-
- bReturnVal = true;
- break;
-
- }
-
- }
- while (i--);
-
- }
-
- return bReturnVal;
-
- },
-
-
- /**
- * @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 = (Event.getCharCode(p_oEvent) == 40);
-
-
- var onKeyPress = function (p_oEvent) {
-
- Event.preventDefault(p_oEvent);
-
- this.removeListener("keypress", onKeyPress);
-
- };
-
-
- // Prevent the browser from scrolling the window
- if (bShowMenu) {
-
- if (UA.opera) {
-
- this.on("keypress", onKeyPress);
-
- }
-
- Event.preventDefault(p_oEvent);
- }
-
- 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._onFormSubmit, 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 oMenu = this._menu,
- aMenuAlignment = this.get("menualignment"),
- bFocusMenu = this.get("focusmenu"),
- fnFocusMethod;
-
-
- if (this._renderedMenu) {
-
- oMenu.cfg.setProperty("context",
- [this.get("element"), aMenuAlignment[0], aMenuAlignment[1]]);
-
- oMenu.cfg.setProperty("preventcontextoverlap", true);
- oMenu.cfg.setProperty("constraintoviewport", true);
-
- }
- else {
-
- oMenu.cfg.queueProperty("context",
- [this.get("element"), aMenuAlignment[0], aMenuAlignment[1]]);
-
- oMenu.cfg.queueProperty("preventcontextoverlap", true);
- oMenu.cfg.queueProperty("constraintoviewport", true);
-
- }
-
-
- /*
- Refocus the Button before showing its Menu in case the call to
- YAHOO.widget.MenuManager.hideVisible() resulted in another element in the
- DOM being focused after another Menu was hidden.
- */
-
- this.focus();
-
-
- if (Menu && oMenu && (oMenu instanceof Menu)) {
-
- // Since Menus automatically focus themselves when made visible, temporarily
- // replace the Menu focus method so that the value of the Button's "focusmenu"
- // attribute determines if the Menu should be focus when made visible.
-
- fnFocusMethod = oMenu.focus;
-
- oMenu.focus = function () {};
-
- if (this._renderedMenu) {
-
- oMenu.cfg.setProperty("minscrollheight", this.get("menuminscrollheight"));
- oMenu.cfg.setProperty("maxheight", this.get("menumaxheight"));
-
- }
- else {
-
- oMenu.cfg.queueProperty("minscrollheight", this.get("menuminscrollheight"));
- oMenu.cfg.queueProperty("maxheight", this.get("menumaxheight"));
-
- }
-
-
- oMenu.show();
-
- oMenu.focus = fnFocusMethod;
-
- oMenu.align();
-
-
- /*
- 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);
- }
-
-
- if (bFocusMenu) {
- oMenu.focus();
- }
-
- }
- else if (Overlay && oMenu && (oMenu instanceof Overlay)) {
-
- if (!this._renderedMenu) {
- oMenu.render(this.get("element").parentNode);
- }
-
- oMenu.show();
- oMenu.align();
-
- }
-
- },
-
-
- /**
- * @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) {
-
- var sType = this.get("type"),
- oElement,
- nOptionRegionX;
-
-
- if (sType === "split") {
-
- oElement = this.get("element");
- nOptionRegionX =
- (Dom.getX(oElement) + (oElement.offsetWidth - this.OPTION_AREA_WIDTH));
-
- this._nOptionRegionX = nOptionRegionX;
-
- }
-
-
- if (!this._hasMouseEventHandlers) {
-
- if (sType === "split") {
-
- this.on("mousemove", this._onMouseMove);
-
- }
-
- this.on("mouseout", this._onMouseOut);
-
- this._hasMouseEventHandlers = true;
-
- }
-
-
- this.addStateCSSClasses("hover");
-
-
- if (sType === "split" && (Event.getPageX(p_oEvent) > nOptionRegionX)) {
-
- this.addStateCSSClasses("hoveroption");
-
- }
-
-
- if (this._activationButtonPressed) {
-
- this.addStateCSSClasses("active");
-
- }
-
-
- if (this._bOptionPressed) {
-
- this.addStateCSSClasses("activeoption");
-
- }
-
-
- if (this._activationButtonPressed || this._bOptionPressed) {
-
- Event.removeListener(document, "mouseup", this._onDocumentMouseUp);
-
- }
-
- },
-
-
- /**
- * @method _onMouseMove
- * @description "mousemove" 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).
- */
- _onMouseMove: function (p_oEvent) {
-
- var nOptionRegionX = this._nOptionRegionX;
-
- if (nOptionRegionX) {
-
- if (Event.getPageX(p_oEvent) > nOptionRegionX) {
-
- this.addStateCSSClasses("hoveroption");
-
- }
- else {
-
- this.removeStateCSSClasses("hoveroption");
-
- }
-
- }
-
- },
-
- /**
- * @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) {
-
- var sType = this.get("type");
-
- this.removeStateCSSClasses("hover");
-
-
- if (sType != "menu") {
-
- this.removeStateCSSClasses("active");
-
- }
-
-
- if (this._activationButtonPressed || this._bOptionPressed) {
-
- Event.on(document, "mouseup", this._onDocumentMouseUp, null, this);
-
- }
-
-
- if (sType === "split" && (Event.getPageX(p_oEvent) > this._nOptionRegionX)) {
-
- this.removeStateCSSClasses("hoveroption");
-
- }
-
- },
-
-
- /**
- * @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,
- bReturnVal = true;
-
-
- 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") {
-
- if (Event.getPageX(p_oEvent) > this._nOptionRegionX) {
-
- this.fireEvent("option", p_oEvent);
- bReturnVal = false;
-
- }
- 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") {
-
- this._hideMenuTimer = Lang.later(250, this, this.on, ["mouseup", onMouseUp]);
-
- }
-
- }
-
- return bReturnVal;
-
- },
-
-
- /**
- * @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"),
- oHideMenuTimer = this._hideMenuTimer,
- bReturnVal = true;
-
-
- if (oHideMenuTimer) {
-
- oHideMenuTimer.cancel();
-
- }
-
-
- if (sType == "checkbox" || sType == "radio") {
-
- this.set("checked", !(this.get("checked")));
-
- }
-
-
- this._activationButtonPressed = false;
-
-
- if (sType != "menu") {
-
- this.removeStateCSSClasses("active");
-
- }
-
-
- if (sType == "split" && Event.getPageX(p_oEvent) > this._nOptionRegionX) {
-
- bReturnVal = false;
-
- }
-
- return bReturnVal;
-
- },
-
-
- /**
- * @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,
- bReturnVal;
-
-
- switch (sType) {
-
- case "radio":
- case "checkbox":
-
- if (!this._hasDefaultTitle) {
-
- 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":
-
- if (p_oEvent.returnValue !== false) {
-
- 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":
-
- if (this._nOptionRegionX > 0 &&
- (Event.getPageX(p_oEvent) > this._nOptionRegionX)) {
-
- bReturnVal = false;
-
- }
- else {
-
- this._hideMenu();
-
- oSrcElement = this.get("srcelement");
-
- if (oSrcElement && oSrcElement.type == "submit" &&
- p_oEvent.returnValue !== false) {
-
- this.submitForm();
-
- }
-
- }
-
- sTitle = this._menu.cfg.getProperty("visible") ?
- this.SPLITBUTTON_OPTION_VISIBLE_TITLE :
- this.SPLITBUTTON_DEFAULT_TITLE;
-
- this.set("title", sTitle);
-
- break;
-
- }
-
- return bReturnVal;
-
- },
-
-
- /**
- * @method _onDblClick
- * @description "dblclick" 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).
- */
- _onDblClick: function (p_oEvent) {
-
- var bReturnVal = true;
-
- if (this.get("type") == "split" && Event.getPageX(p_oEvent) > this._nOptionRegionX) {
-
- bReturnVal = false;
-
- }
-
- return bReturnVal;
-
- },
-
-
- /**
- * @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.
- */
-
- Lang.later(0, this, this._addListenersToForm);
-
- },
-
-
- /**
- * @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 _onFormSubmit
- * @description "submit" 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).
- */
- _onFormSubmit: function (p_oEvent) {
-
- this.createHiddenFields();
-
- },
-
-
- /**
- * @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 _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,
- oMenu = this._menu,
- oMenuElement = oMenu.element,
- oSrcElement = oMenu.srcElement;
-
-
- if (oButtonParent != oMenuElement.parentNode) {
-
- oButtonParent.appendChild(oMenuElement);
-
- }
-
- this._renderedMenu = true;
-
- // If the user has designated an