From: nicolasconnault
Date: Fri, 3 Oct 2008 13:26:32 +0000 (+0000)
Subject: MDL-16784 Adding YUI 2.6.0
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=36af3d4cdf6f2b2ca851558e0074d38065f5a198;p=moodle.git
MDL-16784 Adding YUI 2.6.0
---
diff --git a/lib/yui/README.txt b/lib/yui/README.txt
index 7c891ccc12..d1e35ad849 100644
--- a/lib/yui/README.txt
+++ b/lib/yui/README.txt
@@ -10,5 +10,5 @@ Updated to YUI 0.12.0, 23 November 2006
Updated to YUI 0.12.1, 8 January 2007
Updated to YUI 0.12.2, 8 Febuary 2007
Updated to YUI 2.3.0, 3 August 2007
-Updated to YUI 2.5.0, 7 March 2008
Updated to YUI 2.5.2, 25 July 2008
+Updated to YUI 2.6.0, 03 October 2008
diff --git a/lib/yui/animation/README b/lib/yui/animation/README
new file mode 100755
index 0000000000..113994467d
--- /dev/null
+++ b/lib/yui/animation/README
@@ -0,0 +1,71 @@
+Animation Release Notes
+
+*** version 2.6.0 ***
+* ColorAnim updated to use getAncestorBy
+
+*** version 2.5.2 ***
+* no change
+
+*** version 2.5.1 ***
+* no change
+
+*** version 2.5.0 ***
+* replace toString overrides with static NAME property
+
+*** version 2.4.0 ***
+* calling stop() on an non-animated Anim no longer fires onComplete
+
+*** version 2.3.1 ***
+* no change
+
+*** version 2.3.0 ***
+
+* duration of zero now executes 1 frame animation
+* added setEl() method to enable reuse
+* fixed stop() for multiple animations
+
+*** version 2.3.0 ***
+* duration of zero now executes 1 frame animation
+* added setEl() method to enable reuse
+* fixed stop() for multiple animations
+
+*** version 2.2.2 ***
+* no change
+
+*** version 2.2.1 ***
+* no change
+
+*** version 2.2.0 ***
+* Fixed AnimMgr.stop() when called without tween
+
+*** version 0.12.2 ***
+* raised AnimMgr.fps to 1000
+
+*** version 0.12.1 ***
+* minified version no longer strips line breaks
+
+*** version 0.12.0 ***
+* added boolean finish argument to Anim.stop()
+
+*** version 0.11.3 ***
+* no changes
+
+*** version 0.11.1 ***
+* changed "prototype" shorthand to "proto" (workaround firefox < 1.5 scoping
+bug)
+
+*** version 0.11.0 ***
+* ColorAnim subclass added
+* Motion and Scroll now inherit from ColorAnim
+* getDefaultUnit method added
+* defaultUnit and defaultUnits deprecated
+* getDefault and setDefault methods deprecated
+
+*** version 0.10.0 ***
+* Scroll now handles relative ("by") animation correctly
+* Now converts "auto" values of "from" to appropriate initial values
+
+*** version 0.9.0 ***
+* Initial release
+
+
diff --git a/lib/yui/animation/animation-debug.js b/lib/yui/animation/animation-debug.js
new file mode 100755
index 0000000000..c85005d239
--- /dev/null
+++ b/lib/yui/animation/animation-debug.js
@@ -0,0 +1,1385 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.6.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) {
+ if ( this.patterns.noNegatives.test(attr) ) {
+ val = (val > 0) ? val : 0;
+ }
+
+ Y.Dom.setStyle(this.getEl(), attr, val + unit);
+ },
+
+ /**
+ * 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
+
+ // 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;
+ }
+
+ 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)
+ * @class ColorAnim
+ * @namespace YAHOO.util
+ * @requires YAHOO.util.Anim
+ * @requires YAHOO.util.AnimMgr
+ * @requires YAHOO.util.Easing
+ * @requires YAHOO.util.Bezier
+ * @requires YAHOO.util.Dom
+ * @requires YAHOO.util.Event
+ * @constructor
+ * @extends YAHOO.util.Anim
+ * @param {HTMLElement | String} 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 ColorAnim = function(el, attributes, duration, method) {
+ ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
+ };
+
+ ColorAnim.NAME = 'ColorAnim';
+
+ ColorAnim.DEFAULT_BGCOLOR = '#fff';
+ // shorthand
+ var Y = YAHOO.util;
+ YAHOO.extend(ColorAnim, Y.Anim);
+
+ var superclass = ColorAnim.superclass;
+ var proto = ColorAnim.prototype;
+
+ proto.patterns.color = /color$/i;
+ proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i;
+ proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;
+ proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;
+ proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/; // need rgba for safari
+
+ /**
+ * Attempts to parse the given string and return a 3-tuple.
+ * @method parseColor
+ * @param {String} s The string to parse.
+ * @return {Array} The 3-tuple of rgb values.
+ */
+ proto.parseColor = function(s) {
+ if (s.length == 3) { return s; }
+
+ var c = this.patterns.hex.exec(s);
+ if (c && c.length == 4) {
+ return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ];
+ }
+
+ c = this.patterns.rgb.exec(s);
+ if (c && c.length == 4) {
+ return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ];
+ }
+
+ c = this.patterns.hex3.exec(s);
+ if (c && c.length == 4) {
+ return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ];
+ }
+
+ return null;
+ };
+
+ proto.getAttribute = function(attr) {
+ var el = this.getEl();
+ if (this.patterns.color.test(attr) ) {
+ var val = YAHOO.util.Dom.getStyle(el, attr);
+
+ var that = this;
+ if (this.patterns.transparent.test(val)) { // bgcolor default
+ var parent = YAHOO.util.Dom.getAncestorBy(el, function(node) {
+ return !that.patterns.transparent.test(val);
+ });
+
+ if (parent) {
+ val = Y.Dom.getStyle(parent, attr);
+ } else {
+ val = ColorAnim.DEFAULT_BGCOLOR;
+ }
+ }
+ } else {
+ val = superclass.getAttribute.call(this, attr);
+ }
+
+ return val;
+ };
+
+ proto.doMethod = function(attr, start, end) {
+ var val;
+
+ if ( this.patterns.color.test(attr) ) {
+ val = [];
+ for (var i = 0, len = start.length; i < len; ++i) {
+ val[i] = superclass.doMethod.call(this, attr, start[i], end[i]);
+ }
+
+ val = 'rgb('+Math.floor(val[0])+','+Math.floor(val[1])+','+Math.floor(val[2])+')';
+ }
+ else {
+ val = superclass.doMethod.call(this, attr, start, end);
+ }
+
+ return val;
+ };
+
+ proto.setRuntimeAttribute = function(attr) {
+ superclass.setRuntimeAttribute.call(this, attr);
+
+ if ( this.patterns.color.test(attr) ) {
+ var attributes = this.attributes;
+ var start = this.parseColor(this.runtimeAttributes[attr].start);
+ var end = this.parseColor(this.runtimeAttributes[attr].end);
+ // fix colors if going "by"
+ if ( typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined' ) {
+ end = this.parseColor(attributes[attr].by);
+
+ for (var i = 0, len = start.length; i < len; ++i) {
+ end[i] = start[i] + end[i];
+ }
+ }
+
+ this.runtimeAttributes[attr].start = start;
+ this.runtimeAttributes[attr].end = end;
+ }
+ };
+
+ Y.ColorAnim = ColorAnim;
+})();
+/*!
+TERMS OF USE - EASING EQUATIONS
+Open source under the BSD License.
+Copyright 2001 Robert Penner All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/**
+ * Singleton that determines how an animation proceeds from start to end.
+ * @class Easing
+ * @namespace YAHOO.util
+*/
+
+YAHOO.util.Easing = {
+
+ /**
+ * Uniform speed between points.
+ * @method easeNone
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeNone: function (t, b, c, d) {
+ return c*t/d + b;
+ },
+
+ /**
+ * Begins slowly and accelerates towards end.
+ * @method easeIn
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeIn: function (t, b, c, d) {
+ return c*(t/=d)*t + b;
+ },
+
+ /**
+ * Begins quickly and decelerates towards end.
+ * @method easeOut
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeOut: function (t, b, c, d) {
+ return -c *(t/=d)*(t-2) + b;
+ },
+
+ /**
+ * Begins slowly and decelerates towards end.
+ * @method easeBoth
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeBoth: function (t, b, c, d) {
+ if ((t/=d/2) < 1) {
+ return c/2*t*t + b;
+ }
+
+ return -c/2 * ((--t)*(t-2) - 1) + b;
+ },
+
+ /**
+ * Begins slowly and accelerates towards end.
+ * @method easeInStrong
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeInStrong: function (t, b, c, d) {
+ return c*(t/=d)*t*t*t + b;
+ },
+
+ /**
+ * Begins quickly and decelerates towards end.
+ * @method easeOutStrong
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeOutStrong: function (t, b, c, d) {
+ return -c * ((t=t/d-1)*t*t*t - 1) + b;
+ },
+
+ /**
+ * Begins slowly and decelerates towards end.
+ * @method easeBothStrong
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeBothStrong: function (t, b, c, d) {
+ if ((t/=d/2) < 1) {
+ return c/2*t*t*t*t + b;
+ }
+
+ return -c/2 * ((t-=2)*t*t*t - 2) + b;
+ },
+
+ /**
+ * Snap in elastic effect.
+ * @method elasticIn
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @param {Number} a Amplitude (optional)
+ * @param {Number} p Period (optional)
+ * @return {Number} The computed value for the current animation frame
+ */
+
+ elasticIn: function (t, b, c, d, a, p) {
+ if (t == 0) {
+ return b;
+ }
+ if ( (t /= d) == 1 ) {
+ return b+c;
+ }
+ if (!p) {
+ p=d*.3;
+ }
+
+ if (!a || a < Math.abs(c)) {
+ a = c;
+ var s = p/4;
+ }
+ else {
+ var s = p/(2*Math.PI) * Math.asin (c/a);
+ }
+
+ return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
+ },
+
+ /**
+ * Snap out elastic effect.
+ * @method elasticOut
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @param {Number} a Amplitude (optional)
+ * @param {Number} p Period (optional)
+ * @return {Number} The computed value for the current animation frame
+ */
+ elasticOut: function (t, b, c, d, a, p) {
+ if (t == 0) {
+ return b;
+ }
+ if ( (t /= d) == 1 ) {
+ return b+c;
+ }
+ if (!p) {
+ p=d*.3;
+ }
+
+ if (!a || a < Math.abs(c)) {
+ a = c;
+ var s = p / 4;
+ }
+ else {
+ var s = p/(2*Math.PI) * Math.asin (c/a);
+ }
+
+ return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
+ },
+
+ /**
+ * Snap both elastic effect.
+ * @method elasticBoth
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @param {Number} a Amplitude (optional)
+ * @param {Number} p Period (optional)
+ * @return {Number} The computed value for the current animation frame
+ */
+ elasticBoth: function (t, b, c, d, a, p) {
+ if (t == 0) {
+ return b;
+ }
+
+ if ( (t /= d/2) == 2 ) {
+ return b+c;
+ }
+
+ if (!p) {
+ p = d*(.3*1.5);
+ }
+
+ if ( !a || a < Math.abs(c) ) {
+ a = c;
+ var s = p/4;
+ }
+ else {
+ var s = p/(2*Math.PI) * Math.asin (c/a);
+ }
+
+ if (t < 1) {
+ return -.5*(a*Math.pow(2,10*(t-=1)) *
+ Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
+ }
+ return a*Math.pow(2,-10*(t-=1)) *
+ Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
+ },
+
+
+ /**
+ * Backtracks slightly, then reverses direction and moves to end.
+ * @method backIn
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @param {Number} s Overshoot (optional)
+ * @return {Number} The computed value for the current animation frame
+ */
+ backIn: function (t, b, c, d, s) {
+ if (typeof s == 'undefined') {
+ s = 1.70158;
+ }
+ return c*(t/=d)*t*((s+1)*t - s) + b;
+ },
+
+ /**
+ * Overshoots end, then reverses and comes back to end.
+ * @method backOut
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @param {Number} s Overshoot (optional)
+ * @return {Number} The computed value for the current animation frame
+ */
+ backOut: function (t, b, c, d, s) {
+ if (typeof s == 'undefined') {
+ s = 1.70158;
+ }
+ return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
+ },
+
+ /**
+ * Backtracks slightly, then reverses direction, overshoots end,
+ * then reverses and comes back to end.
+ * @method backBoth
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @param {Number} s Overshoot (optional)
+ * @return {Number} The computed value for the current animation frame
+ */
+ backBoth: function (t, b, c, d, s) {
+ if (typeof s == 'undefined') {
+ s = 1.70158;
+ }
+
+ if ((t /= d/2 ) < 1) {
+ return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
+ }
+ return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
+ },
+
+ /**
+ * Bounce off of start.
+ * @method bounceIn
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ bounceIn: function (t, b, c, d) {
+ return c - YAHOO.util.Easing.bounceOut(d-t, 0, c, d) + b;
+ },
+
+ /**
+ * Bounces off end.
+ * @method bounceOut
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ bounceOut: function (t, b, c, d) {
+ if ((t/=d) < (1/2.75)) {
+ return c*(7.5625*t*t) + b;
+ } else if (t < (2/2.75)) {
+ return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
+ } else if (t < (2.5/2.75)) {
+ return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
+ }
+ return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
+ },
+
+ /**
+ * Bounces off start and end.
+ * @method bounceBoth
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ bounceBoth: function (t, b, c, d) {
+ if (t < d/2) {
+ return YAHOO.util.Easing.bounceIn(t*2, 0, c, d) * .5 + b;
+ }
+ return YAHOO.util.Easing.bounceOut(t*2-d, 0, c, d) * .5 + c*.5 + b;
+ }
+};
+
+(function() {
+/**
+ * Anim subclass for moving elements along a path defined by the "points"
+ * member of "attributes". All "points" are arrays with x, y coordinates.
+ *
Usage: var myAnim = new YAHOO.util.Motion(el, { points: { to: [800, 800] } }, 1, YAHOO.util.Easing.easeOut);
+ * @class Motion
+ * @namespace YAHOO.util
+ * @requires YAHOO.util.Anim
+ * @requires YAHOO.util.AnimMgr
+ * @requires YAHOO.util.Easing
+ * @requires YAHOO.util.Bezier
+ * @requires YAHOO.util.Dom
+ * @requires YAHOO.util.Event
+ * @requires YAHOO.util.CustomEvent
+ * @constructor
+ * @extends YAHOO.util.ColorAnim
+ * @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 Motion = function(el, attributes, duration, method) {
+ if (el) { // dont break existing subclasses not using YAHOO.extend
+ Motion.superclass.constructor.call(this, el, attributes, duration, method);
+ }
+ };
+
+
+ Motion.NAME = 'Motion';
+
+ // shorthand
+ var Y = YAHOO.util;
+ YAHOO.extend(Motion, Y.ColorAnim);
+
+ var superclass = Motion.superclass;
+ var proto = Motion.prototype;
+
+ proto.patterns.points = /^points$/i;
+
+ proto.setAttribute = function(attr, val, unit) {
+ if ( this.patterns.points.test(attr) ) {
+ unit = unit || 'px';
+ superclass.setAttribute.call(this, 'left', val[0], unit);
+ superclass.setAttribute.call(this, 'top', val[1], unit);
+ } else {
+ superclass.setAttribute.call(this, attr, val, unit);
+ }
+ };
+
+ proto.getAttribute = function(attr) {
+ if ( this.patterns.points.test(attr) ) {
+ var val = [
+ superclass.getAttribute.call(this, 'left'),
+ superclass.getAttribute.call(this, 'top')
+ ];
+ } else {
+ val = superclass.getAttribute.call(this, attr);
+ }
+
+ return val;
+ };
+
+ proto.doMethod = function(attr, start, end) {
+ var val = null;
+
+ if ( this.patterns.points.test(attr) ) {
+ var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100;
+ val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t);
+ } else {
+ val = superclass.doMethod.call(this, attr, start, end);
+ }
+ return val;
+ };
+
+ proto.setRuntimeAttribute = function(attr) {
+ if ( this.patterns.points.test(attr) ) {
+ var el = this.getEl();
+ var attributes = this.attributes;
+ var start;
+ var control = attributes['points']['control'] || [];
+ var end;
+ var i, len;
+
+ if (control.length > 0 && !(control[0] instanceof Array) ) { // could be single point or array of points
+ control = [control];
+ } else { // break reference to attributes.points.control
+ var tmp = [];
+ for (i = 0, len = control.length; i< len; ++i) {
+ tmp[i] = control[i];
+ }
+ control = tmp;
+ }
+
+ if (Y.Dom.getStyle(el, 'position') == 'static') { // default to relative
+ Y.Dom.setStyle(el, 'position', 'relative');
+ }
+
+ if ( isset(attributes['points']['from']) ) {
+ Y.Dom.setXY(el, attributes['points']['from']); // set position to from point
+ }
+ else { Y.Dom.setXY( el, Y.Dom.getXY(el) ); } // set it to current position
+
+ start = this.getAttribute('points'); // get actual top & left
+
+ // TO beats BY, per SMIL 2.1 spec
+ if ( isset(attributes['points']['to']) ) {
+ end = translateValues.call(this, attributes['points']['to'], start);
+
+ var pageXY = Y.Dom.getXY(this.getEl());
+ for (i = 0, len = control.length; i < len; ++i) {
+ control[i] = translateValues.call(this, control[i], start);
+ }
+
+
+ } else if ( isset(attributes['points']['by']) ) {
+ end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ];
+
+ for (i = 0, len = control.length; i < len; ++i) {
+ control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
+ }
+ }
+
+ this.runtimeAttributes[attr] = [start];
+
+ if (control.length > 0) {
+ this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control);
+ }
+
+ this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end;
+ }
+ else {
+ superclass.setRuntimeAttribute.call(this, attr);
+ }
+ };
+
+ var translateValues = function(val, start) {
+ var pageXY = Y.Dom.getXY(this.getEl());
+ val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ];
+
+ return val;
+ };
+
+ var isset = function(prop) {
+ return (typeof prop !== 'undefined');
+ };
+
+ Y.Motion = Motion;
+})();
+(function() {
+/**
+ * Anim subclass for scrolling elements to a position defined by the "scroll"
+ * member of "attributes". All "scroll" members are arrays with x, y scroll positions.
+ *
Usage: var myAnim = new YAHOO.util.Scroll(el, { scroll: { to: [0, 800] } }, 1, YAHOO.util.Easing.easeOut);
+ * @class Scroll
+ * @namespace YAHOO.util
+ * @requires YAHOO.util.Anim
+ * @requires YAHOO.util.AnimMgr
+ * @requires YAHOO.util.Easing
+ * @requires YAHOO.util.Bezier
+ * @requires YAHOO.util.Dom
+ * @requires YAHOO.util.Event
+ * @requires YAHOO.util.CustomEvent
+ * @extends YAHOO.util.ColorAnim
+ * @constructor
+ * @param {String or 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 Scroll = function(el, attributes, duration, method) {
+ if (el) { // dont break existing subclasses not using YAHOO.extend
+ Scroll.superclass.constructor.call(this, el, attributes, duration, method);
+ }
+ };
+
+ Scroll.NAME = 'Scroll';
+
+ // shorthand
+ var Y = YAHOO.util;
+ YAHOO.extend(Scroll, Y.ColorAnim);
+
+ var superclass = Scroll.superclass;
+ var proto = Scroll.prototype;
+
+ proto.doMethod = function(attr, start, end) {
+ var val = null;
+
+ if (attr == 'scroll') {
+ val = [
+ this.method(this.currentFrame, start[0], end[0] - start[0], this.totalFrames),
+ this.method(this.currentFrame, start[1], end[1] - start[1], this.totalFrames)
+ ];
+
+ } else {
+ val = superclass.doMethod.call(this, attr, start, end);
+ }
+ return val;
+ };
+
+ proto.getAttribute = function(attr) {
+ var val = null;
+ var el = this.getEl();
+
+ if (attr == 'scroll') {
+ val = [ el.scrollLeft, el.scrollTop ];
+ } else {
+ val = superclass.getAttribute.call(this, attr);
+ }
+
+ return val;
+ };
+
+ proto.setAttribute = function(attr, val, unit) {
+ var el = this.getEl();
+
+ if (attr == 'scroll') {
+ el.scrollLeft = val[0];
+ el.scrollTop = val[1];
+ } else {
+ superclass.setAttribute.call(this, attr, val, unit);
+ }
+ };
+
+ Y.Scroll = Scroll;
+})();
+YAHOO.register("animation", YAHOO.util.Anim, {version: "2.6.0", build: "1321"});
diff --git a/lib/yui/animation/animation-min.js b/lib/yui/animation/animation-min.js
new file mode 100755
index 0000000000..47fa162342
--- /dev/null
+++ b/lib/yui/animation/animation-min.js
@@ -0,0 +1,23 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.6.0
+*/
+(function(){var B=YAHOO.util;var A=function(D,C,E,F){if(!D){}this.init(D,C,E,F);};A.NAME="Anim";A.prototype={toString:function(){var C=this.getEl()||{};var D=C.id||C.tagName;return(this.constructor.NAME+": "+D);},patterns:{noNegatives:/width|height|opacity|padding/i,offsetAttribute:/^((width|height)|(top|left))$/,defaultUnit:/width|height|top$|bottom$|left$|right$/i,offsetUnit:/\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i},doMethod:function(C,E,D){return this.method(this.currentFrame,E,D-E,this.totalFrames);},setAttribute:function(C,E,D){if(this.patterns.noNegatives.test(C)){E=(E>0)?E:0;}B.Dom.setStyle(this.getEl(),C,E+D);},getAttribute:function(C){var E=this.getEl();var G=B.Dom.getStyle(E,C);if(G!=="auto"&&!this.patterns.offsetUnit.test(G)){return parseFloat(G);}var D=this.patterns.offsetAttribute.exec(C)||[];var H=!!(D[3]);var F=!!(D[2]);if(F||(B.Dom.getStyle(E,"position")=="absolute"&&H)){G=E["offset"+D[0].charAt(0).toUpperCase()+D[0].substr(1)];}else{G=0;}return G;},getDefaultUnit:function(C){if(this.patterns.defaultUnit.test(C)){return"px";}return"";},setRuntimeAttribute:function(D){var I;var E;var F=this.attributes;this.runtimeAttributes[D]={};var H=function(J){return(typeof J!=="undefined");};if(!H(F[D]["to"])&&!H(F[D]["by"])){return false;}I=(H(F[D]["from"]))?F[D]["from"]:this.getAttribute(D);if(H(F[D]["to"])){E=F[D]["to"];}else{if(H(F[D]["by"])){if(I.constructor==Array){E=[];for(var G=0,C=I.length;G0&&isFinite(K)){if(G.currentFrame+K>=J){K=J-(I+1);}G.currentFrame+=K;}};};YAHOO.util.Bezier=new function(){this.getPosition=function(E,D){var F=E.length;var C=[];for(var B=0;B0&&!(L[0] instanceof Array)){L=[L];}else{var K=[];for(M=0,O=L.length;M0){this.runtimeAttributes[P]=this.runtimeAttributes[P].concat(L);}this.runtimeAttributes[P][this.runtimeAttributes[P].length]=I;}else{F.setRuntimeAttribute.call(this,P);}};var B=function(G,I){var H=E.Dom.getXY(this.getEl());G=[G[0]-H[0]+I[0],G[1]-H[1]+I[1]];return G;};var D=function(G){return(typeof G!=="undefined");};E.Motion=A;})();(function(){var D=function(F,E,G,H){if(F){D.superclass.constructor.call(this,F,E,G,H);}};D.NAME="Scroll";var B=YAHOO.util;YAHOO.extend(D,B.ColorAnim);var C=D.superclass;var A=D.prototype;A.doMethod=function(E,H,F){var G=null;if(E=="scroll"){G=[this.method(this.currentFrame,H[0],F[0]-H[0],this.totalFrames),this.method(this.currentFrame,H[1],F[1]-H[1],this.totalFrames)];}else{G=C.doMethod.call(this,E,H,F);}return G;};A.getAttribute=function(E){var G=null;var F=this.getEl();if(E=="scroll"){G=[F.scrollLeft,F.scrollTop];}else{G=C.getAttribute.call(this,E);}return G;};A.setAttribute=function(E,H,G){var F=this.getEl();if(E=="scroll"){F.scrollLeft=H[0];F.scrollTop=H[1];}else{C.setAttribute.call(this,E,H,G);}};B.Scroll=D;})();YAHOO.register("animation",YAHOO.util.Anim,{version:"2.6.0",build:"1321"});
\ No newline at end of file
diff --git a/lib/yui/animation/animation.js b/lib/yui/animation/animation.js
new file mode 100755
index 0000000000..a198559008
--- /dev/null
+++ b/lib/yui/animation/animation.js
@@ -0,0 +1,1381 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.6.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) {
+ }
+ 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) {
+ if ( this.patterns.noNegatives.test(attr) ) {
+ val = (val > 0) ? val : 0;
+ }
+
+ Y.Dom.setStyle(this.getEl(), attr, val + unit);
+ },
+
+ /**
+ * 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
+
+ // 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;
+ }
+
+ 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)
+ * @class ColorAnim
+ * @namespace YAHOO.util
+ * @requires YAHOO.util.Anim
+ * @requires YAHOO.util.AnimMgr
+ * @requires YAHOO.util.Easing
+ * @requires YAHOO.util.Bezier
+ * @requires YAHOO.util.Dom
+ * @requires YAHOO.util.Event
+ * @constructor
+ * @extends YAHOO.util.Anim
+ * @param {HTMLElement | String} 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 ColorAnim = function(el, attributes, duration, method) {
+ ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
+ };
+
+ ColorAnim.NAME = 'ColorAnim';
+
+ ColorAnim.DEFAULT_BGCOLOR = '#fff';
+ // shorthand
+ var Y = YAHOO.util;
+ YAHOO.extend(ColorAnim, Y.Anim);
+
+ var superclass = ColorAnim.superclass;
+ var proto = ColorAnim.prototype;
+
+ proto.patterns.color = /color$/i;
+ proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i;
+ proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;
+ proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;
+ proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/; // need rgba for safari
+
+ /**
+ * Attempts to parse the given string and return a 3-tuple.
+ * @method parseColor
+ * @param {String} s The string to parse.
+ * @return {Array} The 3-tuple of rgb values.
+ */
+ proto.parseColor = function(s) {
+ if (s.length == 3) { return s; }
+
+ var c = this.patterns.hex.exec(s);
+ if (c && c.length == 4) {
+ return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ];
+ }
+
+ c = this.patterns.rgb.exec(s);
+ if (c && c.length == 4) {
+ return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ];
+ }
+
+ c = this.patterns.hex3.exec(s);
+ if (c && c.length == 4) {
+ return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ];
+ }
+
+ return null;
+ };
+
+ proto.getAttribute = function(attr) {
+ var el = this.getEl();
+ if (this.patterns.color.test(attr) ) {
+ var val = YAHOO.util.Dom.getStyle(el, attr);
+
+ var that = this;
+ if (this.patterns.transparent.test(val)) { // bgcolor default
+ var parent = YAHOO.util.Dom.getAncestorBy(el, function(node) {
+ return !that.patterns.transparent.test(val);
+ });
+
+ if (parent) {
+ val = Y.Dom.getStyle(parent, attr);
+ } else {
+ val = ColorAnim.DEFAULT_BGCOLOR;
+ }
+ }
+ } else {
+ val = superclass.getAttribute.call(this, attr);
+ }
+
+ return val;
+ };
+
+ proto.doMethod = function(attr, start, end) {
+ var val;
+
+ if ( this.patterns.color.test(attr) ) {
+ val = [];
+ for (var i = 0, len = start.length; i < len; ++i) {
+ val[i] = superclass.doMethod.call(this, attr, start[i], end[i]);
+ }
+
+ val = 'rgb('+Math.floor(val[0])+','+Math.floor(val[1])+','+Math.floor(val[2])+')';
+ }
+ else {
+ val = superclass.doMethod.call(this, attr, start, end);
+ }
+
+ return val;
+ };
+
+ proto.setRuntimeAttribute = function(attr) {
+ superclass.setRuntimeAttribute.call(this, attr);
+
+ if ( this.patterns.color.test(attr) ) {
+ var attributes = this.attributes;
+ var start = this.parseColor(this.runtimeAttributes[attr].start);
+ var end = this.parseColor(this.runtimeAttributes[attr].end);
+ // fix colors if going "by"
+ if ( typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined' ) {
+ end = this.parseColor(attributes[attr].by);
+
+ for (var i = 0, len = start.length; i < len; ++i) {
+ end[i] = start[i] + end[i];
+ }
+ }
+
+ this.runtimeAttributes[attr].start = start;
+ this.runtimeAttributes[attr].end = end;
+ }
+ };
+
+ Y.ColorAnim = ColorAnim;
+})();
+/*!
+TERMS OF USE - EASING EQUATIONS
+Open source under the BSD License.
+Copyright 2001 Robert Penner All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/**
+ * Singleton that determines how an animation proceeds from start to end.
+ * @class Easing
+ * @namespace YAHOO.util
+*/
+
+YAHOO.util.Easing = {
+
+ /**
+ * Uniform speed between points.
+ * @method easeNone
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeNone: function (t, b, c, d) {
+ return c*t/d + b;
+ },
+
+ /**
+ * Begins slowly and accelerates towards end.
+ * @method easeIn
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeIn: function (t, b, c, d) {
+ return c*(t/=d)*t + b;
+ },
+
+ /**
+ * Begins quickly and decelerates towards end.
+ * @method easeOut
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeOut: function (t, b, c, d) {
+ return -c *(t/=d)*(t-2) + b;
+ },
+
+ /**
+ * Begins slowly and decelerates towards end.
+ * @method easeBoth
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeBoth: function (t, b, c, d) {
+ if ((t/=d/2) < 1) {
+ return c/2*t*t + b;
+ }
+
+ return -c/2 * ((--t)*(t-2) - 1) + b;
+ },
+
+ /**
+ * Begins slowly and accelerates towards end.
+ * @method easeInStrong
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeInStrong: function (t, b, c, d) {
+ return c*(t/=d)*t*t*t + b;
+ },
+
+ /**
+ * Begins quickly and decelerates towards end.
+ * @method easeOutStrong
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeOutStrong: function (t, b, c, d) {
+ return -c * ((t=t/d-1)*t*t*t - 1) + b;
+ },
+
+ /**
+ * Begins slowly and decelerates towards end.
+ * @method easeBothStrong
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ easeBothStrong: function (t, b, c, d) {
+ if ((t/=d/2) < 1) {
+ return c/2*t*t*t*t + b;
+ }
+
+ return -c/2 * ((t-=2)*t*t*t - 2) + b;
+ },
+
+ /**
+ * Snap in elastic effect.
+ * @method elasticIn
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @param {Number} a Amplitude (optional)
+ * @param {Number} p Period (optional)
+ * @return {Number} The computed value for the current animation frame
+ */
+
+ elasticIn: function (t, b, c, d, a, p) {
+ if (t == 0) {
+ return b;
+ }
+ if ( (t /= d) == 1 ) {
+ return b+c;
+ }
+ if (!p) {
+ p=d*.3;
+ }
+
+ if (!a || a < Math.abs(c)) {
+ a = c;
+ var s = p/4;
+ }
+ else {
+ var s = p/(2*Math.PI) * Math.asin (c/a);
+ }
+
+ return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
+ },
+
+ /**
+ * Snap out elastic effect.
+ * @method elasticOut
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @param {Number} a Amplitude (optional)
+ * @param {Number} p Period (optional)
+ * @return {Number} The computed value for the current animation frame
+ */
+ elasticOut: function (t, b, c, d, a, p) {
+ if (t == 0) {
+ return b;
+ }
+ if ( (t /= d) == 1 ) {
+ return b+c;
+ }
+ if (!p) {
+ p=d*.3;
+ }
+
+ if (!a || a < Math.abs(c)) {
+ a = c;
+ var s = p / 4;
+ }
+ else {
+ var s = p/(2*Math.PI) * Math.asin (c/a);
+ }
+
+ return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
+ },
+
+ /**
+ * Snap both elastic effect.
+ * @method elasticBoth
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @param {Number} a Amplitude (optional)
+ * @param {Number} p Period (optional)
+ * @return {Number} The computed value for the current animation frame
+ */
+ elasticBoth: function (t, b, c, d, a, p) {
+ if (t == 0) {
+ return b;
+ }
+
+ if ( (t /= d/2) == 2 ) {
+ return b+c;
+ }
+
+ if (!p) {
+ p = d*(.3*1.5);
+ }
+
+ if ( !a || a < Math.abs(c) ) {
+ a = c;
+ var s = p/4;
+ }
+ else {
+ var s = p/(2*Math.PI) * Math.asin (c/a);
+ }
+
+ if (t < 1) {
+ return -.5*(a*Math.pow(2,10*(t-=1)) *
+ Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
+ }
+ return a*Math.pow(2,-10*(t-=1)) *
+ Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
+ },
+
+
+ /**
+ * Backtracks slightly, then reverses direction and moves to end.
+ * @method backIn
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @param {Number} s Overshoot (optional)
+ * @return {Number} The computed value for the current animation frame
+ */
+ backIn: function (t, b, c, d, s) {
+ if (typeof s == 'undefined') {
+ s = 1.70158;
+ }
+ return c*(t/=d)*t*((s+1)*t - s) + b;
+ },
+
+ /**
+ * Overshoots end, then reverses and comes back to end.
+ * @method backOut
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @param {Number} s Overshoot (optional)
+ * @return {Number} The computed value for the current animation frame
+ */
+ backOut: function (t, b, c, d, s) {
+ if (typeof s == 'undefined') {
+ s = 1.70158;
+ }
+ return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
+ },
+
+ /**
+ * Backtracks slightly, then reverses direction, overshoots end,
+ * then reverses and comes back to end.
+ * @method backBoth
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @param {Number} s Overshoot (optional)
+ * @return {Number} The computed value for the current animation frame
+ */
+ backBoth: function (t, b, c, d, s) {
+ if (typeof s == 'undefined') {
+ s = 1.70158;
+ }
+
+ if ((t /= d/2 ) < 1) {
+ return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
+ }
+ return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
+ },
+
+ /**
+ * Bounce off of start.
+ * @method bounceIn
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ bounceIn: function (t, b, c, d) {
+ return c - YAHOO.util.Easing.bounceOut(d-t, 0, c, d) + b;
+ },
+
+ /**
+ * Bounces off end.
+ * @method bounceOut
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ bounceOut: function (t, b, c, d) {
+ if ((t/=d) < (1/2.75)) {
+ return c*(7.5625*t*t) + b;
+ } else if (t < (2/2.75)) {
+ return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
+ } else if (t < (2.5/2.75)) {
+ return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
+ }
+ return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
+ },
+
+ /**
+ * Bounces off start and end.
+ * @method bounceBoth
+ * @param {Number} t Time value used to compute current value
+ * @param {Number} b Starting value
+ * @param {Number} c Delta between start and end values
+ * @param {Number} d Total length of animation
+ * @return {Number} The computed value for the current animation frame
+ */
+ bounceBoth: function (t, b, c, d) {
+ if (t < d/2) {
+ return YAHOO.util.Easing.bounceIn(t*2, 0, c, d) * .5 + b;
+ }
+ return YAHOO.util.Easing.bounceOut(t*2-d, 0, c, d) * .5 + c*.5 + b;
+ }
+};
+
+(function() {
+/**
+ * Anim subclass for moving elements along a path defined by the "points"
+ * member of "attributes". All "points" are arrays with x, y coordinates.
+ *
Usage: var myAnim = new YAHOO.util.Motion(el, { points: { to: [800, 800] } }, 1, YAHOO.util.Easing.easeOut);
+ * @class Motion
+ * @namespace YAHOO.util
+ * @requires YAHOO.util.Anim
+ * @requires YAHOO.util.AnimMgr
+ * @requires YAHOO.util.Easing
+ * @requires YAHOO.util.Bezier
+ * @requires YAHOO.util.Dom
+ * @requires YAHOO.util.Event
+ * @requires YAHOO.util.CustomEvent
+ * @constructor
+ * @extends YAHOO.util.ColorAnim
+ * @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 Motion = function(el, attributes, duration, method) {
+ if (el) { // dont break existing subclasses not using YAHOO.extend
+ Motion.superclass.constructor.call(this, el, attributes, duration, method);
+ }
+ };
+
+
+ Motion.NAME = 'Motion';
+
+ // shorthand
+ var Y = YAHOO.util;
+ YAHOO.extend(Motion, Y.ColorAnim);
+
+ var superclass = Motion.superclass;
+ var proto = Motion.prototype;
+
+ proto.patterns.points = /^points$/i;
+
+ proto.setAttribute = function(attr, val, unit) {
+ if ( this.patterns.points.test(attr) ) {
+ unit = unit || 'px';
+ superclass.setAttribute.call(this, 'left', val[0], unit);
+ superclass.setAttribute.call(this, 'top', val[1], unit);
+ } else {
+ superclass.setAttribute.call(this, attr, val, unit);
+ }
+ };
+
+ proto.getAttribute = function(attr) {
+ if ( this.patterns.points.test(attr) ) {
+ var val = [
+ superclass.getAttribute.call(this, 'left'),
+ superclass.getAttribute.call(this, 'top')
+ ];
+ } else {
+ val = superclass.getAttribute.call(this, attr);
+ }
+
+ return val;
+ };
+
+ proto.doMethod = function(attr, start, end) {
+ var val = null;
+
+ if ( this.patterns.points.test(attr) ) {
+ var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100;
+ val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t);
+ } else {
+ val = superclass.doMethod.call(this, attr, start, end);
+ }
+ return val;
+ };
+
+ proto.setRuntimeAttribute = function(attr) {
+ if ( this.patterns.points.test(attr) ) {
+ var el = this.getEl();
+ var attributes = this.attributes;
+ var start;
+ var control = attributes['points']['control'] || [];
+ var end;
+ var i, len;
+
+ if (control.length > 0 && !(control[0] instanceof Array) ) { // could be single point or array of points
+ control = [control];
+ } else { // break reference to attributes.points.control
+ var tmp = [];
+ for (i = 0, len = control.length; i< len; ++i) {
+ tmp[i] = control[i];
+ }
+ control = tmp;
+ }
+
+ if (Y.Dom.getStyle(el, 'position') == 'static') { // default to relative
+ Y.Dom.setStyle(el, 'position', 'relative');
+ }
+
+ if ( isset(attributes['points']['from']) ) {
+ Y.Dom.setXY(el, attributes['points']['from']); // set position to from point
+ }
+ else { Y.Dom.setXY( el, Y.Dom.getXY(el) ); } // set it to current position
+
+ start = this.getAttribute('points'); // get actual top & left
+
+ // TO beats BY, per SMIL 2.1 spec
+ if ( isset(attributes['points']['to']) ) {
+ end = translateValues.call(this, attributes['points']['to'], start);
+
+ var pageXY = Y.Dom.getXY(this.getEl());
+ for (i = 0, len = control.length; i < len; ++i) {
+ control[i] = translateValues.call(this, control[i], start);
+ }
+
+
+ } else if ( isset(attributes['points']['by']) ) {
+ end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ];
+
+ for (i = 0, len = control.length; i < len; ++i) {
+ control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
+ }
+ }
+
+ this.runtimeAttributes[attr] = [start];
+
+ if (control.length > 0) {
+ this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control);
+ }
+
+ this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end;
+ }
+ else {
+ superclass.setRuntimeAttribute.call(this, attr);
+ }
+ };
+
+ var translateValues = function(val, start) {
+ var pageXY = Y.Dom.getXY(this.getEl());
+ val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ];
+
+ return val;
+ };
+
+ var isset = function(prop) {
+ return (typeof prop !== 'undefined');
+ };
+
+ Y.Motion = Motion;
+})();
+(function() {
+/**
+ * Anim subclass for scrolling elements to a position defined by the "scroll"
+ * member of "attributes". All "scroll" members are arrays with x, y scroll positions.
+ *
Usage: var myAnim = new YAHOO.util.Scroll(el, { scroll: { to: [0, 800] } }, 1, YAHOO.util.Easing.easeOut);
+
+* The default queryDelay value has been changed to 0.2. In low-latency
+implementations (e.g., when queryDelay is set to 0 against a local
+JavaScript DataSource), typeAhead functionality may experience a race condition
+when retrieving the value of the textbox. To avoid this problem, implementers
+are advised not to set the queryDelay value too low.
+
+* Fixed runtime property value validation.
+
+* Implemented new method doBeforeSendQuery().
+
+* Implemented new method destroy().
+
+* Added support for latest JSON lib http://www.json.org/json.js.
+
+* Fixed forceSelection issues with matched selections and multiple selections.
+
+* No longer create var oAnim in global scope.
+
+* The properties alwaysShowContainer and useShadow should not be enabled together.
+
+* There is a known issue in Firefox where the native browser autocomplete
+attribute cannot be disabled programmatically on input boxes that are in use.
+
+
+
+
+
+**** version 2.2.2 ***
+
+* No changes.
+
+
+
+*** version 2.2.1 ***
+
+* Fixed form submission in Safari bug.
+* Fixed broken DS_JSArray support for minQueryLength=0.
+* Improved type checking with YAHOO.lang.
+
+
+
+*** version 2.2.0 ***
+
+* No changes.
+
+
+
+*** version 0.12.2 ***
+
+* No changes.
+
+
+
+*** version 0.12.1 ***
+
+* No longer trigger typeAhead feature when user is backspacing on input text.
+
+
+
+*** version 0.12.0 ***
+
+* The following constants must be defined as static class properties and are no longer
+available as instance properties:
+
+YAHOO.widget.DataSource.ERROR_DATANULL
+YAHOO.widget.DataSource.ERROR_DATAPARSE
+YAHOO.widget.DS_XHR.TYPE_JSON
+YAHOO.widget.DS_XHR.TYPE_XML
+YAHOO.widget.DS_XHR.TYPE_FLAT
+YAHOO.widget.DS_XHR.ERROR_DATAXHR
+
+* The property minQueryLength now supports zero and negative number values for
+DS_JSFunction and DS_XHR objects, to enable null or empty string queries and to disable
+AutoComplete functionality altogether, respectively.
+
+* Enabling the alwaysShowContainer feature will no longer send containerExpandEvent or
+containerCollapseEvent.
+
+
+
+**** version 0.11.3 ***
+
+* The iFrameSrc property has been deprecated. Implementers no longer need to
+specify an https URL to avoid IE security warnings when working with sites over
+SSL.
+
+
+
+*** version 0.11.0 ***
+
+* The method getListIds() has been deprecated for getListItems(), which returns
+an array of DOM references.
+
+* All classnames have been prefixed with "yui-ac-".
+
+* Container elements should no longer have CSS property "display" set to "none".
+
+* The useIFrame property can now be set after instantiation.
+
+* On some browsers, the unmatchedItemSelectEvent may not be fired properly when
+delimiter characters are defined.
+
+* On some browsers, defining delimiter characters while enabling forceSelection
+may result in unexpected behavior.
+
+
+
+*** version 0.10.0 ***
+
+* Initial release
+
+* In order to enable the useIFrame property, it should be set in the
+constructor.
+
+* On some browsers, defining delimiter characters while enabling forceSelection
+may result in unexpected behavior.
diff --git a/lib/yui/autocomplete/assets/autocomplete-core.css b/lib/yui/autocomplete/assets/autocomplete-core.css
new file mode 100755
index 0000000000..017ea47e64
--- /dev/null
+++ b/lib/yui/autocomplete/assets/autocomplete-core.css
@@ -0,0 +1,7 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.6.0
+*/
+/* This file intentionally left blank */
diff --git a/lib/yui/autocomplete/assets/skins/sam/autocomplete-skin.css b/lib/yui/autocomplete/assets/skins/sam/autocomplete-skin.css
new file mode 100755
index 0000000000..b7f216e6b7
--- /dev/null
+++ b/lib/yui/autocomplete/assets/skins/sam/autocomplete-skin.css
@@ -0,0 +1,57 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.6.0
+*/
+/* styles for entire widget */
+.yui-skin-sam .yui-ac {
+ position:relative;font-family:arial;font-size:100%;
+}
+
+/* styles for input field */
+.yui-skin-sam .yui-ac-input {
+ position:absolute;width:100%;
+}
+
+/* styles for results container */
+.yui-skin-sam .yui-ac-container {
+ position:absolute;top:1.6em;width:100%;
+}
+
+/* styles for header/body/footer wrapper within container */
+.yui-skin-sam .yui-ac-content {
+ position:absolute;width:100%;border:1px solid #808080;background:#fff;overflow:hidden;z-index:9050;
+}
+
+/* styles for container shadow */
+.yui-skin-sam .yui-ac-shadow {
+ position:absolute;margin:.3em;width:100%;background:#000;-moz-opacity: 0.10;opacity:.10;filter:alpha(opacity=10);z-index:9049;
+}
+
+/* styles for container iframe */
+.yui-skin-sam .yui-ac iframe {
+ opacity:0;filter: alpha(opacity=0);
+ padding-right:.3em; padding-bottom:.3em; /* Bug 2026798: extend iframe to shim the shadow */
+}
+
+/* styles for results list */
+.yui-skin-sam .yui-ac-content ul{
+ margin:0;padding:0;width:100%;
+}
+
+/* styles for result item */
+.yui-skin-sam .yui-ac-content li {
+ margin:0;padding:2px 5px;cursor:default;white-space:nowrap;list-style:none;
+ zoom:1; /* For IE to trigger mouse events on LI */
+}
+
+/* styles for prehighlighted result item */
+.yui-skin-sam .yui-ac-content li.yui-ac-prehighlight {
+ background:#B3D4FF;
+}
+
+/* styles for highlighted result item */
+.yui-skin-sam .yui-ac-content li.yui-ac-highlight {
+ background:#426FD9;color:#FFF;
+}
diff --git a/lib/yui/autocomplete/assets/skins/sam/autocomplete.css b/lib/yui/autocomplete/assets/skins/sam/autocomplete.css
new file mode 100755
index 0000000000..82cf7e50b7
--- /dev/null
+++ b/lib/yui/autocomplete/assets/skins/sam/autocomplete.css
@@ -0,0 +1,7 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.6.0
+*/
+.yui-skin-sam .yui-ac{position:relative;font-family:arial;font-size:100%;}.yui-skin-sam .yui-ac-input{position:absolute;width:100%;}.yui-skin-sam .yui-ac-container{position:absolute;top:1.6em;width:100%;}.yui-skin-sam .yui-ac-content{position:absolute;width:100%;border:1px solid #808080;background:#fff;overflow:hidden;z-index:9050;}.yui-skin-sam .yui-ac-shadow{position:absolute;margin:.3em;width:100%;background:#000;-moz-opacity:0.10;opacity:.10;filter:alpha(opacity=10);z-index:9049;}.yui-skin-sam .yui-ac iframe{opacity:0;filter:alpha(opacity=0);padding-right:.3em;padding-bottom:.3em;}.yui-skin-sam .yui-ac-content ul{margin:0;padding:0;width:100%;}.yui-skin-sam .yui-ac-content li{margin:0;padding:2px 5px;cursor:default;white-space:nowrap;list-style:none;zoom:1;}.yui-skin-sam .yui-ac-content li.yui-ac-prehighlight{background:#B3D4FF;}.yui-skin-sam .yui-ac-content li.yui-ac-highlight{background:#426FD9;color:#FFF;}
diff --git a/lib/yui/autocomplete/autocomplete-debug.js b/lib/yui/autocomplete/autocomplete-debug.js
new file mode 100755
index 0000000000..56e2ace688
--- /dev/null
+++ b/lib/yui/autocomplete/autocomplete-debug.js
@@ -0,0 +1,2917 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.6.0
+*/
+/////////////////////////////////////////////////////////////////////////////
+//
+// YAHOO.widget.DataSource Backwards Compatibility
+//
+/////////////////////////////////////////////////////////////////////////////
+
+YAHOO.widget.DS_JSArray = YAHOO.util.LocalDataSource;
+
+YAHOO.widget.DS_JSFunction = YAHOO.util.FunctionDataSource;
+
+YAHOO.widget.DS_XHR = function(sScriptURI, aSchema, oConfigs) {
+ var DS = new YAHOO.util.XHRDataSource(sScriptURI, oConfigs);
+ DS._aDeprecatedSchema = aSchema;
+ return DS;
+};
+
+YAHOO.widget.DS_ScriptNode = function(sScriptURI, aSchema, oConfigs) {
+ var DS = new YAHOO.util.ScriptNodeDataSource(sScriptURI, oConfigs);
+ DS._aDeprecatedSchema = aSchema;
+ return DS;
+};
+
+YAHOO.widget.DS_XHR.TYPE_JSON = YAHOO.util.DataSourceBase.TYPE_JSON;
+YAHOO.widget.DS_XHR.TYPE_XML = YAHOO.util.DataSourceBase.TYPE_XML;
+YAHOO.widget.DS_XHR.TYPE_FLAT = YAHOO.util.DataSourceBase.TYPE_TEXT;
+
+// TODO: widget.DS_ScriptNode.scriptCallbackParam
+
+
+
+ /**
+ * The AutoComplete control provides the front-end logic for text-entry suggestion and
+ * completion functionality.
+ *
+ * @module autocomplete
+ * @requires yahoo, dom, event, datasource
+ * @optional animation
+ * @namespace YAHOO.widget
+ * @title AutoComplete Widget
+ */
+
+/****************************************************************************/
+/****************************************************************************/
+/****************************************************************************/
+
+/**
+ * The AutoComplete class provides the customizable functionality of a plug-and-play DHTML
+ * auto completion widget. Some key features:
+ *
+ *
Navigate with up/down arrow keys and/or mouse to pick a selection
+ *
The drop down container can "roll down" or "fly out" via configurable
+ * animation
+ *
UI look-and-feel customizable through CSS, including container
+ * attributes, borders, position, fonts, etc
+ *
+ *
+ * @class AutoComplete
+ * @constructor
+ * @param elInput {HTMLElement} DOM element reference of an input field.
+ * @param elInput {String} String ID of an input field.
+ * @param elContainer {HTMLElement} DOM element reference of an existing DIV.
+ * @param elContainer {String} String ID of an existing DIV.
+ * @param oDataSource {YAHOO.widget.DataSource} DataSource instance.
+ * @param oConfigs {Object} (optional) Object literal of configuration params.
+ */
+YAHOO.widget.AutoComplete = function(elInput,elContainer,oDataSource,oConfigs) {
+ if(elInput && elContainer && oDataSource) {
+ // Validate DataSource
+ if(oDataSource instanceof YAHOO.util.DataSourceBase) {
+ this.dataSource = oDataSource;
+ }
+ else {
+ YAHOO.log("Could not instantiate AutoComplete due to an invalid DataSource", "error", this.toString());
+ return;
+ }
+
+ // YAHOO.widget.DataSource schema backwards compatibility
+ // Converted deprecated schema into supported schema
+ // First assume key data is held in position 0 of results array
+ this.key = 0;
+ var schema = oDataSource.responseSchema;
+ // An old school schema has been defined in the deprecated DataSource constructor
+ if(oDataSource._aDeprecatedSchema) {
+ var aDeprecatedSchema = oDataSource._aDeprecatedSchema;
+ if(YAHOO.lang.isArray(aDeprecatedSchema)) {
+
+ if((oDataSource.responseType === YAHOO.util.DataSourceBase.TYPE_JSON) ||
+ (oDataSource.responseType === YAHOO.util.DataSourceBase.TYPE_UNKNOWN)) { // Used to default to unknown
+ // Store the resultsList
+ schema.resultsList = aDeprecatedSchema[0];
+ // Store the key
+ this.key = aDeprecatedSchema[1];
+ // Only resultsList and key are defined, so grab all the data
+ schema.fields = (aDeprecatedSchema.length < 3) ? null : aDeprecatedSchema.slice(1);
+ }
+ else if(oDataSource.responseType === YAHOO.util.DataSourceBase.TYPE_XML) {
+ schema.resultNode = aDeprecatedSchema[0];
+ this.key = aDeprecatedSchema[1];
+ schema.fields = aDeprecatedSchema.slice(1);
+ }
+ else if(oDataSource.responseType === YAHOO.util.DataSourceBase.TYPE_TEXT) {
+ schema.recordDelim = aDeprecatedSchema[0];
+ schema.fieldDelim = aDeprecatedSchema[1];
+ }
+ oDataSource.responseSchema = schema;
+ }
+ }
+
+ // Validate input element
+ if(YAHOO.util.Dom.inDocument(elInput)) {
+ if(YAHOO.lang.isString(elInput)) {
+ this._sName = "instance" + YAHOO.widget.AutoComplete._nIndex + " " + elInput;
+ this._elTextbox = document.getElementById(elInput);
+ }
+ else {
+ this._sName = (elInput.id) ?
+ "instance" + YAHOO.widget.AutoComplete._nIndex + " " + elInput.id:
+ "instance" + YAHOO.widget.AutoComplete._nIndex;
+ this._elTextbox = elInput;
+ }
+ YAHOO.util.Dom.addClass(this._elTextbox, "yui-ac-input");
+ }
+ else {
+ YAHOO.log("Could not instantiate AutoComplete due to an invalid input element", "error", this.toString());
+ return;
+ }
+
+ // Validate container element
+ if(YAHOO.util.Dom.inDocument(elContainer)) {
+ if(YAHOO.lang.isString(elContainer)) {
+ this._elContainer = document.getElementById(elContainer);
+ }
+ else {
+ this._elContainer = elContainer;
+ }
+ if(this._elContainer.style.display == "none") {
+ YAHOO.log("The container may not display properly if display is set to \"none\" in CSS", "warn", this.toString());
+ }
+
+ // For skinning
+ var elParent = this._elContainer.parentNode;
+ var elTag = elParent.tagName.toLowerCase();
+ if(elTag == "div") {
+ YAHOO.util.Dom.addClass(elParent, "yui-ac");
+ }
+ else {
+ YAHOO.log("Could not find the wrapper element for skinning", "warn", this.toString());
+ }
+ }
+ else {
+ YAHOO.log("Could not instantiate AutoComplete due to an invalid container element", "error", this.toString());
+ return;
+ }
+
+ // Default applyLocalFilter setting is to enable for local sources
+ if(this.dataSource.dataType === YAHOO.util.DataSourceBase.TYPE_LOCAL) {
+ this.applyLocalFilter = true;
+ }
+
+ // Set any config params passed in to override defaults
+ if(oConfigs && (oConfigs.constructor == Object)) {
+ for(var sConfig in oConfigs) {
+ if(sConfig) {
+ this[sConfig] = oConfigs[sConfig];
+ }
+ }
+ }
+
+ // Initialization sequence
+ this._initContainerEl();
+ this._initProps();
+ this._initListEl();
+ this._initContainerHelperEls();
+
+ // Set up events
+ var oSelf = this;
+ var elTextbox = this._elTextbox;
+
+ // Dom events
+ YAHOO.util.Event.addListener(elTextbox,"keyup",oSelf._onTextboxKeyUp,oSelf);
+ YAHOO.util.Event.addListener(elTextbox,"keydown",oSelf._onTextboxKeyDown,oSelf);
+ YAHOO.util.Event.addListener(elTextbox,"focus",oSelf._onTextboxFocus,oSelf);
+ YAHOO.util.Event.addListener(elTextbox,"blur",oSelf._onTextboxBlur,oSelf);
+ YAHOO.util.Event.addListener(elContainer,"mouseover",oSelf._onContainerMouseover,oSelf);
+ YAHOO.util.Event.addListener(elContainer,"mouseout",oSelf._onContainerMouseout,oSelf);
+ YAHOO.util.Event.addListener(elContainer,"click",oSelf._onContainerClick,oSelf);
+ YAHOO.util.Event.addListener(elContainer,"scroll",oSelf._onContainerScroll,oSelf);
+ YAHOO.util.Event.addListener(elContainer,"resize",oSelf._onContainerResize,oSelf);
+ YAHOO.util.Event.addListener(elTextbox,"keypress",oSelf._onTextboxKeyPress,oSelf);
+ YAHOO.util.Event.addListener(window,"unload",oSelf._onWindowUnload,oSelf);
+
+ // Custom events
+ this.textboxFocusEvent = new YAHOO.util.CustomEvent("textboxFocus", this);
+ this.textboxKeyEvent = new YAHOO.util.CustomEvent("textboxKey", this);
+ this.dataRequestEvent = new YAHOO.util.CustomEvent("dataRequest", this);
+ this.dataReturnEvent = new YAHOO.util.CustomEvent("dataReturn", this);
+ this.dataErrorEvent = new YAHOO.util.CustomEvent("dataError", this);
+ this.containerPopulateEvent = new YAHOO.util.CustomEvent("containerPopulate", this);
+ this.containerExpandEvent = new YAHOO.util.CustomEvent("containerExpand", this);
+ this.typeAheadEvent = new YAHOO.util.CustomEvent("typeAhead", this);
+ this.itemMouseOverEvent = new YAHOO.util.CustomEvent("itemMouseOver", this);
+ this.itemMouseOutEvent = new YAHOO.util.CustomEvent("itemMouseOut", this);
+ this.itemArrowToEvent = new YAHOO.util.CustomEvent("itemArrowTo", this);
+ this.itemArrowFromEvent = new YAHOO.util.CustomEvent("itemArrowFrom", this);
+ this.itemSelectEvent = new YAHOO.util.CustomEvent("itemSelect", this);
+ this.unmatchedItemSelectEvent = new YAHOO.util.CustomEvent("unmatchedItemSelect", this);
+ this.selectionEnforceEvent = new YAHOO.util.CustomEvent("selectionEnforce", this);
+ this.containerCollapseEvent = new YAHOO.util.CustomEvent("containerCollapse", this);
+ this.textboxBlurEvent = new YAHOO.util.CustomEvent("textboxBlur", this);
+ this.textboxChangeEvent = new YAHOO.util.CustomEvent("textboxChange", this);
+
+ // Finish up
+ elTextbox.setAttribute("autocomplete","off");
+ YAHOO.widget.AutoComplete._nIndex++;
+ YAHOO.log("AutoComplete initialized","info",this.toString());
+ }
+ // Required arguments were not found
+ else {
+ YAHOO.log("Could not instantiate AutoComplete due invalid arguments", "error", this.toString());
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Public member variables
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ * The DataSource object that encapsulates the data used for auto completion.
+ * This object should be an inherited object from YAHOO.widget.DataSource.
+ *
+ * @property dataSource
+ * @type YAHOO.widget.DataSource
+ */
+YAHOO.widget.AutoComplete.prototype.dataSource = null;
+
+/**
+ * By default, results from local DataSources will pass through the filterResults
+ * method to apply a client-side matching algorithm.
+ *
+ * @property applyLocalFilter
+ * @type Boolean
+ * @default true for local arrays and json, otherwise false
+ */
+YAHOO.widget.AutoComplete.prototype.applyLocalFilter = null;
+
+/**
+ * When applyLocalFilter is true, the local filtering algorthim can have case sensitivity
+ * enabled.
+ *
+ * @property queryMatchCase
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.queryMatchCase = false;
+
+/**
+ * When applyLocalFilter is true, results can be locally filtered to return
+ * matching strings that "contain" the query string rather than simply "start with"
+ * the query string.
+ *
+ * @property queryMatchContains
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.queryMatchContains = false;
+
+/**
+ * Enables query subset matching. When the DataSource's cache is enabled and queryMatchSubset is
+ * true, substrings of queries will return matching cached results. For
+ * instance, if the first query is for "abc" susequent queries that start with
+ * "abc", like "abcd", will be queried against the cache, and not the live data
+ * source. Recommended only for DataSources that return comprehensive results
+ * for queries with very few characters.
+ *
+ * @property queryMatchSubset
+ * @type Boolean
+ * @default false
+ *
+ */
+YAHOO.widget.AutoComplete.prototype.queryMatchSubset = false;
+
+/**
+ * Number of characters that must be entered before querying for results. A negative value
+ * effectively turns off the widget. A value of 0 allows queries of null or empty string
+ * values.
+ *
+ * @property minQueryLength
+ * @type Number
+ * @default 1
+ */
+YAHOO.widget.AutoComplete.prototype.minQueryLength = 1;
+
+/**
+ * Maximum number of results to display in results container.
+ *
+ * @property maxResultsDisplayed
+ * @type Number
+ * @default 10
+ */
+YAHOO.widget.AutoComplete.prototype.maxResultsDisplayed = 10;
+
+/**
+ * Number of seconds to delay before submitting a query request. If a query
+ * request is received before a previous one has completed its delay, the
+ * previous request is cancelled and the new request is set to the delay. If
+ * typeAhead is also enabled, this value must always be less than the typeAheadDelay
+ * in order to avoid certain race conditions.
+ *
+ * @property queryDelay
+ * @type Number
+ * @default 0.2
+ */
+YAHOO.widget.AutoComplete.prototype.queryDelay = 0.2;
+
+/**
+ * If typeAhead is true, number of seconds to delay before updating input with
+ * typeAhead value. In order to prevent certain race conditions, this value must
+ * always be greater than the queryDelay.
+ *
+ * @property typeAheadDelay
+ * @type Number
+ * @default 0.5
+ */
+YAHOO.widget.AutoComplete.prototype.typeAheadDelay = 0.5;
+
+/**
+ * When IME usage is detected, AutoComplete will switch to querying the input
+ * value at the given interval rather than per key event.
+ *
+ * @property queryInterval
+ * @type Number
+ * @default 500
+ */
+YAHOO.widget.AutoComplete.prototype.queryInterval = 500;
+
+/**
+ * Class name of a highlighted item within results container.
+ *
+ * @property highlightClassName
+ * @type String
+ * @default "yui-ac-highlight"
+ */
+YAHOO.widget.AutoComplete.prototype.highlightClassName = "yui-ac-highlight";
+
+/**
+ * Class name of a pre-highlighted item within results container.
+ *
+ * @property prehighlightClassName
+ * @type String
+ */
+YAHOO.widget.AutoComplete.prototype.prehighlightClassName = null;
+
+/**
+ * Query delimiter. A single character separator for multiple delimited
+ * selections. Multiple delimiter characteres may be defined as an array of
+ * strings. A null value or empty string indicates that query results cannot
+ * be delimited. This feature is not recommended if you need forceSelection to
+ * be true.
+ *
+ * @property delimChar
+ * @type String | String[]
+ */
+YAHOO.widget.AutoComplete.prototype.delimChar = null;
+
+/**
+ * Whether or not the first item in results container should be automatically highlighted
+ * on expand.
+ *
+ * @property autoHighlight
+ * @type Boolean
+ * @default true
+ */
+YAHOO.widget.AutoComplete.prototype.autoHighlight = true;
+
+/**
+ * If autohighlight is enabled, whether or not the input field should be automatically updated
+ * with the first query result as the user types, auto-selecting the substring portion
+ * of the first result that the user has not yet typed.
+ *
+ * @property typeAhead
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.typeAhead = false;
+
+/**
+ * Whether or not to animate the expansion/collapse of the results container in the
+ * horizontal direction.
+ *
+ * @property animHoriz
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.animHoriz = false;
+
+/**
+ * Whether or not to animate the expansion/collapse of the results container in the
+ * vertical direction.
+ *
+ * @property animVert
+ * @type Boolean
+ * @default true
+ */
+YAHOO.widget.AutoComplete.prototype.animVert = true;
+
+/**
+ * Speed of container expand/collapse animation, in seconds..
+ *
+ * @property animSpeed
+ * @type Number
+ * @default 0.3
+ */
+YAHOO.widget.AutoComplete.prototype.animSpeed = 0.3;
+
+/**
+ * Whether or not to force the user's selection to match one of the query
+ * results. Enabling this feature essentially transforms the input field into a
+ * <select> field. This feature is not recommended with delimiter character(s)
+ * defined.
+ *
+ * @property forceSelection
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.forceSelection = false;
+
+/**
+ * Whether or not to allow browsers to cache user-typed input in the input
+ * field. Disabling this feature will prevent the widget from setting the
+ * autocomplete="off" on the input field. When autocomplete="off"
+ * and users click the back button after form submission, user-typed input can
+ * be prefilled by the browser from its cache. This caching of user input may
+ * not be desired for sensitive data, such as credit card numbers, in which
+ * case, implementers should consider setting allowBrowserAutocomplete to false.
+ *
+ * @property allowBrowserAutocomplete
+ * @type Boolean
+ * @default true
+ */
+YAHOO.widget.AutoComplete.prototype.allowBrowserAutocomplete = true;
+
+/**
+ * Enabling this feature prevents the toggling of the container to a collapsed state.
+ * Setting to true does not automatically trigger the opening of the container.
+ * Implementers are advised to pre-load the container with an explicit "sendQuery()" call.
+ *
+ * @property alwaysShowContainer
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.alwaysShowContainer = false;
+
+/**
+ * Whether or not to use an iFrame to layer over Windows form elements in
+ * IE. Set to true only when the results container will be on top of a
+ * <select> field in IE and thus exposed to the IE z-index bug (i.e.,
+ * 5.5 < IE < 7).
+ *
+ * @property useIFrame
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.useIFrame = false;
+
+/**
+ * Whether or not the results container should have a shadow.
+ *
+ * @property useShadow
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.useShadow = false;
+
+/**
+ * Whether or not the input field should be updated with selections.
+ *
+ * @property supressInputUpdate
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.suppressInputUpdate = false;
+
+/**
+ * For backward compatibility to pre-2.6.0 formatResults() signatures, setting
+ * resultsTypeList to true will take each object literal result returned by
+ * DataSource and flatten into an array.
+ *
+ * @property resultTypeList
+ * @type Boolean
+ * @default true
+ */
+YAHOO.widget.AutoComplete.prototype.resultTypeList = true;
+
+/**
+ * For XHR DataSources, AutoComplete will automatically insert a "?" between the server URI and
+ * the "query" param/value pair. To prevent this behavior, implementers should
+ * set this value to false. To more fully customize the query syntax, implementers
+ * should override the generateRequest() method.
+ *
+ * @property queryQuestionMark
+ * @type Boolean
+ * @default true
+ */
+YAHOO.widget.AutoComplete.prototype.queryQuestionMark = true;
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Public methods
+//
+/////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Public accessor to the unique name of the AutoComplete instance.
+ *
+ * @method toString
+ * @return {String} Unique name of the AutoComplete instance.
+ */
+YAHOO.widget.AutoComplete.prototype.toString = function() {
+ return "AutoComplete " + this._sName;
+};
+
+ /**
+ * Returns DOM reference to input element.
+ *
+ * @method getInputEl
+ * @return {HTMLELement} DOM reference to input element.
+ */
+YAHOO.widget.AutoComplete.prototype.getInputEl = function() {
+ return this._elTextbox;
+};
+
+ /**
+ * Returns DOM reference to container element.
+ *
+ * @method getContainerEl
+ * @return {HTMLELement} DOM reference to container element.
+ */
+YAHOO.widget.AutoComplete.prototype.getContainerEl = function() {
+ return this._elContainer;
+};
+
+ /**
+ * Returns true if widget instance is currently focused.
+ *
+ * @method isFocused
+ * @return {Boolean} Returns true if widget instance is currently focused.
+ */
+YAHOO.widget.AutoComplete.prototype.isFocused = function() {
+ return (this._bFocused === null) ? false : this._bFocused;
+};
+
+ /**
+ * Returns true if container is in an expanded state, false otherwise.
+ *
+ * @method isContainerOpen
+ * @return {Boolean} Returns true if container is in an expanded state, false otherwise.
+ */
+YAHOO.widget.AutoComplete.prototype.isContainerOpen = function() {
+ return this._bContainerOpen;
+};
+
+/**
+ * Public accessor to the <ul> element that displays query results within the results container.
+ *
+ * @method getListEl
+ * @return {HTMLElement[]} Reference to <ul> element within the results container.
+ */
+YAHOO.widget.AutoComplete.prototype.getListEl = function() {
+ return this._elList;
+};
+
+/**
+ * Public accessor to the matching string associated with a given <li> result.
+ *
+ * @method getListItemMatch
+ * @param elListItem {HTMLElement} Reference to <LI> element.
+ * @return {String} Matching string.
+ */
+YAHOO.widget.AutoComplete.prototype.getListItemMatch = function(elListItem) {
+ if(elListItem._sResultMatch) {
+ return elListItem._sResultMatch;
+ }
+ else {
+ return null;
+ }
+};
+
+/**
+ * Public accessor to the result data associated with a given <li> result.
+ *
+ * @method getListItemData
+ * @param elListItem {HTMLElement} Reference to <LI> element.
+ * @return {Object} Result data.
+ */
+YAHOO.widget.AutoComplete.prototype.getListItemData = function(elListItem) {
+ if(elListItem._oResultData) {
+ return elListItem._oResultData;
+ }
+ else {
+ return null;
+ }
+};
+
+/**
+ * Public accessor to the index of the associated with a given <li> result.
+ *
+ * @method getListItemIndex
+ * @param elListItem {HTMLElement} Reference to <LI> element.
+ * @return {Number} Index.
+ */
+YAHOO.widget.AutoComplete.prototype.getListItemIndex = function(elListItem) {
+ if(YAHOO.lang.isNumber(elListItem._nItemIndex)) {
+ return elListItem._nItemIndex;
+ }
+ else {
+ return null;
+ }
+};
+
+/**
+ * Sets HTML markup for the results container header. This markup will be
+ * inserted within a <div> tag with a class of "yui-ac-hd".
+ *
+ * @method setHeader
+ * @param sHeader {String} HTML markup for results container header.
+ */
+YAHOO.widget.AutoComplete.prototype.setHeader = function(sHeader) {
+ if(this._elHeader) {
+ var elHeader = this._elHeader;
+ if(sHeader) {
+ elHeader.innerHTML = sHeader;
+ elHeader.style.display = "block";
+ }
+ else {
+ elHeader.innerHTML = "";
+ elHeader.style.display = "none";
+ }
+ }
+};
+
+/**
+ * Sets HTML markup for the results container footer. This markup will be
+ * inserted within a <div> tag with a class of "yui-ac-ft".
+ *
+ * @method setFooter
+ * @param sFooter {String} HTML markup for results container footer.
+ */
+YAHOO.widget.AutoComplete.prototype.setFooter = function(sFooter) {
+ if(this._elFooter) {
+ var elFooter = this._elFooter;
+ if(sFooter) {
+ elFooter.innerHTML = sFooter;
+ elFooter.style.display = "block";
+ }
+ else {
+ elFooter.innerHTML = "";
+ elFooter.style.display = "none";
+ }
+ }
+};
+
+/**
+ * Sets HTML markup for the results container body. This markup will be
+ * inserted within a <div> tag with a class of "yui-ac-bd".
+ *
+ * @method setBody
+ * @param sBody {String} HTML markup for results container body.
+ */
+YAHOO.widget.AutoComplete.prototype.setBody = function(sBody) {
+ if(this._elBody) {
+ var elBody = this._elBody;
+ YAHOO.util.Event.purgeElement(elBody, true);
+ if(sBody) {
+ elBody.innerHTML = sBody;
+ elBody.style.display = "block";
+ }
+ else {
+ elBody.innerHTML = "";
+ elBody.style.display = "none";
+ }
+ this._elList = null;
+ }
+};
+
+/**
+* A function that converts an AutoComplete query into a request value which is then
+* passed to the DataSource's sendRequest method in order to retrieve data for
+* the query. By default, returns a String with the syntax: "query={query}"
+* Implementers can customize this method for custom request syntaxes.
+*
+* @method generateRequest
+* @param sQuery {String} Query string
+*/
+YAHOO.widget.AutoComplete.prototype.generateRequest = function(sQuery) {
+ var dataType = this.dataSource.dataType;
+
+ // Transform query string in to a request for remote data
+ // By default, local data doesn't need a transformation, just passes along the query as is.
+ if(dataType === YAHOO.util.DataSourceBase.TYPE_XHR) {
+ // By default, XHR GET requests look like "{scriptURI}?{scriptQueryParam}={sQuery}&{scriptQueryAppend}"
+ if(!this.dataSource.connMethodPost) {
+ sQuery = (this.queryQuestionMark ? "?" : "") + (this.dataSource.scriptQueryParam || "query") + "=" + sQuery +
+ (this.dataSource.scriptQueryAppend ? ("&" + this.dataSource.scriptQueryAppend) : "");
+ }
+ // By default, XHR POST bodies are sent to the {scriptURI} like "{scriptQueryParam}={sQuery}&{scriptQueryAppend}"
+ else {
+ sQuery = (this.dataSource.scriptQueryParam || "query") + "=" + sQuery +
+ (this.dataSource.scriptQueryAppend ? ("&" + this.dataSource.scriptQueryAppend) : "");
+ }
+ }
+ // By default, remote script node requests look like "{scriptURI}&{scriptCallbackParam}={callbackString}&{scriptQueryParam}={sQuery}&{scriptQueryAppend}"
+ else if(dataType === YAHOO.util.DataSourceBase.TYPE_SCRIPTNODE) {
+ sQuery = "&" + (this.dataSource.scriptQueryParam || "query") + "=" + sQuery +
+ (this.dataSource.scriptQueryAppend ? ("&" + this.dataSource.scriptQueryAppend) : "");
+ }
+
+ return sQuery;
+};
+
+/**
+ * Makes query request to the DataSource.
+ *
+ * @method sendQuery
+ * @param sQuery {String} Query string.
+ */
+YAHOO.widget.AutoComplete.prototype.sendQuery = function(sQuery) {
+ // Adjust programatically sent queries to look like they input by user
+ // when delimiters are enabled
+ var newQuery = (this.delimChar) ? this._elTextbox.value + sQuery : sQuery;
+ this._sendQuery(newQuery);
+};
+
+/**
+ * Collapses container.
+ *
+ * @method collapseContainer
+ */
+YAHOO.widget.AutoComplete.prototype.collapseContainer = function() {
+ this._toggleContainer(false);
+};
+
+/**
+ * Handles subset matching for when queryMatchSubset is enabled.
+ *
+ * @method getSubsetMatches
+ * @param sQuery {String} Query string.
+ * @return {Object} oParsedResponse or null.
+ */
+YAHOO.widget.AutoComplete.prototype.getSubsetMatches = function(sQuery) {
+ var subQuery, oCachedResponse, subRequest;
+ // Loop through substrings of each cached element's query property...
+ for(var i = sQuery.length; i >= this.minQueryLength ; i--) {
+ subRequest = this.generateRequest(sQuery.substr(0,i));
+ this.dataRequestEvent.fire(this, subQuery, subRequest);
+ YAHOO.log("Searching for query subset \"" + subQuery + "\" in cache", "info", this.toString());
+
+ // If a substring of the query is found in the cache
+ oCachedResponse = this.dataSource.getCachedResponse(subRequest);
+ if(oCachedResponse) {
+ YAHOO.log("Found match for query subset \"" + subQuery + "\": " + YAHOO.lang.dump(oCachedResponse), "info", this.toString());
+ return this.filterResults.apply(this.dataSource, [sQuery, oCachedResponse, oCachedResponse, {scope:this}]);
+ }
+ }
+ YAHOO.log("Did not find subset match for query subset \"" + sQuery + "\"" , "info", this.toString());
+ return null;
+};
+
+/**
+ * Executed by DataSource (within DataSource scope via doBeforeParseData()) to
+ * handle responseStripAfter cleanup.
+ *
+ * @method preparseRawResponse
+ * @param sQuery {String} Query string.
+ * @return {Object} oParsedResponse or null.
+ */
+YAHOO.widget.AutoComplete.prototype.preparseRawResponse = function(oRequest, oFullResponse, oCallback) {
+ var nEnd = ((this.responseStripAfter !== "") && (oFullResponse.indexOf)) ?
+ oFullResponse.indexOf(this.responseStripAfter) : -1;
+ if(nEnd != -1) {
+ oFullResponse = oFullResponse.substring(0,nEnd);
+ }
+ return oFullResponse;
+};
+
+/**
+ * Executed by DataSource (within DataSource scope via doBeforeCallback()) to
+ * filter results through a simple client-side matching algorithm.
+ *
+ * @method filterResults
+ * @param sQuery {String} Original request.
+ * @param oFullResponse {Object} Full response object.
+ * @param oParsedResponse {Object} Parsed response object.
+ * @param oCallback {Object} Callback object.
+ * @return {Object} Filtered response object.
+ */
+
+YAHOO.widget.AutoComplete.prototype.filterResults = function(sQuery, oFullResponse, oParsedResponse, oCallback) {
+ // Only if a query string is available to match against
+ if(sQuery && sQuery !== "") {
+ // First make a copy of the oParseResponse
+ oParsedResponse = YAHOO.widget.AutoComplete._cloneObject(oParsedResponse);
+
+ var oAC = oCallback.scope,
+ oDS = this,
+ allResults = oParsedResponse.results, // the array of results
+ filteredResults = [], // container for filtered results
+ bMatchFound = false,
+ bMatchCase = (oDS.queryMatchCase || oAC.queryMatchCase), // backward compat
+ bMatchContains = (oDS.queryMatchContains || oAC.queryMatchContains); // backward compat
+
+ // Loop through each result object...
+ for(var i = allResults.length-1; i >= 0; i--) {
+ var oResult = allResults[i];
+
+ // Grab the data to match against from the result object...
+ var sResult = null;
+
+ // Result object is a simple string already
+ if(YAHOO.lang.isString(oResult)) {
+ sResult = oResult;
+ }
+ // Result object is an array of strings
+ else if(YAHOO.lang.isArray(oResult)) {
+ sResult = oResult[0];
+
+ }
+ // Result object is an object literal of strings
+ else if(this.responseSchema.fields) {
+ var key = this.responseSchema.fields[0].key || this.responseSchema.fields[0];
+ sResult = oResult[key];
+ }
+ // Backwards compatibility
+ else if(this.key) {
+ sResult = oResult[this.key];
+ }
+
+ if(YAHOO.lang.isString(sResult)) {
+
+ var sKeyIndex = (bMatchCase) ?
+ sResult.indexOf(decodeURIComponent(sQuery)) :
+ sResult.toLowerCase().indexOf(decodeURIComponent(sQuery).toLowerCase());
+
+ // A STARTSWITH match is when the query is found at the beginning of the key string...
+ if((!bMatchContains && (sKeyIndex === 0)) ||
+ // A CONTAINS match is when the query is found anywhere within the key string...
+ (bMatchContains && (sKeyIndex > -1))) {
+ // Stash the match
+ filteredResults.unshift(oResult);
+ }
+ }
+ }
+ oParsedResponse.results = filteredResults;
+ YAHOO.log("Filtered " + filteredResults.length + " results against query \"" + sQuery + "\": " + YAHOO.lang.dump(filteredResults), "info", this.toString());
+ }
+ else {
+ YAHOO.log("Did not filter results against query", "info", this.toString());
+ }
+
+ return oParsedResponse;
+};
+
+/**
+ * Handles response for display. This is the callback function method passed to
+ * YAHOO.util.DataSourceBase#sendRequest so results from the DataSource are
+ * returned to the AutoComplete instance.
+ *
+ * @method handleResponse
+ * @param sQuery {String} Original request.
+ * @param oResponse {Object} Response object.
+ * @param oPayload {MIXED} (optional) Additional argument(s)
+ */
+YAHOO.widget.AutoComplete.prototype.handleResponse = function(sQuery, oResponse, oPayload) {
+ if((this instanceof YAHOO.widget.AutoComplete) && this._sName) {
+ this._populateList(sQuery, oResponse, oPayload);
+ }
+};
+
+/**
+ * Overridable method called before container is loaded with result data.
+ *
+ * @method doBeforeLoadData
+ * @param sQuery {String} Original request.
+ * @param oResponse {Object} Response object.
+ * @param oPayload {MIXED} (optional) Additional argument(s)
+ * @return {Boolean} Return true to continue loading data, false to cancel.
+ */
+YAHOO.widget.AutoComplete.prototype.doBeforeLoadData = function(sQuery, oResponse, oPayload) {
+ return true;
+};
+
+/**
+ * Overridable method that returns HTML markup for one result to be populated
+ * as innerHTML of an <LI> element.
+ *
+ * @method formatResult
+ * @param oResultData {Object} Result data object.
+ * @param sQuery {String} The corresponding query string.
+ * @param sResultMatch {HTMLElement} The current query string.
+ * @return {String} HTML markup of formatted result data.
+ */
+YAHOO.widget.AutoComplete.prototype.formatResult = function(oResultData, sQuery, sResultMatch) {
+ var sMarkup = (sResultMatch) ? sResultMatch : "";
+ return sMarkup;
+};
+
+/**
+ * Overridable method called before container expands allows implementers to access data
+ * and DOM elements.
+ *
+ * @method doBeforeExpandContainer
+ * @param elTextbox {HTMLElement} The text input box.
+ * @param elContainer {HTMLElement} The container element.
+ * @param sQuery {String} The query string.
+ * @param aResults {Object[]} An array of query results.
+ * @return {Boolean} Return true to continue expanding container, false to cancel the expand.
+ */
+YAHOO.widget.AutoComplete.prototype.doBeforeExpandContainer = function(elTextbox, elContainer, sQuery, aResults) {
+ return true;
+};
+
+
+/**
+ * Nulls out the entire AutoComplete instance and related objects, removes attached
+ * event listeners, and clears out DOM elements inside the container. After
+ * calling this method, the instance reference should be expliclitly nulled by
+ * implementer, as in myDataTable = null. Use with caution!
+ *
+ * @method destroy
+ */
+YAHOO.widget.AutoComplete.prototype.destroy = function() {
+ var instanceName = this.toString();
+ var elInput = this._elTextbox;
+ var elContainer = this._elContainer;
+
+ // Unhook custom events
+ this.textboxFocusEvent.unsubscribeAll();
+ this.textboxKeyEvent.unsubscribeAll();
+ this.dataRequestEvent.unsubscribeAll();
+ this.dataReturnEvent.unsubscribeAll();
+ this.dataErrorEvent.unsubscribeAll();
+ this.containerPopulateEvent.unsubscribeAll();
+ this.containerExpandEvent.unsubscribeAll();
+ this.typeAheadEvent.unsubscribeAll();
+ this.itemMouseOverEvent.unsubscribeAll();
+ this.itemMouseOutEvent.unsubscribeAll();
+ this.itemArrowToEvent.unsubscribeAll();
+ this.itemArrowFromEvent.unsubscribeAll();
+ this.itemSelectEvent.unsubscribeAll();
+ this.unmatchedItemSelectEvent.unsubscribeAll();
+ this.selectionEnforceEvent.unsubscribeAll();
+ this.containerCollapseEvent.unsubscribeAll();
+ this.textboxBlurEvent.unsubscribeAll();
+ this.textboxChangeEvent.unsubscribeAll();
+
+ // Unhook DOM events
+ YAHOO.util.Event.purgeElement(elInput, true);
+ YAHOO.util.Event.purgeElement(elContainer, true);
+
+ // Remove DOM elements
+ elContainer.innerHTML = "";
+
+ // Null out objects
+ for(var key in this) {
+ if(YAHOO.lang.hasOwnProperty(this, key)) {
+ this[key] = null;
+ }
+ }
+
+ YAHOO.log("AutoComplete instance destroyed: " + instanceName);
+};
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Public events
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Fired when the input field receives focus.
+ *
+ * @event textboxFocusEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ */
+YAHOO.widget.AutoComplete.prototype.textboxFocusEvent = null;
+
+/**
+ * Fired when the input field receives key input.
+ *
+ * @event textboxKeyEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @param nKeycode {Number} The keycode number.
+ */
+YAHOO.widget.AutoComplete.prototype.textboxKeyEvent = null;
+
+/**
+ * Fired when the AutoComplete instance makes a request to the DataSource.
+ *
+ * @event dataRequestEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @param sQuery {String} The query string.
+ * @param oRequest {Object} The request.
+ */
+YAHOO.widget.AutoComplete.prototype.dataRequestEvent = null;
+
+/**
+ * Fired when the AutoComplete instance receives query results from the data
+ * source.
+ *
+ * @event dataReturnEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @param sQuery {String} The query string.
+ * @param aResults {Object[]} Results array.
+ */
+YAHOO.widget.AutoComplete.prototype.dataReturnEvent = null;
+
+/**
+ * Fired when the AutoComplete instance does not receive query results from the
+ * DataSource due to an error.
+ *
+ * @event dataErrorEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @param sQuery {String} The query string.
+ */
+YAHOO.widget.AutoComplete.prototype.dataErrorEvent = null;
+
+/**
+ * Fired when the results container is populated.
+ *
+ * @event containerPopulateEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ */
+YAHOO.widget.AutoComplete.prototype.containerPopulateEvent = null;
+
+/**
+ * Fired when the results container is expanded.
+ *
+ * @event containerExpandEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @param sQuery {String} The query string.
+ * @param aResults {Object[]} Results array.
+ */
+YAHOO.widget.AutoComplete.prototype.containerExpandEvent = null;
+
+/**
+ * Fired when the input field has been prefilled by the type-ahead
+ * feature.
+ *
+ * @event typeAheadEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @param sQuery {String} The query string.
+ * @param sPrefill {String} The prefill string.
+ */
+YAHOO.widget.AutoComplete.prototype.typeAheadEvent = null;
+
+/**
+ * Fired when result item has been moused over.
+ *
+ * @event itemMouseOverEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @param elItem {HTMLElement} The <li> element item moused to.
+ */
+YAHOO.widget.AutoComplete.prototype.itemMouseOverEvent = null;
+
+/**
+ * Fired when result item has been moused out.
+ *
+ * @event itemMouseOutEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @param elItem {HTMLElement} The <li> element item moused from.
+ */
+YAHOO.widget.AutoComplete.prototype.itemMouseOutEvent = null;
+
+/**
+ * Fired when result item has been arrowed to.
+ *
+ * @event itemArrowToEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @param elItem {HTMLElement} The <li> element item arrowed to.
+ */
+YAHOO.widget.AutoComplete.prototype.itemArrowToEvent = null;
+
+/**
+ * Fired when result item has been arrowed away from.
+ *
+ * @event itemArrowFromEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @param elItem {HTMLElement} The <li> element item arrowed from.
+ */
+YAHOO.widget.AutoComplete.prototype.itemArrowFromEvent = null;
+
+/**
+ * Fired when an item is selected via mouse click, ENTER key, or TAB key.
+ *
+ * @event itemSelectEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @param elItem {HTMLElement} The selected <li> element item.
+ * @param oData {Object} The data returned for the item, either as an object,
+ * or mapped from the schema into an array.
+ */
+YAHOO.widget.AutoComplete.prototype.itemSelectEvent = null;
+
+/**
+ * Fired when a user selection does not match any of the displayed result items.
+ *
+ * @event unmatchedItemSelectEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @param sSelection {String} The selected string.
+ */
+YAHOO.widget.AutoComplete.prototype.unmatchedItemSelectEvent = null;
+
+/**
+ * Fired if forceSelection is enabled and the user's input has been cleared
+ * because it did not match one of the returned query results.
+ *
+ * @event selectionEnforceEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ */
+YAHOO.widget.AutoComplete.prototype.selectionEnforceEvent = null;
+
+/**
+ * Fired when the results container is collapsed.
+ *
+ * @event containerCollapseEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ */
+YAHOO.widget.AutoComplete.prototype.containerCollapseEvent = null;
+
+/**
+ * Fired when the input field loses focus.
+ *
+ * @event textboxBlurEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ */
+YAHOO.widget.AutoComplete.prototype.textboxBlurEvent = null;
+
+/**
+ * Fired when the input field value has changed when it loses focus.
+ *
+ * @event textboxChangeEvent
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ */
+YAHOO.widget.AutoComplete.prototype.textboxChangeEvent = null;
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Private member variables
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Internal class variable to index multiple AutoComplete instances.
+ *
+ * @property _nIndex
+ * @type Number
+ * @default 0
+ * @private
+ */
+YAHOO.widget.AutoComplete._nIndex = 0;
+
+/**
+ * Name of AutoComplete instance.
+ *
+ * @property _sName
+ * @type String
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._sName = null;
+
+/**
+ * Text input field DOM element.
+ *
+ * @property _elTextbox
+ * @type HTMLElement
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._elTextbox = null;
+
+/**
+ * Container DOM element.
+ *
+ * @property _elContainer
+ * @type HTMLElement
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._elContainer = null;
+
+/**
+ * Reference to content element within container element.
+ *
+ * @property _elContent
+ * @type HTMLElement
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._elContent = null;
+
+/**
+ * Reference to header element within content element.
+ *
+ * @property _elHeader
+ * @type HTMLElement
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._elHeader = null;
+
+/**
+ * Reference to body element within content element.
+ *
+ * @property _elBody
+ * @type HTMLElement
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._elBody = null;
+
+/**
+ * Reference to footer element within content element.
+ *
+ * @property _elFooter
+ * @type HTMLElement
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._elFooter = null;
+
+/**
+ * Reference to shadow element within container element.
+ *
+ * @property _elShadow
+ * @type HTMLElement
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._elShadow = null;
+
+/**
+ * Reference to iframe element within container element.
+ *
+ * @property _elIFrame
+ * @type HTMLElement
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._elIFrame = null;
+
+/**
+ * Whether or not the input field is currently in focus. If query results come back
+ * but the user has already moved on, do not proceed with auto complete behavior.
+ *
+ * @property _bFocused
+ * @type Boolean
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._bFocused = null;
+
+/**
+ * Animation instance for container expand/collapse.
+ *
+ * @property _oAnim
+ * @type Boolean
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._oAnim = null;
+
+/**
+ * Whether or not the results container is currently open.
+ *
+ * @property _bContainerOpen
+ * @type Boolean
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._bContainerOpen = false;
+
+/**
+ * Whether or not the mouse is currently over the results
+ * container. This is necessary in order to prevent clicks on container items
+ * from being text input field blur events.
+ *
+ * @property _bOverContainer
+ * @type Boolean
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._bOverContainer = false;
+
+/**
+ * Internal reference to <ul> elements that contains query results within the
+ * results container.
+ *
+ * @property _elList
+ * @type HTMLElement
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._elList = null;
+
+/*
+ * Array of <li> elements references that contain query results within the
+ * results container.
+ *
+ * @property _aListItemEls
+ * @type HTMLElement[]
+ * @private
+ */
+//YAHOO.widget.AutoComplete.prototype._aListItemEls = null;
+
+/**
+ * Number of <li> elements currently displayed in results container.
+ *
+ * @property _nDisplayedItems
+ * @type Number
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._nDisplayedItems = 0;
+
+/*
+ * Internal count of <li> elements displayed and hidden in results container.
+ *
+ * @property _maxResultsDisplayed
+ * @type Number
+ * @private
+ */
+//YAHOO.widget.AutoComplete.prototype._maxResultsDisplayed = 0;
+
+/**
+ * Current query string
+ *
+ * @property _sCurQuery
+ * @type String
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._sCurQuery = null;
+
+/**
+ * Selections from previous queries (for saving delimited queries).
+ *
+ * @property _sPastSelections
+ * @type String
+ * @default ""
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._sPastSelections = "";
+
+/**
+ * Stores initial input value used to determine if textboxChangeEvent should be fired.
+ *
+ * @property _sInitInputValue
+ * @type String
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._sInitInputValue = null;
+
+/**
+ * Pointer to the currently highlighted <li> element in the container.
+ *
+ * @property _elCurListItem
+ * @type HTMLElement
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._elCurListItem = null;
+
+/**
+ * Whether or not an item has been selected since the container was populated
+ * with results. Reset to false by _populateList, and set to true when item is
+ * selected.
+ *
+ * @property _bItemSelected
+ * @type Boolean
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._bItemSelected = false;
+
+/**
+ * Key code of the last key pressed in textbox.
+ *
+ * @property _nKeyCode
+ * @type Number
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._nKeyCode = null;
+
+/**
+ * Delay timeout ID.
+ *
+ * @property _nDelayID
+ * @type Number
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._nDelayID = -1;
+
+/**
+ * TypeAhead delay timeout ID.
+ *
+ * @property _nTypeAheadDelayID
+ * @type Number
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._nTypeAheadDelayID = -1;
+
+/**
+ * Src to iFrame used when useIFrame = true. Supports implementations over SSL
+ * as well.
+ *
+ * @property _iFrameSrc
+ * @type String
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._iFrameSrc = "javascript:false;";
+
+/**
+ * For users typing via certain IMEs, queries must be triggered by intervals,
+ * since key events yet supported across all browsers for all IMEs.
+ *
+ * @property _queryInterval
+ * @type Object
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._queryInterval = null;
+
+/**
+ * Internal tracker to last known textbox value, used to determine whether or not
+ * to trigger a query via interval for certain IME users.
+ *
+ * @event _sLastTextboxValue
+ * @type String
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._sLastTextboxValue = null;
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Private methods
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Updates and validates latest public config properties.
+ *
+ * @method __initProps
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._initProps = function() {
+ // Correct any invalid values
+ var minQueryLength = this.minQueryLength;
+ if(!YAHOO.lang.isNumber(minQueryLength)) {
+ this.minQueryLength = 1;
+ }
+ var maxResultsDisplayed = this.maxResultsDisplayed;
+ if(!YAHOO.lang.isNumber(maxResultsDisplayed) || (maxResultsDisplayed < 1)) {
+ this.maxResultsDisplayed = 10;
+ }
+ var queryDelay = this.queryDelay;
+ if(!YAHOO.lang.isNumber(queryDelay) || (queryDelay < 0)) {
+ this.queryDelay = 0.2;
+ }
+ var typeAheadDelay = this.typeAheadDelay;
+ if(!YAHOO.lang.isNumber(typeAheadDelay) || (typeAheadDelay < 0)) {
+ this.typeAheadDelay = 0.2;
+ }
+ var delimChar = this.delimChar;
+ if(YAHOO.lang.isString(delimChar) && (delimChar.length > 0)) {
+ this.delimChar = [delimChar];
+ }
+ else if(!YAHOO.lang.isArray(delimChar)) {
+ this.delimChar = null;
+ }
+ var animSpeed = this.animSpeed;
+ if((this.animHoriz || this.animVert) && YAHOO.util.Anim) {
+ if(!YAHOO.lang.isNumber(animSpeed) || (animSpeed < 0)) {
+ this.animSpeed = 0.3;
+ }
+ if(!this._oAnim ) {
+ this._oAnim = new YAHOO.util.Anim(this._elContent, {}, this.animSpeed);
+ }
+ else {
+ this._oAnim.duration = this.animSpeed;
+ }
+ }
+ if(this.forceSelection && delimChar) {
+ YAHOO.log("The forceSelection feature has been enabled with delimChar defined.","warn", this.toString());
+ }
+};
+
+/**
+ * Initializes the results container helpers if they are enabled and do
+ * not exist
+ *
+ * @method _initContainerHelperEls
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._initContainerHelperEls = function() {
+ if(this.useShadow && !this._elShadow) {
+ var elShadow = document.createElement("div");
+ elShadow.className = "yui-ac-shadow";
+ elShadow.style.width = 0;
+ elShadow.style.height = 0;
+ this._elShadow = this._elContainer.appendChild(elShadow);
+ }
+ if(this.useIFrame && !this._elIFrame) {
+ var elIFrame = document.createElement("iframe");
+ elIFrame.src = this._iFrameSrc;
+ elIFrame.frameBorder = 0;
+ elIFrame.scrolling = "no";
+ elIFrame.style.position = "absolute";
+ elIFrame.style.width = 0;
+ elIFrame.style.height = 0;
+ elIFrame.tabIndex = -1;
+ elIFrame.style.padding = 0;
+ this._elIFrame = this._elContainer.appendChild(elIFrame);
+ }
+};
+
+/**
+ * Initializes the results container once at object creation
+ *
+ * @method _initContainerEl
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._initContainerEl = function() {
+ YAHOO.util.Dom.addClass(this._elContainer, "yui-ac-container");
+
+ if(!this._elContent) {
+ // The elContent div is assigned DOM listeners and
+ // helps size the iframe and shadow properly
+ var elContent = document.createElement("div");
+ elContent.className = "yui-ac-content";
+ elContent.style.display = "none";
+
+ this._elContent = this._elContainer.appendChild(elContent);
+
+ var elHeader = document.createElement("div");
+ elHeader.className = "yui-ac-hd";
+ elHeader.style.display = "none";
+ this._elHeader = this._elContent.appendChild(elHeader);
+
+ var elBody = document.createElement("div");
+ elBody.className = "yui-ac-bd";
+ this._elBody = this._elContent.appendChild(elBody);
+
+ var elFooter = document.createElement("div");
+ elFooter.className = "yui-ac-ft";
+ elFooter.style.display = "none";
+ this._elFooter = this._elContent.appendChild(elFooter);
+ }
+ else {
+ YAHOO.log("Could not initialize the container","warn",this.toString());
+ }
+};
+
+/**
+ * Clears out contents of container body and creates up to
+ * YAHOO.widget.AutoComplete#maxResultsDisplayed <li> elements in an
+ * <ul> element.
+ *
+ * @method _initListEl
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._initListEl = function() {
+ var nListLength = this.maxResultsDisplayed;
+
+ var elList = this._elList || document.createElement("ul");
+ var elListItem;
+ while(elList.childNodes.length < nListLength) {
+ elListItem = document.createElement("li");
+ elListItem.style.display = "none";
+ elListItem._nItemIndex = elList.childNodes.length;
+ elList.appendChild(elListItem);
+ }
+ if(!this._elList) {
+ var elBody = this._elBody;
+ YAHOO.util.Event.purgeElement(elBody, true);
+ elBody.innerHTML = "";
+ this._elList = elBody.appendChild(elList);
+ }
+
+};
+
+/**
+ * Enables interval detection for IME support.
+ *
+ * @method _enableIntervalDetection
+ * @re
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._enableIntervalDetection = function() {
+ var oSelf = this;
+ if(!oSelf._queryInterval && oSelf.queryInterval) {
+ oSelf._queryInterval = setInterval(function() { oSelf._onInterval(); }, oSelf.queryInterval);
+ YAHOO.log("Interval set", "info", this.toString());
+ }
+};
+
+/**
+ * Enables query triggers based on text input detection by intervals (rather
+ * than by key events).
+ *
+ * @method _onInterval
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._onInterval = function() {
+ var currValue = this._elTextbox.value;
+ var lastValue = this._sLastTextboxValue;
+ if(currValue != lastValue) {
+ this._sLastTextboxValue = currValue;
+ this._sendQuery(currValue);
+ }
+};
+
+/**
+ * Cancels text input detection by intervals.
+ *
+ * @method _clearInterval
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._clearInterval = function() {
+ if(this._queryInterval) {
+ clearInterval(this._queryInterval);
+ this._queryInterval = null;
+ YAHOO.log("Interval cleared", "info", this.toString());
+ }
+};
+
+/**
+ * Whether or not key is functional or should be ignored. Note that the right
+ * arrow key is NOT an ignored key since it triggers queries for certain intl
+ * charsets.
+ *
+ * @method _isIgnoreKey
+ * @param nKeycode {Number} Code of key pressed.
+ * @return {Boolean} True if key should be ignored, false otherwise.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._isIgnoreKey = function(nKeyCode) {
+ if((nKeyCode == 9) || (nKeyCode == 13) || // tab, enter
+ (nKeyCode == 16) || (nKeyCode == 17) || // shift, ctl
+ (nKeyCode >= 18 && nKeyCode <= 20) || // alt, pause/break,caps lock
+ (nKeyCode == 27) || // esc
+ (nKeyCode >= 33 && nKeyCode <= 35) || // page up,page down,end
+ /*(nKeyCode >= 36 && nKeyCode <= 38) || // home,left,up
+ (nKeyCode == 40) || // down*/
+ (nKeyCode >= 36 && nKeyCode <= 40) || // home,left,up, right, down
+ (nKeyCode >= 44 && nKeyCode <= 45) || // print screen,insert
+ (nKeyCode == 229) // Bug 2041973: Korean XP fires 2 keyup events, the key and 229
+ ) {
+ return true;
+ }
+ return false;
+};
+
+/**
+ * Makes query request to the DataSource.
+ *
+ * @method _sendQuery
+ * @param sQuery {String} Query string.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._sendQuery = function(sQuery) {
+ // Widget has been effectively turned off
+ if(this.minQueryLength < 0) {
+ this._toggleContainer(false);
+ YAHOO.log("Property minQueryLength is less than 0", "info", this.toString());
+ return;
+ }
+ // Delimiter has been enabled
+ var aDelimChar = (this.delimChar) ? this.delimChar : null;
+ if(aDelimChar) {
+ // Loop through all possible delimiters and find the rightmost one in the query
+ // A " " may be a false positive if they are defined as delimiters AND
+ // are used to separate delimited queries
+ var nDelimIndex = -1;
+ for(var i = aDelimChar.length-1; i >= 0; i--) {
+ var nNewIndex = sQuery.lastIndexOf(aDelimChar[i]);
+ if(nNewIndex > nDelimIndex) {
+ nDelimIndex = nNewIndex;
+ }
+ }
+ // If we think the last delimiter is a space (" "), make sure it is NOT
+ // a false positive by also checking the char directly before it
+ if(aDelimChar[i] == " ") {
+ for (var j = aDelimChar.length-1; j >= 0; j--) {
+ if(sQuery[nDelimIndex - 1] == aDelimChar[j]) {
+ nDelimIndex--;
+ break;
+ }
+ }
+ }
+ // A delimiter has been found in the query so extract the latest query from past selections
+ if(nDelimIndex > -1) {
+ var nQueryStart = nDelimIndex + 1;
+ // Trim any white space from the beginning...
+ while(sQuery.charAt(nQueryStart) == " ") {
+ nQueryStart += 1;
+ }
+ // ...and save the rest of the string for later
+ this._sPastSelections = sQuery.substring(0,nQueryStart);
+ // Here is the query itself
+ sQuery = sQuery.substr(nQueryStart);
+ }
+ // No delimiter found in the query, so there are no selections from past queries
+ else {
+ this._sPastSelections = "";
+ }
+ }
+
+ // Don't search queries that are too short
+ if((sQuery && (sQuery.length < this.minQueryLength)) || (!sQuery && this.minQueryLength > 0)) {
+ if(this._nDelayID != -1) {
+ clearTimeout(this._nDelayID);
+ }
+ this._toggleContainer(false);
+ YAHOO.log("Query \"" + sQuery + "\" is too short", "info", this.toString());
+ return;
+ }
+
+ sQuery = encodeURIComponent(sQuery);
+ this._nDelayID = -1; // Reset timeout ID because request is being made
+
+ // Subset matching
+ if(this.dataSource.queryMatchSubset || this.queryMatchSubset) { // backward compat
+ var oResponse = this.getSubsetMatches(sQuery);
+ if(oResponse) {
+ this.handleResponse(sQuery, oResponse, {query: sQuery});
+ return;
+ }
+ }
+
+ if(this.responseStripAfter) {
+ this.dataSource.doBeforeParseData = this.preparseRawResponse;
+ }
+ if(this.applyLocalFilter) {
+ this.dataSource.doBeforeCallback = this.filterResults;
+ }
+
+ var sRequest = this.generateRequest(sQuery);
+ this.dataRequestEvent.fire(this, sQuery, sRequest);
+ YAHOO.log("Sending query \"" + sRequest + "\"", "info", this.toString());
+
+ this.dataSource.sendRequest(sRequest, {
+ success : this.handleResponse,
+ failure : this.handleResponse,
+ scope : this,
+ argument: {
+ query: sQuery
+ }
+ });
+};
+
+/**
+ * Populates the array of <li> elements in the container with query
+ * results.
+ *
+ * @method _populateList
+ * @param sQuery {String} Original request.
+ * @param oResponse {Object} Response object.
+ * @param oPayload {MIXED} (optional) Additional argument(s)
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._populateList = function(sQuery, oResponse, oPayload) {
+ // Clear previous timeout
+ if(this._nTypeAheadDelayID != -1) {
+ clearTimeout(this._nTypeAheadDelayID);
+ }
+
+ sQuery = (oPayload && oPayload.query) ? oPayload.query : sQuery;
+
+ // Pass data through abstract method for any transformations
+ var ok = this.doBeforeLoadData(sQuery, oResponse, oPayload);
+
+ // Data is ok
+ if(ok && !oResponse.error) {
+ this.dataReturnEvent.fire(this, sQuery, oResponse.results);
+
+ // Continue only if instance is still focused (i.e., user hasn't already moved on)
+ // Null indicates initialized state, which is ok too
+ if(this._bFocused || (this._bFocused === null)) {
+
+ //TODO: is this still necessary?
+ /*var isOpera = (YAHOO.env.ua.opera);
+ var contentStyle = this._elContent.style;
+ contentStyle.width = (!isOpera) ? null : "";
+ contentStyle.height = (!isOpera) ? null : "";*/
+
+ // Store state for this interaction
+ var sCurQuery = decodeURIComponent(sQuery);
+ this._sCurQuery = sCurQuery;
+ this._bItemSelected = false;
+
+ var allResults = oResponse.results,
+ nItemsToShow = Math.min(allResults.length,this.maxResultsDisplayed),
+ sMatchKey = (this.dataSource.responseSchema.fields) ?
+ (this.dataSource.responseSchema.fields[0].key || this.dataSource.responseSchema.fields[0]) : 0;
+
+ if(nItemsToShow > 0) {
+ // Make sure container and helpers are ready to go
+ if(!this._elList || (this._elList.childNodes.length < nItemsToShow)) {
+ this._initListEl();
+ }
+ this._initContainerHelperEls();
+
+ var allListItemEls = this._elList.childNodes;
+ // Fill items with data from the bottom up
+ for(var i = nItemsToShow-1; i >= 0; i--) {
+ var elListItem = allListItemEls[i],
+ oResult = allResults[i];
+
+ // Backward compatibility
+ if(this.resultTypeList) {
+ // Results need to be converted back to an array
+ var aResult = [];
+ // Match key is first
+ aResult[0] = (YAHOO.lang.isString(oResult)) ? oResult : oResult[sMatchKey] || oResult[this.key];
+ // Add additional data to the result array
+ var fields = this.dataSource.responseSchema.fields;
+ if(YAHOO.lang.isArray(fields) && (fields.length > 1)) {
+ for(var k=1, len=fields.length; k= nItemsToShow; j--) {
+ extraListItem = allListItemEls[j];
+ extraListItem.style.display = "none";
+ }
+ }
+
+ this._nDisplayedItems = nItemsToShow;
+
+ this.containerPopulateEvent.fire(this, sQuery, allResults);
+
+ // Highlight the first item
+ if(this.autoHighlight) {
+ var elFirstListItem = this._elList.firstChild;
+ this._toggleHighlight(elFirstListItem,"to");
+ this.itemArrowToEvent.fire(this, elFirstListItem);
+ YAHOO.log("Arrowed to first item", "info", this.toString());
+ this._typeAhead(elFirstListItem,sQuery);
+ }
+ // Unhighlight any previous time
+ else {
+ this._toggleHighlight(this._elCurListItem,"from");
+ }
+
+ // Expand the container
+ ok = this.doBeforeExpandContainer(this._elTextbox, this._elContainer, sQuery, allResults);
+ this._toggleContainer(ok);
+ }
+ else {
+ this._toggleContainer(false);
+ }
+
+ YAHOO.log("Container populated with " + nItemsToShow + " list items", "info", this.toString());
+ return;
+ }
+ }
+ // Error
+ else {
+ this.dataErrorEvent.fire(this, sQuery);
+ }
+
+ YAHOO.log("Could not populate list", "info", this.toString());
+};
+
+/**
+ * When forceSelection is true and the user attempts
+ * leave the text input box without selecting an item from the query results,
+ * the user selection is cleared.
+ *
+ * @method _clearSelection
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._clearSelection = function() {
+ var sValue = this._elTextbox.value;
+ //TODO: need to check against all delimChars?
+ var sChar = (this.delimChar) ? this.delimChar[0] : null;
+ var nIndex = (sChar) ? sValue.lastIndexOf(sChar, sValue.length-2) : -1;
+ if(nIndex > -1) {
+ this._elTextbox.value = sValue.substring(0,nIndex);
+ }
+ else {
+ this._elTextbox.value = "";
+ }
+ this._sPastSelections = this._elTextbox.value;
+
+ // Fire custom event
+ this.selectionEnforceEvent.fire(this);
+ YAHOO.log("Selection enforced", "info", this.toString());
+};
+
+/**
+ * Whether or not user-typed value in the text input box matches any of the
+ * query results.
+ *
+ * @method _textMatchesOption
+ * @return {HTMLElement} Matching list item element if user-input text matches
+ * a result, null otherwise.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._textMatchesOption = function() {
+ var elMatch = null;
+
+ for(var i = this._nDisplayedItems-1; i >= 0 ; i--) {
+ var elListItem = this._elList.childNodes[i];
+ var sMatch = ("" + elListItem._sResultMatch).toLowerCase();
+ if(sMatch == this._sCurQuery.toLowerCase()) {
+ elMatch = elListItem;
+ break;
+ }
+ }
+ return(elMatch);
+};
+
+/**
+ * Updates in the text input box with the first query result as the user types,
+ * selecting the substring that the user has not typed.
+ *
+ * @method _typeAhead
+ * @param elListItem {HTMLElement} The <li> element item whose data populates the input field.
+ * @param sQuery {String} Query string.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._typeAhead = function(elListItem, sQuery) {
+ // Don't typeAhead if turned off or is backspace
+ if(!this.typeAhead || (this._nKeyCode == 8)) {
+ return;
+ }
+
+ var oSelf = this,
+ elTextbox = this._elTextbox;
+
+ // Only if text selection is supported
+ if(elTextbox.setSelectionRange || elTextbox.createTextRange) {
+ // Set and store timeout for this typeahead
+ this._nTypeAheadDelayID = setTimeout(function() {
+ // Select the portion of text that the user has not typed
+ var nStart = elTextbox.value.length; // any saved queries plus what user has typed
+ oSelf._updateValue(elListItem);
+ var nEnd = elTextbox.value.length;
+ oSelf._selectText(elTextbox,nStart,nEnd);
+ var sPrefill = elTextbox.value.substr(nStart,nEnd);
+ oSelf.typeAheadEvent.fire(oSelf,sQuery,sPrefill);
+ YAHOO.log("Typeahead occured with prefill string \"" + sPrefill + "\"", "info", oSelf.toString());
+ },(this.typeAheadDelay*1000));
+ }
+};
+
+/**
+ * Selects text in the input field.
+ *
+ * @method _selectText
+ * @param elTextbox {HTMLElement} Text input box element in which to select text.
+ * @param nStart {Number} Starting index of text string to select.
+ * @param nEnd {Number} Ending index of text selection.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._selectText = function(elTextbox, nStart, nEnd) {
+ if(elTextbox.setSelectionRange) { // For Mozilla
+ elTextbox.setSelectionRange(nStart,nEnd);
+ }
+ else if(elTextbox.createTextRange) { // For IE
+ var oTextRange = elTextbox.createTextRange();
+ oTextRange.moveStart("character", nStart);
+ oTextRange.moveEnd("character", nEnd-elTextbox.value.length);
+ oTextRange.select();
+ }
+ else {
+ elTextbox.select();
+ }
+};
+
+/**
+ * Syncs results container with its helpers.
+ *
+ * @method _toggleContainerHelpers
+ * @param bShow {Boolean} True if container is expanded, false if collapsed
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._toggleContainerHelpers = function(bShow) {
+ var width = this._elContent.offsetWidth + "px";
+ var height = this._elContent.offsetHeight + "px";
+
+ if(this.useIFrame && this._elIFrame) {
+ var elIFrame = this._elIFrame;
+ if(bShow) {
+ elIFrame.style.width = width;
+ elIFrame.style.height = height;
+ elIFrame.style.padding = "";
+ YAHOO.log("Iframe expanded", "info", this.toString());
+ }
+ else {
+ elIFrame.style.width = 0;
+ elIFrame.style.height = 0;
+ elIFrame.style.padding = 0;
+ YAHOO.log("Iframe collapsed", "info", this.toString());
+ }
+ }
+ if(this.useShadow && this._elShadow) {
+ var elShadow = this._elShadow;
+ if(bShow) {
+ elShadow.style.width = width;
+ elShadow.style.height = height;
+ YAHOO.log("Shadow expanded", "info", this.toString());
+ }
+ else {
+ elShadow.style.width = 0;
+ elShadow.style.height = 0;
+ YAHOO.log("Shadow collapsed", "info", this.toString());
+ }
+ }
+};
+
+/**
+ * Animates expansion or collapse of the container.
+ *
+ * @method _toggleContainer
+ * @param bShow {Boolean} True if container should be expanded, false if container should be collapsed
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._toggleContainer = function(bShow) {
+ var elContainer = this._elContainer;
+
+ // If implementer has container always open and it's already open, don't mess with it
+ // Container is initialized with display "none" so it may need to be shown first time through
+ if(this.alwaysShowContainer && this._bContainerOpen) {
+ return;
+ }
+
+ // Reset states
+ if(!bShow) {
+ this._toggleHighlight(this._elCurListItem,"from");
+ this._nDisplayedItems = 0;
+ this._sCurQuery = null;
+
+ // Container is already closed, so don't bother with changing the UI
+ if(!this._bContainerOpen) {
+ this._elContent.style.display = "none";
+ return;
+ }
+ }
+
+ // If animation is enabled...
+ var oAnim = this._oAnim;
+ if(oAnim && oAnim.getEl() && (this.animHoriz || this.animVert)) {
+ if(oAnim.isAnimated()) {
+ oAnim.stop(true);
+ }
+
+ // Clone container to grab current size offscreen
+ var oClone = this._elContent.cloneNode(true);
+ elContainer.appendChild(oClone);
+ oClone.style.top = "-9000px";
+ oClone.style.width = "";
+ oClone.style.height = "";
+ oClone.style.display = "";
+
+ // Current size of the container is the EXPANDED size
+ var wExp = oClone.offsetWidth;
+ var hExp = oClone.offsetHeight;
+
+ // Calculate COLLAPSED sizes based on horiz and vert anim
+ var wColl = (this.animHoriz) ? 0 : wExp;
+ var hColl = (this.animVert) ? 0 : hExp;
+
+ // Set animation sizes
+ oAnim.attributes = (bShow) ?
+ {width: { to: wExp }, height: { to: hExp }} :
+ {width: { to: wColl}, height: { to: hColl }};
+
+ // If opening anew, set to a collapsed size...
+ if(bShow && !this._bContainerOpen) {
+ this._elContent.style.width = wColl+"px";
+ this._elContent.style.height = hColl+"px";
+ }
+ // Else, set it to its last known size.
+ else {
+ this._elContent.style.width = wExp+"px";
+ this._elContent.style.height = hExp+"px";
+ }
+
+ elContainer.removeChild(oClone);
+ oClone = null;
+
+ var oSelf = this;
+ var onAnimComplete = function() {
+ // Finish the collapse
+ oAnim.onComplete.unsubscribeAll();
+
+ if(bShow) {
+ oSelf._toggleContainerHelpers(true);
+ oSelf._bContainerOpen = bShow;
+ oSelf.containerExpandEvent.fire(oSelf);
+ YAHOO.log("Container expanded", "info", oSelf.toString());
+ }
+ else {
+ oSelf._elContent.style.display = "none";
+ oSelf._bContainerOpen = bShow;
+ oSelf.containerCollapseEvent.fire(oSelf);
+ YAHOO.log("Container collapsed", "info", oSelf.toString());
+ }
+ };
+
+ // Display container and animate it
+ this._toggleContainerHelpers(false); // Bug 1424486: Be early to hide, late to show;
+ this._elContent.style.display = "";
+ oAnim.onComplete.subscribe(onAnimComplete);
+ oAnim.animate();
+ }
+ // Else don't animate, just show or hide
+ else {
+ if(bShow) {
+ this._elContent.style.display = "";
+ this._toggleContainerHelpers(true);
+ this._bContainerOpen = bShow;
+ this.containerExpandEvent.fire(this);
+ YAHOO.log("Container expanded", "info", this.toString());
+ }
+ else {
+ this._toggleContainerHelpers(false);
+ this._elContent.style.display = "none";
+ this._bContainerOpen = bShow;
+ this.containerCollapseEvent.fire(this);
+ YAHOO.log("Container collapsed", "info", this.toString());
+ }
+ }
+
+};
+
+/**
+ * Toggles the highlight on or off for an item in the container, and also cleans
+ * up highlighting of any previous item.
+ *
+ * @method _toggleHighlight
+ * @param elNewListItem {HTMLElement} The <li> element item to receive highlight behavior.
+ * @param sType {String} Type "mouseover" will toggle highlight on, and "mouseout" will toggle highlight off.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._toggleHighlight = function(elNewListItem, sType) {
+ if(elNewListItem) {
+ var sHighlight = this.highlightClassName;
+ if(this._elCurListItem) {
+ // Remove highlight from old item
+ YAHOO.util.Dom.removeClass(this._elCurListItem, sHighlight);
+ this._elCurListItem = null;
+ }
+
+ if((sType == "to") && sHighlight) {
+ // Apply highlight to new item
+ YAHOO.util.Dom.addClass(elNewListItem, sHighlight);
+ this._elCurListItem = elNewListItem;
+ }
+ }
+};
+
+/**
+ * Toggles the pre-highlight on or off for an item in the container.
+ *
+ * @method _togglePrehighlight
+ * @param elNewListItem {HTMLElement} The <li> element item to receive highlight behavior.
+ * @param sType {String} Type "mouseover" will toggle highlight on, and "mouseout" will toggle highlight off.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._togglePrehighlight = function(elNewListItem, sType) {
+ if(elNewListItem == this._elCurListItem) {
+ return;
+ }
+
+ var sPrehighlight = this.prehighlightClassName;
+ if((sType == "mouseover") && sPrehighlight) {
+ // Apply prehighlight to new item
+ YAHOO.util.Dom.addClass(elNewListItem, sPrehighlight);
+ }
+ else {
+ // Remove prehighlight from old item
+ YAHOO.util.Dom.removeClass(elNewListItem, sPrehighlight);
+ }
+};
+
+/**
+ * Updates the text input box value with selected query result. If a delimiter
+ * has been defined, then the value gets appended with the delimiter.
+ *
+ * @method _updateValue
+ * @param elListItem {HTMLElement} The <li> element item with which to update the value.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._updateValue = function(elListItem) {
+ if(!this.suppressInputUpdate) {
+ var elTextbox = this._elTextbox;
+ var sDelimChar = (this.delimChar) ? (this.delimChar[0] || this.delimChar) : null;
+ var sResultMatch = elListItem._sResultMatch;
+
+ // Calculate the new value
+ var sNewValue = "";
+ if(sDelimChar) {
+ // Preserve selections from past queries
+ sNewValue = this._sPastSelections;
+ // Add new selection plus delimiter
+ sNewValue += sResultMatch + sDelimChar;
+ if(sDelimChar != " ") {
+ sNewValue += " ";
+ }
+ }
+ else {
+ sNewValue = sResultMatch;
+ }
+
+ // Update input field
+ elTextbox.value = sNewValue;
+
+ // Scroll to bottom of textarea if necessary
+ if(elTextbox.type == "textarea") {
+ elTextbox.scrollTop = elTextbox.scrollHeight;
+ }
+
+ // Move cursor to end
+ var end = elTextbox.value.length;
+ this._selectText(elTextbox,end,end);
+
+ this._elCurListItem = elListItem;
+ }
+};
+
+/**
+ * Selects a result item from the container
+ *
+ * @method _selectItem
+ * @param elListItem {HTMLElement} The selected <li> element item.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._selectItem = function(elListItem) {
+ this._bItemSelected = true;
+ this._updateValue(elListItem);
+ this._sPastSelections = this._elTextbox.value;
+ this._clearInterval();
+ this.itemSelectEvent.fire(this, elListItem, elListItem._oResultData);
+ YAHOO.log("Item selected: " + YAHOO.lang.dump(elListItem._oResultData), "info", this.toString());
+ this._toggleContainer(false);
+};
+
+/**
+ * If an item is highlighted in the container, the right arrow key jumps to the
+ * end of the textbox and selects the highlighted item, otherwise the container
+ * is closed.
+ *
+ * @method _jumpSelection
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._jumpSelection = function() {
+ if(this._elCurListItem) {
+ this._selectItem(this._elCurListItem);
+ }
+ else {
+ this._toggleContainer(false);
+ }
+};
+
+/**
+ * Triggered by up and down arrow keys, changes the current highlighted
+ * <li> element item. Scrolls container if necessary.
+ *
+ * @method _moveSelection
+ * @param nKeyCode {Number} Code of key pressed.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._moveSelection = function(nKeyCode) {
+ if(this._bContainerOpen) {
+ // Determine current item's id number
+ var elCurListItem = this._elCurListItem;
+ var nCurItemIndex = -1;
+
+ if(elCurListItem) {
+ nCurItemIndex = elCurListItem._nItemIndex;
+ }
+
+ var nNewItemIndex = (nKeyCode == 40) ?
+ (nCurItemIndex + 1) : (nCurItemIndex - 1);
+
+ // Out of bounds
+ if(nNewItemIndex < -2 || nNewItemIndex >= this._nDisplayedItems) {
+ return;
+ }
+
+ if(elCurListItem) {
+ // Unhighlight current item
+ this._toggleHighlight(elCurListItem, "from");
+ this.itemArrowFromEvent.fire(this, elCurListItem);
+ YAHOO.log("Item arrowed from: " + elCurListItem._nItemIndex, "info", this.toString());
+ }
+ if(nNewItemIndex == -1) {
+ // Go back to query (remove type-ahead string)
+ if(this.delimChar) {
+ this._elTextbox.value = this._sPastSelections + this._sCurQuery;
+ }
+ else {
+ this._elTextbox.value = this._sCurQuery;
+ }
+ return;
+ }
+ if(nNewItemIndex == -2) {
+ // Close container
+ this._toggleContainer(false);
+ return;
+ }
+
+ var elNewListItem = this._elList.childNodes[nNewItemIndex];
+
+ // Scroll the container if necessary
+ var elContent = this._elContent;
+ var scrollOn = ((YAHOO.util.Dom.getStyle(elContent,"overflow") == "auto") ||
+ (YAHOO.util.Dom.getStyle(elContent,"overflowY") == "auto"));
+ if(scrollOn && (nNewItemIndex > -1) &&
+ (nNewItemIndex < this._nDisplayedItems)) {
+ // User is keying down
+ if(nKeyCode == 40) {
+ // Bottom of selected item is below scroll area...
+ if((elNewListItem.offsetTop+elNewListItem.offsetHeight) > (elContent.scrollTop + elContent.offsetHeight)) {
+ // Set bottom of scroll area to bottom of selected item
+ elContent.scrollTop = (elNewListItem.offsetTop+elNewListItem.offsetHeight) - elContent.offsetHeight;
+ }
+ // Bottom of selected item is above scroll area...
+ else if((elNewListItem.offsetTop+elNewListItem.offsetHeight) < elContent.scrollTop) {
+ // Set top of selected item to top of scroll area
+ elContent.scrollTop = elNewListItem.offsetTop;
+
+ }
+ }
+ // User is keying up
+ else {
+ // Top of selected item is above scroll area
+ if(elNewListItem.offsetTop < elContent.scrollTop) {
+ // Set top of scroll area to top of selected item
+ this._elContent.scrollTop = elNewListItem.offsetTop;
+ }
+ // Top of selected item is below scroll area
+ else if(elNewListItem.offsetTop > (elContent.scrollTop + elContent.offsetHeight)) {
+ // Set bottom of selected item to bottom of scroll area
+ this._elContent.scrollTop = (elNewListItem.offsetTop+elNewListItem.offsetHeight) - elContent.offsetHeight;
+ }
+ }
+ }
+
+ this._toggleHighlight(elNewListItem, "to");
+ this.itemArrowToEvent.fire(this, elNewListItem);
+ YAHOO.log("Item arrowed to " + elNewListItem._nItemIndex, "info", this.toString());
+ if(this.typeAhead) {
+ this._updateValue(elNewListItem);
+ }
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Private event handlers
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Handles <li> element mouseover events in the container.
+ *
+ * @method _onItemMouseover
+ * @param v {HTMLEvent} The mouseover event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+/*YAHOO.widget.AutoComplete.prototype._onItemMouseover = function(v,oSelf) {
+ if(oSelf.prehighlightClassName) {
+ oSelf._togglePrehighlight(this,"mouseover");
+ }
+ else {
+ oSelf._toggleHighlight(this,"to");
+ }
+
+ oSelf.itemMouseOverEvent.fire(oSelf, this);
+ YAHOO.log("Item moused over", "info", oSelf.toString());
+};*/
+
+/**
+ * Handles <li> element mouseout events in the container.
+ *
+ * @method _onItemMouseout
+ * @param v {HTMLEvent} The mouseout event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+/*YAHOO.widget.AutoComplete.prototype._onItemMouseout = function(v,oSelf) {
+ if(oSelf.prehighlightClassName) {
+ oSelf._togglePrehighlight(this,"mouseout");
+ }
+ else {
+ oSelf._toggleHighlight(this,"from");
+ }
+
+ oSelf.itemMouseOutEvent.fire(oSelf, this);
+ YAHOO.log("Item moused out", "info", oSelf.toString());
+};*/
+
+/**
+ * Handles <li> element click events in the container.
+ *
+ * @method _onItemMouseclick
+ * @param v {HTMLEvent} The click event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+/*YAHOO.widget.AutoComplete.prototype._onItemMouseclick = function(v,oSelf) {
+ // In case item has not been moused over
+ oSelf._toggleHighlight(this,"to");
+ oSelf._selectItem(this);
+};*/
+
+/**
+ * Handles container mouseover events.
+ *
+ * @method _onContainerMouseover
+ * @param v {HTMLEvent} The mouseover event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._onContainerMouseover = function(v,oSelf) {
+ var elTarget = YAHOO.util.Event.getTarget(v);
+ var elTag = elTarget.nodeName.toLowerCase();
+ while(elTarget && (elTag != "table")) {
+ switch(elTag) {
+ case "body":
+ return;
+ case "li":
+ if(oSelf.prehighlightClassName) {
+ oSelf._togglePrehighlight(elTarget,"mouseover");
+ }
+ else {
+ oSelf._toggleHighlight(elTarget,"to");
+ }
+
+ oSelf.itemMouseOverEvent.fire(oSelf, elTarget);
+ YAHOO.log("Item moused over " + elTarget._nItemIndex, "info", oSelf.toString());
+ break;
+ case "div":
+ if(YAHOO.util.Dom.hasClass(elTarget,"yui-ac-container")) {
+ oSelf._bOverContainer = true;
+ return;
+ }
+ break;
+ default:
+ break;
+ }
+
+ elTarget = elTarget.parentNode;
+ if(elTarget) {
+ elTag = elTarget.nodeName.toLowerCase();
+ }
+ }
+};
+
+/**
+ * Handles container mouseout events.
+ *
+ * @method _onContainerMouseout
+ * @param v {HTMLEvent} The mouseout event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._onContainerMouseout = function(v,oSelf) {
+ var elTarget = YAHOO.util.Event.getTarget(v);
+ var elTag = elTarget.nodeName.toLowerCase();
+ while(elTarget && (elTag != "table")) {
+ switch(elTag) {
+ case "body":
+ return;
+ case "li":
+ if(oSelf.prehighlightClassName) {
+ oSelf._togglePrehighlight(elTarget,"mouseout");
+ }
+ else {
+ oSelf._toggleHighlight(elTarget,"from");
+ }
+
+ oSelf.itemMouseOutEvent.fire(oSelf, elTarget);
+ YAHOO.log("Item moused out " + elTarget._nItemIndex, "info", oSelf.toString());
+ break;
+ case "ul":
+ oSelf._toggleHighlight(oSelf._elCurListItem,"to");
+ break;
+ case "div":
+ if(YAHOO.util.Dom.hasClass(elTarget,"yui-ac-container")) {
+ oSelf._bOverContainer = false;
+ return;
+ }
+ break;
+ default:
+ break;
+ }
+
+ elTarget = elTarget.parentNode;
+ if(elTarget) {
+ elTag = elTarget.nodeName.toLowerCase();
+ }
+ }
+};
+
+/**
+ * Handles container click events.
+ *
+ * @method _onContainerClick
+ * @param v {HTMLEvent} The click event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._onContainerClick = function(v,oSelf) {
+ var elTarget = YAHOO.util.Event.getTarget(v);
+ var elTag = elTarget.nodeName.toLowerCase();
+ while(elTarget && (elTag != "table")) {
+ switch(elTag) {
+ case "body":
+ return;
+ case "li":
+ // In case item has not been moused over
+ oSelf._toggleHighlight(elTarget,"to");
+ oSelf._selectItem(elTarget);
+ return;
+ default:
+ break;
+ }
+
+ elTarget = elTarget.parentNode;
+ if(elTarget) {
+ elTag = elTarget.nodeName.toLowerCase();
+ }
+ }
+};
+
+
+/**
+ * Handles container scroll events.
+ *
+ * @method _onContainerScroll
+ * @param v {HTMLEvent} The scroll event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._onContainerScroll = function(v,oSelf) {
+ oSelf._elTextbox.focus();
+};
+
+/**
+ * Handles container resize events.
+ *
+ * @method _onContainerResize
+ * @param v {HTMLEvent} The resize event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._onContainerResize = function(v,oSelf) {
+ oSelf._toggleContainerHelpers(oSelf._bContainerOpen);
+};
+
+
+/**
+ * Handles textbox keydown events of functional keys, mainly for UI behavior.
+ *
+ * @method _onTextboxKeyDown
+ * @param v {HTMLEvent} The keydown event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._onTextboxKeyDown = function(v,oSelf) {
+ var nKeyCode = v.keyCode;
+
+ // Clear timeout
+ if(oSelf._nTypeAheadDelayID != -1) {
+ clearTimeout(oSelf._nTypeAheadDelayID);
+ }
+
+ switch (nKeyCode) {
+ case 9: // tab
+ if(!YAHOO.env.ua.opera && (navigator.userAgent.toLowerCase().indexOf("mac") == -1) || (YAHOO.env.ua.webkit>420)) {
+ // select an item or clear out
+ if(oSelf._elCurListItem) {
+ if(oSelf.delimChar && (oSelf._nKeyCode != nKeyCode)) {
+ if(oSelf._bContainerOpen) {
+ YAHOO.util.Event.stopEvent(v);
+ }
+ }
+ oSelf._selectItem(oSelf._elCurListItem);
+ }
+ else {
+ oSelf._toggleContainer(false);
+ }
+ }
+ break;
+ case 13: // enter
+ if(!YAHOO.env.ua.opera && (navigator.userAgent.toLowerCase().indexOf("mac") == -1) || (YAHOO.env.ua.webkit>420)) {
+ if(oSelf._elCurListItem) {
+ if(oSelf._nKeyCode != nKeyCode) {
+ if(oSelf._bContainerOpen) {
+ YAHOO.util.Event.stopEvent(v);
+ }
+ }
+ oSelf._selectItem(oSelf._elCurListItem);
+ }
+ else {
+ oSelf._toggleContainer(false);
+ }
+ }
+ break;
+ case 27: // esc
+ oSelf._toggleContainer(false);
+ return;
+ case 39: // right
+ oSelf._jumpSelection();
+ break;
+ case 38: // up
+ if(oSelf._bContainerOpen) {
+ YAHOO.util.Event.stopEvent(v);
+ oSelf._moveSelection(nKeyCode);
+ }
+ break;
+ case 40: // down
+ if(oSelf._bContainerOpen) {
+ YAHOO.util.Event.stopEvent(v);
+ oSelf._moveSelection(nKeyCode);
+ }
+ break;
+ default:
+ oSelf._bItemSelected = false;
+ oSelf._toggleHighlight(oSelf._elCurListItem, "from");
+
+ oSelf.textboxKeyEvent.fire(oSelf, nKeyCode);
+ YAHOO.log("Textbox keyed", "info", oSelf.toString());
+ break;
+ }
+
+ if(nKeyCode === 18){
+ oSelf._enableIntervalDetection();
+ }
+ oSelf._nKeyCode = nKeyCode;
+};
+
+/**
+ * Handles textbox keypress events.
+ * @method _onTextboxKeyPress
+ * @param v {HTMLEvent} The keypress event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._onTextboxKeyPress = function(v,oSelf) {
+ var nKeyCode = v.keyCode;
+
+ // Expose only to non SF3 (bug 1978549) Mac browsers (bug 790337) and Opera browsers (bug 583531),
+ // where stopEvent is ineffective on keydown events
+ if(YAHOO.env.ua.opera || (navigator.userAgent.toLowerCase().indexOf("mac") != -1) && (YAHOO.env.ua.webkit < 420)) {
+ switch (nKeyCode) {
+ case 9: // tab
+ // select an item or clear out
+ if(oSelf._bContainerOpen) {
+ if(oSelf.delimChar) {
+ YAHOO.util.Event.stopEvent(v);
+ }
+ if(oSelf._elCurListItem) {
+ oSelf._selectItem(oSelf._elCurListItem);
+ }
+ else {
+ oSelf._toggleContainer(false);
+ }
+ }
+ break;
+ case 13: // enter
+ if(oSelf._bContainerOpen) {
+ YAHOO.util.Event.stopEvent(v);
+ if(oSelf._elCurListItem) {
+ oSelf._selectItem(oSelf._elCurListItem);
+ }
+ else {
+ oSelf._toggleContainer(false);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ //TODO: (?) limit only to non-IE, non-Mac-FF for Korean IME support (bug 811948)
+ // Korean IME detected
+ else if(nKeyCode == 229) {
+ oSelf._enableIntervalDetection();
+ }
+};
+
+/**
+ * Handles textbox keyup events to trigger queries.
+ *
+ * @method _onTextboxKeyUp
+ * @param v {HTMLEvent} The keyup event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._onTextboxKeyUp = function(v,oSelf) {
+ var sText = this.value; //string in textbox
+
+ // Check to see if any of the public properties have been updated
+ oSelf._initProps();
+
+ // Filter out chars that don't trigger queries
+ var nKeyCode = v.keyCode;
+ if(oSelf._isIgnoreKey(nKeyCode)) {
+ return;
+ }
+
+ // Clear previous timeout
+ /*if(oSelf._nTypeAheadDelayID != -1) {
+ clearTimeout(oSelf._nTypeAheadDelayID);
+ }*/
+ if(oSelf._nDelayID != -1) {
+ clearTimeout(oSelf._nDelayID);
+ }
+
+ // Set new timeout
+ oSelf._nDelayID = setTimeout(function(){
+ oSelf._sendQuery(sText);
+ },(oSelf.queryDelay * 1000));
+
+ //= nDelayID;
+ //else {
+ // No delay so send request immediately
+ //oSelf._sendQuery(sText);
+ //}
+};
+
+/**
+ * Handles text input box receiving focus.
+ *
+ * @method _onTextboxFocus
+ * @param v {HTMLEvent} The focus event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._onTextboxFocus = function (v,oSelf) {
+ // Start of a new interaction
+ if(!oSelf._bFocused) {
+ oSelf._elTextbox.setAttribute("autocomplete","off");
+ oSelf._bFocused = true;
+ oSelf._sInitInputValue = oSelf._elTextbox.value;
+ oSelf.textboxFocusEvent.fire(oSelf);
+ YAHOO.log("Textbox focused", "info", oSelf.toString());
+ }
+};
+
+/**
+ * Handles text input box losing focus.
+ *
+ * @method _onTextboxBlur
+ * @param v {HTMLEvent} The focus event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._onTextboxBlur = function (v,oSelf) {
+ // Don't treat as a blur if it was a selection via mouse click
+ if(!oSelf._bOverContainer || (oSelf._nKeyCode == 9)) {
+ // Current query needs to be validated as a selection
+ if(!oSelf._bItemSelected) {
+ var elMatchListItem = oSelf._textMatchesOption();
+ // Container is closed or current query doesn't match any result
+ if(!oSelf._bContainerOpen || (oSelf._bContainerOpen && (elMatchListItem === null))) {
+ // Force selection is enabled so clear the current query
+ if(oSelf.forceSelection) {
+ oSelf._clearSelection();
+ }
+ // Treat current query as a valid selection
+ else {
+ oSelf.unmatchedItemSelectEvent.fire(oSelf, oSelf._sCurQuery);
+ YAHOO.log("Unmatched item selected: " + oSelf._sCurQuery, "info", oSelf.toString());
+ }
+ }
+ // Container is open and current query matches a result
+ else {
+ // Force a selection when textbox is blurred with a match
+ if(oSelf.forceSelection) {
+ oSelf._selectItem(elMatchListItem);
+ }
+ }
+ }
+
+ if(oSelf._bContainerOpen) {
+ oSelf._toggleContainer(false);
+ }
+ oSelf._clearInterval();
+ oSelf._bFocused = false;
+ if(oSelf._sInitInputValue !== oSelf._elTextbox.value) {
+ oSelf.textboxChangeEvent.fire(oSelf);
+ }
+ oSelf.textboxBlurEvent.fire(oSelf);
+ YAHOO.log("Textbox blurred", "info", oSelf.toString());
+ }
+};
+
+/**
+ * Handles window unload event.
+ *
+ * @method _onWindowUnload
+ * @param v {HTMLEvent} The unload event.
+ * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._onWindowUnload = function(v,oSelf) {
+ if(oSelf && oSelf._elTextbox && oSelf.allowBrowserAutocomplete) {
+ oSelf._elTextbox.setAttribute("autocomplete","on");
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Deprecated for Backwards Compatibility
+//
+/////////////////////////////////////////////////////////////////////////////
+/**
+ * @method doBeforeSendQuery
+ * @deprecated Use generateRequest.
+ */
+YAHOO.widget.AutoComplete.prototype.doBeforeSendQuery = function(sQuery) {
+ return this.generateRequest(sQuery);
+};
+
+/**
+ * @method getListItems
+ * @deprecated Use getListEl().childNodes.
+ */
+YAHOO.widget.AutoComplete.prototype.getListItems = function() {
+ var allListItemEls = [],
+ els = this._elList.childNodes;
+ for(var i=els.length-1; i>=0; i--) {
+ allListItemEls[i] = els[i];
+ }
+ return allListItemEls;
+};
+
+/////////////////////////////////////////////////////////////////////////
+//
+// Private static methods
+//
+/////////////////////////////////////////////////////////////////////////
+
+/**
+ * Clones object literal or array of object literals.
+ *
+ * @method AutoComplete._cloneObject
+ * @param o {Object} Object.
+ * @private
+ * @static
+ */
+YAHOO.widget.AutoComplete._cloneObject = function(o) {
+ if(!YAHOO.lang.isValue(o)) {
+ return o;
+ }
+
+ var copy = {};
+
+ if(YAHOO.lang.isFunction(o)) {
+ copy = o;
+ }
+ else if(YAHOO.lang.isArray(o)) {
+ var array = [];
+ for(var i=0,len=o.length;i=this.minQueryLength;B--){A=this.generateRequest(E.substr(0,B));this.dataRequestEvent.fire(this,D,A);C=this.dataSource.getCachedResponse(A);if(C){return this.filterResults.apply(this.dataSource,[E,C,C,{scope:this}]);}}return null;};YAHOO.widget.AutoComplete.prototype.preparseRawResponse=function(C,B,A){var D=((this.responseStripAfter!=="")&&(B.indexOf))?B.indexOf(this.responseStripAfter):-1;if(D!=-1){B=B.substring(0,D);}return B;};YAHOO.widget.AutoComplete.prototype.filterResults=function(J,L,P,K){if(J&&J!==""){P=YAHOO.widget.AutoComplete._cloneObject(P);var H=K.scope,O=this,B=P.results,M=[],D=false,I=(O.queryMatchCase||H.queryMatchCase),A=(O.queryMatchContains||H.queryMatchContains);for(var C=B.length-1;C>=0;C--){var F=B[C];var E=null;if(YAHOO.lang.isString(F)){E=F;}else{if(YAHOO.lang.isArray(F)){E=F[0];}else{if(this.responseSchema.fields){var N=this.responseSchema.fields[0].key||this.responseSchema.fields[0];E=F[N];}else{if(this.key){E=F[this.key];}}}}if(YAHOO.lang.isString(E)){var G=(I)?E.indexOf(decodeURIComponent(J)):E.toLowerCase().indexOf(decodeURIComponent(J).toLowerCase());if((!A&&(G===0))||(A&&(G>-1))){M.unshift(F);}}}P.results=M;}else{}return P;};YAHOO.widget.AutoComplete.prototype.handleResponse=function(C,A,B){if((this instanceof YAHOO.widget.AutoComplete)&&this._sName){this._populateList(C,A,B);}};YAHOO.widget.AutoComplete.prototype.doBeforeLoadData=function(C,A,B){return true;};YAHOO.widget.AutoComplete.prototype.formatResult=function(B,D,A){var C=(A)?A:"";return C;};YAHOO.widget.AutoComplete.prototype.doBeforeExpandContainer=function(D,A,C,B){return true;};YAHOO.widget.AutoComplete.prototype.destroy=function(){var B=this.toString();var A=this._elTextbox;var D=this._elContainer;this.textboxFocusEvent.unsubscribeAll();this.textboxKeyEvent.unsubscribeAll();this.dataRequestEvent.unsubscribeAll();this.dataReturnEvent.unsubscribeAll();this.dataErrorEvent.unsubscribeAll();this.containerPopulateEvent.unsubscribeAll();this.containerExpandEvent.unsubscribeAll();this.typeAheadEvent.unsubscribeAll();this.itemMouseOverEvent.unsubscribeAll();this.itemMouseOutEvent.unsubscribeAll();this.itemArrowToEvent.unsubscribeAll();this.itemArrowFromEvent.unsubscribeAll();this.itemSelectEvent.unsubscribeAll();this.unmatchedItemSelectEvent.unsubscribeAll();this.selectionEnforceEvent.unsubscribeAll();this.containerCollapseEvent.unsubscribeAll();this.textboxBlurEvent.unsubscribeAll();this.textboxChangeEvent.unsubscribeAll();YAHOO.util.Event.purgeElement(A,true);YAHOO.util.Event.purgeElement(D,true);D.innerHTML="";for(var C in this){if(YAHOO.lang.hasOwnProperty(this,C)){this[C]=null;}}};YAHOO.widget.AutoComplete.prototype.textboxFocusEvent=null;YAHOO.widget.AutoComplete.prototype.textboxKeyEvent=null;YAHOO.widget.AutoComplete.prototype.dataRequestEvent=null;YAHOO.widget.AutoComplete.prototype.dataReturnEvent=null;YAHOO.widget.AutoComplete.prototype.dataErrorEvent=null;YAHOO.widget.AutoComplete.prototype.containerPopulateEvent=null;YAHOO.widget.AutoComplete.prototype.containerExpandEvent=null;YAHOO.widget.AutoComplete.prototype.typeAheadEvent=null;YAHOO.widget.AutoComplete.prototype.itemMouseOverEvent=null;YAHOO.widget.AutoComplete.prototype.itemMouseOutEvent=null;YAHOO.widget.AutoComplete.prototype.itemArrowToEvent=null;YAHOO.widget.AutoComplete.prototype.itemArrowFromEvent=null;YAHOO.widget.AutoComplete.prototype.itemSelectEvent=null;YAHOO.widget.AutoComplete.prototype.unmatchedItemSelectEvent=null;YAHOO.widget.AutoComplete.prototype.selectionEnforceEvent=null;YAHOO.widget.AutoComplete.prototype.containerCollapseEvent=null;YAHOO.widget.AutoComplete.prototype.textboxBlurEvent=null;YAHOO.widget.AutoComplete.prototype.textboxChangeEvent=null;YAHOO.widget.AutoComplete._nIndex=0;
+YAHOO.widget.AutoComplete.prototype._sName=null;YAHOO.widget.AutoComplete.prototype._elTextbox=null;YAHOO.widget.AutoComplete.prototype._elContainer=null;YAHOO.widget.AutoComplete.prototype._elContent=null;YAHOO.widget.AutoComplete.prototype._elHeader=null;YAHOO.widget.AutoComplete.prototype._elBody=null;YAHOO.widget.AutoComplete.prototype._elFooter=null;YAHOO.widget.AutoComplete.prototype._elShadow=null;YAHOO.widget.AutoComplete.prototype._elIFrame=null;YAHOO.widget.AutoComplete.prototype._bFocused=null;YAHOO.widget.AutoComplete.prototype._oAnim=null;YAHOO.widget.AutoComplete.prototype._bContainerOpen=false;YAHOO.widget.AutoComplete.prototype._bOverContainer=false;YAHOO.widget.AutoComplete.prototype._elList=null;YAHOO.widget.AutoComplete.prototype._nDisplayedItems=0;YAHOO.widget.AutoComplete.prototype._sCurQuery=null;YAHOO.widget.AutoComplete.prototype._sPastSelections="";YAHOO.widget.AutoComplete.prototype._sInitInputValue=null;YAHOO.widget.AutoComplete.prototype._elCurListItem=null;YAHOO.widget.AutoComplete.prototype._bItemSelected=false;YAHOO.widget.AutoComplete.prototype._nKeyCode=null;YAHOO.widget.AutoComplete.prototype._nDelayID=-1;YAHOO.widget.AutoComplete.prototype._nTypeAheadDelayID=-1;YAHOO.widget.AutoComplete.prototype._iFrameSrc="javascript:false;";YAHOO.widget.AutoComplete.prototype._queryInterval=null;YAHOO.widget.AutoComplete.prototype._sLastTextboxValue=null;YAHOO.widget.AutoComplete.prototype._initProps=function(){var B=this.minQueryLength;if(!YAHOO.lang.isNumber(B)){this.minQueryLength=1;}var E=this.maxResultsDisplayed;if(!YAHOO.lang.isNumber(E)||(E<1)){this.maxResultsDisplayed=10;}var F=this.queryDelay;if(!YAHOO.lang.isNumber(F)||(F<0)){this.queryDelay=0.2;}var C=this.typeAheadDelay;if(!YAHOO.lang.isNumber(C)||(C<0)){this.typeAheadDelay=0.2;}var A=this.delimChar;if(YAHOO.lang.isString(A)&&(A.length>0)){this.delimChar=[A];}else{if(!YAHOO.lang.isArray(A)){this.delimChar=null;}}var D=this.animSpeed;if((this.animHoriz||this.animVert)&&YAHOO.util.Anim){if(!YAHOO.lang.isNumber(D)||(D<0)){this.animSpeed=0.3;}if(!this._oAnim){this._oAnim=new YAHOO.util.Anim(this._elContent,{},this.animSpeed);}else{this._oAnim.duration=this.animSpeed;}}if(this.forceSelection&&A){}};YAHOO.widget.AutoComplete.prototype._initContainerHelperEls=function(){if(this.useShadow&&!this._elShadow){var A=document.createElement("div");A.className="yui-ac-shadow";A.style.width=0;A.style.height=0;this._elShadow=this._elContainer.appendChild(A);}if(this.useIFrame&&!this._elIFrame){var B=document.createElement("iframe");B.src=this._iFrameSrc;B.frameBorder=0;B.scrolling="no";B.style.position="absolute";B.style.width=0;B.style.height=0;B.tabIndex=-1;B.style.padding=0;this._elIFrame=this._elContainer.appendChild(B);}};YAHOO.widget.AutoComplete.prototype._initContainerEl=function(){YAHOO.util.Dom.addClass(this._elContainer,"yui-ac-container");if(!this._elContent){var C=document.createElement("div");C.className="yui-ac-content";C.style.display="none";this._elContent=this._elContainer.appendChild(C);var B=document.createElement("div");B.className="yui-ac-hd";B.style.display="none";this._elHeader=this._elContent.appendChild(B);var D=document.createElement("div");D.className="yui-ac-bd";this._elBody=this._elContent.appendChild(D);var A=document.createElement("div");A.className="yui-ac-ft";A.style.display="none";this._elFooter=this._elContent.appendChild(A);}else{}};YAHOO.widget.AutoComplete.prototype._initListEl=function(){var C=this.maxResultsDisplayed;var A=this._elList||document.createElement("ul");var B;while(A.childNodes.length=18&&A<=20)||(A==27)||(A>=33&&A<=35)||(A>=36&&A<=40)||(A>=44&&A<=45)||(A==229)){return true;}return false;};YAHOO.widget.AutoComplete.prototype._sendQuery=function(G){if(this.minQueryLength<0){this._toggleContainer(false);return ;}var I=(this.delimChar)?this.delimChar:null;if(I){var B=-1;for(var F=I.length-1;F>=0;F--){var D=G.lastIndexOf(I[F]);if(D>B){B=D;}}if(I[F]==" "){for(var E=I.length-1;E>=0;E--){if(G[B-1]==I[E]){B--;break;}}}if(B>-1){var H=B+1;while(G.charAt(H)==" "){H+=1;}this._sPastSelections=G.substring(0,H);G=G.substr(H);}else{this._sPastSelections="";}}if((G&&(G.length0)){if(this._nDelayID!=-1){clearTimeout(this._nDelayID);}this._toggleContainer(false);return ;}G=encodeURIComponent(G);this._nDelayID=-1;if(this.dataSource.queryMatchSubset||this.queryMatchSubset){var A=this.getSubsetMatches(G);if(A){this.handleResponse(G,A,{query:G});return ;}}if(this.responseStripAfter){this.dataSource.doBeforeParseData=this.preparseRawResponse;}if(this.applyLocalFilter){this.dataSource.doBeforeCallback=this.filterResults;}var C=this.generateRequest(G);this.dataRequestEvent.fire(this,G,C);this.dataSource.sendRequest(C,{success:this.handleResponse,failure:this.handleResponse,scope:this,argument:{query:G}});};YAHOO.widget.AutoComplete.prototype._populateList=function(K,F,C){if(this._nTypeAheadDelayID!=-1){clearTimeout(this._nTypeAheadDelayID);}K=(C&&C.query)?C.query:K;var H=this.doBeforeLoadData(K,F,C);if(H&&!F.error){this.dataReturnEvent.fire(this,K,F.results);if(this._bFocused||(this._bFocused===null)){var M=decodeURIComponent(K);
+this._sCurQuery=M;this._bItemSelected=false;var R=F.results,A=Math.min(R.length,this.maxResultsDisplayed),J=(this.dataSource.responseSchema.fields)?(this.dataSource.responseSchema.fields[0].key||this.dataSource.responseSchema.fields[0]):0;if(A>0){if(!this._elList||(this._elList.childNodes.length=0;Q--){var P=I[Q],E=R[Q];if(this.resultTypeList){var B=[];B[0]=(YAHOO.lang.isString(E))?E:E[J]||E[this.key];var L=this.dataSource.responseSchema.fields;if(YAHOO.lang.isArray(L)&&(L.length>1)){for(var N=1,S=L.length;N=A;O--){G=I[O];G.style.display="none";}}this._nDisplayedItems=A;this.containerPopulateEvent.fire(this,K,R);if(this.autoHighlight){var D=this._elList.firstChild;this._toggleHighlight(D,"to");this.itemArrowToEvent.fire(this,D);this._typeAhead(D,K);}else{this._toggleHighlight(this._elCurListItem,"from");}H=this.doBeforeExpandContainer(this._elTextbox,this._elContainer,K,R);this._toggleContainer(H);}else{this._toggleContainer(false);}return ;}}else{this.dataErrorEvent.fire(this,K);}};YAHOO.widget.AutoComplete.prototype._clearSelection=function(){var C=this._elTextbox.value;var B=(this.delimChar)?this.delimChar[0]:null;var A=(B)?C.lastIndexOf(B,C.length-2):-1;if(A>-1){this._elTextbox.value=C.substring(0,A);}else{this._elTextbox.value="";}this._sPastSelections=this._elTextbox.value;this.selectionEnforceEvent.fire(this);};YAHOO.widget.AutoComplete.prototype._textMatchesOption=function(){var A=null;for(var B=this._nDisplayedItems-1;B>=0;B--){var C=this._elList.childNodes[B];var D=(""+C._sResultMatch).toLowerCase();if(D==this._sCurQuery.toLowerCase()){A=C;break;}}return(A);};YAHOO.widget.AutoComplete.prototype._typeAhead=function(B,D){if(!this.typeAhead||(this._nKeyCode==8)){return ;}var A=this,C=this._elTextbox;if(C.setSelectionRange||C.createTextRange){this._nTypeAheadDelayID=setTimeout(function(){var F=C.value.length;A._updateValue(B);var G=C.value.length;A._selectText(C,F,G);var E=C.value.substr(F,G);A.typeAheadEvent.fire(A,D,E);},(this.typeAheadDelay*1000));}};YAHOO.widget.AutoComplete.prototype._selectText=function(D,A,B){if(D.setSelectionRange){D.setSelectionRange(A,B);}else{if(D.createTextRange){var C=D.createTextRange();C.moveStart("character",A);C.moveEnd("character",B-D.value.length);C.select();}else{D.select();}}};YAHOO.widget.AutoComplete.prototype._toggleContainerHelpers=function(D){var E=this._elContent.offsetWidth+"px";var B=this._elContent.offsetHeight+"px";if(this.useIFrame&&this._elIFrame){var C=this._elIFrame;if(D){C.style.width=E;C.style.height=B;C.style.padding="";}else{C.style.width=0;C.style.height=0;C.style.padding=0;}}if(this.useShadow&&this._elShadow){var A=this._elShadow;if(D){A.style.width=E;A.style.height=B;}else{A.style.width=0;A.style.height=0;}}};YAHOO.widget.AutoComplete.prototype._toggleContainer=function(I){var D=this._elContainer;if(this.alwaysShowContainer&&this._bContainerOpen){return ;}if(!I){this._toggleHighlight(this._elCurListItem,"from");this._nDisplayedItems=0;this._sCurQuery=null;if(!this._bContainerOpen){this._elContent.style.display="none";return ;}}var A=this._oAnim;if(A&&A.getEl()&&(this.animHoriz||this.animVert)){if(A.isAnimated()){A.stop(true);}var G=this._elContent.cloneNode(true);D.appendChild(G);G.style.top="-9000px";G.style.width="";G.style.height="";G.style.display="";var F=G.offsetWidth;var C=G.offsetHeight;var B=(this.animHoriz)?0:F;var E=(this.animVert)?0:C;A.attributes=(I)?{width:{to:F},height:{to:C}}:{width:{to:B},height:{to:E}};if(I&&!this._bContainerOpen){this._elContent.style.width=B+"px";this._elContent.style.height=E+"px";}else{this._elContent.style.width=F+"px";this._elContent.style.height=C+"px";}D.removeChild(G);G=null;var H=this;var J=function(){A.onComplete.unsubscribeAll();if(I){H._toggleContainerHelpers(true);H._bContainerOpen=I;H.containerExpandEvent.fire(H);}else{H._elContent.style.display="none";H._bContainerOpen=I;H.containerCollapseEvent.fire(H);}};this._toggleContainerHelpers(false);this._elContent.style.display="";A.onComplete.subscribe(J);A.animate();}else{if(I){this._elContent.style.display="";this._toggleContainerHelpers(true);this._bContainerOpen=I;this.containerExpandEvent.fire(this);}else{this._toggleContainerHelpers(false);this._elContent.style.display="none";this._bContainerOpen=I;this.containerCollapseEvent.fire(this);}}};YAHOO.widget.AutoComplete.prototype._toggleHighlight=function(A,C){if(A){var B=this.highlightClassName;if(this._elCurListItem){YAHOO.util.Dom.removeClass(this._elCurListItem,B);this._elCurListItem=null;}if((C=="to")&&B){YAHOO.util.Dom.addClass(A,B);this._elCurListItem=A;}}};YAHOO.widget.AutoComplete.prototype._togglePrehighlight=function(B,C){if(B==this._elCurListItem){return ;}var A=this.prehighlightClassName;if((C=="mouseover")&&A){YAHOO.util.Dom.addClass(B,A);}else{YAHOO.util.Dom.removeClass(B,A);}};YAHOO.widget.AutoComplete.prototype._updateValue=function(C){if(!this.suppressInputUpdate){var F=this._elTextbox;var E=(this.delimChar)?(this.delimChar[0]||this.delimChar):null;var B=C._sResultMatch;var D="";if(E){D=this._sPastSelections;D+=B+E;if(E!=" "){D+=" ";}}else{D=B;}F.value=D;if(F.type=="textarea"){F.scrollTop=F.scrollHeight;}var A=F.value.length;this._selectText(F,A,A);this._elCurListItem=C;}};YAHOO.widget.AutoComplete.prototype._selectItem=function(A){this._bItemSelected=true;this._updateValue(A);this._sPastSelections=this._elTextbox.value;this._clearInterval();this.itemSelectEvent.fire(this,A,A._oResultData);this._toggleContainer(false);};YAHOO.widget.AutoComplete.prototype._jumpSelection=function(){if(this._elCurListItem){this._selectItem(this._elCurListItem);
+}else{this._toggleContainer(false);}};YAHOO.widget.AutoComplete.prototype._moveSelection=function(G){if(this._bContainerOpen){var F=this._elCurListItem;var E=-1;if(F){E=F._nItemIndex;}var C=(G==40)?(E+1):(E-1);if(C<-2||C>=this._nDisplayedItems){return ;}if(F){this._toggleHighlight(F,"from");this.itemArrowFromEvent.fire(this,F);}if(C==-1){if(this.delimChar){this._elTextbox.value=this._sPastSelections+this._sCurQuery;}else{this._elTextbox.value=this._sCurQuery;}return ;}if(C==-2){this._toggleContainer(false);return ;}var D=this._elList.childNodes[C];var A=this._elContent;var B=((YAHOO.util.Dom.getStyle(A,"overflow")=="auto")||(YAHOO.util.Dom.getStyle(A,"overflowY")=="auto"));if(B&&(C>-1)&&(C(A.scrollTop+A.offsetHeight)){A.scrollTop=(D.offsetTop+D.offsetHeight)-A.offsetHeight;}else{if((D.offsetTop+D.offsetHeight)(A.scrollTop+A.offsetHeight)){this._elContent.scrollTop=(D.offsetTop+D.offsetHeight)-A.offsetHeight;}}}}this._toggleHighlight(D,"to");this.itemArrowToEvent.fire(this,D);if(this.typeAhead){this._updateValue(D);}}};YAHOO.widget.AutoComplete.prototype._onContainerMouseover=function(A,C){var D=YAHOO.util.Event.getTarget(A);var B=D.nodeName.toLowerCase();while(D&&(B!="table")){switch(B){case"body":return ;case"li":if(C.prehighlightClassName){C._togglePrehighlight(D,"mouseover");}else{C._toggleHighlight(D,"to");}C.itemMouseOverEvent.fire(C,D);break;case"div":if(YAHOO.util.Dom.hasClass(D,"yui-ac-container")){C._bOverContainer=true;return ;}break;default:break;}D=D.parentNode;if(D){B=D.nodeName.toLowerCase();}}};YAHOO.widget.AutoComplete.prototype._onContainerMouseout=function(A,C){var D=YAHOO.util.Event.getTarget(A);var B=D.nodeName.toLowerCase();while(D&&(B!="table")){switch(B){case"body":return ;case"li":if(C.prehighlightClassName){C._togglePrehighlight(D,"mouseout");}else{C._toggleHighlight(D,"from");}C.itemMouseOutEvent.fire(C,D);break;case"ul":C._toggleHighlight(C._elCurListItem,"to");break;case"div":if(YAHOO.util.Dom.hasClass(D,"yui-ac-container")){C._bOverContainer=false;return ;}break;default:break;}D=D.parentNode;if(D){B=D.nodeName.toLowerCase();}}};YAHOO.widget.AutoComplete.prototype._onContainerClick=function(A,C){var D=YAHOO.util.Event.getTarget(A);var B=D.nodeName.toLowerCase();while(D&&(B!="table")){switch(B){case"body":return ;case"li":C._toggleHighlight(D,"to");C._selectItem(D);return ;default:break;}D=D.parentNode;if(D){B=D.nodeName.toLowerCase();}}};YAHOO.widget.AutoComplete.prototype._onContainerScroll=function(A,B){B._elTextbox.focus();};YAHOO.widget.AutoComplete.prototype._onContainerResize=function(A,B){B._toggleContainerHelpers(B._bContainerOpen);};YAHOO.widget.AutoComplete.prototype._onTextboxKeyDown=function(A,B){var C=A.keyCode;if(B._nTypeAheadDelayID!=-1){clearTimeout(B._nTypeAheadDelayID);}switch(C){case 9:if(!YAHOO.env.ua.opera&&(navigator.userAgent.toLowerCase().indexOf("mac")==-1)||(YAHOO.env.ua.webkit>420)){if(B._elCurListItem){if(B.delimChar&&(B._nKeyCode!=C)){if(B._bContainerOpen){YAHOO.util.Event.stopEvent(A);}}B._selectItem(B._elCurListItem);}else{B._toggleContainer(false);}}break;case 13:if(!YAHOO.env.ua.opera&&(navigator.userAgent.toLowerCase().indexOf("mac")==-1)||(YAHOO.env.ua.webkit>420)){if(B._elCurListItem){if(B._nKeyCode!=C){if(B._bContainerOpen){YAHOO.util.Event.stopEvent(A);}}B._selectItem(B._elCurListItem);}else{B._toggleContainer(false);}}break;case 27:B._toggleContainer(false);return ;case 39:B._jumpSelection();break;case 38:if(B._bContainerOpen){YAHOO.util.Event.stopEvent(A);B._moveSelection(C);}break;case 40:if(B._bContainerOpen){YAHOO.util.Event.stopEvent(A);B._moveSelection(C);}break;default:B._bItemSelected=false;B._toggleHighlight(B._elCurListItem,"from");B.textboxKeyEvent.fire(B,C);break;}if(C===18){B._enableIntervalDetection();}B._nKeyCode=C;};YAHOO.widget.AutoComplete.prototype._onTextboxKeyPress=function(A,B){var C=A.keyCode;if(YAHOO.env.ua.opera||(navigator.userAgent.toLowerCase().indexOf("mac")!=-1)&&(YAHOO.env.ua.webkit<420)){switch(C){case 9:if(B._bContainerOpen){if(B.delimChar){YAHOO.util.Event.stopEvent(A);}if(B._elCurListItem){B._selectItem(B._elCurListItem);}else{B._toggleContainer(false);}}break;case 13:if(B._bContainerOpen){YAHOO.util.Event.stopEvent(A);if(B._elCurListItem){B._selectItem(B._elCurListItem);}else{B._toggleContainer(false);}}break;default:break;}}else{if(C==229){B._enableIntervalDetection();}}};YAHOO.widget.AutoComplete.prototype._onTextboxKeyUp=function(A,C){var B=this.value;C._initProps();var D=A.keyCode;if(C._isIgnoreKey(D)){return ;}if(C._nDelayID!=-1){clearTimeout(C._nDelayID);}C._nDelayID=setTimeout(function(){C._sendQuery(B);},(C.queryDelay*1000));};YAHOO.widget.AutoComplete.prototype._onTextboxFocus=function(A,B){if(!B._bFocused){B._elTextbox.setAttribute("autocomplete","off");B._bFocused=true;B._sInitInputValue=B._elTextbox.value;B.textboxFocusEvent.fire(B);}};YAHOO.widget.AutoComplete.prototype._onTextboxBlur=function(A,C){if(!C._bOverContainer||(C._nKeyCode==9)){if(!C._bItemSelected){var B=C._textMatchesOption();if(!C._bContainerOpen||(C._bContainerOpen&&(B===null))){if(C.forceSelection){C._clearSelection();}else{C.unmatchedItemSelectEvent.fire(C,C._sCurQuery);}}else{if(C.forceSelection){C._selectItem(B);}}}if(C._bContainerOpen){C._toggleContainer(false);}C._clearInterval();C._bFocused=false;if(C._sInitInputValue!==C._elTextbox.value){C.textboxChangeEvent.fire(C);}C.textboxBlurEvent.fire(C);}};YAHOO.widget.AutoComplete.prototype._onWindowUnload=function(A,B){if(B&&B._elTextbox&&B.allowBrowserAutocomplete){B._elTextbox.setAttribute("autocomplete","on");}};YAHOO.widget.AutoComplete.prototype.doBeforeSendQuery=function(A){return this.generateRequest(A);};YAHOO.widget.AutoComplete.prototype.getListItems=function(){var C=[],B=this._elList.childNodes;for(var A=B.length-1;A>=0;A--){C[A]=B[A];}return C;};YAHOO.widget.AutoComplete._cloneObject=function(D){if(!YAHOO.lang.isValue(D)){return D;
+}var F={};if(YAHOO.lang.isFunction(D)){F=D;}else{if(YAHOO.lang.isArray(D)){var E=[];for(var C=0,B=D.length;C
+ *
+* NOTE: As of 2.4.0, the constructor's ID argument is optional.
+* The Calendar can be constructed by simply providing a container ID string,
+* or a reference to a container DIV HTMLElement (the element needs to exist
+* in the document).
+*
+* E.g.:
+*
+* var c = new YAHOO.widget.Calendar("calContainer", configOptions);
+*
+* or:
+*
+* var containerDiv = YAHOO.util.Dom.get("calContainer");
+* var c = new YAHOO.widget.Calendar(containerDiv, configOptions);
+*
+*
+*
+* If not provided, the ID will be generated from the container DIV ID by adding an "_t" suffix.
+* For example if an ID is not provided, and the container's ID is "calContainer", the Calendar's ID will be set to "calContainer_t".
+*
+*
+* @namespace YAHOO.widget
+* @class Calendar
+* @constructor
+* @param {String} id optional The id of the table element that will represent the Calendar widget. As of 2.4.0, this argument is optional.
+* @param {String | HTMLElement} container The id of the container div element that will wrap the Calendar table, or a reference to a DIV element which exists in the document.
+* @param {Object} config optional The configuration object containing the initial configuration values for the Calendar.
+*/
+function Calendar(id, containerId, config) {
+ this.init.apply(this, arguments);
+}
+
+/**
+* The path to be used for images loaded for the Calendar
+* @property YAHOO.widget.Calendar.IMG_ROOT
+* @static
+* @deprecated You can now customize images by overriding the calclose, calnavleft and calnavright default CSS classes for the close icon, left arrow and right arrow respectively
+* @type String
+*/
+Calendar.IMG_ROOT = null;
+
+/**
+* Type constant used for renderers to represent an individual date (M/D/Y)
+* @property YAHOO.widget.Calendar.DATE
+* @static
+* @final
+* @type String
+*/
+Calendar.DATE = "D";
+
+/**
+* Type constant used for renderers to represent an individual date across any year (M/D)
+* @property YAHOO.widget.Calendar.MONTH_DAY
+* @static
+* @final
+* @type String
+*/
+Calendar.MONTH_DAY = "MD";
+
+/**
+* Type constant used for renderers to represent a weekday
+* @property YAHOO.widget.Calendar.WEEKDAY
+* @static
+* @final
+* @type String
+*/
+Calendar.WEEKDAY = "WD";
+
+/**
+* Type constant used for renderers to represent a range of individual dates (M/D/Y-M/D/Y)
+* @property YAHOO.widget.Calendar.RANGE
+* @static
+* @final
+* @type String
+*/
+Calendar.RANGE = "R";
+
+/**
+* Type constant used for renderers to represent a month across any year
+* @property YAHOO.widget.Calendar.MONTH
+* @static
+* @final
+* @type String
+*/
+Calendar.MONTH = "M";
+
+/**
+* Constant that represents the total number of date cells that are displayed in a given month
+* @property YAHOO.widget.Calendar.DISPLAY_DAYS
+* @static
+* @final
+* @type Number
+*/
+Calendar.DISPLAY_DAYS = 42;
+
+/**
+* Constant used for halting the execution of the remainder of the render stack
+* @property YAHOO.widget.Calendar.STOP_RENDER
+* @static
+* @final
+* @type String
+*/
+Calendar.STOP_RENDER = "S";
+
+/**
+* Constant used to represent short date field string formats (e.g. Tu or Feb)
+* @property YAHOO.widget.Calendar.SHORT
+* @static
+* @final
+* @type String
+*/
+Calendar.SHORT = "short";
+
+/**
+* Constant used to represent long date field string formats (e.g. Monday or February)
+* @property YAHOO.widget.Calendar.LONG
+* @static
+* @final
+* @type String
+*/
+Calendar.LONG = "long";
+
+/**
+* Constant used to represent medium date field string formats (e.g. Mon)
+* @property YAHOO.widget.Calendar.MEDIUM
+* @static
+* @final
+* @type String
+*/
+Calendar.MEDIUM = "medium";
+
+/**
+* Constant used to represent single character date field string formats (e.g. M, T, W)
+* @property YAHOO.widget.Calendar.ONE_CHAR
+* @static
+* @final
+* @type String
+*/
+Calendar.ONE_CHAR = "1char";
+
+/**
+* The set of default Config property keys and values for the Calendar
+* @property YAHOO.widget.Calendar._DEFAULT_CONFIG
+* @final
+* @static
+* @private
+* @type Object
+*/
+Calendar._DEFAULT_CONFIG = {
+ // Default values for pagedate and selected are not class level constants - they are set during instance creation
+ PAGEDATE : {key:"pagedate", value:null},
+ SELECTED : {key:"selected", value:null},
+ TITLE : {key:"title", value:""},
+ CLOSE : {key:"close", value:false},
+ IFRAME : {key:"iframe", value:(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 6) ? true : false},
+ MINDATE : {key:"mindate", value:null},
+ MAXDATE : {key:"maxdate", value:null},
+ MULTI_SELECT : {key:"multi_select", value:false},
+ START_WEEKDAY : {key:"start_weekday", value:0},
+ SHOW_WEEKDAYS : {key:"show_weekdays", value:true},
+ SHOW_WEEK_HEADER : {key:"show_week_header", value:false},
+ SHOW_WEEK_FOOTER : {key:"show_week_footer", value:false},
+ HIDE_BLANK_WEEKS : {key:"hide_blank_weeks", value:false},
+ NAV_ARROW_LEFT: {key:"nav_arrow_left", value:null} ,
+ NAV_ARROW_RIGHT : {key:"nav_arrow_right", value:null} ,
+ MONTHS_SHORT : {key:"months_short", value:["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]},
+ MONTHS_LONG: {key:"months_long", value:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]},
+ WEEKDAYS_1CHAR: {key:"weekdays_1char", value:["S", "M", "T", "W", "T", "F", "S"]},
+ WEEKDAYS_SHORT: {key:"weekdays_short", value:["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]},
+ WEEKDAYS_MEDIUM: {key:"weekdays_medium", value:["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]},
+ WEEKDAYS_LONG: {key:"weekdays_long", value:["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]},
+ LOCALE_MONTHS:{key:"locale_months", value:"long"},
+ LOCALE_WEEKDAYS:{key:"locale_weekdays", value:"short"},
+ DATE_DELIMITER:{key:"date_delimiter", value:","},
+ DATE_FIELD_DELIMITER:{key:"date_field_delimiter", value:"/"},
+ DATE_RANGE_DELIMITER:{key:"date_range_delimiter", value:"-"},
+ MY_MONTH_POSITION:{key:"my_month_position", value:1},
+ MY_YEAR_POSITION:{key:"my_year_position", value:2},
+ MD_MONTH_POSITION:{key:"md_month_position", value:1},
+ MD_DAY_POSITION:{key:"md_day_position", value:2},
+ MDY_MONTH_POSITION:{key:"mdy_month_position", value:1},
+ MDY_DAY_POSITION:{key:"mdy_day_position", value:2},
+ MDY_YEAR_POSITION:{key:"mdy_year_position", value:3},
+ MY_LABEL_MONTH_POSITION:{key:"my_label_month_position", value:1},
+ MY_LABEL_YEAR_POSITION:{key:"my_label_year_position", value:2},
+ MY_LABEL_MONTH_SUFFIX:{key:"my_label_month_suffix", value:" "},
+ MY_LABEL_YEAR_SUFFIX:{key:"my_label_year_suffix", value:""},
+ NAV: {key:"navigator", value: null},
+ STRINGS : {
+ key:"strings",
+ value: {
+ previousMonth : "Previous Month",
+ nextMonth : "Next Month",
+ close: "Close"
+ },
+ supercedes : ["close", "title"]
+ }
+};
+
+var DEF_CFG = Calendar._DEFAULT_CONFIG;
+
+/**
+* The set of Custom Event types supported by the Calendar
+* @property YAHOO.widget.Calendar._EVENT_TYPES
+* @final
+* @static
+* @private
+* @type Object
+*/
+Calendar._EVENT_TYPES = {
+ BEFORE_SELECT : "beforeSelect",
+ SELECT : "select",
+ BEFORE_DESELECT : "beforeDeselect",
+ DESELECT : "deselect",
+ CHANGE_PAGE : "changePage",
+ BEFORE_RENDER : "beforeRender",
+ RENDER : "render",
+ BEFORE_DESTROY : "beforeDestroy",
+ DESTROY : "destroy",
+ RESET : "reset",
+ CLEAR : "clear",
+ BEFORE_HIDE : "beforeHide",
+ HIDE : "hide",
+ BEFORE_SHOW : "beforeShow",
+ SHOW : "show",
+ BEFORE_HIDE_NAV : "beforeHideNav",
+ HIDE_NAV : "hideNav",
+ BEFORE_SHOW_NAV : "beforeShowNav",
+ SHOW_NAV : "showNav",
+ BEFORE_RENDER_NAV : "beforeRenderNav",
+ RENDER_NAV : "renderNav"
+};
+
+/**
+* The set of default style constants for the Calendar
+* @property YAHOO.widget.Calendar._STYLES
+* @final
+* @static
+* @private
+* @type Object
+*/
+Calendar._STYLES = {
+ CSS_ROW_HEADER: "calrowhead",
+ CSS_ROW_FOOTER: "calrowfoot",
+ CSS_CELL : "calcell",
+ CSS_CELL_SELECTOR : "selector",
+ CSS_CELL_SELECTED : "selected",
+ CSS_CELL_SELECTABLE : "selectable",
+ CSS_CELL_RESTRICTED : "restricted",
+ CSS_CELL_TODAY : "today",
+ CSS_CELL_OOM : "oom",
+ CSS_CELL_OOB : "previous",
+ CSS_HEADER : "calheader",
+ CSS_HEADER_TEXT : "calhead",
+ CSS_BODY : "calbody",
+ CSS_WEEKDAY_CELL : "calweekdaycell",
+ CSS_WEEKDAY_ROW : "calweekdayrow",
+ CSS_FOOTER : "calfoot",
+ CSS_CALENDAR : "yui-calendar",
+ CSS_SINGLE : "single",
+ CSS_CONTAINER : "yui-calcontainer",
+ CSS_NAV_LEFT : "calnavleft",
+ CSS_NAV_RIGHT : "calnavright",
+ CSS_NAV : "calnav",
+ CSS_CLOSE : "calclose",
+ CSS_CELL_TOP : "calcelltop",
+ CSS_CELL_LEFT : "calcellleft",
+ CSS_CELL_RIGHT : "calcellright",
+ CSS_CELL_BOTTOM : "calcellbottom",
+ CSS_CELL_HOVER : "calcellhover",
+ CSS_CELL_HIGHLIGHT1 : "highlight1",
+ CSS_CELL_HIGHLIGHT2 : "highlight2",
+ CSS_CELL_HIGHLIGHT3 : "highlight3",
+ CSS_CELL_HIGHLIGHT4 : "highlight4"
+};
+
+Calendar.prototype = {
+
+ /**
+ * The configuration object used to set up the calendars various locale and style options.
+ * @property Config
+ * @private
+ * @deprecated Configuration properties should be set by calling Calendar.cfg.setProperty.
+ * @type Object
+ */
+ Config : null,
+
+ /**
+ * The parent CalendarGroup, only to be set explicitly by the parent group
+ * @property parent
+ * @type CalendarGroup
+ */
+ parent : null,
+
+ /**
+ * The index of this item in the parent group
+ * @property index
+ * @type Number
+ */
+ index : -1,
+
+ /**
+ * The collection of calendar table cells
+ * @property cells
+ * @type HTMLTableCellElement[]
+ */
+ cells : null,
+
+ /**
+ * The collection of calendar cell dates that is parallel to the cells collection. The array contains dates field arrays in the format of [YYYY, M, D].
+ * @property cellDates
+ * @type Array[](Number[])
+ */
+ cellDates : null,
+
+ /**
+ * The id that uniquely identifies this Calendar.
+ * @property id
+ * @type String
+ */
+ id : null,
+
+ /**
+ * The unique id associated with the Calendar's container
+ * @property containerId
+ * @type String
+ */
+ containerId: null,
+
+ /**
+ * The DOM element reference that points to this calendar's container element. The calendar will be inserted into this element when the shell is rendered.
+ * @property oDomContainer
+ * @type HTMLElement
+ */
+ oDomContainer : null,
+
+ /**
+ * A Date object representing today's date.
+ * @property today
+ * @type Date
+ */
+ today : null,
+
+ /**
+ * The list of render functions, along with required parameters, used to render cells.
+ * @property renderStack
+ * @type Array[]
+ */
+ renderStack : null,
+
+ /**
+ * A copy of the initial render functions created before rendering.
+ * @property _renderStack
+ * @private
+ * @type Array
+ */
+ _renderStack : null,
+
+ /**
+ * A reference to the CalendarNavigator instance created for this Calendar.
+ * Will be null if the "navigator" configuration property has not been set
+ * @property oNavigator
+ * @type CalendarNavigator
+ */
+ oNavigator : null,
+
+ /**
+ * The private list of initially selected dates.
+ * @property _selectedDates
+ * @private
+ * @type Array
+ */
+ _selectedDates : null,
+
+ /**
+ * A map of DOM event handlers to attach to cells associated with specific CSS class names
+ * @property domEventMap
+ * @type Object
+ */
+ domEventMap : null,
+
+ /**
+ * Protected helper used to parse Calendar constructor/init arguments.
+ *
+ * As of 2.4.0, Calendar supports a simpler constructor
+ * signature. This method reconciles arguments
+ * received in the pre 2.4.0 and 2.4.0 formats.
+ *
+ * @protected
+ * @method _parseArgs
+ * @param {Array} Function "arguments" array
+ * @return {Object} Object with id, container, config properties containing
+ * the reconciled argument values.
+ **/
+ _parseArgs : function(args) {
+ /*
+ 2.4.0 Constructors signatures
+
+ new Calendar(String)
+ new Calendar(HTMLElement)
+ new Calendar(String, ConfigObject)
+ new Calendar(HTMLElement, ConfigObject)
+
+ Pre 2.4.0 Constructor signatures
+
+ new Calendar(String, String)
+ new Calendar(String, HTMLElement)
+ new Calendar(String, String, ConfigObject)
+ new Calendar(String, HTMLElement, ConfigObject)
+ */
+ var nArgs = {id:null, container:null, config:null};
+
+ if (args && args.length && args.length > 0) {
+ switch (args.length) {
+ case 1:
+ nArgs.id = null;
+ nArgs.container = args[0];
+ nArgs.config = null;
+ break;
+ case 2:
+ if (Lang.isObject(args[1]) && !args[1].tagName && !(args[1] instanceof String)) {
+ nArgs.id = null;
+ nArgs.container = args[0];
+ nArgs.config = args[1];
+ } else {
+ nArgs.id = args[0];
+ nArgs.container = args[1];
+ nArgs.config = null;
+ }
+ break;
+ default: // 3+
+ nArgs.id = args[0];
+ nArgs.container = args[1];
+ nArgs.config = args[2];
+ break;
+ }
+ } else {
+ this.logger.log("Invalid constructor/init arguments", "error");
+ }
+ return nArgs;
+ },
+
+ /**
+ * Initializes the Calendar widget.
+ * @method init
+ *
+ * @param {String} id optional The id of the table element that will represent the Calendar widget. As of 2.4.0, this argument is optional.
+ * @param {String | HTMLElement} container The id of the container div element that will wrap the Calendar table, or a reference to a DIV element which exists in the document.
+ * @param {Object} config optional The configuration object containing the initial configuration values for the Calendar.
+ */
+ init : function(id, container, config) {
+ // Normalize 2.4.0, pre 2.4.0 args
+ var nArgs = this._parseArgs(arguments);
+
+ id = nArgs.id;
+ container = nArgs.container;
+ config = nArgs.config;
+
+ this.oDomContainer = Dom.get(container);
+ if (!this.oDomContainer) { this.logger.log("Container not found in document.", "error"); }
+
+ if (!this.oDomContainer.id) {
+ this.oDomContainer.id = Dom.generateId();
+ }
+ if (!id) {
+ id = this.oDomContainer.id + "_t";
+ }
+
+ this.id = id;
+ this.containerId = this.oDomContainer.id;
+
+ this.logger = new YAHOO.widget.LogWriter("Calendar " + this.id);
+ this.initEvents();
+
+ this.today = new Date();
+ DateMath.clearTime(this.today);
+
+ /**
+ * The Config object used to hold the configuration variables for the Calendar
+ * @property cfg
+ * @type YAHOO.util.Config
+ */
+ this.cfg = new YAHOO.util.Config(this);
+
+ /**
+ * The local object which contains the Calendar's options
+ * @property Options
+ * @type Object
+ */
+ this.Options = {};
+
+ /**
+ * The local object which contains the Calendar's locale settings
+ * @property Locale
+ * @type Object
+ */
+ this.Locale = {};
+
+ this.initStyles();
+
+ Dom.addClass(this.oDomContainer, this.Style.CSS_CONTAINER);
+ Dom.addClass(this.oDomContainer, this.Style.CSS_SINGLE);
+
+ this.cellDates = [];
+ this.cells = [];
+ this.renderStack = [];
+ this._renderStack = [];
+
+ this.setupConfig();
+
+ if (config) {
+ this.cfg.applyConfig(config, true);
+ }
+
+ this.cfg.fireQueue();
+ },
+
+ /**
+ * Default Config listener for the iframe property. If the iframe config property is set to true,
+ * renders the built-in IFRAME shim if the container is relatively or absolutely positioned.
+ *
+ * @method configIframe
+ */
+ configIframe : function(type, args, obj) {
+ var useIframe = args[0];
+
+ if (!this.parent) {
+ if (Dom.inDocument(this.oDomContainer)) {
+ if (useIframe) {
+ var pos = Dom.getStyle(this.oDomContainer, "position");
+
+ if (pos == "absolute" || pos == "relative") {
+
+ if (!Dom.inDocument(this.iframe)) {
+ this.iframe = document.createElement("iframe");
+ this.iframe.src = "javascript:false;";
+
+ Dom.setStyle(this.iframe, "opacity", "0");
+
+ if (YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 6) {
+ Dom.addClass(this.iframe, "fixedsize");
+ }
+
+ this.oDomContainer.insertBefore(this.iframe, this.oDomContainer.firstChild);
+ }
+ }
+ } else {
+ if (this.iframe) {
+ if (this.iframe.parentNode) {
+ this.iframe.parentNode.removeChild(this.iframe);
+ }
+ this.iframe = null;
+ }
+ }
+ }
+ }
+ },
+
+ /**
+ * Default handler for the "title" property
+ * @method configTitle
+ */
+ configTitle : function(type, args, obj) {
+ var title = args[0];
+
+ // "" disables title bar
+ if (title) {
+ this.createTitleBar(title);
+ } else {
+ var close = this.cfg.getProperty(DEF_CFG.CLOSE.key);
+ if (!close) {
+ this.removeTitleBar();
+ } else {
+ this.createTitleBar(" ");
+ }
+ }
+ },
+
+ /**
+ * Default handler for the "close" property
+ * @method configClose
+ */
+ configClose : function(type, args, obj) {
+ var close = args[0],
+ title = this.cfg.getProperty(DEF_CFG.TITLE.key);
+
+ if (close) {
+ if (!title) {
+ this.createTitleBar(" ");
+ }
+ this.createCloseButton();
+ } else {
+ this.removeCloseButton();
+ if (!title) {
+ this.removeTitleBar();
+ }
+ }
+ },
+
+ /**
+ * Initializes Calendar's built-in CustomEvents
+ * @method initEvents
+ */
+ initEvents : function() {
+
+ var defEvents = Calendar._EVENT_TYPES,
+ CE = YAHOO.util.CustomEvent,
+ cal = this; // To help with minification
+
+ /**
+ * Fired before a selection is made
+ * @event beforeSelectEvent
+ */
+ cal.beforeSelectEvent = new CE(defEvents.BEFORE_SELECT);
+
+ /**
+ * Fired when a selection is made
+ * @event selectEvent
+ * @param {Array} Array of Date field arrays in the format [YYYY, MM, DD].
+ */
+ cal.selectEvent = new CE(defEvents.SELECT);
+
+ /**
+ * Fired before a selection is made
+ * @event beforeDeselectEvent
+ */
+ cal.beforeDeselectEvent = new CE(defEvents.BEFORE_DESELECT);
+
+ /**
+ * Fired when a selection is made
+ * @event deselectEvent
+ * @param {Array} Array of Date field arrays in the format [YYYY, MM, DD].
+ */
+ cal.deselectEvent = new CE(defEvents.DESELECT);
+
+ /**
+ * Fired when the Calendar page is changed
+ * @event changePageEvent
+ */
+ cal.changePageEvent = new CE(defEvents.CHANGE_PAGE);
+
+ /**
+ * Fired before the Calendar is rendered
+ * @event beforeRenderEvent
+ */
+ cal.beforeRenderEvent = new CE(defEvents.BEFORE_RENDER);
+
+ /**
+ * Fired when the Calendar is rendered
+ * @event renderEvent
+ */
+ cal.renderEvent = new CE(defEvents.RENDER);
+
+ /**
+ * Fired just before the Calendar is to be destroyed
+ * @event beforeDestroyEvent
+ */
+ cal.beforeDestroyEvent = new CE(defEvents.BEFORE_DESTROY);
+
+ /**
+ * Fired after the Calendar is destroyed. This event should be used
+ * for notification only. When this event is fired, important Calendar instance
+ * properties, dom references and event listeners have already been
+ * removed/dereferenced, and hence the Calendar instance is not in a usable
+ * state.
+ *
+ * @event destroyEvent
+ */
+ cal.destroyEvent = new CE(defEvents.DESTROY);
+
+ /**
+ * Fired when the Calendar is reset
+ * @event resetEvent
+ */
+ cal.resetEvent = new CE(defEvents.RESET);
+
+ /**
+ * Fired when the Calendar is cleared
+ * @event clearEvent
+ */
+ cal.clearEvent = new CE(defEvents.CLEAR);
+
+ /**
+ * Fired just before the Calendar is to be shown
+ * @event beforeShowEvent
+ */
+ cal.beforeShowEvent = new CE(defEvents.BEFORE_SHOW);
+
+ /**
+ * Fired after the Calendar is shown
+ * @event showEvent
+ */
+ cal.showEvent = new CE(defEvents.SHOW);
+
+ /**
+ * Fired just before the Calendar is to be hidden
+ * @event beforeHideEvent
+ */
+ cal.beforeHideEvent = new CE(defEvents.BEFORE_HIDE);
+
+ /**
+ * Fired after the Calendar is hidden
+ * @event hideEvent
+ */
+ cal.hideEvent = new CE(defEvents.HIDE);
+
+ /**
+ * Fired just before the CalendarNavigator is to be shown
+ * @event beforeShowNavEvent
+ */
+ cal.beforeShowNavEvent = new CE(defEvents.BEFORE_SHOW_NAV);
+
+ /**
+ * Fired after the CalendarNavigator is shown
+ * @event showNavEvent
+ */
+ cal.showNavEvent = new CE(defEvents.SHOW_NAV);
+
+ /**
+ * Fired just before the CalendarNavigator is to be hidden
+ * @event beforeHideNavEvent
+ */
+ cal.beforeHideNavEvent = new CE(defEvents.BEFORE_HIDE_NAV);
+
+ /**
+ * Fired after the CalendarNavigator is hidden
+ * @event hideNavEvent
+ */
+ cal.hideNavEvent = new CE(defEvents.HIDE_NAV);
+
+ /**
+ * Fired just before the CalendarNavigator is to be rendered
+ * @event beforeRenderNavEvent
+ */
+ cal.beforeRenderNavEvent = new CE(defEvents.BEFORE_RENDER_NAV);
+
+ /**
+ * Fired after the CalendarNavigator is rendered
+ * @event renderNavEvent
+ */
+ cal.renderNavEvent = new CE(defEvents.RENDER_NAV);
+
+ cal.beforeSelectEvent.subscribe(cal.onBeforeSelect, this, true);
+ cal.selectEvent.subscribe(cal.onSelect, this, true);
+ cal.beforeDeselectEvent.subscribe(cal.onBeforeDeselect, this, true);
+ cal.deselectEvent.subscribe(cal.onDeselect, this, true);
+ cal.changePageEvent.subscribe(cal.onChangePage, this, true);
+ cal.renderEvent.subscribe(cal.onRender, this, true);
+ cal.resetEvent.subscribe(cal.onReset, this, true);
+ cal.clearEvent.subscribe(cal.onClear, this, true);
+ },
+
+ /**
+ * The default event handler for clicks on the "Previous Month" navigation UI
+ *
+ * @method doPreviousMonthNav
+ * @param {DOMEvent} e The DOM event
+ * @param {Calendar} cal A reference to the calendar
+ */
+ doPreviousMonthNav : function(e, cal) {
+ Event.preventDefault(e);
+ // previousMonth invoked in a timeout, to allow
+ // event to bubble up, with correct target. Calling
+ // previousMonth, will call render which will remove
+ // HTML which generated the event, resulting in an
+ // invalid event target in certain browsers.
+ setTimeout(function() {
+ cal.previousMonth();
+ var navs = Dom.getElementsByClassName(cal.Style.CSS_NAV_LEFT, "a", cal.oDomContainer);
+ if (navs && navs[0]) {
+ try {
+ navs[0].focus();
+ } catch (e) {
+ // ignore
+ }
+ }
+ }, 0);
+ },
+
+ /**
+ * The default event handler for clicks on the "Next Month" navigation UI
+ *
+ * @method doNextMonthNav
+ * @param {DOMEvent} e The DOM event
+ * @param {Calendar} cal A reference to the calendar
+ */
+ doNextMonthNav : function(e, cal) {
+ Event.preventDefault(e);
+ setTimeout(function() {
+ cal.nextMonth();
+ var navs = Dom.getElementsByClassName(cal.Style.CSS_NAV_RIGHT, "a", cal.oDomContainer);
+ if (navs && navs[0]) {
+ try {
+ navs[0].focus();
+ } catch (e) {
+ // ignore
+ }
+ }
+ }, 0);
+ },
+
+ /**
+ * The default event handler for date cell selection. Currently attached to
+ * the Calendar's bounding box, referenced by it's oDomContainer property.
+ *
+ * @method doSelectCell
+ * @param {DOMEvent} e The DOM event
+ * @param {Calendar} cal A reference to the calendar
+ */
+ doSelectCell : function(e, cal) {
+ var cell, d, date, index;
+
+ var target = Event.getTarget(e),
+ tagName = target.tagName.toLowerCase(),
+ defSelector = false;
+
+ while (tagName != "td" && !Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) {
+
+ if (!defSelector && tagName == "a" && Dom.hasClass(target, cal.Style.CSS_CELL_SELECTOR)) {
+ defSelector = true;
+ }
+
+ target = target.parentNode;
+ tagName = target.tagName.toLowerCase();
+
+ if (target == this.oDomContainer || tagName == "html") {
+ return;
+ }
+ }
+
+ if (defSelector) {
+ // Stop link href navigation for default renderer
+ Event.preventDefault(e);
+ }
+
+ cell = target;
+
+ if (Dom.hasClass(cell, cal.Style.CSS_CELL_SELECTABLE)) {
+ index = cal.getIndexFromId(cell.id);
+ if (index > -1) {
+ d = cal.cellDates[index];
+ if (d) {
+ date = DateMath.getDate(d[0],d[1]-1,d[2]);
+
+ var link;
+
+ cal.logger.log("Selecting cell " + index + " via click", "info");
+ if (cal.Options.MULTI_SELECT) {
+ link = cell.getElementsByTagName("a")[0];
+ if (link) {
+ link.blur();
+ }
+
+ var cellDate = cal.cellDates[index];
+ var cellDateIndex = cal._indexOfSelectedFieldArray(cellDate);
+
+ if (cellDateIndex > -1) {
+ cal.deselectCell(index);
+ } else {
+ cal.selectCell(index);
+ }
+
+ } else {
+ link = cell.getElementsByTagName("a")[0];
+ if (link) {
+ link.blur();
+ }
+ cal.selectCell(index);
+ }
+ }
+ }
+ }
+ },
+
+ /**
+ * The event that is executed when the user hovers over a cell
+ * @method doCellMouseOver
+ * @param {DOMEvent} e The event
+ * @param {Calendar} cal A reference to the calendar passed by the Event utility
+ */
+ doCellMouseOver : function(e, cal) {
+ var target;
+ if (e) {
+ target = Event.getTarget(e);
+ } else {
+ target = this;
+ }
+
+ while (target.tagName && target.tagName.toLowerCase() != "td") {
+ target = target.parentNode;
+ if (!target.tagName || target.tagName.toLowerCase() == "html") {
+ return;
+ }
+ }
+
+ if (Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) {
+ Dom.addClass(target, cal.Style.CSS_CELL_HOVER);
+ }
+ },
+
+ /**
+ * The event that is executed when the user moves the mouse out of a cell
+ * @method doCellMouseOut
+ * @param {DOMEvent} e The event
+ * @param {Calendar} cal A reference to the calendar passed by the Event utility
+ */
+ doCellMouseOut : function(e, cal) {
+ var target;
+ if (e) {
+ target = Event.getTarget(e);
+ } else {
+ target = this;
+ }
+
+ while (target.tagName && target.tagName.toLowerCase() != "td") {
+ target = target.parentNode;
+ if (!target.tagName || target.tagName.toLowerCase() == "html") {
+ return;
+ }
+ }
+
+ if (Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) {
+ Dom.removeClass(target, cal.Style.CSS_CELL_HOVER);
+ }
+ },
+
+ setupConfig : function() {
+ var cfg = this.cfg;
+
+ /**
+ * The month/year representing the current visible Calendar date (mm/yyyy)
+ * @config pagedate
+ * @type String | Date
+ * @default today's date
+ */
+ cfg.addProperty(DEF_CFG.PAGEDATE.key, { value:new Date(), handler:this.configPageDate } );
+
+ /**
+ * The date or range of dates representing the current Calendar selection
+ * @config selected
+ * @type String
+ * @default []
+ */
+ cfg.addProperty(DEF_CFG.SELECTED.key, { value:[], handler:this.configSelected } );
+
+ /**
+ * The title to display above the Calendar's month header
+ * @config title
+ * @type String
+ * @default ""
+ */
+ cfg.addProperty(DEF_CFG.TITLE.key, { value:DEF_CFG.TITLE.value, handler:this.configTitle } );
+
+ /**
+ * Whether or not a close button should be displayed for this Calendar
+ * @config close
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.CLOSE.key, { value:DEF_CFG.CLOSE.value, handler:this.configClose } );
+
+ /**
+ * Whether or not an iframe shim should be placed under the Calendar to prevent select boxes from bleeding through in Internet Explorer 6 and below.
+ * This property is enabled by default for IE6 and below. It is disabled by default for other browsers for performance reasons, but can be
+ * enabled if required.
+ *
+ * @config iframe
+ * @type Boolean
+ * @default true for IE6 and below, false for all other browsers
+ */
+ cfg.addProperty(DEF_CFG.IFRAME.key, { value:DEF_CFG.IFRAME.value, handler:this.configIframe, validator:cfg.checkBoolean } );
+
+ /**
+ * The minimum selectable date in the current Calendar (mm/dd/yyyy)
+ * @config mindate
+ * @type String | Date
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.MINDATE.key, { value:DEF_CFG.MINDATE.value, handler:this.configMinDate } );
+
+ /**
+ * The maximum selectable date in the current Calendar (mm/dd/yyyy)
+ * @config maxdate
+ * @type String | Date
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.MAXDATE.key, { value:DEF_CFG.MAXDATE.value, handler:this.configMaxDate } );
+
+
+ // Options properties
+
+ /**
+ * True if the Calendar should allow multiple selections. False by default.
+ * @config MULTI_SELECT
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.MULTI_SELECT.key, { value:DEF_CFG.MULTI_SELECT.value, handler:this.configOptions, validator:cfg.checkBoolean } );
+
+ /**
+ * The weekday the week begins on. Default is 0 (Sunday = 0, Monday = 1 ... Saturday = 6).
+ * @config START_WEEKDAY
+ * @type number
+ * @default 0
+ */
+ cfg.addProperty(DEF_CFG.START_WEEKDAY.key, { value:DEF_CFG.START_WEEKDAY.value, handler:this.configOptions, validator:cfg.checkNumber } );
+
+ /**
+ * True if the Calendar should show weekday labels. True by default.
+ * @config SHOW_WEEKDAYS
+ * @type Boolean
+ * @default true
+ */
+ cfg.addProperty(DEF_CFG.SHOW_WEEKDAYS.key, { value:DEF_CFG.SHOW_WEEKDAYS.value, handler:this.configOptions, validator:cfg.checkBoolean } );
+
+ /**
+ * True if the Calendar should show week row headers. False by default.
+ * @config SHOW_WEEK_HEADER
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.SHOW_WEEK_HEADER.key, { value:DEF_CFG.SHOW_WEEK_HEADER.value, handler:this.configOptions, validator:cfg.checkBoolean } );
+
+ /**
+ * True if the Calendar should show week row footers. False by default.
+ * @config SHOW_WEEK_FOOTER
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.SHOW_WEEK_FOOTER.key,{ value:DEF_CFG.SHOW_WEEK_FOOTER.value, handler:this.configOptions, validator:cfg.checkBoolean } );
+
+ /**
+ * True if the Calendar should suppress weeks that are not a part of the current month. False by default.
+ * @config HIDE_BLANK_WEEKS
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.HIDE_BLANK_WEEKS.key, { value:DEF_CFG.HIDE_BLANK_WEEKS.value, handler:this.configOptions, validator:cfg.checkBoolean } );
+
+ /**
+ * The image that should be used for the left navigation arrow.
+ * @config NAV_ARROW_LEFT
+ * @type String
+ * @deprecated You can customize the image by overriding the default CSS class for the left arrow - "calnavleft"
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.NAV_ARROW_LEFT.key, { value:DEF_CFG.NAV_ARROW_LEFT.value, handler:this.configOptions } );
+
+ /**
+ * The image that should be used for the right navigation arrow.
+ * @config NAV_ARROW_RIGHT
+ * @type String
+ * @deprecated You can customize the image by overriding the default CSS class for the right arrow - "calnavright"
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.NAV_ARROW_RIGHT.key, { value:DEF_CFG.NAV_ARROW_RIGHT.value, handler:this.configOptions } );
+
+ // Locale properties
+
+ /**
+ * The short month labels for the current locale.
+ * @config MONTHS_SHORT
+ * @type String[]
+ * @default ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
+ */
+ cfg.addProperty(DEF_CFG.MONTHS_SHORT.key, { value:DEF_CFG.MONTHS_SHORT.value, handler:this.configLocale } );
+
+ /**
+ * The long month labels for the current locale.
+ * @config MONTHS_LONG
+ * @type String[]
+ * @default ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
+ */
+ cfg.addProperty(DEF_CFG.MONTHS_LONG.key, { value:DEF_CFG.MONTHS_LONG.value, handler:this.configLocale } );
+
+ /**
+ * The 1-character weekday labels for the current locale.
+ * @config WEEKDAYS_1CHAR
+ * @type String[]
+ * @default ["S", "M", "T", "W", "T", "F", "S"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_1CHAR.key, { value:DEF_CFG.WEEKDAYS_1CHAR.value, handler:this.configLocale } );
+
+ /**
+ * The short weekday labels for the current locale.
+ * @config WEEKDAYS_SHORT
+ * @type String[]
+ * @default ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_SHORT.key, { value:DEF_CFG.WEEKDAYS_SHORT.value, handler:this.configLocale } );
+
+ /**
+ * The medium weekday labels for the current locale.
+ * @config WEEKDAYS_MEDIUM
+ * @type String[]
+ * @default ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_MEDIUM.key, { value:DEF_CFG.WEEKDAYS_MEDIUM.value, handler:this.configLocale } );
+
+ /**
+ * The long weekday labels for the current locale.
+ * @config WEEKDAYS_LONG
+ * @type String[]
+ * @default ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_LONG.key, { value:DEF_CFG.WEEKDAYS_LONG.value, handler:this.configLocale } );
+
+ /**
+ * Refreshes the locale values used to build the Calendar.
+ * @method refreshLocale
+ * @private
+ */
+ var refreshLocale = function() {
+ cfg.refireEvent(DEF_CFG.LOCALE_MONTHS.key);
+ cfg.refireEvent(DEF_CFG.LOCALE_WEEKDAYS.key);
+ };
+
+ cfg.subscribeToConfigEvent(DEF_CFG.START_WEEKDAY.key, refreshLocale, this, true);
+ cfg.subscribeToConfigEvent(DEF_CFG.MONTHS_SHORT.key, refreshLocale, this, true);
+ cfg.subscribeToConfigEvent(DEF_CFG.MONTHS_LONG.key, refreshLocale, this, true);
+ cfg.subscribeToConfigEvent(DEF_CFG.WEEKDAYS_1CHAR.key, refreshLocale, this, true);
+ cfg.subscribeToConfigEvent(DEF_CFG.WEEKDAYS_SHORT.key, refreshLocale, this, true);
+ cfg.subscribeToConfigEvent(DEF_CFG.WEEKDAYS_MEDIUM.key, refreshLocale, this, true);
+ cfg.subscribeToConfigEvent(DEF_CFG.WEEKDAYS_LONG.key, refreshLocale, this, true);
+
+ /**
+ * The setting that determines which length of month labels should be used. Possible values are "short" and "long".
+ * @config LOCALE_MONTHS
+ * @type String
+ * @default "long"
+ */
+ cfg.addProperty(DEF_CFG.LOCALE_MONTHS.key, { value:DEF_CFG.LOCALE_MONTHS.value, handler:this.configLocaleValues } );
+
+ /**
+ * The setting that determines which length of weekday labels should be used. Possible values are "1char", "short", "medium", and "long".
+ * @config LOCALE_WEEKDAYS
+ * @type String
+ * @default "short"
+ */
+ cfg.addProperty(DEF_CFG.LOCALE_WEEKDAYS.key, { value:DEF_CFG.LOCALE_WEEKDAYS.value, handler:this.configLocaleValues } );
+
+ /**
+ * The value used to delimit individual dates in a date string passed to various Calendar functions.
+ * @config DATE_DELIMITER
+ * @type String
+ * @default ","
+ */
+ cfg.addProperty(DEF_CFG.DATE_DELIMITER.key, { value:DEF_CFG.DATE_DELIMITER.value, handler:this.configLocale } );
+
+ /**
+ * The value used to delimit date fields in a date string passed to various Calendar functions.
+ * @config DATE_FIELD_DELIMITER
+ * @type String
+ * @default "/"
+ */
+ cfg.addProperty(DEF_CFG.DATE_FIELD_DELIMITER.key, { value:DEF_CFG.DATE_FIELD_DELIMITER.value, handler:this.configLocale } );
+
+ /**
+ * The value used to delimit date ranges in a date string passed to various Calendar functions.
+ * @config DATE_RANGE_DELIMITER
+ * @type String
+ * @default "-"
+ */
+ cfg.addProperty(DEF_CFG.DATE_RANGE_DELIMITER.key, { value:DEF_CFG.DATE_RANGE_DELIMITER.value, handler:this.configLocale } );
+
+ /**
+ * The position of the month in a month/year date string
+ * @config MY_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MY_MONTH_POSITION.key, { value:DEF_CFG.MY_MONTH_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the year in a month/year date string
+ * @config MY_YEAR_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MY_YEAR_POSITION.key, { value:DEF_CFG.MY_YEAR_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the month in a month/day date string
+ * @config MD_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MD_MONTH_POSITION.key, { value:DEF_CFG.MD_MONTH_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the day in a month/year date string
+ * @config MD_DAY_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MD_DAY_POSITION.key, { value:DEF_CFG.MD_DAY_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the month in a month/day/year date string
+ * @config MDY_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MDY_MONTH_POSITION.key, { value:DEF_CFG.MDY_MONTH_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the day in a month/day/year date string
+ * @config MDY_DAY_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MDY_DAY_POSITION.key, { value:DEF_CFG.MDY_DAY_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the year in a month/day/year date string
+ * @config MDY_YEAR_POSITION
+ * @type Number
+ * @default 3
+ */
+ cfg.addProperty(DEF_CFG.MDY_YEAR_POSITION.key, { value:DEF_CFG.MDY_YEAR_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the month in the month year label string used as the Calendar header
+ * @config MY_LABEL_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_MONTH_POSITION.key, { value:DEF_CFG.MY_LABEL_MONTH_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the year in the month year label string used as the Calendar header
+ * @config MY_LABEL_YEAR_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_YEAR_POSITION.key, { value:DEF_CFG.MY_LABEL_YEAR_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The suffix used after the month when rendering the Calendar header
+ * @config MY_LABEL_MONTH_SUFFIX
+ * @type String
+ * @default " "
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_MONTH_SUFFIX.key, { value:DEF_CFG.MY_LABEL_MONTH_SUFFIX.value, handler:this.configLocale } );
+
+ /**
+ * The suffix used after the year when rendering the Calendar header
+ * @config MY_LABEL_YEAR_SUFFIX
+ * @type String
+ * @default ""
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_YEAR_SUFFIX.key, { value:DEF_CFG.MY_LABEL_YEAR_SUFFIX.value, handler:this.configLocale } );
+
+ /**
+ * Configuration for the Month/Year CalendarNavigator UI which allows the user to jump directly to a
+ * specific Month/Year without having to scroll sequentially through months.
+ *
+ * Setting this property to null (default value) or false, will disable the CalendarNavigator UI.
+ *
+ *
+ * Setting this property to true will enable the CalendarNavigatior UI with the default CalendarNavigator configuration values.
+ *
+ *
+ * This property can also be set to an object literal containing configuration properties for the CalendarNavigator UI.
+ * The configuration object expects the the following case-sensitive properties, with the "strings" property being a nested object.
+ * Any properties which are not provided will use the default values (defined in the CalendarNavigator class).
+ *
+ *
+ *
strings
+ *
Object : An object with the properties shown below, defining the string labels to use in the Navigator's UI
+ *
+ *
month
String : The string to use for the month label. Defaults to "Month".
+ *
year
String : The string to use for the year label. Defaults to "Year".
+ *
submit
String : The string to use for the submit button label. Defaults to "Okay".
+ *
cancel
String : The string to use for the cancel button label. Defaults to "Cancel".
+ *
invalidYear
String : The string to use for invalid year values. Defaults to "Year needs to be a number".
+ *
+ *
+ *
monthFormat
String : The month format to use. Either YAHOO.widget.Calendar.LONG, or YAHOO.widget.Calendar.SHORT. Defaults to YAHOO.widget.Calendar.LONG
+ *
initialFocus
String : Either "year" or "month" specifying which input control should get initial focus. Defaults to "year"
';
+
+ return html;
+ },
+
+ /**
+ * Renders the calendar body.
+ * @method renderBody
+ * @param {Date} workingDate The current working Date being used for the render process
+ * @param {Array} html The current working HTML array
+ * @return {Array} The current working HTML array
+ */
+ renderBody : function(workingDate, html) {
+ this.logger.log("Rendering body", "render");
+
+ var startDay = this.cfg.getProperty(DEF_CFG.START_WEEKDAY.key);
+
+ this.preMonthDays = workingDate.getDay();
+ if (startDay > 0) {
+ this.preMonthDays -= startDay;
+ }
+ if (this.preMonthDays < 0) {
+ this.preMonthDays += 7;
+ }
+
+ this.monthDays = DateMath.findMonthEnd(workingDate).getDate();
+ this.postMonthDays = Calendar.DISPLAY_DAYS-this.preMonthDays-this.monthDays;
+
+ this.logger.log(this.preMonthDays + " preciding out-of-month days", "render");
+ this.logger.log(this.monthDays + " month days", "render");
+ this.logger.log(this.postMonthDays + " post-month days", "render");
+
+ workingDate = DateMath.subtract(workingDate, DateMath.DAY, this.preMonthDays);
+ this.logger.log("Calendar page starts on " + workingDate, "render");
+
+ var weekNum,
+ weekClass,
+ weekPrefix = "w",
+ cellPrefix = "_cell",
+ workingDayPrefix = "wd",
+ dayPrefix = "d",
+ cellRenderers,
+ renderer,
+ t = this.today,
+ cfg = this.cfg,
+ todayYear = t.getFullYear(),
+ todayMonth = t.getMonth(),
+ todayDate = t.getDate(),
+ useDate = cfg.getProperty(DEF_CFG.PAGEDATE.key),
+ hideBlankWeeks = cfg.getProperty(DEF_CFG.HIDE_BLANK_WEEKS.key),
+ showWeekFooter = cfg.getProperty(DEF_CFG.SHOW_WEEK_FOOTER.key),
+ showWeekHeader = cfg.getProperty(DEF_CFG.SHOW_WEEK_HEADER.key),
+ mindate = cfg.getProperty(DEF_CFG.MINDATE.key),
+ maxdate = cfg.getProperty(DEF_CFG.MAXDATE.key);
+
+ if (mindate) {
+ mindate = DateMath.clearTime(mindate);
+ }
+ if (maxdate) {
+ maxdate = DateMath.clearTime(maxdate);
+ }
+
+ html[html.length] = '';
+
+ var i = 0,
+ tempDiv = document.createElement("div"),
+ cell = document.createElement("td");
+
+ tempDiv.appendChild(cell);
+
+ var cal = this.parent || this;
+
+ for (var r=0;r<6;r++) {
+ weekNum = DateMath.getWeekNumber(workingDate, startDay);
+ weekClass = weekPrefix + weekNum;
+
+ // Local OOM check for performance, since we already have pagedate
+ if (r !== 0 && hideBlankWeeks === true && workingDate.getMonth() != useDate.getMonth()) {
+ break;
+ } else {
+ html[html.length] = '
';
+
+ if (showWeekHeader) { html = this.renderRowHeader(weekNum, html); }
+
+ for (var d=0; d < 7; d++){ // Render actual days
+
+ cellRenderers = [];
+
+ this.clearElement(cell);
+ cell.className = this.Style.CSS_CELL;
+ cell.id = this.id + cellPrefix + i;
+ this.logger.log("Rendering cell " + cell.id + " (" + workingDate.getFullYear() + "-" + (workingDate.getMonth()+1) + "-" + workingDate.getDate() + ")", "cellrender");
+
+ if (workingDate.getDate() == todayDate &&
+ workingDate.getMonth() == todayMonth &&
+ workingDate.getFullYear() == todayYear) {
+ cellRenderers[cellRenderers.length]=cal.renderCellStyleToday;
+ }
+
+ var workingArray = [workingDate.getFullYear(),workingDate.getMonth()+1,workingDate.getDate()];
+ this.cellDates[this.cellDates.length] = workingArray; // Add this date to cellDates
+
+ // Local OOM check for performance, since we already have pagedate
+ if (workingDate.getMonth() != useDate.getMonth()) {
+ cellRenderers[cellRenderers.length]=cal.renderCellNotThisMonth;
+ } else {
+ Dom.addClass(cell, workingDayPrefix + workingDate.getDay());
+ Dom.addClass(cell, dayPrefix + workingDate.getDate());
+
+ for (var s=0;s= d1.getTime() && workingDate.getTime() <= d2.getTime()) {
+ renderer = rArray[2];
+
+ if (workingDate.getTime()==d2.getTime()) {
+ this.renderStack.splice(s,1);
+ }
+ }
+ break;
+ case Calendar.WEEKDAY:
+ var weekday = rArray[1][0];
+ if (workingDate.getDay()+1 == weekday) {
+ renderer = rArray[2];
+ }
+ break;
+ case Calendar.MONTH:
+ month = rArray[1][0];
+ if (workingDate.getMonth()+1 == month) {
+ renderer = rArray[2];
+ }
+ break;
+ }
+
+ if (renderer) {
+ cellRenderers[cellRenderers.length]=renderer;
+ }
+ }
+
+ }
+
+ if (this._indexOfSelectedFieldArray(workingArray) > -1) {
+ cellRenderers[cellRenderers.length]=cal.renderCellStyleSelected;
+ }
+
+ if ((mindate && (workingDate.getTime() < mindate.getTime())) ||
+ (maxdate && (workingDate.getTime() > maxdate.getTime()))
+ ) {
+ cellRenderers[cellRenderers.length]=cal.renderOutOfBoundsDate;
+ } else {
+ cellRenderers[cellRenderers.length]=cal.styleCellDefault;
+ cellRenderers[cellRenderers.length]=cal.renderCellDefault;
+ }
+
+ for (var x=0; x < cellRenderers.length; ++x) {
+ this.logger.log("renderer[" + x + "] for (" + workingDate.getFullYear() + "-" + (workingDate.getMonth()+1) + "-" + workingDate.getDate() + ")", "cellrender");
+ if (cellRenderers[x].call(cal, workingDate, cell) == Calendar.STOP_RENDER) {
+ break;
+ }
+ }
+
+ workingDate.setTime(workingDate.getTime() + DateMath.ONE_DAY_MS);
+ // Just in case we crossed DST/Summertime boundaries
+ workingDate = DateMath.clearTime(workingDate);
+
+ if (i >= 0 && i <= 6) {
+ Dom.addClass(cell, this.Style.CSS_CELL_TOP);
+ }
+ if ((i % 7) === 0) {
+ Dom.addClass(cell, this.Style.CSS_CELL_LEFT);
+ }
+ if (((i+1) % 7) === 0) {
+ Dom.addClass(cell, this.Style.CSS_CELL_RIGHT);
+ }
+
+ var postDays = this.postMonthDays;
+ if (hideBlankWeeks && postDays >= 7) {
+ var blankWeeks = Math.floor(postDays/7);
+ for (var p=0;p= ((this.preMonthDays+postDays+this.monthDays)-7)) {
+ Dom.addClass(cell, this.Style.CSS_CELL_BOTTOM);
+ }
+
+ html[html.length] = tempDiv.innerHTML;
+ i++;
+ }
+
+ if (showWeekFooter) { html = this.renderRowFooter(weekNum, html); }
+
+ html[html.length] = '
';
+ }
+ }
+
+ html[html.length] = '';
+
+ return html;
+ },
+
+ /**
+ * Renders the calendar footer. In the default implementation, there is
+ * no footer.
+ * @method renderFooter
+ * @param {Array} html The current working HTML array
+ * @return {Array} The current working HTML array
+ */
+ renderFooter : function(html) { return html; },
+
+ /**
+ * Renders the calendar after it has been configured. The render() method has a specific call chain that will execute
+ * when the method is called: renderHeader, renderBody, renderFooter.
+ * Refer to the documentation for those methods for information on
+ * individual render tasks.
+ * @method render
+ */
+ render : function() {
+ this.beforeRenderEvent.fire();
+
+ // Find starting day of the current month
+ var workingDate = DateMath.findMonthStart(this.cfg.getProperty(DEF_CFG.PAGEDATE.key));
+
+ this.resetRenderers();
+ this.cellDates.length = 0;
+
+ Event.purgeElement(this.oDomContainer, true);
+
+ var html = [];
+
+ html[html.length] = '
';
+ html = this.renderHeader(html);
+ html = this.renderBody(workingDate, html);
+ html = this.renderFooter(html);
+ html[html.length] = '
';
+
+ this.oDomContainer.innerHTML = html.join("\n");
+
+ this.applyListeners();
+ this.cells = this.oDomContainer.getElementsByTagName("td");
+
+ this.cfg.refireEvent(DEF_CFG.TITLE.key);
+ this.cfg.refireEvent(DEF_CFG.CLOSE.key);
+ this.cfg.refireEvent(DEF_CFG.IFRAME.key);
+
+ this.renderEvent.fire();
+ },
+
+ /**
+ * Applies the Calendar's DOM listeners to applicable elements.
+ * @method applyListeners
+ */
+ applyListeners : function() {
+ var root = this.oDomContainer,
+ cal = this.parent || this,
+ anchor = "a",
+ click = "click";
+
+ var linkLeft = Dom.getElementsByClassName(this.Style.CSS_NAV_LEFT, anchor, root),
+ linkRight = Dom.getElementsByClassName(this.Style.CSS_NAV_RIGHT, anchor, root);
+
+ if (linkLeft && linkLeft.length > 0) {
+ this.linkLeft = linkLeft[0];
+ Event.addListener(this.linkLeft, click, this.doPreviousMonthNav, cal, true);
+ }
+
+ if (linkRight && linkRight.length > 0) {
+ this.linkRight = linkRight[0];
+ Event.addListener(this.linkRight, click, this.doNextMonthNav, cal, true);
+ }
+
+ if (cal.cfg.getProperty("navigator") !== null) {
+ this.applyNavListeners();
+ }
+
+ if (this.domEventMap) {
+ var el,elements;
+ for (var cls in this.domEventMap) {
+ if (Lang.hasOwnProperty(this.domEventMap, cls)) {
+ var items = this.domEventMap[cls];
+
+ if (! (items instanceof Array)) {
+ items = [items];
+ }
+
+ for (var i=0;i 0) {
+
+ Event.addListener(navBtns, "click", function (e, obj) {
+ var target = Event.getTarget(e);
+ // this == navBtn
+ if (this === target || Dom.isAncestor(this, target)) {
+ Event.preventDefault(e);
+ }
+ var navigator = calParent.oNavigator;
+ if (navigator) {
+ var pgdate = cal.cfg.getProperty("pagedate");
+ navigator.setYear(pgdate.getFullYear());
+ navigator.setMonth(pgdate.getMonth());
+ navigator.show();
+ }
+ });
+ }
+ },
+
+ /**
+ * Retrieves the Date object for the specified Calendar cell
+ * @method getDateByCellId
+ * @param {String} id The id of the cell
+ * @return {Date} The Date object for the specified Calendar cell
+ */
+ getDateByCellId : function(id) {
+ var date = this.getDateFieldsByCellId(id);
+ return (date) ? DateMath.getDate(date[0],date[1]-1,date[2]) : null;
+ },
+
+ /**
+ * Retrieves the Date object for the specified Calendar cell
+ * @method getDateFieldsByCellId
+ * @param {String} id The id of the cell
+ * @return {Array} The array of Date fields for the specified Calendar cell
+ */
+ getDateFieldsByCellId : function(id) {
+ id = this.getIndexFromId(id);
+ return (id > -1) ? this.cellDates[id] : null;
+ },
+
+ /**
+ * Find the Calendar's cell index for a given date.
+ * If the date is not found, the method returns -1.
+ *
+ * The returned index can be used to lookup the cell HTMLElement
+ * using the Calendar's cells array or passed to selectCell to select
+ * cells by index.
+ *
+ *
+ * See cells, selectCell.
+ *
+ * @method getCellIndex
+ * @param {Date} date JavaScript Date object, for which to find a cell index.
+ * @return {Number} The index of the date in Calendars cellDates/cells arrays, or -1 if the date
+ * is not on the curently rendered Calendar page.
+ */
+ getCellIndex : function(date) {
+ var idx = -1;
+ if (date) {
+ var m = date.getMonth(),
+ y = date.getFullYear(),
+ d = date.getDate(),
+ dates = this.cellDates;
+
+ for (var i = 0; i < dates.length; ++i) {
+ var cellDate = dates[i];
+ if (cellDate[0] === y && cellDate[1] === m+1 && cellDate[2] === d) {
+ idx = i;
+ break;
+ }
+ }
+ }
+ return idx;
+ },
+
+ /**
+ * Given the id used to mark each Calendar cell, this method
+ * extracts the index number from the id.
+ *
+ * @param {String} strId The cell id
+ * @return {Number} The index of the cell, or -1 if id does not contain an index number
+ */
+ getIndexFromId : function(strId) {
+ var idx = -1,
+ li = strId.lastIndexOf("_cell");
+
+ if (li > -1) {
+ idx = parseInt(strId.substring(li + 5), 10);
+ }
+
+ return idx;
+ },
+
+ // BEGIN BUILT-IN TABLE CELL RENDERERS
+
+ /**
+ * Renders a cell that falls before the minimum date or after the maximum date.
+ * widget class.
+ * @method renderOutOfBoundsDate
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ * @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering
+ * should not be terminated
+ */
+ renderOutOfBoundsDate : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_OOB);
+ cell.innerHTML = workingDate.getDate();
+ return Calendar.STOP_RENDER;
+ },
+
+ /**
+ * Renders the row header for a week.
+ * @method renderRowHeader
+ * @param {Number} weekNum The week number of the current row
+ * @param {Array} cell The current working HTML array
+ */
+ renderRowHeader : function(weekNum, html) {
+ html[html.length] = '
' + weekNum + '
';
+ return html;
+ },
+
+ /**
+ * Renders the row footer for a week.
+ * @method renderRowFooter
+ * @param {Number} weekNum The week number of the current row
+ * @param {Array} cell The current working HTML array
+ */
+ renderRowFooter : function(weekNum, html) {
+ html[html.length] = '
' + weekNum + '
';
+ return html;
+ },
+
+ /**
+ * Renders a single standard calendar cell in the calendar widget table.
+ * All logic for determining how a standard default cell will be rendered is
+ * encapsulated in this method, and must be accounted for when extending the
+ * widget class.
+ * @method renderCellDefault
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ renderCellDefault : function(workingDate, cell) {
+ cell.innerHTML = '' + this.buildDayLabel(workingDate) + "";
+ },
+
+ /**
+ * Styles a selectable cell.
+ * @method styleCellDefault
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ styleCellDefault : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_SELECTABLE);
+ },
+
+
+ /**
+ * Renders a single standard calendar cell using the CSS hightlight1 style
+ * @method renderCellStyleHighlight1
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ renderCellStyleHighlight1 : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT1);
+ },
+
+ /**
+ * Renders a single standard calendar cell using the CSS hightlight2 style
+ * @method renderCellStyleHighlight2
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ renderCellStyleHighlight2 : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT2);
+ },
+
+ /**
+ * Renders a single standard calendar cell using the CSS hightlight3 style
+ * @method renderCellStyleHighlight3
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ renderCellStyleHighlight3 : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT3);
+ },
+
+ /**
+ * Renders a single standard calendar cell using the CSS hightlight4 style
+ * @method renderCellStyleHighlight4
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ renderCellStyleHighlight4 : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT4);
+ },
+
+ /**
+ * Applies the default style used for rendering today's date to the current calendar cell
+ * @method renderCellStyleToday
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ renderCellStyleToday : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_TODAY);
+ },
+
+ /**
+ * Applies the default style used for rendering selected dates to the current calendar cell
+ * @method renderCellStyleSelected
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ * @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering
+ * should not be terminated
+ */
+ renderCellStyleSelected : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_SELECTED);
+ },
+
+ /**
+ * Applies the default style used for rendering dates that are not a part of the current
+ * month (preceding or trailing the cells for the current month)
+ * @method renderCellNotThisMonth
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ * @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering
+ * should not be terminated
+ */
+ renderCellNotThisMonth : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_OOM);
+ cell.innerHTML=workingDate.getDate();
+ return Calendar.STOP_RENDER;
+ },
+
+ /**
+ * Renders the current calendar cell as a non-selectable "black-out" date using the default
+ * restricted style.
+ * @method renderBodyCellRestricted
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ * @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering
+ * should not be terminated
+ */
+ renderBodyCellRestricted : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL);
+ Dom.addClass(cell, this.Style.CSS_CELL_RESTRICTED);
+ cell.innerHTML=workingDate.getDate();
+ return Calendar.STOP_RENDER;
+ },
+
+ // END BUILT-IN TABLE CELL RENDERERS
+
+ // BEGIN MONTH NAVIGATION METHODS
+
+ /**
+ * Adds the designated number of months to the current calendar month, and sets the current
+ * calendar page date to the new month.
+ * @method addMonths
+ * @param {Number} count The number of months to add to the current calendar
+ */
+ addMonths : function(count) {
+ var cfgPageDate = DEF_CFG.PAGEDATE.key;
+ this.cfg.setProperty(cfgPageDate, DateMath.add(this.cfg.getProperty(cfgPageDate), DateMath.MONTH, count));
+ this.resetRenderers();
+ this.changePageEvent.fire();
+ },
+
+ /**
+ * Subtracts the designated number of months from the current calendar month, and sets the current
+ * calendar page date to the new month.
+ * @method subtractMonths
+ * @param {Number} count The number of months to subtract from the current calendar
+ */
+ subtractMonths : function(count) {
+ var cfgPageDate = DEF_CFG.PAGEDATE.key;
+ this.cfg.setProperty(cfgPageDate, DateMath.subtract(this.cfg.getProperty(cfgPageDate), DateMath.MONTH, count));
+ this.resetRenderers();
+ this.changePageEvent.fire();
+ },
+
+ /**
+ * Adds the designated number of years to the current calendar, and sets the current
+ * calendar page date to the new month.
+ * @method addYears
+ * @param {Number} count The number of years to add to the current calendar
+ */
+ addYears : function(count) {
+ var cfgPageDate = DEF_CFG.PAGEDATE.key;
+ this.cfg.setProperty(cfgPageDate, DateMath.add(this.cfg.getProperty(cfgPageDate), DateMath.YEAR, count));
+ this.resetRenderers();
+ this.changePageEvent.fire();
+ },
+
+ /**
+ * Subtcats the designated number of years from the current calendar, and sets the current
+ * calendar page date to the new month.
+ * @method subtractYears
+ * @param {Number} count The number of years to subtract from the current calendar
+ */
+ subtractYears : function(count) {
+ var cfgPageDate = DEF_CFG.PAGEDATE.key;
+ this.cfg.setProperty(cfgPageDate, DateMath.subtract(this.cfg.getProperty(cfgPageDate), DateMath.YEAR, count));
+ this.resetRenderers();
+ this.changePageEvent.fire();
+ },
+
+ /**
+ * Navigates to the next month page in the calendar widget.
+ * @method nextMonth
+ */
+ nextMonth : function() {
+ this.addMonths(1);
+ },
+
+ /**
+ * Navigates to the previous month page in the calendar widget.
+ * @method previousMonth
+ */
+ previousMonth : function() {
+ this.subtractMonths(1);
+ },
+
+ /**
+ * Navigates to the next year in the currently selected month in the calendar widget.
+ * @method nextYear
+ */
+ nextYear : function() {
+ this.addYears(1);
+ },
+
+ /**
+ * Navigates to the previous year in the currently selected month in the calendar widget.
+ * @method previousYear
+ */
+ previousYear : function() {
+ this.subtractYears(1);
+ },
+
+ // END MONTH NAVIGATION METHODS
+
+ // BEGIN SELECTION METHODS
+
+ /**
+ * Resets the calendar widget to the originally selected month and year, and
+ * sets the calendar to the initial selection(s).
+ * @method reset
+ */
+ reset : function() {
+ this.cfg.resetProperty(DEF_CFG.SELECTED.key);
+ this.cfg.resetProperty(DEF_CFG.PAGEDATE.key);
+ this.resetEvent.fire();
+ },
+
+ /**
+ * Clears the selected dates in the current calendar widget and sets the calendar
+ * to the current month and year.
+ * @method clear
+ */
+ clear : function() {
+ this.cfg.setProperty(DEF_CFG.SELECTED.key, []);
+ this.cfg.setProperty(DEF_CFG.PAGEDATE.key, new Date(this.today.getTime()));
+ this.clearEvent.fire();
+ },
+
+ /**
+ * Selects a date or a collection of dates on the current calendar. This method, by default,
+ * does not call the render method explicitly. Once selection has completed, render must be
+ * called for the changes to be reflected visually.
+ *
+ * Any dates which are OOB (out of bounds, not selectable) will not be selected and the array of
+ * selected dates passed to the selectEvent will not contain OOB dates.
+ *
+ * If all dates are OOB, the no state change will occur; beforeSelect and select events will not be fired.
+ *
+ * @method select
+ * @param {String/Date/Date[]} date The date string of dates to select in the current calendar. Valid formats are
+ * individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006).
+ * Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005).
+ * This method can also take a JavaScript Date object or an array of Date objects.
+ * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected.
+ */
+ select : function(date) {
+ this.logger.log("Select: " + date, "info");
+
+ var aToBeSelected = this._toFieldArray(date),
+ validDates = [],
+ selected = [],
+ cfgSelected = DEF_CFG.SELECTED.key;
+
+ this.logger.log("Selection field array: " + aToBeSelected, "info");
+
+ for (var a=0; a < aToBeSelected.length; ++a) {
+ var toSelect = aToBeSelected[a];
+
+ if (!this.isDateOOB(this._toDate(toSelect))) {
+
+ if (validDates.length === 0) {
+ this.beforeSelectEvent.fire();
+ selected = this.cfg.getProperty(cfgSelected);
+ }
+ validDates.push(toSelect);
+
+ if (this._indexOfSelectedFieldArray(toSelect) == -1) {
+ selected[selected.length] = toSelect;
+ }
+ }
+ }
+
+ if (validDates.length === 0) { this.logger.log("All provided dates were OOB. beforeSelect and select events not fired", "info"); }
+
+ if (validDates.length > 0) {
+ if (this.parent) {
+ this.parent.cfg.setProperty(cfgSelected, selected);
+ } else {
+ this.cfg.setProperty(cfgSelected, selected);
+ }
+ this.selectEvent.fire(validDates);
+ }
+
+ return this.getSelectedDates();
+ },
+
+ /**
+ * Selects a date on the current calendar by referencing the index of the cell that should be selected.
+ * This method is used to easily select a single cell (usually with a mouse click) without having to do
+ * a full render. The selected style is applied to the cell directly.
+ *
+ * If the cell is not marked with the CSS_CELL_SELECTABLE class (as is the case by default for out of month
+ * or out of bounds cells), it will not be selected and in such a case beforeSelect and select events will not be fired.
+ *
+ * @method selectCell
+ * @param {Number} cellIndex The index of the cell to select in the current calendar.
+ * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected.
+ */
+ selectCell : function(cellIndex) {
+
+ var cell = this.cells[cellIndex],
+ cellDate = this.cellDates[cellIndex],
+ dCellDate = this._toDate(cellDate),
+ selectable = Dom.hasClass(cell, this.Style.CSS_CELL_SELECTABLE);
+
+ this.logger.log("Select: " + dCellDate, "info");
+ if (!selectable) {this.logger.log("The cell at cellIndex:" + cellIndex + " is not a selectable cell. beforeSelect, select events not fired", "info"); }
+
+ if (selectable) {
+
+ this.beforeSelectEvent.fire();
+
+ var cfgSelected = DEF_CFG.SELECTED.key;
+ var selected = this.cfg.getProperty(cfgSelected);
+
+ var selectDate = cellDate.concat();
+
+ if (this._indexOfSelectedFieldArray(selectDate) == -1) {
+ selected[selected.length] = selectDate;
+ }
+ if (this.parent) {
+ this.parent.cfg.setProperty(cfgSelected, selected);
+ } else {
+ this.cfg.setProperty(cfgSelected, selected);
+ }
+ this.renderCellStyleSelected(dCellDate,cell);
+ this.selectEvent.fire([selectDate]);
+
+ this.doCellMouseOut.call(cell, null, this);
+ }
+
+ return this.getSelectedDates();
+ },
+
+ /**
+ * Deselects a date or a collection of dates on the current calendar. This method, by default,
+ * does not call the render method explicitly. Once deselection has completed, render must be
+ * called for the changes to be reflected visually.
+ *
+ * The method will not attempt to deselect any dates which are OOB (out of bounds, and hence not selectable)
+ * and the array of deselected dates passed to the deselectEvent will not contain any OOB dates.
+ *
+ * If all dates are OOB, beforeDeselect and deselect events will not be fired.
+ *
+ * @method deselect
+ * @param {String/Date/Date[]} date The date string of dates to deselect in the current calendar. Valid formats are
+ * individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006).
+ * Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005).
+ * This method can also take a JavaScript Date object or an array of Date objects.
+ * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected.
+ */
+ deselect : function(date) {
+ this.logger.log("Deselect: " + date, "info");
+
+ var aToBeDeselected = this._toFieldArray(date),
+ validDates = [],
+ selected = [],
+ cfgSelected = DEF_CFG.SELECTED.key;
+
+ this.logger.log("Deselection field array: " + aToBeDeselected, "info");
+
+ for (var a=0; a < aToBeDeselected.length; ++a) {
+ var toDeselect = aToBeDeselected[a];
+
+ if (!this.isDateOOB(this._toDate(toDeselect))) {
+
+ if (validDates.length === 0) {
+ this.beforeDeselectEvent.fire();
+ selected = this.cfg.getProperty(cfgSelected);
+ }
+
+ validDates.push(toDeselect);
+
+ var index = this._indexOfSelectedFieldArray(toDeselect);
+ if (index != -1) {
+ selected.splice(index,1);
+ }
+ }
+ }
+
+ if (validDates.length === 0) { this.logger.log("All provided dates were OOB. beforeDeselect and deselect events not fired");}
+
+ if (validDates.length > 0) {
+ if (this.parent) {
+ this.parent.cfg.setProperty(cfgSelected, selected);
+ } else {
+ this.cfg.setProperty(cfgSelected, selected);
+ }
+ this.deselectEvent.fire(validDates);
+ }
+
+ return this.getSelectedDates();
+ },
+
+ /**
+ * Deselects a date on the current calendar by referencing the index of the cell that should be deselected.
+ * This method is used to easily deselect a single cell (usually with a mouse click) without having to do
+ * a full render. The selected style is removed from the cell directly.
+ *
+ * If the cell is not marked with the CSS_CELL_SELECTABLE class (as is the case by default for out of month
+ * or out of bounds cells), the method will not attempt to deselect it and in such a case, beforeDeselect and
+ * deselect events will not be fired.
+ *
+ * @method deselectCell
+ * @param {Number} cellIndex The index of the cell to deselect in the current calendar.
+ * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected.
+ */
+ deselectCell : function(cellIndex) {
+ var cell = this.cells[cellIndex],
+ cellDate = this.cellDates[cellIndex],
+ cellDateIndex = this._indexOfSelectedFieldArray(cellDate);
+
+ var selectable = Dom.hasClass(cell, this.Style.CSS_CELL_SELECTABLE);
+ if (!selectable) { this.logger.log("The cell at cellIndex:" + cellIndex + " is not a selectable/deselectable cell", "info"); }
+
+ if (selectable) {
+
+ this.beforeDeselectEvent.fire();
+
+ var selected = this.cfg.getProperty(DEF_CFG.SELECTED.key),
+ dCellDate = this._toDate(cellDate),
+ selectDate = cellDate.concat();
+
+ if (cellDateIndex > -1) {
+ if (this.cfg.getProperty(DEF_CFG.PAGEDATE.key).getMonth() == dCellDate.getMonth() &&
+ this.cfg.getProperty(DEF_CFG.PAGEDATE.key).getFullYear() == dCellDate.getFullYear()) {
+ Dom.removeClass(cell, this.Style.CSS_CELL_SELECTED);
+ }
+ selected.splice(cellDateIndex, 1);
+ }
+
+ if (this.parent) {
+ this.parent.cfg.setProperty(DEF_CFG.SELECTED.key, selected);
+ } else {
+ this.cfg.setProperty(DEF_CFG.SELECTED.key, selected);
+ }
+
+ this.deselectEvent.fire(selectDate);
+ }
+
+ return this.getSelectedDates();
+ },
+
+ /**
+ * Deselects all dates on the current calendar.
+ * @method deselectAll
+ * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected.
+ * Assuming that this function executes properly, the return value should be an empty array.
+ * However, the empty array is returned for the sake of being able to check the selection status
+ * of the calendar.
+ */
+ deselectAll : function() {
+ this.beforeDeselectEvent.fire();
+
+ var cfgSelected = DEF_CFG.SELECTED.key,
+ selected = this.cfg.getProperty(cfgSelected),
+ count = selected.length,
+ sel = selected.concat();
+
+ if (this.parent) {
+ this.parent.cfg.setProperty(cfgSelected, []);
+ } else {
+ this.cfg.setProperty(cfgSelected, []);
+ }
+
+ if (count > 0) {
+ this.deselectEvent.fire(sel);
+ }
+
+ return this.getSelectedDates();
+ },
+
+ // END SELECTION METHODS
+
+ // BEGIN TYPE CONVERSION METHODS
+
+ /**
+ * Converts a date (either a JavaScript Date object, or a date string) to the internal data structure
+ * used to represent dates: [[yyyy,mm,dd],[yyyy,mm,dd]].
+ * @method _toFieldArray
+ * @private
+ * @param {String/Date/Date[]} date The date string of dates to deselect in the current calendar. Valid formats are
+ * individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006).
+ * Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005).
+ * This method can also take a JavaScript Date object or an array of Date objects.
+ * @return {Array[](Number[])} Array of date field arrays
+ */
+ _toFieldArray : function(date) {
+ var returnDate = [];
+
+ if (date instanceof Date) {
+ returnDate = [[date.getFullYear(), date.getMonth()+1, date.getDate()]];
+ } else if (Lang.isString(date)) {
+ returnDate = this._parseDates(date);
+ } else if (Lang.isArray(date)) {
+ for (var i=0;i maxDate.getTime()));
+ },
+
+ /**
+ * Parses a pagedate configuration property value. The value can either be specified as a string of form "mm/yyyy" or a Date object
+ * and is parsed into a Date object normalized to the first day of the month. If no value is passed in, the month and year from today's date are used to create the Date object
+ * @method _parsePageDate
+ * @private
+ * @param {Date|String} date Pagedate value which needs to be parsed
+ * @return {Date} The Date object representing the pagedate
+ */
+ _parsePageDate : function(date) {
+ var parsedDate;
+
+ if (date) {
+ if (date instanceof Date) {
+ parsedDate = DateMath.findMonthStart(date);
+ } else {
+ var month, year, aMonthYear;
+ aMonthYear = date.split(this.cfg.getProperty(DEF_CFG.DATE_FIELD_DELIMITER.key));
+ month = parseInt(aMonthYear[this.cfg.getProperty(DEF_CFG.MY_MONTH_POSITION.key)-1], 10)-1;
+ year = parseInt(aMonthYear[this.cfg.getProperty(DEF_CFG.MY_YEAR_POSITION.key)-1], 10);
+
+ parsedDate = DateMath.getDate(year, month, 1);
+ }
+ } else {
+ parsedDate = DateMath.getDate(this.today.getFullYear(), this.today.getMonth(), 1);
+ }
+ return parsedDate;
+ },
+
+ // END UTILITY METHODS
+
+ // BEGIN EVENT HANDLERS
+
+ /**
+ * Event executed before a date is selected in the calendar widget.
+ * @deprecated Event handlers for this event should be susbcribed to beforeSelectEvent.
+ */
+ onBeforeSelect : function() {
+ if (this.cfg.getProperty(DEF_CFG.MULTI_SELECT.key) === false) {
+ if (this.parent) {
+ this.parent.callChildFunction("clearAllBodyCellStyles", this.Style.CSS_CELL_SELECTED);
+ this.parent.deselectAll();
+ } else {
+ this.clearAllBodyCellStyles(this.Style.CSS_CELL_SELECTED);
+ this.deselectAll();
+ }
+ }
+ },
+
+ /**
+ * Event executed when a date is selected in the calendar widget.
+ * @param {Array} selected An array of date field arrays representing which date or dates were selected. Example: [ [2006,8,6],[2006,8,7],[2006,8,8] ]
+ * @deprecated Event handlers for this event should be susbcribed to selectEvent.
+ */
+ onSelect : function(selected) { },
+
+ /**
+ * Event executed before a date is deselected in the calendar widget.
+ * @deprecated Event handlers for this event should be susbcribed to beforeDeselectEvent.
+ */
+ onBeforeDeselect : function() { },
+
+ /**
+ * Event executed when a date is deselected in the calendar widget.
+ * @param {Array} selected An array of date field arrays representing which date or dates were deselected. Example: [ [2006,8,6],[2006,8,7],[2006,8,8] ]
+ * @deprecated Event handlers for this event should be susbcribed to deselectEvent.
+ */
+ onDeselect : function(deselected) { },
+
+ /**
+ * Event executed when the user navigates to a different calendar page.
+ * @deprecated Event handlers for this event should be susbcribed to changePageEvent.
+ */
+ onChangePage : function() {
+ this.render();
+ },
+
+ /**
+ * Event executed when the calendar widget is rendered.
+ * @deprecated Event handlers for this event should be susbcribed to renderEvent.
+ */
+ onRender : function() { },
+
+ /**
+ * Event executed when the calendar widget is reset to its original state.
+ * @deprecated Event handlers for this event should be susbcribed to resetEvemt.
+ */
+ onReset : function() { this.render(); },
+
+ /**
+ * Event executed when the calendar widget is completely cleared to the current month with no selections.
+ * @deprecated Event handlers for this event should be susbcribed to clearEvent.
+ */
+ onClear : function() { this.render(); },
+
+ /**
+ * Validates the calendar widget. This method has no default implementation
+ * and must be extended by subclassing the widget.
+ * @return Should return true if the widget validates, and false if
+ * it doesn't.
+ * @type Boolean
+ */
+ validate : function() { return true; },
+
+ // END EVENT HANDLERS
+
+ // BEGIN DATE PARSE METHODS
+
+ /**
+ * Converts a date string to a date field array
+ * @private
+ * @param {String} sDate Date string. Valid formats are mm/dd and mm/dd/yyyy.
+ * @return A date field array representing the string passed to the method
+ * @type Array[](Number[])
+ */
+ _parseDate : function(sDate) {
+ var aDate = sDate.split(this.Locale.DATE_FIELD_DELIMITER),
+ rArray;
+
+ if (aDate.length == 2) {
+ rArray = [aDate[this.Locale.MD_MONTH_POSITION-1],aDate[this.Locale.MD_DAY_POSITION-1]];
+ rArray.type = Calendar.MONTH_DAY;
+ } else {
+ rArray = [aDate[this.Locale.MDY_YEAR_POSITION-1],aDate[this.Locale.MDY_MONTH_POSITION-1],aDate[this.Locale.MDY_DAY_POSITION-1]];
+ rArray.type = Calendar.DATE;
+ }
+
+ for (var i=0;i
+*
+*
+*
+* The tables for the calendars ("cal1_0" and "cal1_1") will be inserted into those containers.
+*
+*
+* NOTE: As of 2.4.0, the constructor's ID argument is optional.
+* The CalendarGroup can be constructed by simply providing a container ID string,
+* or a reference to a container DIV HTMLElement (the element needs to exist
+* in the document).
+*
+* E.g.:
+*
+* var c = new YAHOO.widget.CalendarGroup("calContainer", configOptions);
+*
+* or:
+*
+* var containerDiv = YAHOO.util.Dom.get("calContainer");
+* var c = new YAHOO.widget.CalendarGroup(containerDiv, configOptions);
+*
+*
+*
+* If not provided, the ID will be generated from the container DIV ID by adding an "_t" suffix.
+* For example if an ID is not provided, and the container's ID is "calContainer", the CalendarGroup's ID will be set to "calContainer_t".
+*
+*
+* @namespace YAHOO.widget
+* @class CalendarGroup
+* @constructor
+* @param {String} id optional The id of the table element that will represent the CalendarGroup widget. As of 2.4.0, this argument is optional.
+* @param {String | HTMLElement} container The id of the container div element that will wrap the CalendarGroup table, or a reference to a DIV element which exists in the document.
+* @param {Object} config optional The configuration object containing the initial configuration values for the CalendarGroup.
+*/
+function CalendarGroup(id, containerId, config) {
+ if (arguments.length > 0) {
+ this.init.apply(this, arguments);
+ }
+}
+
+/**
+* The set of default Config property keys and values for the CalendarGroup
+* @property YAHOO.widget.CalendarGroup._DEFAULT_CONFIG
+* @final
+* @static
+* @private
+* @type Object
+*/
+CalendarGroup._DEFAULT_CONFIG = Calendar._DEFAULT_CONFIG;
+CalendarGroup._DEFAULT_CONFIG.PAGES = {key:"pages", value:2};
+
+var DEF_CFG = CalendarGroup._DEFAULT_CONFIG;
+
+CalendarGroup.prototype = {
+
+ /**
+ * Initializes the calendar group. All subclasses must call this method in order for the
+ * group to be initialized properly.
+ * @method init
+ * @param {String} id optional The id of the table element that will represent the CalendarGroup widget. As of 2.4.0, this argument is optional.
+ * @param {String | HTMLElement} container The id of the container div element that will wrap the CalendarGroup table, or a reference to a DIV element which exists in the document.
+ * @param {Object} config optional The configuration object containing the initial configuration values for the CalendarGroup.
+ */
+ init : function(id, container, config) {
+
+ // Normalize 2.4.0, pre 2.4.0 args
+ var nArgs = this._parseArgs(arguments);
+
+ id = nArgs.id;
+ container = nArgs.container;
+ config = nArgs.config;
+
+ this.oDomContainer = Dom.get(container);
+ if (!this.oDomContainer) { this.logger.log("Container not found in document.", "error"); }
+
+ if (!this.oDomContainer.id) {
+ this.oDomContainer.id = Dom.generateId();
+ }
+ if (!id) {
+ id = this.oDomContainer.id + "_t";
+ }
+
+ /**
+ * The unique id associated with the CalendarGroup
+ * @property id
+ * @type String
+ */
+ this.id = id;
+
+ /**
+ * The unique id associated with the CalendarGroup container
+ * @property containerId
+ * @type String
+ */
+ this.containerId = this.oDomContainer.id;
+
+ this.logger = new YAHOO.widget.LogWriter("CalendarGroup " + this.id);
+ this.initEvents();
+ this.initStyles();
+
+ /**
+ * The collection of Calendar pages contained within the CalendarGroup
+ * @property pages
+ * @type YAHOO.widget.Calendar[]
+ */
+ this.pages = [];
+
+ Dom.addClass(this.oDomContainer, CalendarGroup.CSS_CONTAINER);
+ Dom.addClass(this.oDomContainer, CalendarGroup.CSS_MULTI_UP);
+
+ /**
+ * The Config object used to hold the configuration variables for the CalendarGroup
+ * @property cfg
+ * @type YAHOO.util.Config
+ */
+ this.cfg = new YAHOO.util.Config(this);
+
+ /**
+ * The local object which contains the CalendarGroup's options
+ * @property Options
+ * @type Object
+ */
+ this.Options = {};
+
+ /**
+ * The local object which contains the CalendarGroup's locale settings
+ * @property Locale
+ * @type Object
+ */
+ this.Locale = {};
+
+ this.setupConfig();
+
+ if (config) {
+ this.cfg.applyConfig(config, true);
+ }
+
+ this.cfg.fireQueue();
+
+ // OPERA HACK FOR MISWRAPPED FLOATS
+ if (YAHOO.env.ua.opera){
+ this.renderEvent.subscribe(this._fixWidth, this, true);
+ this.showEvent.subscribe(this._fixWidth, this, true);
+ }
+
+ this.logger.log("Initialized " + this.pages.length + "-page CalendarGroup", "info");
+ },
+
+ setupConfig : function() {
+
+ var cfg = this.cfg;
+
+ /**
+ * The number of pages to include in the CalendarGroup. This value can only be set once, in the CalendarGroup's constructor arguments.
+ * @config pages
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.PAGES.key, { value:DEF_CFG.PAGES.value, validator:cfg.checkNumber, handler:this.configPages } );
+
+ /**
+ * The month/year representing the current visible Calendar date (mm/yyyy)
+ * @config pagedate
+ * @type String | Date
+ * @default today's date
+ */
+ cfg.addProperty(DEF_CFG.PAGEDATE.key, { value:new Date(), handler:this.configPageDate } );
+
+ /**
+ * The date or range of dates representing the current Calendar selection
+ *
+ * @config selected
+ * @type String
+ * @default []
+ */
+ cfg.addProperty(DEF_CFG.SELECTED.key, { value:[], handler:this.configSelected } );
+
+ /**
+ * The title to display above the CalendarGroup's month header
+ * @config title
+ * @type String
+ * @default ""
+ */
+ cfg.addProperty(DEF_CFG.TITLE.key, { value:DEF_CFG.TITLE.value, handler:this.configTitle } );
+
+ /**
+ * Whether or not a close button should be displayed for this CalendarGroup
+ * @config close
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.CLOSE.key, { value:DEF_CFG.CLOSE.value, handler:this.configClose } );
+
+ /**
+ * Whether or not an iframe shim should be placed under the Calendar to prevent select boxes from bleeding through in Internet Explorer 6 and below.
+ * This property is enabled by default for IE6 and below. It is disabled by default for other browsers for performance reasons, but can be
+ * enabled if required.
+ *
+ * @config iframe
+ * @type Boolean
+ * @default true for IE6 and below, false for all other browsers
+ */
+ cfg.addProperty(DEF_CFG.IFRAME.key, { value:DEF_CFG.IFRAME.value, handler:this.configIframe, validator:cfg.checkBoolean } );
+
+ /**
+ * The minimum selectable date in the current Calendar (mm/dd/yyyy)
+ * @config mindate
+ * @type String | Date
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.MINDATE.key, { value:DEF_CFG.MINDATE.value, handler:this.delegateConfig } );
+
+ /**
+ * The maximum selectable date in the current Calendar (mm/dd/yyyy)
+ * @config maxdate
+ * @type String | Date
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.MAXDATE.key, { value:DEF_CFG.MAXDATE.value, handler:this.delegateConfig } );
+
+ // Options properties
+
+ /**
+ * True if the Calendar should allow multiple selections. False by default.
+ * @config MULTI_SELECT
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.MULTI_SELECT.key, { value:DEF_CFG.MULTI_SELECT.value, handler:this.delegateConfig, validator:cfg.checkBoolean } );
+
+ /**
+ * The weekday the week begins on. Default is 0 (Sunday).
+ * @config START_WEEKDAY
+ * @type number
+ * @default 0
+ */
+ cfg.addProperty(DEF_CFG.START_WEEKDAY.key, { value:DEF_CFG.START_WEEKDAY.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * True if the Calendar should show weekday labels. True by default.
+ * @config SHOW_WEEKDAYS
+ * @type Boolean
+ * @default true
+ */
+ cfg.addProperty(DEF_CFG.SHOW_WEEKDAYS.key, { value:DEF_CFG.SHOW_WEEKDAYS.value, handler:this.delegateConfig, validator:cfg.checkBoolean } );
+
+ /**
+ * True if the Calendar should show week row headers. False by default.
+ * @config SHOW_WEEK_HEADER
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.SHOW_WEEK_HEADER.key,{ value:DEF_CFG.SHOW_WEEK_HEADER.value, handler:this.delegateConfig, validator:cfg.checkBoolean } );
+
+ /**
+ * True if the Calendar should show week row footers. False by default.
+ * @config SHOW_WEEK_FOOTER
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.SHOW_WEEK_FOOTER.key,{ value:DEF_CFG.SHOW_WEEK_FOOTER.value, handler:this.delegateConfig, validator:cfg.checkBoolean } );
+
+ /**
+ * True if the Calendar should suppress weeks that are not a part of the current month. False by default.
+ * @config HIDE_BLANK_WEEKS
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.HIDE_BLANK_WEEKS.key,{ value:DEF_CFG.HIDE_BLANK_WEEKS.value, handler:this.delegateConfig, validator:cfg.checkBoolean } );
+
+ /**
+ * The image that should be used for the left navigation arrow.
+ * @config NAV_ARROW_LEFT
+ * @type String
+ * @deprecated You can customize the image by overriding the default CSS class for the left arrow - "calnavleft"
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.NAV_ARROW_LEFT.key, { value:DEF_CFG.NAV_ARROW_LEFT.value, handler:this.delegateConfig } );
+
+ /**
+ * The image that should be used for the right navigation arrow.
+ * @config NAV_ARROW_RIGHT
+ * @type String
+ * @deprecated You can customize the image by overriding the default CSS class for the right arrow - "calnavright"
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.NAV_ARROW_RIGHT.key, { value:DEF_CFG.NAV_ARROW_RIGHT.value, handler:this.delegateConfig } );
+
+ // Locale properties
+
+ /**
+ * The short month labels for the current locale.
+ * @config MONTHS_SHORT
+ * @type String[]
+ * @default ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
+ */
+ cfg.addProperty(DEF_CFG.MONTHS_SHORT.key, { value:DEF_CFG.MONTHS_SHORT.value, handler:this.delegateConfig } );
+
+ /**
+ * The long month labels for the current locale.
+ * @config MONTHS_LONG
+ * @type String[]
+ * @default ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
+ */
+ cfg.addProperty(DEF_CFG.MONTHS_LONG.key, { value:DEF_CFG.MONTHS_LONG.value, handler:this.delegateConfig } );
+
+ /**
+ * The 1-character weekday labels for the current locale.
+ * @config WEEKDAYS_1CHAR
+ * @type String[]
+ * @default ["S", "M", "T", "W", "T", "F", "S"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_1CHAR.key, { value:DEF_CFG.WEEKDAYS_1CHAR.value, handler:this.delegateConfig } );
+
+ /**
+ * The short weekday labels for the current locale.
+ * @config WEEKDAYS_SHORT
+ * @type String[]
+ * @default ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_SHORT.key, { value:DEF_CFG.WEEKDAYS_SHORT.value, handler:this.delegateConfig } );
+
+ /**
+ * The medium weekday labels for the current locale.
+ * @config WEEKDAYS_MEDIUM
+ * @type String[]
+ * @default ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_MEDIUM.key, { value:DEF_CFG.WEEKDAYS_MEDIUM.value, handler:this.delegateConfig } );
+
+ /**
+ * The long weekday labels for the current locale.
+ * @config WEEKDAYS_LONG
+ * @type String[]
+ * @default ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_LONG.key, { value:DEF_CFG.WEEKDAYS_LONG.value, handler:this.delegateConfig } );
+
+ /**
+ * The setting that determines which length of month labels should be used. Possible values are "short" and "long".
+ * @config LOCALE_MONTHS
+ * @type String
+ * @default "long"
+ */
+ cfg.addProperty(DEF_CFG.LOCALE_MONTHS.key, { value:DEF_CFG.LOCALE_MONTHS.value, handler:this.delegateConfig } );
+
+ /**
+ * The setting that determines which length of weekday labels should be used. Possible values are "1char", "short", "medium", and "long".
+ * @config LOCALE_WEEKDAYS
+ * @type String
+ * @default "short"
+ */
+ cfg.addProperty(DEF_CFG.LOCALE_WEEKDAYS.key, { value:DEF_CFG.LOCALE_WEEKDAYS.value, handler:this.delegateConfig } );
+
+ /**
+ * The value used to delimit individual dates in a date string passed to various Calendar functions.
+ * @config DATE_DELIMITER
+ * @type String
+ * @default ","
+ */
+ cfg.addProperty(DEF_CFG.DATE_DELIMITER.key, { value:DEF_CFG.DATE_DELIMITER.value, handler:this.delegateConfig } );
+
+ /**
+ * The value used to delimit date fields in a date string passed to various Calendar functions.
+ * @config DATE_FIELD_DELIMITER
+ * @type String
+ * @default "/"
+ */
+ cfg.addProperty(DEF_CFG.DATE_FIELD_DELIMITER.key,{ value:DEF_CFG.DATE_FIELD_DELIMITER.value, handler:this.delegateConfig } );
+
+ /**
+ * The value used to delimit date ranges in a date string passed to various Calendar functions.
+ * @config DATE_RANGE_DELIMITER
+ * @type String
+ * @default "-"
+ */
+ cfg.addProperty(DEF_CFG.DATE_RANGE_DELIMITER.key,{ value:DEF_CFG.DATE_RANGE_DELIMITER.value, handler:this.delegateConfig } );
+
+ /**
+ * The position of the month in a month/year date string
+ * @config MY_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MY_MONTH_POSITION.key, { value:DEF_CFG.MY_MONTH_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the year in a month/year date string
+ * @config MY_YEAR_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MY_YEAR_POSITION.key, { value:DEF_CFG.MY_YEAR_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the month in a month/day date string
+ * @config MD_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MD_MONTH_POSITION.key, { value:DEF_CFG.MD_MONTH_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the day in a month/year date string
+ * @config MD_DAY_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MD_DAY_POSITION.key, { value:DEF_CFG.MD_DAY_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the month in a month/day/year date string
+ * @config MDY_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MDY_MONTH_POSITION.key, { value:DEF_CFG.MDY_MONTH_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the day in a month/day/year date string
+ * @config MDY_DAY_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MDY_DAY_POSITION.key, { value:DEF_CFG.MDY_DAY_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the year in a month/day/year date string
+ * @config MDY_YEAR_POSITION
+ * @type Number
+ * @default 3
+ */
+ cfg.addProperty(DEF_CFG.MDY_YEAR_POSITION.key, { value:DEF_CFG.MDY_YEAR_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the month in the month year label string used as the Calendar header
+ * @config MY_LABEL_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_MONTH_POSITION.key, { value:DEF_CFG.MY_LABEL_MONTH_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the year in the month year label string used as the Calendar header
+ * @config MY_LABEL_YEAR_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_YEAR_POSITION.key, { value:DEF_CFG.MY_LABEL_YEAR_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The suffix used after the month when rendering the Calendar header
+ * @config MY_LABEL_MONTH_SUFFIX
+ * @type String
+ * @default " "
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_MONTH_SUFFIX.key, { value:DEF_CFG.MY_LABEL_MONTH_SUFFIX.value, handler:this.delegateConfig } );
+
+ /**
+ * The suffix used after the year when rendering the Calendar header
+ * @config MY_LABEL_YEAR_SUFFIX
+ * @type String
+ * @default ""
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_YEAR_SUFFIX.key, { value:DEF_CFG.MY_LABEL_YEAR_SUFFIX.value, handler:this.delegateConfig } );
+
+ /**
+ * Configuration for the Month Year Navigation UI. By default it is disabled
+ * @config NAV
+ * @type Object
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.NAV.key, { value:DEF_CFG.NAV.value, handler:this.configNavigator } );
+
+ /**
+ * The map of UI strings which the CalendarGroup UI uses.
+ *
+ * @config strings
+ * @type {Object}
+ * @default An object with the properties shown below:
+ *
+ *
previousMonth
String : The string to use for the "Previous Month" navigation UI. Defaults to "Previous Month".
+ *
nextMonth
String : The string to use for the "Next Month" navigation UI. Defaults to "Next Month".
+ *
close
String : The string to use for the close button label. Defaults to "Close".
+ *
+ */
+ cfg.addProperty(DEF_CFG.STRINGS.key, {
+ value:DEF_CFG.STRINGS.value,
+ handler:this.configStrings,
+ validator: function(val) {
+ return Lang.isObject(val);
+ },
+ supercedes: DEF_CFG.STRINGS.supercedes
+ });
+ },
+
+ /**
+ * Initializes CalendarGroup's built-in CustomEvents
+ * @method initEvents
+ */
+ initEvents : function() {
+
+ var me = this,
+ strEvent = "Event",
+ CE = YAHOO.util.CustomEvent;
+
+ /**
+ * Proxy subscriber to subscribe to the CalendarGroup's child Calendars' CustomEvents
+ * @method sub
+ * @private
+ * @param {Function} fn The function to subscribe to this CustomEvent
+ * @param {Object} obj The CustomEvent's scope object
+ * @param {Boolean} bOverride Whether or not to apply scope correction
+ */
+ var sub = function(fn, obj, bOverride) {
+ for (var p=0;p 0) ? this.pages[0].cfg.getProperty(cfgSelected) : [];
+ this.cfg.setProperty(cfgSelected, selected, true);
+ },
+
+
+ /**
+ * Delegates a configuration property to the CustomEvents associated with the CalendarGroup's children
+ * @method delegateConfig
+ * @param {String} type The CustomEvent type (usually the property name)
+ * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
+ * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner.
+ */
+ delegateConfig : function(type, args, obj) {
+ var val = args[0];
+ var cal;
+
+ for (var p=0;p0) {
+ year+=1;
+ }
+ cal.setYear(year);
+ }
+ },
+
+ /**
+ * Calls the render function of all child calendars within the group.
+ * @method render
+ */
+ render : function() {
+ this.renderHeader();
+ for (var p=0;p
+ *
If MULTI_SELECT is false, selectCell will select the cell at the specified index for only the last displayed Calendar page.
+ *
If MULTI_SELECT is true, selectCell will select the cell at the specified index, on each displayed Calendar page.
+ *
+ * @method selectCell
+ * @param {Number} cellIndex The index of the cell to be selected.
+ * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected.
+ */
+ selectCell : function(cellIndex) {
+ for (var p=0;p=0;--p) {
+ var cal = this.pages[p];
+ cal.previousMonth();
+ }
+ },
+
+ /**
+ * Navigates to the next year in the currently selected month in the calendar widget.
+ * @method nextYear
+ */
+ nextYear : function() {
+ for (var p=0;p 11)) {
+ var newDate = DateMath.add(date, DateMath.MONTH, iMonth-date.getMonth());
+ date.setTime(newDate.getTime());
+ } else {
+ date.setMonth(iMonth);
+ }
+ },
+
+ /**
+ * Fixes the width of the CalendarGroup container element, to account for miswrapped floats
+ * @method _fixWidth
+ * @private
+ */
+ _fixWidth : function() {
+ var w = 0;
+ for (var p=0;p 0) {
+ this.oDomContainer.style.width = w + "px";
+ }
+ },
+
+ /**
+ * Returns a string representation of the object.
+ * @method toString
+ * @return {String} A string representation of the CalendarGroup object.
+ */
+ toString : function() {
+ return "CalendarGroup " + this.id;
+ },
+
+ /**
+ * Destroys the CalendarGroup instance. The method will remove references
+ * to HTML elements, remove any event listeners added by the CalendarGroup.
+ *
+ * It will also destroy the Config and CalendarNavigator instances created by the
+ * CalendarGroup and the individual Calendar instances created for each page.
+ *
+ * @method destroy
+ */
+ destroy : function() {
+
+ if (this.beforeDestroyEvent.fire()) {
+
+ var cal = this;
+
+ // Child objects
+ if (cal.navigator) {
+ cal.navigator.destroy();
+ }
+
+ if (cal.cfg) {
+ cal.cfg.destroy();
+ }
+
+ // DOM event listeners
+ Event.purgeElement(cal.oDomContainer, true);
+
+ // Generated markup/DOM - Not removing the container DIV since we didn't create it.
+ Dom.removeClass(cal.oDomContainer, CalendarGroup.CSS_CONTAINER);
+ Dom.removeClass(cal.oDomContainer, CalendarGroup.CSS_MULTI_UP);
+
+ for (var i = 0, l = cal.pages.length; i < l; i++) {
+ cal.pages[i].destroy();
+ cal.pages[i] = null;
+ }
+
+ cal.oDomContainer.innerHTML = "";
+
+ // JS-to-DOM references
+ cal.oDomContainer = null;
+
+ this.destroyEvent.fire();
+ }
+ }
+};
+
+/**
+* CSS class representing the container for the calendar
+* @property YAHOO.widget.CalendarGroup.CSS_CONTAINER
+* @static
+* @final
+* @type String
+*/
+CalendarGroup.CSS_CONTAINER = "yui-calcontainer";
+
+/**
+* CSS class representing the container for the calendar
+* @property YAHOO.widget.CalendarGroup.CSS_MULTI_UP
+* @static
+* @final
+* @type String
+*/
+CalendarGroup.CSS_MULTI_UP = "multi";
+
+/**
+* CSS class representing the title for the 2-up calendar
+* @property YAHOO.widget.CalendarGroup.CSS_2UPTITLE
+* @static
+* @final
+* @type String
+*/
+CalendarGroup.CSS_2UPTITLE = "title";
+
+/**
+* CSS class representing the close icon for the 2-up calendar
+* @property YAHOO.widget.CalendarGroup.CSS_2UPCLOSE
+* @static
+* @final
+* @deprecated Along with Calendar.IMG_ROOT and NAV_ARROW_LEFT, NAV_ARROW_RIGHT configuration properties.
+* Calendar's Style.CSS_CLOSE property now represents the CSS class used to render the close icon
+* @type String
+*/
+CalendarGroup.CSS_2UPCLOSE = "close-icon";
+
+YAHOO.lang.augmentProto(CalendarGroup, Calendar, "buildDayLabel",
+ "buildMonthLabel",
+ "renderOutOfBoundsDate",
+ "renderRowHeader",
+ "renderRowFooter",
+ "renderCellDefault",
+ "styleCellDefault",
+ "renderCellStyleHighlight1",
+ "renderCellStyleHighlight2",
+ "renderCellStyleHighlight3",
+ "renderCellStyleHighlight4",
+ "renderCellStyleToday",
+ "renderCellStyleSelected",
+ "renderCellNotThisMonth",
+ "renderBodyCellRestricted",
+ "initStyles",
+ "configTitle",
+ "configClose",
+ "configIframe",
+ "configStrings",
+ "configNavigator",
+ "createTitleBar",
+ "createCloseButton",
+ "removeTitleBar",
+ "removeCloseButton",
+ "hide",
+ "show",
+ "toDate",
+ "_toDate",
+ "_parseArgs",
+ "browser");
+
+YAHOO.widget.CalGrp = CalendarGroup;
+YAHOO.widget.CalendarGroup = CalendarGroup;
+
+/**
+* @class YAHOO.widget.Calendar2up
+* @extends YAHOO.widget.CalendarGroup
+* @deprecated The old Calendar2up class is no longer necessary, since CalendarGroup renders in a 2up view by default.
+*/
+YAHOO.widget.Calendar2up = function(id, containerId, config) {
+ this.init(id, containerId, config);
+};
+
+YAHOO.extend(YAHOO.widget.Calendar2up, CalendarGroup);
+
+/**
+* @deprecated The old Calendar2up class is no longer necessary, since CalendarGroup renders in a 2up view by default.
+*/
+YAHOO.widget.Cal2up = YAHOO.widget.Calendar2up;
+
+})();
+
+/**
+ * The CalendarNavigator is used along with a Calendar/CalendarGroup to
+ * provide a Month/Year popup navigation control, allowing the user to navigate
+ * to a specific month/year in the Calendar/CalendarGroup without having to
+ * scroll through months sequentially
+ *
+ * @namespace YAHOO.widget
+ * @class CalendarNavigator
+ * @constructor
+ * @param {Calendar|CalendarGroup} cal The instance of the Calendar or CalendarGroup to which this CalendarNavigator should be attached.
+ */
+YAHOO.widget.CalendarNavigator = function(cal) {
+ this.init(cal);
+};
+
+(function() {
+ // Setup static properties (inside anon fn, so that we can use shortcuts)
+ var CN = YAHOO.widget.CalendarNavigator;
+
+ /**
+ * YAHOO.widget.CalendarNavigator.CLASSES contains constants
+ * for the class values applied to the CalendarNaviatgator's
+ * DOM elements
+ * @property YAHOO.widget.CalendarNavigator.CLASSES
+ * @type Object
+ * @static
+ */
+ CN.CLASSES = {
+ /**
+ * Class applied to the Calendar Navigator's bounding box
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.NAV
+ * @type String
+ * @static
+ */
+ NAV :"yui-cal-nav",
+ /**
+ * Class applied to the Calendar/CalendarGroup's bounding box to indicate
+ * the Navigator is currently visible
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.NAV_VISIBLE
+ * @type String
+ * @static
+ */
+ NAV_VISIBLE: "yui-cal-nav-visible",
+ /**
+ * Class applied to the Navigator mask's bounding box
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.MASK
+ * @type String
+ * @static
+ */
+ MASK : "yui-cal-nav-mask",
+ /**
+ * Class applied to the year label/control bounding box
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.YEAR
+ * @type String
+ * @static
+ */
+ YEAR : "yui-cal-nav-y",
+ /**
+ * Class applied to the month label/control bounding box
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.MONTH
+ * @type String
+ * @static
+ */
+ MONTH : "yui-cal-nav-m",
+ /**
+ * Class applied to the submit/cancel button's bounding box
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.BUTTONS
+ * @type String
+ * @static
+ */
+ BUTTONS : "yui-cal-nav-b",
+ /**
+ * Class applied to buttons wrapping element
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.BUTTON
+ * @type String
+ * @static
+ */
+ BUTTON : "yui-cal-nav-btn",
+ /**
+ * Class applied to the validation error area's bounding box
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.ERROR
+ * @type String
+ * @static
+ */
+ ERROR : "yui-cal-nav-e",
+ /**
+ * Class applied to the year input control
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.YEAR_CTRL
+ * @type String
+ * @static
+ */
+ YEAR_CTRL : "yui-cal-nav-yc",
+ /**
+ * Class applied to the month input control
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.MONTH_CTRL
+ * @type String
+ * @static
+ */
+ MONTH_CTRL : "yui-cal-nav-mc",
+ /**
+ * Class applied to controls with invalid data (e.g. a year input field with invalid an year)
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.INVALID
+ * @type String
+ * @static
+ */
+ INVALID : "yui-invalid",
+ /**
+ * Class applied to default controls
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.DEFAULT
+ * @type String
+ * @static
+ */
+ DEFAULT : "yui-default"
+ };
+
+ /**
+ * Object literal containing the default configuration values for the CalendarNavigator
+ * The configuration object is expected to follow the format below, with the properties being
+ * case sensitive.
+ *
+ *
strings
+ *
Object : An object with the properties shown below, defining the string labels to use in the Navigator's UI
+ *
+ *
month
String : The string to use for the month label. Defaults to "Month".
+ *
year
String : The string to use for the year label. Defaults to "Year".
+ *
submit
String : The string to use for the submit button label. Defaults to "Okay".
+ *
cancel
String : The string to use for the cancel button label. Defaults to "Cancel".
+ *
invalidYear
String : The string to use for invalid year values. Defaults to "Year needs to be a number".
+ *
+ *
+ *
monthFormat
String : The month format to use. Either YAHOO.widget.Calendar.LONG, or YAHOO.widget.Calendar.SHORT. Defaults to YAHOO.widget.Calendar.LONG
+ *
initialFocus
String : Either "year" or "month" specifying which input control should get initial focus. Defaults to "year"
+ *
+ * @property _DEFAULT_CFG
+ * @protected
+ * @type Object
+ * @static
+ */
+ CN._DEFAULT_CFG = {
+ strings : {
+ month: "Month",
+ year: "Year",
+ submit: "Okay",
+ cancel: "Cancel",
+ invalidYear : "Year needs to be a number"
+ },
+ monthFormat: YAHOO.widget.Calendar.LONG,
+ initialFocus: "year"
+ };
+
+ /**
+ * The suffix added to the Calendar/CalendarGroup's ID, to generate
+ * a unique ID for the Navigator and it's bounding box.
+ * @property YAHOO.widget.CalendarNavigator.ID_SUFFIX
+ * @static
+ * @type String
+ * @final
+ */
+ CN.ID_SUFFIX = "_nav";
+ /**
+ * The suffix added to the Navigator's ID, to generate
+ * a unique ID for the month control.
+ * @property YAHOO.widget.CalendarNavigator.MONTH_SUFFIX
+ * @static
+ * @type String
+ * @final
+ */
+ CN.MONTH_SUFFIX = "_month";
+ /**
+ * The suffix added to the Navigator's ID, to generate
+ * a unique ID for the year control.
+ * @property YAHOO.widget.CalendarNavigator.YEAR_SUFFIX
+ * @static
+ * @type String
+ * @final
+ */
+ CN.YEAR_SUFFIX = "_year";
+ /**
+ * The suffix added to the Navigator's ID, to generate
+ * a unique ID for the error bounding box.
+ * @property YAHOO.widget.CalendarNavigator.ERROR_SUFFIX
+ * @static
+ * @type String
+ * @final
+ */
+ CN.ERROR_SUFFIX = "_error";
+ /**
+ * The suffix added to the Navigator's ID, to generate
+ * a unique ID for the "Cancel" button.
+ * @property YAHOO.widget.CalendarNavigator.CANCEL_SUFFIX
+ * @static
+ * @type String
+ * @final
+ */
+ CN.CANCEL_SUFFIX = "_cancel";
+ /**
+ * The suffix added to the Navigator's ID, to generate
+ * a unique ID for the "Submit" button.
+ * @property YAHOO.widget.CalendarNavigator.SUBMIT_SUFFIX
+ * @static
+ * @type String
+ * @final
+ */
+ CN.SUBMIT_SUFFIX = "_submit";
+
+ /**
+ * The number of digits to which the year input control is to be limited.
+ * @property YAHOO.widget.CalendarNavigator.YR_MAX_DIGITS
+ * @static
+ * @type Number
+ */
+ CN.YR_MAX_DIGITS = 4;
+
+ /**
+ * The amount by which to increment the current year value,
+ * when the arrow up/down key is pressed on the year control
+ * @property YAHOO.widget.CalendarNavigator.YR_MINOR_INC
+ * @static
+ * @type Number
+ */
+ CN.YR_MINOR_INC = 1;
+
+ /**
+ * The amount by which to increment the current year value,
+ * when the page up/down key is pressed on the year control
+ * @property YAHOO.widget.CalendarNavigator.YR_MAJOR_INC
+ * @static
+ * @type Number
+ */
+ CN.YR_MAJOR_INC = 10;
+
+ /**
+ * Artificial delay (in ms) between the time the Navigator is hidden
+ * and the Calendar/CalendarGroup state is updated. Allows the user
+ * the see the Calendar/CalendarGroup page changing. If set to 0
+ * the Calendar/CalendarGroup page will be updated instantly
+ * @property YAHOO.widget.CalendarNavigator.UPDATE_DELAY
+ * @static
+ * @type Number
+ */
+ CN.UPDATE_DELAY = 50;
+
+ /**
+ * Regular expression used to validate the year input
+ * @property YAHOO.widget.CalendarNavigator.YR_PATTERN
+ * @static
+ * @type RegExp
+ */
+ CN.YR_PATTERN = /^\d+$/;
+ /**
+ * Regular expression used to trim strings
+ * @property YAHOO.widget.CalendarNavigator.TRIM
+ * @static
+ * @type RegExp
+ */
+ CN.TRIM = /^\s*(.*?)\s*$/;
+})();
+
+YAHOO.widget.CalendarNavigator.prototype = {
+
+ /**
+ * The unique ID for this CalendarNavigator instance
+ * @property id
+ * @type String
+ */
+ id : null,
+
+ /**
+ * The Calendar/CalendarGroup instance to which the navigator belongs
+ * @property cal
+ * @type {Calendar|CalendarGroup}
+ */
+ cal : null,
+
+ /**
+ * Reference to the HTMLElement used to render the navigator's bounding box
+ * @property navEl
+ * @type HTMLElement
+ */
+ navEl : null,
+
+ /**
+ * Reference to the HTMLElement used to render the navigator's mask
+ * @property maskEl
+ * @type HTMLElement
+ */
+ maskEl : null,
+
+ /**
+ * Reference to the HTMLElement used to input the year
+ * @property yearEl
+ * @type HTMLElement
+ */
+ yearEl : null,
+
+ /**
+ * Reference to the HTMLElement used to input the month
+ * @property monthEl
+ * @type HTMLElement
+ */
+ monthEl : null,
+
+ /**
+ * Reference to the HTMLElement used to display validation errors
+ * @property errorEl
+ * @type HTMLElement
+ */
+ errorEl : null,
+
+ /**
+ * Reference to the HTMLElement used to update the Calendar/Calendar group
+ * with the month/year values
+ * @property submitEl
+ * @type HTMLElement
+ */
+ submitEl : null,
+
+ /**
+ * Reference to the HTMLElement used to hide the navigator without updating the
+ * Calendar/Calendar group
+ * @property cancelEl
+ * @type HTMLElement
+ */
+ cancelEl : null,
+
+ /**
+ * Reference to the first focusable control in the navigator (by default monthEl)
+ * @property firstCtrl
+ * @type HTMLElement
+ */
+ firstCtrl : null,
+
+ /**
+ * Reference to the last focusable control in the navigator (by default cancelEl)
+ * @property lastCtrl
+ * @type HTMLElement
+ */
+ lastCtrl : null,
+
+ /**
+ * The document containing the Calendar/Calendar group instance
+ * @protected
+ * @property _doc
+ * @type HTMLDocument
+ */
+ _doc : null,
+
+ /**
+ * Internal state property for the current year displayed in the navigator
+ * @protected
+ * @property _year
+ * @type Number
+ */
+ _year: null,
+
+ /**
+ * Internal state property for the current month index displayed in the navigator
+ * @protected
+ * @property _month
+ * @type Number
+ */
+ _month: 0,
+
+ /**
+ * Private internal state property which indicates whether or not the
+ * Navigator has been rendered.
+ * @private
+ * @property __rendered
+ * @type Boolean
+ */
+ __rendered: false,
+
+ /**
+ * Init lifecycle method called as part of construction
+ *
+ * @method init
+ * @param {Calendar} cal The instance of the Calendar or CalendarGroup to which this CalendarNavigator should be attached
+ */
+ init : function(cal) {
+ var calBox = cal.oDomContainer;
+
+ this.cal = cal;
+ this.id = calBox.id + YAHOO.widget.CalendarNavigator.ID_SUFFIX;
+ this._doc = calBox.ownerDocument;
+
+ /**
+ * Private flag, to identify IE6/IE7 Quirks
+ * @private
+ * @property __isIEQuirks
+ */
+ var ie = YAHOO.env.ua.ie;
+ this.__isIEQuirks = (ie && ((ie <= 6) || (ie === 7 && this._doc.compatMode == "BackCompat")));
+ },
+
+ /**
+ * Displays the navigator and mask, updating the input controls to reflect the
+ * currently set month and year. The show method will invoke the render method
+ * if the navigator has not been renderered already, allowing for lazy rendering
+ * of the control.
+ *
+ * The show method will fire the Calendar/CalendarGroup's beforeShowNav and showNav events
+ *
+ * @method show
+ */
+ show : function() {
+ var CLASSES = YAHOO.widget.CalendarNavigator.CLASSES;
+
+ if (this.cal.beforeShowNavEvent.fire()) {
+ if (!this.__rendered) {
+ this.render();
+ }
+ this.clearErrors();
+
+ this._updateMonthUI();
+ this._updateYearUI();
+ this._show(this.navEl, true);
+
+ this.setInitialFocus();
+ this.showMask();
+
+ YAHOO.util.Dom.addClass(this.cal.oDomContainer, CLASSES.NAV_VISIBLE);
+ this.cal.showNavEvent.fire();
+ }
+ },
+
+ /**
+ * Hides the navigator and mask
+ *
+ * The show method will fire the Calendar/CalendarGroup's beforeHideNav event and hideNav events
+ * @method hide
+ */
+ hide : function() {
+ var CLASSES = YAHOO.widget.CalendarNavigator.CLASSES;
+
+ if (this.cal.beforeHideNavEvent.fire()) {
+ this._show(this.navEl, false);
+ this.hideMask();
+ YAHOO.util.Dom.removeClass(this.cal.oDomContainer, CLASSES.NAV_VISIBLE);
+ this.cal.hideNavEvent.fire();
+ }
+ },
+
+
+ /**
+ * Displays the navigator's mask element
+ *
+ * @method showMask
+ */
+ showMask : function() {
+ this._show(this.maskEl, true);
+ if (this.__isIEQuirks) {
+ this._syncMask();
+ }
+ },
+
+ /**
+ * Hides the navigator's mask element
+ *
+ * @method hideMask
+ */
+ hideMask : function() {
+ this._show(this.maskEl, false);
+ },
+
+ /**
+ * Returns the current month set on the navigator
+ *
+ * Note: This may not be the month set in the UI, if
+ * the UI contains an invalid value.
+ *
+ * @method getMonth
+ * @return {Number} The Navigator's current month index
+ */
+ getMonth: function() {
+ return this._month;
+ },
+
+ /**
+ * Returns the current year set on the navigator
+ *
+ * Note: This may not be the year set in the UI, if
+ * the UI contains an invalid value.
+ *
+ * @method getYear
+ * @return {Number} The Navigator's current year value
+ */
+ getYear: function() {
+ return this._year;
+ },
+
+ /**
+ * Sets the current month on the Navigator, and updates the UI
+ *
+ * @method setMonth
+ * @param {Number} nMonth The month index, from 0 (Jan) through 11 (Dec).
+ */
+ setMonth : function(nMonth) {
+ if (nMonth >= 0 && nMonth < 12) {
+ this._month = nMonth;
+ }
+ this._updateMonthUI();
+ },
+
+ /**
+ * Sets the current year on the Navigator, and updates the UI. If the
+ * provided year is invalid, it will not be set.
+ *
+ * @method setYear
+ * @param {Number} nYear The full year value to set the Navigator to.
+ */
+ setYear : function(nYear) {
+ var yrPattern = YAHOO.widget.CalendarNavigator.YR_PATTERN;
+ if (YAHOO.lang.isNumber(nYear) && yrPattern.test(nYear+"")) {
+ this._year = nYear;
+ }
+ this._updateYearUI();
+ },
+
+ /**
+ * Renders the HTML for the navigator, adding it to the
+ * document and attaches event listeners if it has not
+ * already been rendered.
+ *
+ * @method render
+ */
+ render: function() {
+ this.cal.beforeRenderNavEvent.fire();
+ if (!this.__rendered) {
+ this.createNav();
+ this.createMask();
+ this.applyListeners();
+ this.__rendered = true;
+ }
+ this.cal.renderNavEvent.fire();
+ },
+
+ /**
+ * Creates the navigator's containing HTMLElement, it's contents, and appends
+ * the containg element to the Calendar/CalendarGroup's container.
+ *
+ * @method createNav
+ */
+ createNav : function() {
+ var NAV = YAHOO.widget.CalendarNavigator;
+ var doc = this._doc;
+
+ var d = doc.createElement("div");
+ d.className = NAV.CLASSES.NAV;
+
+ var htmlBuf = this.renderNavContents([]);
+
+ d.innerHTML = htmlBuf.join('');
+ this.cal.oDomContainer.appendChild(d);
+
+ this.navEl = d;
+
+ this.yearEl = doc.getElementById(this.id + NAV.YEAR_SUFFIX);
+ this.monthEl = doc.getElementById(this.id + NAV.MONTH_SUFFIX);
+ this.errorEl = doc.getElementById(this.id + NAV.ERROR_SUFFIX);
+ this.submitEl = doc.getElementById(this.id + NAV.SUBMIT_SUFFIX);
+ this.cancelEl = doc.getElementById(this.id + NAV.CANCEL_SUFFIX);
+
+ if (YAHOO.env.ua.gecko && this.yearEl && this.yearEl.type == "text") {
+ // Avoid XUL error on focus, select [ https://bugzilla.mozilla.org/show_bug.cgi?id=236791,
+ // supposedly fixed in 1.8.1, but there are reports of it still being around for methods other than blur ]
+ this.yearEl.setAttribute("autocomplete", "off");
+ }
+
+ this._setFirstLastElements();
+ },
+
+ /**
+ * Creates the Mask HTMLElement and appends it to the Calendar/CalendarGroups
+ * container.
+ *
+ * @method createMask
+ */
+ createMask : function() {
+ var C = YAHOO.widget.CalendarNavigator.CLASSES;
+
+ var d = this._doc.createElement("div");
+ d.className = C.MASK;
+
+ this.cal.oDomContainer.appendChild(d);
+ this.maskEl = d;
+ },
+
+ /**
+ * Used to set the width/height of the mask in pixels to match the Calendar Container.
+ * Currently only used for IE6 and IE7 quirks mode. The other A-Grade browser are handled using CSS (width/height 100%).
+ *
+ * The method is also registered as an HTMLElement resize listener on the Calendars container element.
+ *
+ * @protected
+ * @method _syncMask
+ */
+ _syncMask : function() {
+ var c = this.cal.oDomContainer;
+ if (c && this.maskEl) {
+ var r = YAHOO.util.Dom.getRegion(c);
+ YAHOO.util.Dom.setStyle(this.maskEl, "width", r.right - r.left + "px");
+ YAHOO.util.Dom.setStyle(this.maskEl, "height", r.bottom - r.top + "px");
+ }
+ },
+
+ /**
+ * Renders the contents of the navigator
+ *
+ * @method renderNavContents
+ *
+ * @param {Array} html The HTML buffer to append the HTML to.
+ * @return {Array} A reference to the buffer passed in.
+ */
+ renderNavContents : function(html) {
+ var NAV = YAHOO.widget.CalendarNavigator,
+ C = NAV.CLASSES,
+ h = html; // just to use a shorter name
+
+ h[h.length] = '
';
+ this.renderMonth(h);
+ h[h.length] = '
';
+ h[h.length] = '
';
+ this.renderYear(h);
+ h[h.length] = '
';
+ h[h.length] = '
';
+ this.renderButtons(h);
+ h[h.length] = '
';
+ h[h.length] = '';
+
+ return h;
+ },
+
+ /**
+ * Renders the month label and control for the navigator
+ *
+ * @method renderNavContents
+ * @param {Array} html The HTML buffer to append the HTML to.
+ * @return {Array} A reference to the buffer passed in.
+ */
+ renderMonth : function(html) {
+ var NAV = YAHOO.widget.CalendarNavigator,
+ C = NAV.CLASSES;
+
+ var id = this.id + NAV.MONTH_SUFFIX,
+ mf = this.__getCfg("monthFormat"),
+ months = this.cal.cfg.getProperty((mf == YAHOO.widget.Calendar.SHORT) ? "MONTHS_SHORT" : "MONTHS_LONG"),
+ h = html;
+
+ if (months && months.length > 0) {
+ h[h.length] = '';
+ h[h.length] = '';
+ }
+ return h;
+ },
+
+ /**
+ * Renders the year label and control for the navigator
+ *
+ * @method renderYear
+ * @param {Array} html The HTML buffer to append the HTML to.
+ * @return {Array} A reference to the buffer passed in.
+ */
+ renderYear : function(html) {
+ var NAV = YAHOO.widget.CalendarNavigator,
+ C = NAV.CLASSES;
+
+ var id = this.id + NAV.YEAR_SUFFIX,
+ size = NAV.YR_MAX_DIGITS,
+ h = html;
+
+ h[h.length] = '';
+ h[h.length] = '';
+ return h;
+ },
+
+ /**
+ * Renders the submit/cancel buttons for the navigator
+ *
+ * @method renderButton
+ * @return {String} The HTML created for the Button UI
+ */
+ renderButtons : function(html) {
+ var C = YAHOO.widget.CalendarNavigator.CLASSES;
+ var h = html;
+
+ h[h.length] = '';
+ h[h.length] = '';
+ h[h.length] = this.__getCfg("submit", true);
+ h[h.length] = '';
+ h[h.length] = '';
+ h[h.length] = '';
+ h[h.length] = '';
+ h[h.length] = this.__getCfg("cancel", true);
+ h[h.length] = '';
+ h[h.length] = '';
+
+ return h;
+ },
+
+ /**
+ * Attaches DOM event listeners to the rendered elements
+ *
+ * The method will call applyKeyListeners, to setup keyboard specific
+ * listeners
+ *
+ * @method applyListeners
+ */
+ applyListeners : function() {
+ var E = YAHOO.util.Event;
+
+ function yearUpdateHandler() {
+ if (this.validate()) {
+ this.setYear(this._getYearFromUI());
+ }
+ }
+
+ function monthUpdateHandler() {
+ this.setMonth(this._getMonthFromUI());
+ }
+
+ E.on(this.submitEl, "click", this.submit, this, true);
+ E.on(this.cancelEl, "click", this.cancel, this, true);
+ E.on(this.yearEl, "blur", yearUpdateHandler, this, true);
+ E.on(this.monthEl, "change", monthUpdateHandler, this, true);
+
+ if (this.__isIEQuirks) {
+ YAHOO.util.Event.on(this.cal.oDomContainer, "resize", this._syncMask, this, true);
+ }
+
+ this.applyKeyListeners();
+ },
+
+ /**
+ * Removes/purges DOM event listeners from the rendered elements
+ *
+ * @method purgeListeners
+ */
+ purgeListeners : function() {
+ var E = YAHOO.util.Event;
+ E.removeListener(this.submitEl, "click", this.submit);
+ E.removeListener(this.cancelEl, "click", this.cancel);
+ E.removeListener(this.yearEl, "blur");
+ E.removeListener(this.monthEl, "change");
+ if (this.__isIEQuirks) {
+ E.removeListener(this.cal.oDomContainer, "resize", this._syncMask);
+ }
+
+ this.purgeKeyListeners();
+ },
+
+ /**
+ * Attaches DOM listeners for keyboard support.
+ * Tab/Shift-Tab looping, Enter Key Submit on Year element,
+ * Up/Down/PgUp/PgDown year increment on Year element
+ *
+ * NOTE: MacOSX Safari 2.x doesn't let you tab to buttons and
+ * MacOSX Gecko does not let you tab to buttons or select controls,
+ * so for these browsers, Tab/Shift-Tab looping is limited to the
+ * elements which can be reached using the tab key.
+ *
+ * @method applyKeyListeners
+ */
+ applyKeyListeners : function() {
+ var E = YAHOO.util.Event,
+ ua = YAHOO.env.ua;
+
+ // IE/Safari 3.1 doesn't fire keypress for arrow/pg keys (non-char keys)
+ var arrowEvt = (ua.ie || ua.webkit) ? "keydown" : "keypress";
+
+ // - IE/Safari 3.1 doesn't fire keypress for non-char keys
+ // - Opera doesn't allow us to cancel keydown or keypress for tab, but
+ // changes focus successfully on keydown (keypress is too late to change focus - opera's already moved on).
+ var tabEvt = (ua.ie || ua.opera || ua.webkit) ? "keydown" : "keypress";
+
+ // Everyone likes keypress for Enter (char keys) - whoo hoo!
+ E.on(this.yearEl, "keypress", this._handleEnterKey, this, true);
+
+ E.on(this.yearEl, arrowEvt, this._handleDirectionKeys, this, true);
+ E.on(this.lastCtrl, tabEvt, this._handleTabKey, this, true);
+ E.on(this.firstCtrl, tabEvt, this._handleShiftTabKey, this, true);
+ },
+
+ /**
+ * Removes/purges DOM listeners for keyboard support
+ *
+ * @method purgeKeyListeners
+ */
+ purgeKeyListeners : function() {
+ var E = YAHOO.util.Event,
+ ua = YAHOO.env.ua;
+
+ var arrowEvt = (ua.ie || ua.webkit) ? "keydown" : "keypress";
+ var tabEvt = (ua.ie || ua.opera || ua.webkit) ? "keydown" : "keypress";
+
+ E.removeListener(this.yearEl, "keypress", this._handleEnterKey);
+ E.removeListener(this.yearEl, arrowEvt, this._handleDirectionKeys);
+ E.removeListener(this.lastCtrl, tabEvt, this._handleTabKey);
+ E.removeListener(this.firstCtrl, tabEvt, this._handleShiftTabKey);
+ },
+
+ /**
+ * Updates the Calendar/CalendarGroup's pagedate with the currently set month and year if valid.
+ *
+ * If the currently set month/year is invalid, a validation error will be displayed and the
+ * Calendar/CalendarGroup's pagedate will not be updated.
+ *
+ * @method submit
+ */
+ submit : function() {
+ if (this.validate()) {
+ this.hide();
+
+ this.setMonth(this._getMonthFromUI());
+ this.setYear(this._getYearFromUI());
+
+ var cal = this.cal;
+
+ // Artificial delay, just to help the user see something changed
+ var delay = YAHOO.widget.CalendarNavigator.UPDATE_DELAY;
+ if (delay > 0) {
+ var nav = this;
+ window.setTimeout(function(){ nav._update(cal); }, delay);
+ } else {
+ this._update(cal);
+ }
+ }
+ },
+
+ /**
+ * Updates the Calendar rendered state, based on the state of the CalendarNavigator
+ * @method _update
+ * @param cal The Calendar instance to update
+ * @protected
+ */
+ _update : function(cal) {
+ cal.setYear(this.getYear());
+ cal.setMonth(this.getMonth());
+ cal.render();
+ },
+
+ /**
+ * Hides the navigator and mask, without updating the Calendar/CalendarGroup's state
+ *
+ * @method cancel
+ */
+ cancel : function() {
+ this.hide();
+ },
+
+ /**
+ * Validates the current state of the UI controls
+ *
+ * @method validate
+ * @return {Boolean} true, if the current UI state contains valid values, false if not
+ */
+ validate : function() {
+ if (this._getYearFromUI() !== null) {
+ this.clearErrors();
+ return true;
+ } else {
+ this.setYearError();
+ this.setError(this.__getCfg("invalidYear", true));
+ return false;
+ }
+ },
+
+ /**
+ * Displays an error message in the Navigator's error panel
+ * @method setError
+ * @param {String} msg The error message to display
+ */
+ setError : function(msg) {
+ if (this.errorEl) {
+ this.errorEl.innerHTML = msg;
+ this._show(this.errorEl, true);
+ }
+ },
+
+ /**
+ * Clears the navigator's error message and hides the error panel
+ * @method clearError
+ */
+ clearError : function() {
+ if (this.errorEl) {
+ this.errorEl.innerHTML = "";
+ this._show(this.errorEl, false);
+ }
+ },
+
+ /**
+ * Displays the validation error UI for the year control
+ * @method setYearError
+ */
+ setYearError : function() {
+ YAHOO.util.Dom.addClass(this.yearEl, YAHOO.widget.CalendarNavigator.CLASSES.INVALID);
+ },
+
+ /**
+ * Removes the validation error UI for the year control
+ * @method clearYearError
+ */
+ clearYearError : function() {
+ YAHOO.util.Dom.removeClass(this.yearEl, YAHOO.widget.CalendarNavigator.CLASSES.INVALID);
+ },
+
+ /**
+ * Clears all validation and error messages in the UI
+ * @method clearErrors
+ */
+ clearErrors : function() {
+ this.clearError();
+ this.clearYearError();
+ },
+
+ /**
+ * Sets the initial focus, based on the configured value
+ * @method setInitialFocus
+ */
+ setInitialFocus : function() {
+ var el = this.submitEl,
+ f = this.__getCfg("initialFocus");
+
+ if (f && f.toLowerCase) {
+ f = f.toLowerCase();
+ if (f == "year") {
+ el = this.yearEl;
+ try {
+ this.yearEl.select();
+ } catch (selErr) {
+ // Ignore;
+ }
+ } else if (f == "month") {
+ el = this.monthEl;
+ }
+ }
+
+ if (el && YAHOO.lang.isFunction(el.focus)) {
+ try {
+ el.focus();
+ } catch (focusErr) {
+ // TODO: Fall back if focus fails?
+ }
+ }
+ },
+
+ /**
+ * Removes all renderered HTML elements for the Navigator from
+ * the DOM, purges event listeners and clears (nulls) any property
+ * references to HTML references
+ * @method erase
+ */
+ erase : function() {
+ if (this.__rendered) {
+ this.purgeListeners();
+
+ // Clear out innerHTML references
+ this.yearEl = null;
+ this.monthEl = null;
+ this.errorEl = null;
+ this.submitEl = null;
+ this.cancelEl = null;
+ this.firstCtrl = null;
+ this.lastCtrl = null;
+ if (this.navEl) {
+ this.navEl.innerHTML = "";
+ }
+
+ var p = this.navEl.parentNode;
+ if (p) {
+ p.removeChild(this.navEl);
+ }
+ this.navEl = null;
+
+ var pm = this.maskEl.parentNode;
+ if (pm) {
+ pm.removeChild(this.maskEl);
+ }
+ this.maskEl = null;
+ this.__rendered = false;
+ }
+ },
+
+ /**
+ * Destroys the Navigator object and any HTML references
+ * @method destroy
+ */
+ destroy : function() {
+ this.erase();
+ this._doc = null;
+ this.cal = null;
+ this.id = null;
+ },
+
+ /**
+ * Protected implementation to handle how UI elements are
+ * hidden/shown.
+ *
+ * @method _show
+ * @protected
+ */
+ _show : function(el, bShow) {
+ if (el) {
+ YAHOO.util.Dom.setStyle(el, "display", (bShow) ? "block" : "none");
+ }
+ },
+
+ /**
+ * Returns the month value (index), from the month UI element
+ * @protected
+ * @method _getMonthFromUI
+ * @return {Number} The month index, or 0 if a UI element for the month
+ * is not found
+ */
+ _getMonthFromUI : function() {
+ if (this.monthEl) {
+ return this.monthEl.selectedIndex;
+ } else {
+ return 0; // Default to Jan
+ }
+ },
+
+ /**
+ * Returns the year value, from the Navitator's year UI element
+ * @protected
+ * @method _getYearFromUI
+ * @return {Number} The year value set in the UI, if valid. null is returned if
+ * the UI does not contain a valid year value.
+ */
+ _getYearFromUI : function() {
+ var NAV = YAHOO.widget.CalendarNavigator;
+
+ var yr = null;
+ if (this.yearEl) {
+ var value = this.yearEl.value;
+ value = value.replace(NAV.TRIM, "$1");
+
+ if (NAV.YR_PATTERN.test(value)) {
+ yr = parseInt(value, 10);
+ }
+ }
+ return yr;
+ },
+
+ /**
+ * Updates the Navigator's year UI, based on the year value set on the Navigator object
+ * @protected
+ * @method _updateYearUI
+ */
+ _updateYearUI : function() {
+ if (this.yearEl && this._year !== null) {
+ this.yearEl.value = this._year;
+ }
+ },
+
+ /**
+ * Updates the Navigator's month UI, based on the month value set on the Navigator object
+ * @protected
+ * @method _updateMonthUI
+ */
+ _updateMonthUI : function() {
+ if (this.monthEl) {
+ this.monthEl.selectedIndex = this._month;
+ }
+ },
+
+ /**
+ * Sets up references to the first and last focusable element in the Navigator's UI
+ * in terms of tab order (Naviagator's firstEl and lastEl properties). The references
+ * are used to control modality by looping around from the first to the last control
+ * and visa versa for tab/shift-tab navigation.
+ *
+ * @protected
+ * @method _setFirstLastElements
+ */
+ _setFirstLastElements : function() {
+ this.firstCtrl = this.monthEl;
+ this.lastCtrl = this.cancelEl;
+
+ // Special handling for MacOSX.
+ // - Safari 2.x can't focus on buttons
+ // - Gecko can't focus on select boxes or buttons
+ if (this.__isMac) {
+ if (YAHOO.env.ua.webkit && YAHOO.env.ua.webkit < 420){
+ this.firstCtrl = this.monthEl;
+ this.lastCtrl = this.yearEl;
+ }
+ if (YAHOO.env.ua.gecko) {
+ this.firstCtrl = this.yearEl;
+ this.lastCtrl = this.yearEl;
+ }
+ }
+ },
+
+ /**
+ * Default Keyboard event handler to capture Enter
+ * on the Navigator's year control (yearEl)
+ *
+ * @method _handleEnterKey
+ * @protected
+ * @param {Event} e The DOM event being handled
+ */
+ _handleEnterKey : function(e) {
+ var KEYS = YAHOO.util.KeyListener.KEY;
+
+ if (YAHOO.util.Event.getCharCode(e) == KEYS.ENTER) {
+ YAHOO.util.Event.preventDefault(e);
+ this.submit();
+ }
+ },
+
+ /**
+ * Default Keyboard event handler to capture up/down/pgup/pgdown
+ * on the Navigator's year control (yearEl).
+ *
+ * @method _handleDirectionKeys
+ * @protected
+ * @param {Event} e The DOM event being handled
+ */
+ _handleDirectionKeys : function(e) {
+ var E = YAHOO.util.Event,
+ KEYS = YAHOO.util.KeyListener.KEY,
+ NAV = YAHOO.widget.CalendarNavigator;
+
+ var value = (this.yearEl.value) ? parseInt(this.yearEl.value, 10) : null;
+ if (isFinite(value)) {
+ var dir = false;
+ switch(E.getCharCode(e)) {
+ case KEYS.UP:
+ this.yearEl.value = value + NAV.YR_MINOR_INC;
+ dir = true;
+ break;
+ case KEYS.DOWN:
+ this.yearEl.value = Math.max(value - NAV.YR_MINOR_INC, 0);
+ dir = true;
+ break;
+ case KEYS.PAGE_UP:
+ this.yearEl.value = value + NAV.YR_MAJOR_INC;
+ dir = true;
+ break;
+ case KEYS.PAGE_DOWN:
+ this.yearEl.value = Math.max(value - NAV.YR_MAJOR_INC, 0);
+ dir = true;
+ break;
+ default:
+ break;
+ }
+ if (dir) {
+ E.preventDefault(e);
+ try {
+ this.yearEl.select();
+ } catch(err) {
+ // Ignore
+ }
+ }
+ }
+ },
+
+ /**
+ * Default Keyboard event handler to capture Tab
+ * on the last control (lastCtrl) in the Navigator.
+ *
+ * @method _handleTabKey
+ * @protected
+ * @param {Event} e The DOM event being handled
+ */
+ _handleTabKey : function(e) {
+ var E = YAHOO.util.Event,
+ KEYS = YAHOO.util.KeyListener.KEY;
+
+ if (E.getCharCode(e) == KEYS.TAB && !e.shiftKey) {
+ try {
+ E.preventDefault(e);
+ this.firstCtrl.focus();
+ } catch (err) {
+ // Ignore - mainly for focus edge cases
+ }
+ }
+ },
+
+ /**
+ * Default Keyboard event handler to capture Shift-Tab
+ * on the first control (firstCtrl) in the Navigator.
+ *
+ * @method _handleShiftTabKey
+ * @protected
+ * @param {Event} e The DOM event being handled
+ */
+ _handleShiftTabKey : function(e) {
+ var E = YAHOO.util.Event,
+ KEYS = YAHOO.util.KeyListener.KEY;
+
+ if (e.shiftKey && E.getCharCode(e) == KEYS.TAB) {
+ try {
+ E.preventDefault(e);
+ this.lastCtrl.focus();
+ } catch (err) {
+ // Ignore - mainly for focus edge cases
+ }
+ }
+ },
+
+ /**
+ * Retrieve Navigator configuration values from
+ * the parent Calendar/CalendarGroup's config value.
+ *
+ * If it has not been set in the user provided configuration, the method will
+ * return the default value of the configuration property, as set in _DEFAULT_CFG
+ *
";B[B.length]='';return B;},renderMonth:function(D){var G=YAHOO.widget.CalendarNavigator,H=G.CLASSES;var I=this.id+G.MONTH_SUFFIX,F=this.__getCfg("monthFormat"),A=this.cal.cfg.getProperty((F==YAHOO.widget.Calendar.SHORT)?"MONTHS_SHORT":"MONTHS_LONG"),E=D;if(A&&A.length>0){E[E.length]='";E[E.length]='";}return E;},renderYear:function(B){var E=YAHOO.widget.CalendarNavigator,F=E.CLASSES;var G=this.id+E.YEAR_SUFFIX,A=E.YR_MAX_DIGITS,D=B;D[D.length]='";D[D.length]='';return D;},renderButtons:function(A){var D=YAHOO.widget.CalendarNavigator.CLASSES;var B=A;B[B.length]='';B[B.length]='';B[B.length]=this.__getCfg("submit",true);B[B.length]="";B[B.length]="";B[B.length]='';B[B.length]='';B[B.length]=this.__getCfg("cancel",true);B[B.length]="";B[B.length]="";return B;},applyListeners:function(){var B=YAHOO.util.Event;function A(){if(this.validate()){this.setYear(this._getYearFromUI());}}function C(){this.setMonth(this._getMonthFromUI());}B.on(this.submitEl,"click",this.submit,this,true);B.on(this.cancelEl,"click",this.cancel,this,true);B.on(this.yearEl,"blur",A,this,true);B.on(this.monthEl,"change",C,this,true);if(this.__isIEQuirks){YAHOO.util.Event.on(this.cal.oDomContainer,"resize",this._syncMask,this,true);}this.applyKeyListeners();},purgeListeners:function(){var A=YAHOO.util.Event;A.removeListener(this.submitEl,"click",this.submit);A.removeListener(this.cancelEl,"click",this.cancel);A.removeListener(this.yearEl,"blur");A.removeListener(this.monthEl,"change");if(this.__isIEQuirks){A.removeListener(this.cal.oDomContainer,"resize",this._syncMask);}this.purgeKeyListeners();},applyKeyListeners:function(){var D=YAHOO.util.Event,A=YAHOO.env.ua;var C=(A.ie||A.webkit)?"keydown":"keypress";var B=(A.ie||A.opera||A.webkit)?"keydown":"keypress";D.on(this.yearEl,"keypress",this._handleEnterKey,this,true);D.on(this.yearEl,C,this._handleDirectionKeys,this,true);D.on(this.lastCtrl,B,this._handleTabKey,this,true);D.on(this.firstCtrl,B,this._handleShiftTabKey,this,true);},purgeKeyListeners:function(){var D=YAHOO.util.Event,A=YAHOO.env.ua;var C=(A.ie||A.webkit)?"keydown":"keypress";var B=(A.ie||A.opera||A.webkit)?"keydown":"keypress";D.removeListener(this.yearEl,"keypress",this._handleEnterKey);D.removeListener(this.yearEl,C,this._handleDirectionKeys);D.removeListener(this.lastCtrl,B,this._handleTabKey);D.removeListener(this.firstCtrl,B,this._handleShiftTabKey);},submit:function(){if(this.validate()){this.hide();this.setMonth(this._getMonthFromUI());this.setYear(this._getYearFromUI());var B=this.cal;var A=YAHOO.widget.CalendarNavigator.UPDATE_DELAY;if(A>0){var C=this;window.setTimeout(function(){C._update(B);},A);}else{this._update(B);}}},_update:function(A){A.setYear(this.getYear());A.setMonth(this.getMonth());A.render();},cancel:function(){this.hide();},validate:function(){if(this._getYearFromUI()!==null){this.clearErrors();return true;}else{this.setYearError();this.setError(this.__getCfg("invalidYear",true));return false;}},setError:function(A){if(this.errorEl){this.errorEl.innerHTML=A;this._show(this.errorEl,true);}},clearError:function(){if(this.errorEl){this.errorEl.innerHTML="";this._show(this.errorEl,false);}},setYearError:function(){YAHOO.util.Dom.addClass(this.yearEl,YAHOO.widget.CalendarNavigator.CLASSES.INVALID);},clearYearError:function(){YAHOO.util.Dom.removeClass(this.yearEl,YAHOO.widget.CalendarNavigator.CLASSES.INVALID);},clearErrors:function(){this.clearError();this.clearYearError();},setInitialFocus:function(){var A=this.submitEl,C=this.__getCfg("initialFocus");if(C&&C.toLowerCase){C=C.toLowerCase();if(C=="year"){A=this.yearEl;try{this.yearEl.select();}catch(B){}}else{if(C=="month"){A=this.monthEl;}}}if(A&&YAHOO.lang.isFunction(A.focus)){try{A.focus();}catch(D){}}},erase:function(){if(this.__rendered){this.purgeListeners();this.yearEl=null;this.monthEl=null;this.errorEl=null;this.submitEl=null;this.cancelEl=null;this.firstCtrl=null;this.lastCtrl=null;if(this.navEl){this.navEl.innerHTML="";}var B=this.navEl.parentNode;if(B){B.removeChild(this.navEl);}this.navEl=null;var A=this.maskEl.parentNode;if(A){A.removeChild(this.maskEl);}this.maskEl=null;this.__rendered=false;}},destroy:function(){this.erase();this._doc=null;this.cal=null;this.id=null;},_show:function(B,A){if(B){YAHOO.util.Dom.setStyle(B,"display",(A)?"block":"none");}},_getMonthFromUI:function(){if(this.monthEl){return this.monthEl.selectedIndex;}else{return 0;}},_getYearFromUI:function(){var B=YAHOO.widget.CalendarNavigator;var A=null;if(this.yearEl){var C=this.yearEl.value;C=C.replace(B.TRIM,"$1");if(B.YR_PATTERN.test(C)){A=parseInt(C,10);}}return A;},_updateYearUI:function(){if(this.yearEl&&this._year!==null){this.yearEl.value=this._year;}},_updateMonthUI:function(){if(this.monthEl){this.monthEl.selectedIndex=this._month;}},_setFirstLastElements:function(){this.firstCtrl=this.monthEl;this.lastCtrl=this.cancelEl;if(this.__isMac){if(YAHOO.env.ua.webkit&&YAHOO.env.ua.webkit<420){this.firstCtrl=this.monthEl;this.lastCtrl=this.yearEl;
+}if(YAHOO.env.ua.gecko){this.firstCtrl=this.yearEl;this.lastCtrl=this.yearEl;}}},_handleEnterKey:function(B){var A=YAHOO.util.KeyListener.KEY;if(YAHOO.util.Event.getCharCode(B)==A.ENTER){YAHOO.util.Event.preventDefault(B);this.submit();}},_handleDirectionKeys:function(H){var G=YAHOO.util.Event,A=YAHOO.util.KeyListener.KEY,D=YAHOO.widget.CalendarNavigator;var F=(this.yearEl.value)?parseInt(this.yearEl.value,10):null;if(isFinite(F)){var B=false;switch(G.getCharCode(H)){case A.UP:this.yearEl.value=F+D.YR_MINOR_INC;B=true;break;case A.DOWN:this.yearEl.value=Math.max(F-D.YR_MINOR_INC,0);B=true;break;case A.PAGE_UP:this.yearEl.value=F+D.YR_MAJOR_INC;B=true;break;case A.PAGE_DOWN:this.yearEl.value=Math.max(F-D.YR_MAJOR_INC,0);B=true;break;default:break;}if(B){G.preventDefault(H);try{this.yearEl.select();}catch(C){}}}},_handleTabKey:function(D){var C=YAHOO.util.Event,A=YAHOO.util.KeyListener.KEY;if(C.getCharCode(D)==A.TAB&&!D.shiftKey){try{C.preventDefault(D);this.firstCtrl.focus();}catch(B){}}},_handleShiftTabKey:function(D){var C=YAHOO.util.Event,A=YAHOO.util.KeyListener.KEY;if(D.shiftKey&&C.getCharCode(D)==A.TAB){try{C.preventDefault(D);this.lastCtrl.focus();}catch(B){}}},__getCfg:function(D,B){var C=YAHOO.widget.CalendarNavigator._DEFAULT_CFG;var A=this.cal.cfg.getProperty("navigator");if(B){return(A!==true&&A.strings&&A.strings[D])?A.strings[D]:C.strings[D];}else{return(A!==true&&A[D])?A[D]:C[D];}},__isMac:(navigator.userAgent.toLowerCase().indexOf("macintosh")!=-1)};YAHOO.register("calendar",YAHOO.widget.Calendar,{version:"2.6.0",build:"1321"});
\ No newline at end of file
diff --git a/lib/yui/calendar/calendar.js b/lib/yui/calendar/calendar.js
new file mode 100755
index 0000000000..69ddc19817
--- /dev/null
+++ b/lib/yui/calendar/calendar.js
@@ -0,0 +1,7138 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.6.0
+*/
+(function () {
+
+ /**
+ * Config is a utility used within an Object to allow the implementer to
+ * maintain a list of local configuration properties and listen for changes
+ * to those properties dynamically using CustomEvent. The initial values are
+ * also maintained so that the configuration can be reset at any given point
+ * to its initial state.
+ * @namespace YAHOO.util
+ * @class Config
+ * @constructor
+ * @param {Object} owner The owner Object to which this Config Object belongs
+ */
+ YAHOO.util.Config = function (owner) {
+
+ if (owner) {
+ this.init(owner);
+ }
+
+
+ };
+
+
+ var Lang = YAHOO.lang,
+ CustomEvent = YAHOO.util.CustomEvent,
+ Config = YAHOO.util.Config;
+
+
+ /**
+ * Constant representing the CustomEvent type for the config changed event.
+ * @property YAHOO.util.Config.CONFIG_CHANGED_EVENT
+ * @private
+ * @static
+ * @final
+ */
+ Config.CONFIG_CHANGED_EVENT = "configChanged";
+
+ /**
+ * Constant representing the boolean type string
+ * @property YAHOO.util.Config.BOOLEAN_TYPE
+ * @private
+ * @static
+ * @final
+ */
+ Config.BOOLEAN_TYPE = "boolean";
+
+ Config.prototype = {
+
+ /**
+ * Object reference to the owner of this Config Object
+ * @property owner
+ * @type Object
+ */
+ owner: null,
+
+ /**
+ * Boolean flag that specifies whether a queue is currently
+ * being executed
+ * @property queueInProgress
+ * @type Boolean
+ */
+ queueInProgress: false,
+
+ /**
+ * Maintains the local collection of configuration property objects and
+ * their specified values
+ * @property config
+ * @private
+ * @type Object
+ */
+ config: null,
+
+ /**
+ * Maintains the local collection of configuration property objects as
+ * they were initially applied.
+ * This object is used when resetting a property.
+ * @property initialConfig
+ * @private
+ * @type Object
+ */
+ initialConfig: null,
+
+ /**
+ * Maintains the local, normalized CustomEvent queue
+ * @property eventQueue
+ * @private
+ * @type Object
+ */
+ eventQueue: null,
+
+ /**
+ * Custom Event, notifying subscribers when Config properties are set
+ * (setProperty is called without the silent flag
+ * @event configChangedEvent
+ */
+ configChangedEvent: null,
+
+ /**
+ * Initializes the configuration Object and all of its local members.
+ * @method init
+ * @param {Object} owner The owner Object to which this Config
+ * Object belongs
+ */
+ init: function (owner) {
+
+ this.owner = owner;
+
+ this.configChangedEvent =
+ this.createEvent(Config.CONFIG_CHANGED_EVENT);
+
+ this.configChangedEvent.signature = CustomEvent.LIST;
+ this.queueInProgress = false;
+ this.config = {};
+ this.initialConfig = {};
+ this.eventQueue = [];
+
+ },
+
+ /**
+ * Validates that the value passed in is a Boolean.
+ * @method checkBoolean
+ * @param {Object} val The value to validate
+ * @return {Boolean} true, if the value is valid
+ */
+ checkBoolean: function (val) {
+ return (typeof val == Config.BOOLEAN_TYPE);
+ },
+
+ /**
+ * Validates that the value passed in is a number.
+ * @method checkNumber
+ * @param {Object} val The value to validate
+ * @return {Boolean} true, if the value is valid
+ */
+ checkNumber: function (val) {
+ return (!isNaN(val));
+ },
+
+ /**
+ * Fires a configuration property event using the specified value.
+ * @method fireEvent
+ * @private
+ * @param {String} key The configuration property's name
+ * @param {value} Object The value of the correct type for the property
+ */
+ fireEvent: function ( key, value ) {
+ var property = this.config[key];
+
+ if (property && property.event) {
+ property.event.fire(value);
+ }
+ },
+
+ /**
+ * Adds a property to the Config Object's private config hash.
+ * @method addProperty
+ * @param {String} key The configuration property's name
+ * @param {Object} propertyObject The Object containing all of this
+ * property's arguments
+ */
+ addProperty: function ( key, propertyObject ) {
+ key = key.toLowerCase();
+
+ this.config[key] = propertyObject;
+
+ propertyObject.event = this.createEvent(key, { scope: this.owner });
+ propertyObject.event.signature = CustomEvent.LIST;
+
+
+ propertyObject.key = key;
+
+ if (propertyObject.handler) {
+ propertyObject.event.subscribe(propertyObject.handler,
+ this.owner);
+ }
+
+ this.setProperty(key, propertyObject.value, true);
+
+ if (! propertyObject.suppressEvent) {
+ this.queueProperty(key, propertyObject.value);
+ }
+
+ },
+
+ /**
+ * Returns a key-value configuration map of the values currently set in
+ * the Config Object.
+ * @method getConfig
+ * @return {Object} The current config, represented in a key-value map
+ */
+ getConfig: function () {
+
+ var cfg = {},
+ currCfg = this.config,
+ prop,
+ property;
+
+ for (prop in currCfg) {
+ if (Lang.hasOwnProperty(currCfg, prop)) {
+ property = currCfg[prop];
+ if (property && property.event) {
+ cfg[prop] = property.value;
+ }
+ }
+ }
+
+ return cfg;
+ },
+
+ /**
+ * Returns the value of specified property.
+ * @method getProperty
+ * @param {String} key The name of the property
+ * @return {Object} The value of the specified property
+ */
+ getProperty: function (key) {
+ var property = this.config[key.toLowerCase()];
+ if (property && property.event) {
+ return property.value;
+ } else {
+ return undefined;
+ }
+ },
+
+ /**
+ * Resets the specified property's value to its initial value.
+ * @method resetProperty
+ * @param {String} key The name of the property
+ * @return {Boolean} True is the property was reset, false if not
+ */
+ resetProperty: function (key) {
+
+ key = key.toLowerCase();
+
+ var property = this.config[key];
+
+ if (property && property.event) {
+
+ if (this.initialConfig[key] &&
+ !Lang.isUndefined(this.initialConfig[key])) {
+
+ this.setProperty(key, this.initialConfig[key]);
+
+ return true;
+
+ }
+
+ } else {
+
+ return false;
+ }
+
+ },
+
+ /**
+ * Sets the value of a property. If the silent property is passed as
+ * true, the property's event will not be fired.
+ * @method setProperty
+ * @param {String} key The name of the property
+ * @param {String} value The value to set the property to
+ * @param {Boolean} silent Whether the value should be set silently,
+ * without firing the property event.
+ * @return {Boolean} True, if the set was successful, false if it failed.
+ */
+ setProperty: function (key, value, silent) {
+
+ var property;
+
+ key = key.toLowerCase();
+
+ if (this.queueInProgress && ! silent) {
+ // Currently running through a queue...
+ this.queueProperty(key,value);
+ return true;
+
+ } else {
+ property = this.config[key];
+ if (property && property.event) {
+ if (property.validator && !property.validator(value)) {
+ return false;
+ } else {
+ property.value = value;
+ if (! silent) {
+ this.fireEvent(key, value);
+ this.configChangedEvent.fire([key, value]);
+ }
+ return true;
+ }
+ } else {
+ return false;
+ }
+ }
+ },
+
+ /**
+ * Sets the value of a property and queues its event to execute. If the
+ * event is already scheduled to execute, it is
+ * moved from its current position to the end of the queue.
+ * @method queueProperty
+ * @param {String} key The name of the property
+ * @param {String} value The value to set the property to
+ * @return {Boolean} true, if the set was successful, false if
+ * it failed.
+ */
+ queueProperty: function (key, value) {
+
+ key = key.toLowerCase();
+
+ var property = this.config[key],
+ foundDuplicate = false,
+ iLen,
+ queueItem,
+ queueItemKey,
+ queueItemValue,
+ sLen,
+ supercedesCheck,
+ qLen,
+ queueItemCheck,
+ queueItemCheckKey,
+ queueItemCheckValue,
+ i,
+ s,
+ q;
+
+ if (property && property.event) {
+
+ if (!Lang.isUndefined(value) && property.validator &&
+ !property.validator(value)) { // validator
+ return false;
+ } else {
+
+ if (!Lang.isUndefined(value)) {
+ property.value = value;
+ } else {
+ value = property.value;
+ }
+
+ foundDuplicate = false;
+ iLen = this.eventQueue.length;
+
+ for (i = 0; i < iLen; i++) {
+ queueItem = this.eventQueue[i];
+
+ if (queueItem) {
+ queueItemKey = queueItem[0];
+ queueItemValue = queueItem[1];
+
+ if (queueItemKey == key) {
+
+ /*
+ found a dupe... push to end of queue, null
+ current item, and break
+ */
+
+ this.eventQueue[i] = null;
+
+ this.eventQueue.push(
+ [key, (!Lang.isUndefined(value) ?
+ value : queueItemValue)]);
+
+ foundDuplicate = true;
+ break;
+ }
+ }
+ }
+
+ // this is a refire, or a new property in the queue
+
+ if (! foundDuplicate && !Lang.isUndefined(value)) {
+ this.eventQueue.push([key, value]);
+ }
+ }
+
+ if (property.supercedes) {
+
+ sLen = property.supercedes.length;
+
+ for (s = 0; s < sLen; s++) {
+
+ supercedesCheck = property.supercedes[s];
+ qLen = this.eventQueue.length;
+
+ for (q = 0; q < qLen; q++) {
+ queueItemCheck = this.eventQueue[q];
+
+ if (queueItemCheck) {
+ queueItemCheckKey = queueItemCheck[0];
+ queueItemCheckValue = queueItemCheck[1];
+
+ if (queueItemCheckKey ==
+ supercedesCheck.toLowerCase() ) {
+
+ this.eventQueue.push([queueItemCheckKey,
+ queueItemCheckValue]);
+
+ this.eventQueue[q] = null;
+ break;
+
+ }
+ }
+ }
+ }
+ }
+
+
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+ /**
+ * Fires the event for a property using the property's current value.
+ * @method refireEvent
+ * @param {String} key The name of the property
+ */
+ refireEvent: function (key) {
+
+ key = key.toLowerCase();
+
+ var property = this.config[key];
+
+ if (property && property.event &&
+
+ !Lang.isUndefined(property.value)) {
+
+ if (this.queueInProgress) {
+
+ this.queueProperty(key);
+
+ } else {
+
+ this.fireEvent(key, property.value);
+
+ }
+
+ }
+ },
+
+ /**
+ * Applies a key-value Object literal to the configuration, replacing
+ * any existing values, and queueing the property events.
+ * Although the values will be set, fireQueue() must be called for their
+ * associated events to execute.
+ * @method applyConfig
+ * @param {Object} userConfig The configuration Object literal
+ * @param {Boolean} init When set to true, the initialConfig will
+ * be set to the userConfig passed in, so that calling a reset will
+ * reset the properties to the passed values.
+ */
+ applyConfig: function (userConfig, init) {
+
+ var sKey,
+ oConfig;
+
+ if (init) {
+ oConfig = {};
+ for (sKey in userConfig) {
+ if (Lang.hasOwnProperty(userConfig, sKey)) {
+ oConfig[sKey.toLowerCase()] = userConfig[sKey];
+ }
+ }
+ this.initialConfig = oConfig;
+ }
+
+ for (sKey in userConfig) {
+ if (Lang.hasOwnProperty(userConfig, sKey)) {
+ this.queueProperty(sKey, userConfig[sKey]);
+ }
+ }
+ },
+
+ /**
+ * Refires the events for all configuration properties using their
+ * current values.
+ * @method refresh
+ */
+ refresh: function () {
+
+ var prop;
+
+ for (prop in this.config) {
+ if (Lang.hasOwnProperty(this.config, prop)) {
+ this.refireEvent(prop);
+ }
+ }
+ },
+
+ /**
+ * Fires the normalized list of queued property change events
+ * @method fireQueue
+ */
+ fireQueue: function () {
+
+ var i,
+ queueItem,
+ key,
+ value,
+ property;
+
+ this.queueInProgress = true;
+ for (i = 0;i < this.eventQueue.length; i++) {
+ queueItem = this.eventQueue[i];
+ if (queueItem) {
+
+ key = queueItem[0];
+ value = queueItem[1];
+ property = this.config[key];
+
+ property.value = value;
+
+ this.fireEvent(key,value);
+ }
+ }
+
+ this.queueInProgress = false;
+ this.eventQueue = [];
+ },
+
+ /**
+ * Subscribes an external handler to the change event for any
+ * given property.
+ * @method subscribeToConfigEvent
+ * @param {String} key The property name
+ * @param {Function} handler The handler function to use subscribe to
+ * the property's event
+ * @param {Object} obj The Object to use for scoping the event handler
+ * (see CustomEvent documentation)
+ * @param {Boolean} override Optional. If true, will override "this"
+ * within the handler to map to the scope Object passed into the method.
+ * @return {Boolean} True, if the subscription was successful,
+ * otherwise false.
+ */
+ subscribeToConfigEvent: function (key, handler, obj, override) {
+
+ var property = this.config[key.toLowerCase()];
+
+ if (property && property.event) {
+ if (!Config.alreadySubscribed(property.event, handler, obj)) {
+ property.event.subscribe(handler, obj, override);
+ }
+ return true;
+ } else {
+ return false;
+ }
+
+ },
+
+ /**
+ * Unsubscribes an external handler from the change event for any
+ * given property.
+ * @method unsubscribeFromConfigEvent
+ * @param {String} key The property name
+ * @param {Function} handler The handler function to use subscribe to
+ * the property's event
+ * @param {Object} obj The Object to use for scoping the event
+ * handler (see CustomEvent documentation)
+ * @return {Boolean} True, if the unsubscription was successful,
+ * otherwise false.
+ */
+ unsubscribeFromConfigEvent: function (key, handler, obj) {
+ var property = this.config[key.toLowerCase()];
+ if (property && property.event) {
+ return property.event.unsubscribe(handler, obj);
+ } else {
+ return false;
+ }
+ },
+
+ /**
+ * Returns a string representation of the Config object
+ * @method toString
+ * @return {String} The Config object in string format.
+ */
+ toString: function () {
+ var output = "Config";
+ if (this.owner) {
+ output += " [" + this.owner.toString() + "]";
+ }
+ return output;
+ },
+
+ /**
+ * Returns a string representation of the Config object's current
+ * CustomEvent queue
+ * @method outputEventQueue
+ * @return {String} The string list of CustomEvents currently queued
+ * for execution
+ */
+ outputEventQueue: function () {
+
+ var output = "",
+ queueItem,
+ q,
+ nQueue = this.eventQueue.length;
+
+ for (q = 0; q < nQueue; q++) {
+ queueItem = this.eventQueue[q];
+ if (queueItem) {
+ output += queueItem[0] + "=" + queueItem[1] + ", ";
+ }
+ }
+ return output;
+ },
+
+ /**
+ * Sets all properties to null, unsubscribes all listeners from each
+ * property's change event and all listeners from the configChangedEvent.
+ * @method destroy
+ */
+ destroy: function () {
+
+ var oConfig = this.config,
+ sProperty,
+ oProperty;
+
+
+ for (sProperty in oConfig) {
+
+ if (Lang.hasOwnProperty(oConfig, sProperty)) {
+
+ oProperty = oConfig[sProperty];
+
+ oProperty.event.unsubscribeAll();
+ oProperty.event = null;
+
+ }
+
+ }
+
+ this.configChangedEvent.unsubscribeAll();
+
+ this.configChangedEvent = null;
+ this.owner = null;
+ this.config = null;
+ this.initialConfig = null;
+ this.eventQueue = null;
+
+ }
+
+ };
+
+
+
+ /**
+ * Checks to determine if a particular function/Object pair are already
+ * subscribed to the specified CustomEvent
+ * @method YAHOO.util.Config.alreadySubscribed
+ * @static
+ * @param {YAHOO.util.CustomEvent} evt The CustomEvent for which to check
+ * the subscriptions
+ * @param {Function} fn The function to look for in the subscribers list
+ * @param {Object} obj The execution scope Object for the subscription
+ * @return {Boolean} true, if the function/Object pair is already subscribed
+ * to the CustomEvent passed in
+ */
+ Config.alreadySubscribed = function (evt, fn, obj) {
+
+ var nSubscribers = evt.subscribers.length,
+ subsc,
+ i;
+
+ if (nSubscribers > 0) {
+ i = nSubscribers - 1;
+ do {
+ subsc = evt.subscribers[i];
+ if (subsc && subsc.obj == obj && subsc.fn == fn) {
+ return true;
+ }
+ }
+ while (i--);
+ }
+
+ return false;
+
+ };
+
+ YAHOO.lang.augmentProto(Config, YAHOO.util.EventProvider);
+
+}());
+
+/**
+* YAHOO.widget.DateMath is used for simple date manipulation. The class is a static utility
+* used for adding, subtracting, and comparing dates.
+* @namespace YAHOO.widget
+* @class DateMath
+*/
+YAHOO.widget.DateMath = {
+ /**
+ * Constant field representing Day
+ * @property DAY
+ * @static
+ * @final
+ * @type String
+ */
+ DAY : "D",
+
+ /**
+ * Constant field representing Week
+ * @property WEEK
+ * @static
+ * @final
+ * @type String
+ */
+ WEEK : "W",
+
+ /**
+ * Constant field representing Year
+ * @property YEAR
+ * @static
+ * @final
+ * @type String
+ */
+ YEAR : "Y",
+
+ /**
+ * Constant field representing Month
+ * @property MONTH
+ * @static
+ * @final
+ * @type String
+ */
+ MONTH : "M",
+
+ /**
+ * Constant field representing one day, in milliseconds
+ * @property ONE_DAY_MS
+ * @static
+ * @final
+ * @type Number
+ */
+ ONE_DAY_MS : 1000*60*60*24,
+
+ /**
+ * Constant field representing the date in first week of January
+ * which identifies the first week of the year.
+ *
+ * In the U.S, Jan 1st is normally used based on a Sunday start of week.
+ * ISO 8601, used widely throughout Europe, uses Jan 4th, based on a Monday start of week.
+ *
+ * @property WEEK_ONE_JAN_DATE
+ * @static
+ * @type Number
+ */
+ WEEK_ONE_JAN_DATE : 1,
+
+ /**
+ * Adds the specified amount of time to the this instance.
+ * @method add
+ * @param {Date} date The JavaScript Date object to perform addition on
+ * @param {String} field The field constant to be used for performing addition.
+ * @param {Number} amount The number of units (measured in the field constant) to add to the date.
+ * @return {Date} The resulting Date object
+ */
+ add : function(date, field, amount) {
+ var d = new Date(date.getTime());
+ switch (field) {
+ case this.MONTH:
+ var newMonth = date.getMonth() + amount;
+ var years = 0;
+
+ if (newMonth < 0) {
+ while (newMonth < 0) {
+ newMonth += 12;
+ years -= 1;
+ }
+ } else if (newMonth > 11) {
+ while (newMonth > 11) {
+ newMonth -= 12;
+ years += 1;
+ }
+ }
+
+ d.setMonth(newMonth);
+ d.setFullYear(date.getFullYear() + years);
+ break;
+ case this.DAY:
+ this._addDays(d, amount);
+ // d.setDate(date.getDate() + amount);
+ break;
+ case this.YEAR:
+ d.setFullYear(date.getFullYear() + amount);
+ break;
+ case this.WEEK:
+ this._addDays(d, (amount * 7));
+ // d.setDate(date.getDate() + (amount * 7));
+ break;
+ }
+ return d;
+ },
+
+ /**
+ * Private helper method to account for bug in Safari 2 (webkit < 420)
+ * when Date.setDate(n) is called with n less than -128 or greater than 127.
+ *
+ * Fix approach and original findings are available here:
+ * http://brianary.blogspot.com/2006/03/safari-date-bug.html
+ *
+ * @method _addDays
+ * @param {Date} d JavaScript date object
+ * @param {Number} nDays The number of days to add to the date object (can be negative)
+ * @private
+ */
+ _addDays : function(d, nDays) {
+ if (YAHOO.env.ua.webkit && YAHOO.env.ua.webkit < 420) {
+ if (nDays < 0) {
+ // Ensure we don't go below -128 (getDate() is always 1 to 31, so we won't go above 127)
+ for(var min = -128; nDays < min; nDays -= min) {
+ d.setDate(d.getDate() + min);
+ }
+ } else {
+ // Ensure we don't go above 96 + 31 = 127
+ for(var max = 96; nDays > max; nDays -= max) {
+ d.setDate(d.getDate() + max);
+ }
+ }
+ // nDays should be remainder between -128 and 96
+ }
+ d.setDate(d.getDate() + nDays);
+ },
+
+ /**
+ * Subtracts the specified amount of time from the this instance.
+ * @method subtract
+ * @param {Date} date The JavaScript Date object to perform subtraction on
+ * @param {Number} field The this field constant to be used for performing subtraction.
+ * @param {Number} amount The number of units (measured in the field constant) to subtract from the date.
+ * @return {Date} The resulting Date object
+ */
+ subtract : function(date, field, amount) {
+ return this.add(date, field, (amount*-1));
+ },
+
+ /**
+ * Determines whether a given date is before another date on the calendar.
+ * @method before
+ * @param {Date} date The Date object to compare with the compare argument
+ * @param {Date} compareTo The Date object to use for the comparison
+ * @return {Boolean} true if the date occurs before the compared date; false if not.
+ */
+ before : function(date, compareTo) {
+ var ms = compareTo.getTime();
+ if (date.getTime() < ms) {
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+ /**
+ * Determines whether a given date is after another date on the calendar.
+ * @method after
+ * @param {Date} date The Date object to compare with the compare argument
+ * @param {Date} compareTo The Date object to use for the comparison
+ * @return {Boolean} true if the date occurs after the compared date; false if not.
+ */
+ after : function(date, compareTo) {
+ var ms = compareTo.getTime();
+ if (date.getTime() > ms) {
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+ /**
+ * Determines whether a given date is between two other dates on the calendar.
+ * @method between
+ * @param {Date} date The date to check for
+ * @param {Date} dateBegin The start of the range
+ * @param {Date} dateEnd The end of the range
+ * @return {Boolean} true if the date occurs between the compared dates; false if not.
+ */
+ between : function(date, dateBegin, dateEnd) {
+ if (this.after(date, dateBegin) && this.before(date, dateEnd)) {
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+ /**
+ * Retrieves a JavaScript Date object representing January 1 of any given year.
+ * @method getJan1
+ * @param {Number} calendarYear The calendar year for which to retrieve January 1
+ * @return {Date} January 1 of the calendar year specified.
+ */
+ getJan1 : function(calendarYear) {
+ return this.getDate(calendarYear,0,1);
+ },
+
+ /**
+ * Calculates the number of days the specified date is from January 1 of the specified calendar year.
+ * Passing January 1 to this function would return an offset value of zero.
+ * @method getDayOffset
+ * @param {Date} date The JavaScript date for which to find the offset
+ * @param {Number} calendarYear The calendar year to use for determining the offset
+ * @return {Number} The number of days since January 1 of the given year
+ */
+ getDayOffset : function(date, calendarYear) {
+ var beginYear = this.getJan1(calendarYear); // Find the start of the year. This will be in week 1.
+
+ // Find the number of days the passed in date is away from the calendar year start
+ var dayOffset = Math.ceil((date.getTime()-beginYear.getTime()) / this.ONE_DAY_MS);
+ return dayOffset;
+ },
+
+ /**
+ * Calculates the week number for the given date. Can currently support standard
+ * U.S. week numbers, based on Jan 1st defining the 1st week of the year, and
+ * ISO8601 week numbers, based on Jan 4th defining the 1st week of the year.
+ *
+ * @method getWeekNumber
+ * @param {Date} date The JavaScript date for which to find the week number
+ * @param {Number} firstDayOfWeek The index of the first day of the week (0 = Sun, 1 = Mon ... 6 = Sat).
+ * Defaults to 0
+ * @param {Number} janDate The date in the first week of January which defines week one for the year
+ * Defaults to the value of YAHOO.widget.DateMath.WEEK_ONE_JAN_DATE, which is 1 (Jan 1st).
+ * For the U.S, this is normally Jan 1st. ISO8601 uses Jan 4th to define the first week of the year.
+ *
+ * @return {Number} The number of the week containing the given date.
+ */
+ getWeekNumber : function(date, firstDayOfWeek, janDate) {
+
+ // Setup Defaults
+ firstDayOfWeek = firstDayOfWeek || 0;
+ janDate = janDate || this.WEEK_ONE_JAN_DATE;
+
+ var targetDate = this.clearTime(date),
+ startOfWeek,
+ endOfWeek;
+
+ if (targetDate.getDay() === firstDayOfWeek) {
+ startOfWeek = targetDate;
+ } else {
+ startOfWeek = this.getFirstDayOfWeek(targetDate, firstDayOfWeek);
+ }
+
+ var startYear = startOfWeek.getFullYear(),
+ startTime = startOfWeek.getTime();
+
+ // DST shouldn't be a problem here, math is quicker than setDate();
+ endOfWeek = new Date(startOfWeek.getTime() + 6*this.ONE_DAY_MS);
+
+ var weekNum;
+ if (startYear !== endOfWeek.getFullYear() && endOfWeek.getDate() >= janDate) {
+ // If years don't match, endOfWeek is in Jan. and if the
+ // week has WEEK_ONE_JAN_DATE in it, it's week one by definition.
+ weekNum = 1;
+ } else {
+ // Get the 1st day of the 1st week, and
+ // find how many days away we are from it.
+ var weekOne = this.clearTime(this.getDate(startYear, 0, janDate)),
+ weekOneDayOne = this.getFirstDayOfWeek(weekOne, firstDayOfWeek);
+
+ // Round days to smoothen out 1 hr DST diff
+ var daysDiff = Math.round((targetDate.getTime() - weekOneDayOne.getTime())/this.ONE_DAY_MS);
+
+ // Calc. Full Weeks
+ var rem = daysDiff % 7;
+ var weeksDiff = (daysDiff - rem)/7;
+ weekNum = weeksDiff + 1;
+ }
+ return weekNum;
+ },
+
+ /**
+ * Get the first day of the week, for the give date.
+ * @param {Date} dt The date in the week for which the first day is required.
+ * @param {Number} startOfWeek The index for the first day of the week, 0 = Sun, 1 = Mon ... 6 = Sat (defaults to 0)
+ * @return {Date} The first day of the week
+ */
+ getFirstDayOfWeek : function (dt, startOfWeek) {
+ startOfWeek = startOfWeek || 0;
+ var dayOfWeekIndex = dt.getDay(),
+ dayOfWeek = (dayOfWeekIndex - startOfWeek + 7) % 7;
+
+ return this.subtract(dt, this.DAY, dayOfWeek);
+ },
+
+ /**
+ * Determines if a given week overlaps two different years.
+ * @method isYearOverlapWeek
+ * @param {Date} weekBeginDate The JavaScript Date representing the first day of the week.
+ * @return {Boolean} true if the date overlaps two different years.
+ */
+ isYearOverlapWeek : function(weekBeginDate) {
+ var overlaps = false;
+ var nextWeek = this.add(weekBeginDate, this.DAY, 6);
+ if (nextWeek.getFullYear() != weekBeginDate.getFullYear()) {
+ overlaps = true;
+ }
+ return overlaps;
+ },
+
+ /**
+ * Determines if a given week overlaps two different months.
+ * @method isMonthOverlapWeek
+ * @param {Date} weekBeginDate The JavaScript Date representing the first day of the week.
+ * @return {Boolean} true if the date overlaps two different months.
+ */
+ isMonthOverlapWeek : function(weekBeginDate) {
+ var overlaps = false;
+ var nextWeek = this.add(weekBeginDate, this.DAY, 6);
+ if (nextWeek.getMonth() != weekBeginDate.getMonth()) {
+ overlaps = true;
+ }
+ return overlaps;
+ },
+
+ /**
+ * Gets the first day of a month containing a given date.
+ * @method findMonthStart
+ * @param {Date} date The JavaScript Date used to calculate the month start
+ * @return {Date} The JavaScript Date representing the first day of the month
+ */
+ findMonthStart : function(date) {
+ var start = this.getDate(date.getFullYear(), date.getMonth(), 1);
+ return start;
+ },
+
+ /**
+ * Gets the last day of a month containing a given date.
+ * @method findMonthEnd
+ * @param {Date} date The JavaScript Date used to calculate the month end
+ * @return {Date} The JavaScript Date representing the last day of the month
+ */
+ findMonthEnd : function(date) {
+ var start = this.findMonthStart(date);
+ var nextMonth = this.add(start, this.MONTH, 1);
+ var end = this.subtract(nextMonth, this.DAY, 1);
+ return end;
+ },
+
+ /**
+ * Clears the time fields from a given date, effectively setting the time to 12 noon.
+ * @method clearTime
+ * @param {Date} date The JavaScript Date for which the time fields will be cleared
+ * @return {Date} The JavaScript Date cleared of all time fields
+ */
+ clearTime : function(date) {
+ date.setHours(12,0,0,0);
+ return date;
+ },
+
+ /**
+ * Returns a new JavaScript Date object, representing the given year, month and date. Time fields (hr, min, sec, ms) on the new Date object
+ * are set to 0. The method allows Date instances to be created with the a year less than 100. "new Date(year, month, date)" implementations
+ * set the year to 19xx if a year (xx) which is less than 100 is provided.
+ *
+ * NOTE:Validation on argument values is not performed. It is the caller's responsibility to ensure
+ * arguments are valid as per the ECMAScript-262 Date object specification for the new Date(year, month[, date]) constructor.
+ *
+ * @method getDate
+ * @param {Number} y Year.
+ * @param {Number} m Month index from 0 (Jan) to 11 (Dec).
+ * @param {Number} d (optional) Date from 1 to 31. If not provided, defaults to 1.
+ * @return {Date} The JavaScript date object with year, month, date set as provided.
+ */
+ getDate : function(y, m, d) {
+ var dt = null;
+ if (YAHOO.lang.isUndefined(d)) {
+ d = 1;
+ }
+ if (y >= 100) {
+ dt = new Date(y, m, d);
+ } else {
+ dt = new Date();
+ dt.setFullYear(y);
+ dt.setMonth(m);
+ dt.setDate(d);
+ dt.setHours(0,0,0,0);
+ }
+ return dt;
+ }
+};
+
+/**
+* The Calendar component is a UI control that enables users to choose one or more dates from a graphical calendar presented in a one-month or
+* multi-month interface. Calendars are generated entirely via script and can be navigated without any page refreshes.
+* @module calendar
+* @title Calendar
+* @namespace YAHOO.widget
+* @requires yahoo,dom,event
+*/
+(function(){
+
+ var Dom = YAHOO.util.Dom,
+ Event = YAHOO.util.Event,
+ Lang = YAHOO.lang,
+ DateMath = YAHOO.widget.DateMath;
+
+/**
+* Calendar is the base class for the Calendar widget. In its most basic
+* implementation, it has the ability to render a calendar widget on the page
+* that can be manipulated to select a single date, move back and forth between
+* months and years.
+*
To construct the placeholder for the calendar widget, the code is as
+* follows:
+*
+*
+*
+*
+*
+* NOTE: As of 2.4.0, the constructor's ID argument is optional.
+* The Calendar can be constructed by simply providing a container ID string,
+* or a reference to a container DIV HTMLElement (the element needs to exist
+* in the document).
+*
+* E.g.:
+*
+* var c = new YAHOO.widget.Calendar("calContainer", configOptions);
+*
+* or:
+*
+* var containerDiv = YAHOO.util.Dom.get("calContainer");
+* var c = new YAHOO.widget.Calendar(containerDiv, configOptions);
+*
+*
+*
+* If not provided, the ID will be generated from the container DIV ID by adding an "_t" suffix.
+* For example if an ID is not provided, and the container's ID is "calContainer", the Calendar's ID will be set to "calContainer_t".
+*
+*
+* @namespace YAHOO.widget
+* @class Calendar
+* @constructor
+* @param {String} id optional The id of the table element that will represent the Calendar widget. As of 2.4.0, this argument is optional.
+* @param {String | HTMLElement} container The id of the container div element that will wrap the Calendar table, or a reference to a DIV element which exists in the document.
+* @param {Object} config optional The configuration object containing the initial configuration values for the Calendar.
+*/
+function Calendar(id, containerId, config) {
+ this.init.apply(this, arguments);
+}
+
+/**
+* The path to be used for images loaded for the Calendar
+* @property YAHOO.widget.Calendar.IMG_ROOT
+* @static
+* @deprecated You can now customize images by overriding the calclose, calnavleft and calnavright default CSS classes for the close icon, left arrow and right arrow respectively
+* @type String
+*/
+Calendar.IMG_ROOT = null;
+
+/**
+* Type constant used for renderers to represent an individual date (M/D/Y)
+* @property YAHOO.widget.Calendar.DATE
+* @static
+* @final
+* @type String
+*/
+Calendar.DATE = "D";
+
+/**
+* Type constant used for renderers to represent an individual date across any year (M/D)
+* @property YAHOO.widget.Calendar.MONTH_DAY
+* @static
+* @final
+* @type String
+*/
+Calendar.MONTH_DAY = "MD";
+
+/**
+* Type constant used for renderers to represent a weekday
+* @property YAHOO.widget.Calendar.WEEKDAY
+* @static
+* @final
+* @type String
+*/
+Calendar.WEEKDAY = "WD";
+
+/**
+* Type constant used for renderers to represent a range of individual dates (M/D/Y-M/D/Y)
+* @property YAHOO.widget.Calendar.RANGE
+* @static
+* @final
+* @type String
+*/
+Calendar.RANGE = "R";
+
+/**
+* Type constant used for renderers to represent a month across any year
+* @property YAHOO.widget.Calendar.MONTH
+* @static
+* @final
+* @type String
+*/
+Calendar.MONTH = "M";
+
+/**
+* Constant that represents the total number of date cells that are displayed in a given month
+* @property YAHOO.widget.Calendar.DISPLAY_DAYS
+* @static
+* @final
+* @type Number
+*/
+Calendar.DISPLAY_DAYS = 42;
+
+/**
+* Constant used for halting the execution of the remainder of the render stack
+* @property YAHOO.widget.Calendar.STOP_RENDER
+* @static
+* @final
+* @type String
+*/
+Calendar.STOP_RENDER = "S";
+
+/**
+* Constant used to represent short date field string formats (e.g. Tu or Feb)
+* @property YAHOO.widget.Calendar.SHORT
+* @static
+* @final
+* @type String
+*/
+Calendar.SHORT = "short";
+
+/**
+* Constant used to represent long date field string formats (e.g. Monday or February)
+* @property YAHOO.widget.Calendar.LONG
+* @static
+* @final
+* @type String
+*/
+Calendar.LONG = "long";
+
+/**
+* Constant used to represent medium date field string formats (e.g. Mon)
+* @property YAHOO.widget.Calendar.MEDIUM
+* @static
+* @final
+* @type String
+*/
+Calendar.MEDIUM = "medium";
+
+/**
+* Constant used to represent single character date field string formats (e.g. M, T, W)
+* @property YAHOO.widget.Calendar.ONE_CHAR
+* @static
+* @final
+* @type String
+*/
+Calendar.ONE_CHAR = "1char";
+
+/**
+* The set of default Config property keys and values for the Calendar
+* @property YAHOO.widget.Calendar._DEFAULT_CONFIG
+* @final
+* @static
+* @private
+* @type Object
+*/
+Calendar._DEFAULT_CONFIG = {
+ // Default values for pagedate and selected are not class level constants - they are set during instance creation
+ PAGEDATE : {key:"pagedate", value:null},
+ SELECTED : {key:"selected", value:null},
+ TITLE : {key:"title", value:""},
+ CLOSE : {key:"close", value:false},
+ IFRAME : {key:"iframe", value:(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 6) ? true : false},
+ MINDATE : {key:"mindate", value:null},
+ MAXDATE : {key:"maxdate", value:null},
+ MULTI_SELECT : {key:"multi_select", value:false},
+ START_WEEKDAY : {key:"start_weekday", value:0},
+ SHOW_WEEKDAYS : {key:"show_weekdays", value:true},
+ SHOW_WEEK_HEADER : {key:"show_week_header", value:false},
+ SHOW_WEEK_FOOTER : {key:"show_week_footer", value:false},
+ HIDE_BLANK_WEEKS : {key:"hide_blank_weeks", value:false},
+ NAV_ARROW_LEFT: {key:"nav_arrow_left", value:null} ,
+ NAV_ARROW_RIGHT : {key:"nav_arrow_right", value:null} ,
+ MONTHS_SHORT : {key:"months_short", value:["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]},
+ MONTHS_LONG: {key:"months_long", value:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]},
+ WEEKDAYS_1CHAR: {key:"weekdays_1char", value:["S", "M", "T", "W", "T", "F", "S"]},
+ WEEKDAYS_SHORT: {key:"weekdays_short", value:["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]},
+ WEEKDAYS_MEDIUM: {key:"weekdays_medium", value:["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]},
+ WEEKDAYS_LONG: {key:"weekdays_long", value:["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]},
+ LOCALE_MONTHS:{key:"locale_months", value:"long"},
+ LOCALE_WEEKDAYS:{key:"locale_weekdays", value:"short"},
+ DATE_DELIMITER:{key:"date_delimiter", value:","},
+ DATE_FIELD_DELIMITER:{key:"date_field_delimiter", value:"/"},
+ DATE_RANGE_DELIMITER:{key:"date_range_delimiter", value:"-"},
+ MY_MONTH_POSITION:{key:"my_month_position", value:1},
+ MY_YEAR_POSITION:{key:"my_year_position", value:2},
+ MD_MONTH_POSITION:{key:"md_month_position", value:1},
+ MD_DAY_POSITION:{key:"md_day_position", value:2},
+ MDY_MONTH_POSITION:{key:"mdy_month_position", value:1},
+ MDY_DAY_POSITION:{key:"mdy_day_position", value:2},
+ MDY_YEAR_POSITION:{key:"mdy_year_position", value:3},
+ MY_LABEL_MONTH_POSITION:{key:"my_label_month_position", value:1},
+ MY_LABEL_YEAR_POSITION:{key:"my_label_year_position", value:2},
+ MY_LABEL_MONTH_SUFFIX:{key:"my_label_month_suffix", value:" "},
+ MY_LABEL_YEAR_SUFFIX:{key:"my_label_year_suffix", value:""},
+ NAV: {key:"navigator", value: null},
+ STRINGS : {
+ key:"strings",
+ value: {
+ previousMonth : "Previous Month",
+ nextMonth : "Next Month",
+ close: "Close"
+ },
+ supercedes : ["close", "title"]
+ }
+};
+
+var DEF_CFG = Calendar._DEFAULT_CONFIG;
+
+/**
+* The set of Custom Event types supported by the Calendar
+* @property YAHOO.widget.Calendar._EVENT_TYPES
+* @final
+* @static
+* @private
+* @type Object
+*/
+Calendar._EVENT_TYPES = {
+ BEFORE_SELECT : "beforeSelect",
+ SELECT : "select",
+ BEFORE_DESELECT : "beforeDeselect",
+ DESELECT : "deselect",
+ CHANGE_PAGE : "changePage",
+ BEFORE_RENDER : "beforeRender",
+ RENDER : "render",
+ BEFORE_DESTROY : "beforeDestroy",
+ DESTROY : "destroy",
+ RESET : "reset",
+ CLEAR : "clear",
+ BEFORE_HIDE : "beforeHide",
+ HIDE : "hide",
+ BEFORE_SHOW : "beforeShow",
+ SHOW : "show",
+ BEFORE_HIDE_NAV : "beforeHideNav",
+ HIDE_NAV : "hideNav",
+ BEFORE_SHOW_NAV : "beforeShowNav",
+ SHOW_NAV : "showNav",
+ BEFORE_RENDER_NAV : "beforeRenderNav",
+ RENDER_NAV : "renderNav"
+};
+
+/**
+* The set of default style constants for the Calendar
+* @property YAHOO.widget.Calendar._STYLES
+* @final
+* @static
+* @private
+* @type Object
+*/
+Calendar._STYLES = {
+ CSS_ROW_HEADER: "calrowhead",
+ CSS_ROW_FOOTER: "calrowfoot",
+ CSS_CELL : "calcell",
+ CSS_CELL_SELECTOR : "selector",
+ CSS_CELL_SELECTED : "selected",
+ CSS_CELL_SELECTABLE : "selectable",
+ CSS_CELL_RESTRICTED : "restricted",
+ CSS_CELL_TODAY : "today",
+ CSS_CELL_OOM : "oom",
+ CSS_CELL_OOB : "previous",
+ CSS_HEADER : "calheader",
+ CSS_HEADER_TEXT : "calhead",
+ CSS_BODY : "calbody",
+ CSS_WEEKDAY_CELL : "calweekdaycell",
+ CSS_WEEKDAY_ROW : "calweekdayrow",
+ CSS_FOOTER : "calfoot",
+ CSS_CALENDAR : "yui-calendar",
+ CSS_SINGLE : "single",
+ CSS_CONTAINER : "yui-calcontainer",
+ CSS_NAV_LEFT : "calnavleft",
+ CSS_NAV_RIGHT : "calnavright",
+ CSS_NAV : "calnav",
+ CSS_CLOSE : "calclose",
+ CSS_CELL_TOP : "calcelltop",
+ CSS_CELL_LEFT : "calcellleft",
+ CSS_CELL_RIGHT : "calcellright",
+ CSS_CELL_BOTTOM : "calcellbottom",
+ CSS_CELL_HOVER : "calcellhover",
+ CSS_CELL_HIGHLIGHT1 : "highlight1",
+ CSS_CELL_HIGHLIGHT2 : "highlight2",
+ CSS_CELL_HIGHLIGHT3 : "highlight3",
+ CSS_CELL_HIGHLIGHT4 : "highlight4"
+};
+
+Calendar.prototype = {
+
+ /**
+ * The configuration object used to set up the calendars various locale and style options.
+ * @property Config
+ * @private
+ * @deprecated Configuration properties should be set by calling Calendar.cfg.setProperty.
+ * @type Object
+ */
+ Config : null,
+
+ /**
+ * The parent CalendarGroup, only to be set explicitly by the parent group
+ * @property parent
+ * @type CalendarGroup
+ */
+ parent : null,
+
+ /**
+ * The index of this item in the parent group
+ * @property index
+ * @type Number
+ */
+ index : -1,
+
+ /**
+ * The collection of calendar table cells
+ * @property cells
+ * @type HTMLTableCellElement[]
+ */
+ cells : null,
+
+ /**
+ * The collection of calendar cell dates that is parallel to the cells collection. The array contains dates field arrays in the format of [YYYY, M, D].
+ * @property cellDates
+ * @type Array[](Number[])
+ */
+ cellDates : null,
+
+ /**
+ * The id that uniquely identifies this Calendar.
+ * @property id
+ * @type String
+ */
+ id : null,
+
+ /**
+ * The unique id associated with the Calendar's container
+ * @property containerId
+ * @type String
+ */
+ containerId: null,
+
+ /**
+ * The DOM element reference that points to this calendar's container element. The calendar will be inserted into this element when the shell is rendered.
+ * @property oDomContainer
+ * @type HTMLElement
+ */
+ oDomContainer : null,
+
+ /**
+ * A Date object representing today's date.
+ * @property today
+ * @type Date
+ */
+ today : null,
+
+ /**
+ * The list of render functions, along with required parameters, used to render cells.
+ * @property renderStack
+ * @type Array[]
+ */
+ renderStack : null,
+
+ /**
+ * A copy of the initial render functions created before rendering.
+ * @property _renderStack
+ * @private
+ * @type Array
+ */
+ _renderStack : null,
+
+ /**
+ * A reference to the CalendarNavigator instance created for this Calendar.
+ * Will be null if the "navigator" configuration property has not been set
+ * @property oNavigator
+ * @type CalendarNavigator
+ */
+ oNavigator : null,
+
+ /**
+ * The private list of initially selected dates.
+ * @property _selectedDates
+ * @private
+ * @type Array
+ */
+ _selectedDates : null,
+
+ /**
+ * A map of DOM event handlers to attach to cells associated with specific CSS class names
+ * @property domEventMap
+ * @type Object
+ */
+ domEventMap : null,
+
+ /**
+ * Protected helper used to parse Calendar constructor/init arguments.
+ *
+ * As of 2.4.0, Calendar supports a simpler constructor
+ * signature. This method reconciles arguments
+ * received in the pre 2.4.0 and 2.4.0 formats.
+ *
+ * @protected
+ * @method _parseArgs
+ * @param {Array} Function "arguments" array
+ * @return {Object} Object with id, container, config properties containing
+ * the reconciled argument values.
+ **/
+ _parseArgs : function(args) {
+ /*
+ 2.4.0 Constructors signatures
+
+ new Calendar(String)
+ new Calendar(HTMLElement)
+ new Calendar(String, ConfigObject)
+ new Calendar(HTMLElement, ConfigObject)
+
+ Pre 2.4.0 Constructor signatures
+
+ new Calendar(String, String)
+ new Calendar(String, HTMLElement)
+ new Calendar(String, String, ConfigObject)
+ new Calendar(String, HTMLElement, ConfigObject)
+ */
+ var nArgs = {id:null, container:null, config:null};
+
+ if (args && args.length && args.length > 0) {
+ switch (args.length) {
+ case 1:
+ nArgs.id = null;
+ nArgs.container = args[0];
+ nArgs.config = null;
+ break;
+ case 2:
+ if (Lang.isObject(args[1]) && !args[1].tagName && !(args[1] instanceof String)) {
+ nArgs.id = null;
+ nArgs.container = args[0];
+ nArgs.config = args[1];
+ } else {
+ nArgs.id = args[0];
+ nArgs.container = args[1];
+ nArgs.config = null;
+ }
+ break;
+ default: // 3+
+ nArgs.id = args[0];
+ nArgs.container = args[1];
+ nArgs.config = args[2];
+ break;
+ }
+ } else {
+ }
+ return nArgs;
+ },
+
+ /**
+ * Initializes the Calendar widget.
+ * @method init
+ *
+ * @param {String} id optional The id of the table element that will represent the Calendar widget. As of 2.4.0, this argument is optional.
+ * @param {String | HTMLElement} container The id of the container div element that will wrap the Calendar table, or a reference to a DIV element which exists in the document.
+ * @param {Object} config optional The configuration object containing the initial configuration values for the Calendar.
+ */
+ init : function(id, container, config) {
+ // Normalize 2.4.0, pre 2.4.0 args
+ var nArgs = this._parseArgs(arguments);
+
+ id = nArgs.id;
+ container = nArgs.container;
+ config = nArgs.config;
+
+ this.oDomContainer = Dom.get(container);
+
+ if (!this.oDomContainer.id) {
+ this.oDomContainer.id = Dom.generateId();
+ }
+ if (!id) {
+ id = this.oDomContainer.id + "_t";
+ }
+
+ this.id = id;
+ this.containerId = this.oDomContainer.id;
+
+ this.initEvents();
+
+ this.today = new Date();
+ DateMath.clearTime(this.today);
+
+ /**
+ * The Config object used to hold the configuration variables for the Calendar
+ * @property cfg
+ * @type YAHOO.util.Config
+ */
+ this.cfg = new YAHOO.util.Config(this);
+
+ /**
+ * The local object which contains the Calendar's options
+ * @property Options
+ * @type Object
+ */
+ this.Options = {};
+
+ /**
+ * The local object which contains the Calendar's locale settings
+ * @property Locale
+ * @type Object
+ */
+ this.Locale = {};
+
+ this.initStyles();
+
+ Dom.addClass(this.oDomContainer, this.Style.CSS_CONTAINER);
+ Dom.addClass(this.oDomContainer, this.Style.CSS_SINGLE);
+
+ this.cellDates = [];
+ this.cells = [];
+ this.renderStack = [];
+ this._renderStack = [];
+
+ this.setupConfig();
+
+ if (config) {
+ this.cfg.applyConfig(config, true);
+ }
+
+ this.cfg.fireQueue();
+ },
+
+ /**
+ * Default Config listener for the iframe property. If the iframe config property is set to true,
+ * renders the built-in IFRAME shim if the container is relatively or absolutely positioned.
+ *
+ * @method configIframe
+ */
+ configIframe : function(type, args, obj) {
+ var useIframe = args[0];
+
+ if (!this.parent) {
+ if (Dom.inDocument(this.oDomContainer)) {
+ if (useIframe) {
+ var pos = Dom.getStyle(this.oDomContainer, "position");
+
+ if (pos == "absolute" || pos == "relative") {
+
+ if (!Dom.inDocument(this.iframe)) {
+ this.iframe = document.createElement("iframe");
+ this.iframe.src = "javascript:false;";
+
+ Dom.setStyle(this.iframe, "opacity", "0");
+
+ if (YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 6) {
+ Dom.addClass(this.iframe, "fixedsize");
+ }
+
+ this.oDomContainer.insertBefore(this.iframe, this.oDomContainer.firstChild);
+ }
+ }
+ } else {
+ if (this.iframe) {
+ if (this.iframe.parentNode) {
+ this.iframe.parentNode.removeChild(this.iframe);
+ }
+ this.iframe = null;
+ }
+ }
+ }
+ }
+ },
+
+ /**
+ * Default handler for the "title" property
+ * @method configTitle
+ */
+ configTitle : function(type, args, obj) {
+ var title = args[0];
+
+ // "" disables title bar
+ if (title) {
+ this.createTitleBar(title);
+ } else {
+ var close = this.cfg.getProperty(DEF_CFG.CLOSE.key);
+ if (!close) {
+ this.removeTitleBar();
+ } else {
+ this.createTitleBar(" ");
+ }
+ }
+ },
+
+ /**
+ * Default handler for the "close" property
+ * @method configClose
+ */
+ configClose : function(type, args, obj) {
+ var close = args[0],
+ title = this.cfg.getProperty(DEF_CFG.TITLE.key);
+
+ if (close) {
+ if (!title) {
+ this.createTitleBar(" ");
+ }
+ this.createCloseButton();
+ } else {
+ this.removeCloseButton();
+ if (!title) {
+ this.removeTitleBar();
+ }
+ }
+ },
+
+ /**
+ * Initializes Calendar's built-in CustomEvents
+ * @method initEvents
+ */
+ initEvents : function() {
+
+ var defEvents = Calendar._EVENT_TYPES,
+ CE = YAHOO.util.CustomEvent,
+ cal = this; // To help with minification
+
+ /**
+ * Fired before a selection is made
+ * @event beforeSelectEvent
+ */
+ cal.beforeSelectEvent = new CE(defEvents.BEFORE_SELECT);
+
+ /**
+ * Fired when a selection is made
+ * @event selectEvent
+ * @param {Array} Array of Date field arrays in the format [YYYY, MM, DD].
+ */
+ cal.selectEvent = new CE(defEvents.SELECT);
+
+ /**
+ * Fired before a selection is made
+ * @event beforeDeselectEvent
+ */
+ cal.beforeDeselectEvent = new CE(defEvents.BEFORE_DESELECT);
+
+ /**
+ * Fired when a selection is made
+ * @event deselectEvent
+ * @param {Array} Array of Date field arrays in the format [YYYY, MM, DD].
+ */
+ cal.deselectEvent = new CE(defEvents.DESELECT);
+
+ /**
+ * Fired when the Calendar page is changed
+ * @event changePageEvent
+ */
+ cal.changePageEvent = new CE(defEvents.CHANGE_PAGE);
+
+ /**
+ * Fired before the Calendar is rendered
+ * @event beforeRenderEvent
+ */
+ cal.beforeRenderEvent = new CE(defEvents.BEFORE_RENDER);
+
+ /**
+ * Fired when the Calendar is rendered
+ * @event renderEvent
+ */
+ cal.renderEvent = new CE(defEvents.RENDER);
+
+ /**
+ * Fired just before the Calendar is to be destroyed
+ * @event beforeDestroyEvent
+ */
+ cal.beforeDestroyEvent = new CE(defEvents.BEFORE_DESTROY);
+
+ /**
+ * Fired after the Calendar is destroyed. This event should be used
+ * for notification only. When this event is fired, important Calendar instance
+ * properties, dom references and event listeners have already been
+ * removed/dereferenced, and hence the Calendar instance is not in a usable
+ * state.
+ *
+ * @event destroyEvent
+ */
+ cal.destroyEvent = new CE(defEvents.DESTROY);
+
+ /**
+ * Fired when the Calendar is reset
+ * @event resetEvent
+ */
+ cal.resetEvent = new CE(defEvents.RESET);
+
+ /**
+ * Fired when the Calendar is cleared
+ * @event clearEvent
+ */
+ cal.clearEvent = new CE(defEvents.CLEAR);
+
+ /**
+ * Fired just before the Calendar is to be shown
+ * @event beforeShowEvent
+ */
+ cal.beforeShowEvent = new CE(defEvents.BEFORE_SHOW);
+
+ /**
+ * Fired after the Calendar is shown
+ * @event showEvent
+ */
+ cal.showEvent = new CE(defEvents.SHOW);
+
+ /**
+ * Fired just before the Calendar is to be hidden
+ * @event beforeHideEvent
+ */
+ cal.beforeHideEvent = new CE(defEvents.BEFORE_HIDE);
+
+ /**
+ * Fired after the Calendar is hidden
+ * @event hideEvent
+ */
+ cal.hideEvent = new CE(defEvents.HIDE);
+
+ /**
+ * Fired just before the CalendarNavigator is to be shown
+ * @event beforeShowNavEvent
+ */
+ cal.beforeShowNavEvent = new CE(defEvents.BEFORE_SHOW_NAV);
+
+ /**
+ * Fired after the CalendarNavigator is shown
+ * @event showNavEvent
+ */
+ cal.showNavEvent = new CE(defEvents.SHOW_NAV);
+
+ /**
+ * Fired just before the CalendarNavigator is to be hidden
+ * @event beforeHideNavEvent
+ */
+ cal.beforeHideNavEvent = new CE(defEvents.BEFORE_HIDE_NAV);
+
+ /**
+ * Fired after the CalendarNavigator is hidden
+ * @event hideNavEvent
+ */
+ cal.hideNavEvent = new CE(defEvents.HIDE_NAV);
+
+ /**
+ * Fired just before the CalendarNavigator is to be rendered
+ * @event beforeRenderNavEvent
+ */
+ cal.beforeRenderNavEvent = new CE(defEvents.BEFORE_RENDER_NAV);
+
+ /**
+ * Fired after the CalendarNavigator is rendered
+ * @event renderNavEvent
+ */
+ cal.renderNavEvent = new CE(defEvents.RENDER_NAV);
+
+ cal.beforeSelectEvent.subscribe(cal.onBeforeSelect, this, true);
+ cal.selectEvent.subscribe(cal.onSelect, this, true);
+ cal.beforeDeselectEvent.subscribe(cal.onBeforeDeselect, this, true);
+ cal.deselectEvent.subscribe(cal.onDeselect, this, true);
+ cal.changePageEvent.subscribe(cal.onChangePage, this, true);
+ cal.renderEvent.subscribe(cal.onRender, this, true);
+ cal.resetEvent.subscribe(cal.onReset, this, true);
+ cal.clearEvent.subscribe(cal.onClear, this, true);
+ },
+
+ /**
+ * The default event handler for clicks on the "Previous Month" navigation UI
+ *
+ * @method doPreviousMonthNav
+ * @param {DOMEvent} e The DOM event
+ * @param {Calendar} cal A reference to the calendar
+ */
+ doPreviousMonthNav : function(e, cal) {
+ Event.preventDefault(e);
+ // previousMonth invoked in a timeout, to allow
+ // event to bubble up, with correct target. Calling
+ // previousMonth, will call render which will remove
+ // HTML which generated the event, resulting in an
+ // invalid event target in certain browsers.
+ setTimeout(function() {
+ cal.previousMonth();
+ var navs = Dom.getElementsByClassName(cal.Style.CSS_NAV_LEFT, "a", cal.oDomContainer);
+ if (navs && navs[0]) {
+ try {
+ navs[0].focus();
+ } catch (e) {
+ // ignore
+ }
+ }
+ }, 0);
+ },
+
+ /**
+ * The default event handler for clicks on the "Next Month" navigation UI
+ *
+ * @method doNextMonthNav
+ * @param {DOMEvent} e The DOM event
+ * @param {Calendar} cal A reference to the calendar
+ */
+ doNextMonthNav : function(e, cal) {
+ Event.preventDefault(e);
+ setTimeout(function() {
+ cal.nextMonth();
+ var navs = Dom.getElementsByClassName(cal.Style.CSS_NAV_RIGHT, "a", cal.oDomContainer);
+ if (navs && navs[0]) {
+ try {
+ navs[0].focus();
+ } catch (e) {
+ // ignore
+ }
+ }
+ }, 0);
+ },
+
+ /**
+ * The default event handler for date cell selection. Currently attached to
+ * the Calendar's bounding box, referenced by it's oDomContainer property.
+ *
+ * @method doSelectCell
+ * @param {DOMEvent} e The DOM event
+ * @param {Calendar} cal A reference to the calendar
+ */
+ doSelectCell : function(e, cal) {
+ var cell, d, date, index;
+
+ var target = Event.getTarget(e),
+ tagName = target.tagName.toLowerCase(),
+ defSelector = false;
+
+ while (tagName != "td" && !Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) {
+
+ if (!defSelector && tagName == "a" && Dom.hasClass(target, cal.Style.CSS_CELL_SELECTOR)) {
+ defSelector = true;
+ }
+
+ target = target.parentNode;
+ tagName = target.tagName.toLowerCase();
+
+ if (target == this.oDomContainer || tagName == "html") {
+ return;
+ }
+ }
+
+ if (defSelector) {
+ // Stop link href navigation for default renderer
+ Event.preventDefault(e);
+ }
+
+ cell = target;
+
+ if (Dom.hasClass(cell, cal.Style.CSS_CELL_SELECTABLE)) {
+ index = cal.getIndexFromId(cell.id);
+ if (index > -1) {
+ d = cal.cellDates[index];
+ if (d) {
+ date = DateMath.getDate(d[0],d[1]-1,d[2]);
+
+ var link;
+
+ if (cal.Options.MULTI_SELECT) {
+ link = cell.getElementsByTagName("a")[0];
+ if (link) {
+ link.blur();
+ }
+
+ var cellDate = cal.cellDates[index];
+ var cellDateIndex = cal._indexOfSelectedFieldArray(cellDate);
+
+ if (cellDateIndex > -1) {
+ cal.deselectCell(index);
+ } else {
+ cal.selectCell(index);
+ }
+
+ } else {
+ link = cell.getElementsByTagName("a")[0];
+ if (link) {
+ link.blur();
+ }
+ cal.selectCell(index);
+ }
+ }
+ }
+ }
+ },
+
+ /**
+ * The event that is executed when the user hovers over a cell
+ * @method doCellMouseOver
+ * @param {DOMEvent} e The event
+ * @param {Calendar} cal A reference to the calendar passed by the Event utility
+ */
+ doCellMouseOver : function(e, cal) {
+ var target;
+ if (e) {
+ target = Event.getTarget(e);
+ } else {
+ target = this;
+ }
+
+ while (target.tagName && target.tagName.toLowerCase() != "td") {
+ target = target.parentNode;
+ if (!target.tagName || target.tagName.toLowerCase() == "html") {
+ return;
+ }
+ }
+
+ if (Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) {
+ Dom.addClass(target, cal.Style.CSS_CELL_HOVER);
+ }
+ },
+
+ /**
+ * The event that is executed when the user moves the mouse out of a cell
+ * @method doCellMouseOut
+ * @param {DOMEvent} e The event
+ * @param {Calendar} cal A reference to the calendar passed by the Event utility
+ */
+ doCellMouseOut : function(e, cal) {
+ var target;
+ if (e) {
+ target = Event.getTarget(e);
+ } else {
+ target = this;
+ }
+
+ while (target.tagName && target.tagName.toLowerCase() != "td") {
+ target = target.parentNode;
+ if (!target.tagName || target.tagName.toLowerCase() == "html") {
+ return;
+ }
+ }
+
+ if (Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) {
+ Dom.removeClass(target, cal.Style.CSS_CELL_HOVER);
+ }
+ },
+
+ setupConfig : function() {
+ var cfg = this.cfg;
+
+ /**
+ * The month/year representing the current visible Calendar date (mm/yyyy)
+ * @config pagedate
+ * @type String | Date
+ * @default today's date
+ */
+ cfg.addProperty(DEF_CFG.PAGEDATE.key, { value:new Date(), handler:this.configPageDate } );
+
+ /**
+ * The date or range of dates representing the current Calendar selection
+ * @config selected
+ * @type String
+ * @default []
+ */
+ cfg.addProperty(DEF_CFG.SELECTED.key, { value:[], handler:this.configSelected } );
+
+ /**
+ * The title to display above the Calendar's month header
+ * @config title
+ * @type String
+ * @default ""
+ */
+ cfg.addProperty(DEF_CFG.TITLE.key, { value:DEF_CFG.TITLE.value, handler:this.configTitle } );
+
+ /**
+ * Whether or not a close button should be displayed for this Calendar
+ * @config close
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.CLOSE.key, { value:DEF_CFG.CLOSE.value, handler:this.configClose } );
+
+ /**
+ * Whether or not an iframe shim should be placed under the Calendar to prevent select boxes from bleeding through in Internet Explorer 6 and below.
+ * This property is enabled by default for IE6 and below. It is disabled by default for other browsers for performance reasons, but can be
+ * enabled if required.
+ *
+ * @config iframe
+ * @type Boolean
+ * @default true for IE6 and below, false for all other browsers
+ */
+ cfg.addProperty(DEF_CFG.IFRAME.key, { value:DEF_CFG.IFRAME.value, handler:this.configIframe, validator:cfg.checkBoolean } );
+
+ /**
+ * The minimum selectable date in the current Calendar (mm/dd/yyyy)
+ * @config mindate
+ * @type String | Date
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.MINDATE.key, { value:DEF_CFG.MINDATE.value, handler:this.configMinDate } );
+
+ /**
+ * The maximum selectable date in the current Calendar (mm/dd/yyyy)
+ * @config maxdate
+ * @type String | Date
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.MAXDATE.key, { value:DEF_CFG.MAXDATE.value, handler:this.configMaxDate } );
+
+
+ // Options properties
+
+ /**
+ * True if the Calendar should allow multiple selections. False by default.
+ * @config MULTI_SELECT
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.MULTI_SELECT.key, { value:DEF_CFG.MULTI_SELECT.value, handler:this.configOptions, validator:cfg.checkBoolean } );
+
+ /**
+ * The weekday the week begins on. Default is 0 (Sunday = 0, Monday = 1 ... Saturday = 6).
+ * @config START_WEEKDAY
+ * @type number
+ * @default 0
+ */
+ cfg.addProperty(DEF_CFG.START_WEEKDAY.key, { value:DEF_CFG.START_WEEKDAY.value, handler:this.configOptions, validator:cfg.checkNumber } );
+
+ /**
+ * True if the Calendar should show weekday labels. True by default.
+ * @config SHOW_WEEKDAYS
+ * @type Boolean
+ * @default true
+ */
+ cfg.addProperty(DEF_CFG.SHOW_WEEKDAYS.key, { value:DEF_CFG.SHOW_WEEKDAYS.value, handler:this.configOptions, validator:cfg.checkBoolean } );
+
+ /**
+ * True if the Calendar should show week row headers. False by default.
+ * @config SHOW_WEEK_HEADER
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.SHOW_WEEK_HEADER.key, { value:DEF_CFG.SHOW_WEEK_HEADER.value, handler:this.configOptions, validator:cfg.checkBoolean } );
+
+ /**
+ * True if the Calendar should show week row footers. False by default.
+ * @config SHOW_WEEK_FOOTER
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.SHOW_WEEK_FOOTER.key,{ value:DEF_CFG.SHOW_WEEK_FOOTER.value, handler:this.configOptions, validator:cfg.checkBoolean } );
+
+ /**
+ * True if the Calendar should suppress weeks that are not a part of the current month. False by default.
+ * @config HIDE_BLANK_WEEKS
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.HIDE_BLANK_WEEKS.key, { value:DEF_CFG.HIDE_BLANK_WEEKS.value, handler:this.configOptions, validator:cfg.checkBoolean } );
+
+ /**
+ * The image that should be used for the left navigation arrow.
+ * @config NAV_ARROW_LEFT
+ * @type String
+ * @deprecated You can customize the image by overriding the default CSS class for the left arrow - "calnavleft"
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.NAV_ARROW_LEFT.key, { value:DEF_CFG.NAV_ARROW_LEFT.value, handler:this.configOptions } );
+
+ /**
+ * The image that should be used for the right navigation arrow.
+ * @config NAV_ARROW_RIGHT
+ * @type String
+ * @deprecated You can customize the image by overriding the default CSS class for the right arrow - "calnavright"
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.NAV_ARROW_RIGHT.key, { value:DEF_CFG.NAV_ARROW_RIGHT.value, handler:this.configOptions } );
+
+ // Locale properties
+
+ /**
+ * The short month labels for the current locale.
+ * @config MONTHS_SHORT
+ * @type String[]
+ * @default ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
+ */
+ cfg.addProperty(DEF_CFG.MONTHS_SHORT.key, { value:DEF_CFG.MONTHS_SHORT.value, handler:this.configLocale } );
+
+ /**
+ * The long month labels for the current locale.
+ * @config MONTHS_LONG
+ * @type String[]
+ * @default ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
+ */
+ cfg.addProperty(DEF_CFG.MONTHS_LONG.key, { value:DEF_CFG.MONTHS_LONG.value, handler:this.configLocale } );
+
+ /**
+ * The 1-character weekday labels for the current locale.
+ * @config WEEKDAYS_1CHAR
+ * @type String[]
+ * @default ["S", "M", "T", "W", "T", "F", "S"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_1CHAR.key, { value:DEF_CFG.WEEKDAYS_1CHAR.value, handler:this.configLocale } );
+
+ /**
+ * The short weekday labels for the current locale.
+ * @config WEEKDAYS_SHORT
+ * @type String[]
+ * @default ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_SHORT.key, { value:DEF_CFG.WEEKDAYS_SHORT.value, handler:this.configLocale } );
+
+ /**
+ * The medium weekday labels for the current locale.
+ * @config WEEKDAYS_MEDIUM
+ * @type String[]
+ * @default ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_MEDIUM.key, { value:DEF_CFG.WEEKDAYS_MEDIUM.value, handler:this.configLocale } );
+
+ /**
+ * The long weekday labels for the current locale.
+ * @config WEEKDAYS_LONG
+ * @type String[]
+ * @default ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_LONG.key, { value:DEF_CFG.WEEKDAYS_LONG.value, handler:this.configLocale } );
+
+ /**
+ * Refreshes the locale values used to build the Calendar.
+ * @method refreshLocale
+ * @private
+ */
+ var refreshLocale = function() {
+ cfg.refireEvent(DEF_CFG.LOCALE_MONTHS.key);
+ cfg.refireEvent(DEF_CFG.LOCALE_WEEKDAYS.key);
+ };
+
+ cfg.subscribeToConfigEvent(DEF_CFG.START_WEEKDAY.key, refreshLocale, this, true);
+ cfg.subscribeToConfigEvent(DEF_CFG.MONTHS_SHORT.key, refreshLocale, this, true);
+ cfg.subscribeToConfigEvent(DEF_CFG.MONTHS_LONG.key, refreshLocale, this, true);
+ cfg.subscribeToConfigEvent(DEF_CFG.WEEKDAYS_1CHAR.key, refreshLocale, this, true);
+ cfg.subscribeToConfigEvent(DEF_CFG.WEEKDAYS_SHORT.key, refreshLocale, this, true);
+ cfg.subscribeToConfigEvent(DEF_CFG.WEEKDAYS_MEDIUM.key, refreshLocale, this, true);
+ cfg.subscribeToConfigEvent(DEF_CFG.WEEKDAYS_LONG.key, refreshLocale, this, true);
+
+ /**
+ * The setting that determines which length of month labels should be used. Possible values are "short" and "long".
+ * @config LOCALE_MONTHS
+ * @type String
+ * @default "long"
+ */
+ cfg.addProperty(DEF_CFG.LOCALE_MONTHS.key, { value:DEF_CFG.LOCALE_MONTHS.value, handler:this.configLocaleValues } );
+
+ /**
+ * The setting that determines which length of weekday labels should be used. Possible values are "1char", "short", "medium", and "long".
+ * @config LOCALE_WEEKDAYS
+ * @type String
+ * @default "short"
+ */
+ cfg.addProperty(DEF_CFG.LOCALE_WEEKDAYS.key, { value:DEF_CFG.LOCALE_WEEKDAYS.value, handler:this.configLocaleValues } );
+
+ /**
+ * The value used to delimit individual dates in a date string passed to various Calendar functions.
+ * @config DATE_DELIMITER
+ * @type String
+ * @default ","
+ */
+ cfg.addProperty(DEF_CFG.DATE_DELIMITER.key, { value:DEF_CFG.DATE_DELIMITER.value, handler:this.configLocale } );
+
+ /**
+ * The value used to delimit date fields in a date string passed to various Calendar functions.
+ * @config DATE_FIELD_DELIMITER
+ * @type String
+ * @default "/"
+ */
+ cfg.addProperty(DEF_CFG.DATE_FIELD_DELIMITER.key, { value:DEF_CFG.DATE_FIELD_DELIMITER.value, handler:this.configLocale } );
+
+ /**
+ * The value used to delimit date ranges in a date string passed to various Calendar functions.
+ * @config DATE_RANGE_DELIMITER
+ * @type String
+ * @default "-"
+ */
+ cfg.addProperty(DEF_CFG.DATE_RANGE_DELIMITER.key, { value:DEF_CFG.DATE_RANGE_DELIMITER.value, handler:this.configLocale } );
+
+ /**
+ * The position of the month in a month/year date string
+ * @config MY_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MY_MONTH_POSITION.key, { value:DEF_CFG.MY_MONTH_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the year in a month/year date string
+ * @config MY_YEAR_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MY_YEAR_POSITION.key, { value:DEF_CFG.MY_YEAR_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the month in a month/day date string
+ * @config MD_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MD_MONTH_POSITION.key, { value:DEF_CFG.MD_MONTH_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the day in a month/year date string
+ * @config MD_DAY_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MD_DAY_POSITION.key, { value:DEF_CFG.MD_DAY_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the month in a month/day/year date string
+ * @config MDY_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MDY_MONTH_POSITION.key, { value:DEF_CFG.MDY_MONTH_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the day in a month/day/year date string
+ * @config MDY_DAY_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MDY_DAY_POSITION.key, { value:DEF_CFG.MDY_DAY_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the year in a month/day/year date string
+ * @config MDY_YEAR_POSITION
+ * @type Number
+ * @default 3
+ */
+ cfg.addProperty(DEF_CFG.MDY_YEAR_POSITION.key, { value:DEF_CFG.MDY_YEAR_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the month in the month year label string used as the Calendar header
+ * @config MY_LABEL_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_MONTH_POSITION.key, { value:DEF_CFG.MY_LABEL_MONTH_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the year in the month year label string used as the Calendar header
+ * @config MY_LABEL_YEAR_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_YEAR_POSITION.key, { value:DEF_CFG.MY_LABEL_YEAR_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } );
+
+ /**
+ * The suffix used after the month when rendering the Calendar header
+ * @config MY_LABEL_MONTH_SUFFIX
+ * @type String
+ * @default " "
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_MONTH_SUFFIX.key, { value:DEF_CFG.MY_LABEL_MONTH_SUFFIX.value, handler:this.configLocale } );
+
+ /**
+ * The suffix used after the year when rendering the Calendar header
+ * @config MY_LABEL_YEAR_SUFFIX
+ * @type String
+ * @default ""
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_YEAR_SUFFIX.key, { value:DEF_CFG.MY_LABEL_YEAR_SUFFIX.value, handler:this.configLocale } );
+
+ /**
+ * Configuration for the Month/Year CalendarNavigator UI which allows the user to jump directly to a
+ * specific Month/Year without having to scroll sequentially through months.
+ *
+ * Setting this property to null (default value) or false, will disable the CalendarNavigator UI.
+ *
+ *
+ * Setting this property to true will enable the CalendarNavigatior UI with the default CalendarNavigator configuration values.
+ *
+ *
+ * This property can also be set to an object literal containing configuration properties for the CalendarNavigator UI.
+ * The configuration object expects the the following case-sensitive properties, with the "strings" property being a nested object.
+ * Any properties which are not provided will use the default values (defined in the CalendarNavigator class).
+ *
+ *
+ *
strings
+ *
Object : An object with the properties shown below, defining the string labels to use in the Navigator's UI
+ *
+ *
month
String : The string to use for the month label. Defaults to "Month".
+ *
year
String : The string to use for the year label. Defaults to "Year".
+ *
submit
String : The string to use for the submit button label. Defaults to "Okay".
+ *
cancel
String : The string to use for the cancel button label. Defaults to "Cancel".
+ *
invalidYear
String : The string to use for invalid year values. Defaults to "Year needs to be a number".
+ *
+ *
+ *
monthFormat
String : The month format to use. Either YAHOO.widget.Calendar.LONG, or YAHOO.widget.Calendar.SHORT. Defaults to YAHOO.widget.Calendar.LONG
+ *
initialFocus
String : Either "year" or "month" specifying which input control should get initial focus. Defaults to "year"
';
+
+ return html;
+ },
+
+ /**
+ * Renders the calendar body.
+ * @method renderBody
+ * @param {Date} workingDate The current working Date being used for the render process
+ * @param {Array} html The current working HTML array
+ * @return {Array} The current working HTML array
+ */
+ renderBody : function(workingDate, html) {
+
+ var startDay = this.cfg.getProperty(DEF_CFG.START_WEEKDAY.key);
+
+ this.preMonthDays = workingDate.getDay();
+ if (startDay > 0) {
+ this.preMonthDays -= startDay;
+ }
+ if (this.preMonthDays < 0) {
+ this.preMonthDays += 7;
+ }
+
+ this.monthDays = DateMath.findMonthEnd(workingDate).getDate();
+ this.postMonthDays = Calendar.DISPLAY_DAYS-this.preMonthDays-this.monthDays;
+
+
+ workingDate = DateMath.subtract(workingDate, DateMath.DAY, this.preMonthDays);
+
+ var weekNum,
+ weekClass,
+ weekPrefix = "w",
+ cellPrefix = "_cell",
+ workingDayPrefix = "wd",
+ dayPrefix = "d",
+ cellRenderers,
+ renderer,
+ t = this.today,
+ cfg = this.cfg,
+ todayYear = t.getFullYear(),
+ todayMonth = t.getMonth(),
+ todayDate = t.getDate(),
+ useDate = cfg.getProperty(DEF_CFG.PAGEDATE.key),
+ hideBlankWeeks = cfg.getProperty(DEF_CFG.HIDE_BLANK_WEEKS.key),
+ showWeekFooter = cfg.getProperty(DEF_CFG.SHOW_WEEK_FOOTER.key),
+ showWeekHeader = cfg.getProperty(DEF_CFG.SHOW_WEEK_HEADER.key),
+ mindate = cfg.getProperty(DEF_CFG.MINDATE.key),
+ maxdate = cfg.getProperty(DEF_CFG.MAXDATE.key);
+
+ if (mindate) {
+ mindate = DateMath.clearTime(mindate);
+ }
+ if (maxdate) {
+ maxdate = DateMath.clearTime(maxdate);
+ }
+
+ html[html.length] = '';
+
+ var i = 0,
+ tempDiv = document.createElement("div"),
+ cell = document.createElement("td");
+
+ tempDiv.appendChild(cell);
+
+ var cal = this.parent || this;
+
+ for (var r=0;r<6;r++) {
+ weekNum = DateMath.getWeekNumber(workingDate, startDay);
+ weekClass = weekPrefix + weekNum;
+
+ // Local OOM check for performance, since we already have pagedate
+ if (r !== 0 && hideBlankWeeks === true && workingDate.getMonth() != useDate.getMonth()) {
+ break;
+ } else {
+ html[html.length] = '
';
+
+ if (showWeekHeader) { html = this.renderRowHeader(weekNum, html); }
+
+ for (var d=0; d < 7; d++){ // Render actual days
+
+ cellRenderers = [];
+
+ this.clearElement(cell);
+ cell.className = this.Style.CSS_CELL;
+ cell.id = this.id + cellPrefix + i;
+
+ if (workingDate.getDate() == todayDate &&
+ workingDate.getMonth() == todayMonth &&
+ workingDate.getFullYear() == todayYear) {
+ cellRenderers[cellRenderers.length]=cal.renderCellStyleToday;
+ }
+
+ var workingArray = [workingDate.getFullYear(),workingDate.getMonth()+1,workingDate.getDate()];
+ this.cellDates[this.cellDates.length] = workingArray; // Add this date to cellDates
+
+ // Local OOM check for performance, since we already have pagedate
+ if (workingDate.getMonth() != useDate.getMonth()) {
+ cellRenderers[cellRenderers.length]=cal.renderCellNotThisMonth;
+ } else {
+ Dom.addClass(cell, workingDayPrefix + workingDate.getDay());
+ Dom.addClass(cell, dayPrefix + workingDate.getDate());
+
+ for (var s=0;s= d1.getTime() && workingDate.getTime() <= d2.getTime()) {
+ renderer = rArray[2];
+
+ if (workingDate.getTime()==d2.getTime()) {
+ this.renderStack.splice(s,1);
+ }
+ }
+ break;
+ case Calendar.WEEKDAY:
+ var weekday = rArray[1][0];
+ if (workingDate.getDay()+1 == weekday) {
+ renderer = rArray[2];
+ }
+ break;
+ case Calendar.MONTH:
+ month = rArray[1][0];
+ if (workingDate.getMonth()+1 == month) {
+ renderer = rArray[2];
+ }
+ break;
+ }
+
+ if (renderer) {
+ cellRenderers[cellRenderers.length]=renderer;
+ }
+ }
+
+ }
+
+ if (this._indexOfSelectedFieldArray(workingArray) > -1) {
+ cellRenderers[cellRenderers.length]=cal.renderCellStyleSelected;
+ }
+
+ if ((mindate && (workingDate.getTime() < mindate.getTime())) ||
+ (maxdate && (workingDate.getTime() > maxdate.getTime()))
+ ) {
+ cellRenderers[cellRenderers.length]=cal.renderOutOfBoundsDate;
+ } else {
+ cellRenderers[cellRenderers.length]=cal.styleCellDefault;
+ cellRenderers[cellRenderers.length]=cal.renderCellDefault;
+ }
+
+ for (var x=0; x < cellRenderers.length; ++x) {
+ if (cellRenderers[x].call(cal, workingDate, cell) == Calendar.STOP_RENDER) {
+ break;
+ }
+ }
+
+ workingDate.setTime(workingDate.getTime() + DateMath.ONE_DAY_MS);
+ // Just in case we crossed DST/Summertime boundaries
+ workingDate = DateMath.clearTime(workingDate);
+
+ if (i >= 0 && i <= 6) {
+ Dom.addClass(cell, this.Style.CSS_CELL_TOP);
+ }
+ if ((i % 7) === 0) {
+ Dom.addClass(cell, this.Style.CSS_CELL_LEFT);
+ }
+ if (((i+1) % 7) === 0) {
+ Dom.addClass(cell, this.Style.CSS_CELL_RIGHT);
+ }
+
+ var postDays = this.postMonthDays;
+ if (hideBlankWeeks && postDays >= 7) {
+ var blankWeeks = Math.floor(postDays/7);
+ for (var p=0;p= ((this.preMonthDays+postDays+this.monthDays)-7)) {
+ Dom.addClass(cell, this.Style.CSS_CELL_BOTTOM);
+ }
+
+ html[html.length] = tempDiv.innerHTML;
+ i++;
+ }
+
+ if (showWeekFooter) { html = this.renderRowFooter(weekNum, html); }
+
+ html[html.length] = '
';
+ }
+ }
+
+ html[html.length] = '';
+
+ return html;
+ },
+
+ /**
+ * Renders the calendar footer. In the default implementation, there is
+ * no footer.
+ * @method renderFooter
+ * @param {Array} html The current working HTML array
+ * @return {Array} The current working HTML array
+ */
+ renderFooter : function(html) { return html; },
+
+ /**
+ * Renders the calendar after it has been configured. The render() method has a specific call chain that will execute
+ * when the method is called: renderHeader, renderBody, renderFooter.
+ * Refer to the documentation for those methods for information on
+ * individual render tasks.
+ * @method render
+ */
+ render : function() {
+ this.beforeRenderEvent.fire();
+
+ // Find starting day of the current month
+ var workingDate = DateMath.findMonthStart(this.cfg.getProperty(DEF_CFG.PAGEDATE.key));
+
+ this.resetRenderers();
+ this.cellDates.length = 0;
+
+ Event.purgeElement(this.oDomContainer, true);
+
+ var html = [];
+
+ html[html.length] = '
';
+ html = this.renderHeader(html);
+ html = this.renderBody(workingDate, html);
+ html = this.renderFooter(html);
+ html[html.length] = '
';
+
+ this.oDomContainer.innerHTML = html.join("\n");
+
+ this.applyListeners();
+ this.cells = this.oDomContainer.getElementsByTagName("td");
+
+ this.cfg.refireEvent(DEF_CFG.TITLE.key);
+ this.cfg.refireEvent(DEF_CFG.CLOSE.key);
+ this.cfg.refireEvent(DEF_CFG.IFRAME.key);
+
+ this.renderEvent.fire();
+ },
+
+ /**
+ * Applies the Calendar's DOM listeners to applicable elements.
+ * @method applyListeners
+ */
+ applyListeners : function() {
+ var root = this.oDomContainer,
+ cal = this.parent || this,
+ anchor = "a",
+ click = "click";
+
+ var linkLeft = Dom.getElementsByClassName(this.Style.CSS_NAV_LEFT, anchor, root),
+ linkRight = Dom.getElementsByClassName(this.Style.CSS_NAV_RIGHT, anchor, root);
+
+ if (linkLeft && linkLeft.length > 0) {
+ this.linkLeft = linkLeft[0];
+ Event.addListener(this.linkLeft, click, this.doPreviousMonthNav, cal, true);
+ }
+
+ if (linkRight && linkRight.length > 0) {
+ this.linkRight = linkRight[0];
+ Event.addListener(this.linkRight, click, this.doNextMonthNav, cal, true);
+ }
+
+ if (cal.cfg.getProperty("navigator") !== null) {
+ this.applyNavListeners();
+ }
+
+ if (this.domEventMap) {
+ var el,elements;
+ for (var cls in this.domEventMap) {
+ if (Lang.hasOwnProperty(this.domEventMap, cls)) {
+ var items = this.domEventMap[cls];
+
+ if (! (items instanceof Array)) {
+ items = [items];
+ }
+
+ for (var i=0;i 0) {
+
+ Event.addListener(navBtns, "click", function (e, obj) {
+ var target = Event.getTarget(e);
+ // this == navBtn
+ if (this === target || Dom.isAncestor(this, target)) {
+ Event.preventDefault(e);
+ }
+ var navigator = calParent.oNavigator;
+ if (navigator) {
+ var pgdate = cal.cfg.getProperty("pagedate");
+ navigator.setYear(pgdate.getFullYear());
+ navigator.setMonth(pgdate.getMonth());
+ navigator.show();
+ }
+ });
+ }
+ },
+
+ /**
+ * Retrieves the Date object for the specified Calendar cell
+ * @method getDateByCellId
+ * @param {String} id The id of the cell
+ * @return {Date} The Date object for the specified Calendar cell
+ */
+ getDateByCellId : function(id) {
+ var date = this.getDateFieldsByCellId(id);
+ return (date) ? DateMath.getDate(date[0],date[1]-1,date[2]) : null;
+ },
+
+ /**
+ * Retrieves the Date object for the specified Calendar cell
+ * @method getDateFieldsByCellId
+ * @param {String} id The id of the cell
+ * @return {Array} The array of Date fields for the specified Calendar cell
+ */
+ getDateFieldsByCellId : function(id) {
+ id = this.getIndexFromId(id);
+ return (id > -1) ? this.cellDates[id] : null;
+ },
+
+ /**
+ * Find the Calendar's cell index for a given date.
+ * If the date is not found, the method returns -1.
+ *
+ * The returned index can be used to lookup the cell HTMLElement
+ * using the Calendar's cells array or passed to selectCell to select
+ * cells by index.
+ *
+ *
+ * See cells, selectCell.
+ *
+ * @method getCellIndex
+ * @param {Date} date JavaScript Date object, for which to find a cell index.
+ * @return {Number} The index of the date in Calendars cellDates/cells arrays, or -1 if the date
+ * is not on the curently rendered Calendar page.
+ */
+ getCellIndex : function(date) {
+ var idx = -1;
+ if (date) {
+ var m = date.getMonth(),
+ y = date.getFullYear(),
+ d = date.getDate(),
+ dates = this.cellDates;
+
+ for (var i = 0; i < dates.length; ++i) {
+ var cellDate = dates[i];
+ if (cellDate[0] === y && cellDate[1] === m+1 && cellDate[2] === d) {
+ idx = i;
+ break;
+ }
+ }
+ }
+ return idx;
+ },
+
+ /**
+ * Given the id used to mark each Calendar cell, this method
+ * extracts the index number from the id.
+ *
+ * @param {String} strId The cell id
+ * @return {Number} The index of the cell, or -1 if id does not contain an index number
+ */
+ getIndexFromId : function(strId) {
+ var idx = -1,
+ li = strId.lastIndexOf("_cell");
+
+ if (li > -1) {
+ idx = parseInt(strId.substring(li + 5), 10);
+ }
+
+ return idx;
+ },
+
+ // BEGIN BUILT-IN TABLE CELL RENDERERS
+
+ /**
+ * Renders a cell that falls before the minimum date or after the maximum date.
+ * widget class.
+ * @method renderOutOfBoundsDate
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ * @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering
+ * should not be terminated
+ */
+ renderOutOfBoundsDate : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_OOB);
+ cell.innerHTML = workingDate.getDate();
+ return Calendar.STOP_RENDER;
+ },
+
+ /**
+ * Renders the row header for a week.
+ * @method renderRowHeader
+ * @param {Number} weekNum The week number of the current row
+ * @param {Array} cell The current working HTML array
+ */
+ renderRowHeader : function(weekNum, html) {
+ html[html.length] = '
' + weekNum + '
';
+ return html;
+ },
+
+ /**
+ * Renders the row footer for a week.
+ * @method renderRowFooter
+ * @param {Number} weekNum The week number of the current row
+ * @param {Array} cell The current working HTML array
+ */
+ renderRowFooter : function(weekNum, html) {
+ html[html.length] = '
' + weekNum + '
';
+ return html;
+ },
+
+ /**
+ * Renders a single standard calendar cell in the calendar widget table.
+ * All logic for determining how a standard default cell will be rendered is
+ * encapsulated in this method, and must be accounted for when extending the
+ * widget class.
+ * @method renderCellDefault
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ renderCellDefault : function(workingDate, cell) {
+ cell.innerHTML = '' + this.buildDayLabel(workingDate) + "";
+ },
+
+ /**
+ * Styles a selectable cell.
+ * @method styleCellDefault
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ styleCellDefault : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_SELECTABLE);
+ },
+
+
+ /**
+ * Renders a single standard calendar cell using the CSS hightlight1 style
+ * @method renderCellStyleHighlight1
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ renderCellStyleHighlight1 : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT1);
+ },
+
+ /**
+ * Renders a single standard calendar cell using the CSS hightlight2 style
+ * @method renderCellStyleHighlight2
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ renderCellStyleHighlight2 : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT2);
+ },
+
+ /**
+ * Renders a single standard calendar cell using the CSS hightlight3 style
+ * @method renderCellStyleHighlight3
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ renderCellStyleHighlight3 : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT3);
+ },
+
+ /**
+ * Renders a single standard calendar cell using the CSS hightlight4 style
+ * @method renderCellStyleHighlight4
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ renderCellStyleHighlight4 : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT4);
+ },
+
+ /**
+ * Applies the default style used for rendering today's date to the current calendar cell
+ * @method renderCellStyleToday
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ */
+ renderCellStyleToday : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_TODAY);
+ },
+
+ /**
+ * Applies the default style used for rendering selected dates to the current calendar cell
+ * @method renderCellStyleSelected
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ * @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering
+ * should not be terminated
+ */
+ renderCellStyleSelected : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_SELECTED);
+ },
+
+ /**
+ * Applies the default style used for rendering dates that are not a part of the current
+ * month (preceding or trailing the cells for the current month)
+ * @method renderCellNotThisMonth
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ * @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering
+ * should not be terminated
+ */
+ renderCellNotThisMonth : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL_OOM);
+ cell.innerHTML=workingDate.getDate();
+ return Calendar.STOP_RENDER;
+ },
+
+ /**
+ * Renders the current calendar cell as a non-selectable "black-out" date using the default
+ * restricted style.
+ * @method renderBodyCellRestricted
+ * @param {Date} workingDate The current working Date object being used to generate the calendar
+ * @param {HTMLTableCellElement} cell The current working cell in the calendar
+ * @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering
+ * should not be terminated
+ */
+ renderBodyCellRestricted : function(workingDate, cell) {
+ Dom.addClass(cell, this.Style.CSS_CELL);
+ Dom.addClass(cell, this.Style.CSS_CELL_RESTRICTED);
+ cell.innerHTML=workingDate.getDate();
+ return Calendar.STOP_RENDER;
+ },
+
+ // END BUILT-IN TABLE CELL RENDERERS
+
+ // BEGIN MONTH NAVIGATION METHODS
+
+ /**
+ * Adds the designated number of months to the current calendar month, and sets the current
+ * calendar page date to the new month.
+ * @method addMonths
+ * @param {Number} count The number of months to add to the current calendar
+ */
+ addMonths : function(count) {
+ var cfgPageDate = DEF_CFG.PAGEDATE.key;
+ this.cfg.setProperty(cfgPageDate, DateMath.add(this.cfg.getProperty(cfgPageDate), DateMath.MONTH, count));
+ this.resetRenderers();
+ this.changePageEvent.fire();
+ },
+
+ /**
+ * Subtracts the designated number of months from the current calendar month, and sets the current
+ * calendar page date to the new month.
+ * @method subtractMonths
+ * @param {Number} count The number of months to subtract from the current calendar
+ */
+ subtractMonths : function(count) {
+ var cfgPageDate = DEF_CFG.PAGEDATE.key;
+ this.cfg.setProperty(cfgPageDate, DateMath.subtract(this.cfg.getProperty(cfgPageDate), DateMath.MONTH, count));
+ this.resetRenderers();
+ this.changePageEvent.fire();
+ },
+
+ /**
+ * Adds the designated number of years to the current calendar, and sets the current
+ * calendar page date to the new month.
+ * @method addYears
+ * @param {Number} count The number of years to add to the current calendar
+ */
+ addYears : function(count) {
+ var cfgPageDate = DEF_CFG.PAGEDATE.key;
+ this.cfg.setProperty(cfgPageDate, DateMath.add(this.cfg.getProperty(cfgPageDate), DateMath.YEAR, count));
+ this.resetRenderers();
+ this.changePageEvent.fire();
+ },
+
+ /**
+ * Subtcats the designated number of years from the current calendar, and sets the current
+ * calendar page date to the new month.
+ * @method subtractYears
+ * @param {Number} count The number of years to subtract from the current calendar
+ */
+ subtractYears : function(count) {
+ var cfgPageDate = DEF_CFG.PAGEDATE.key;
+ this.cfg.setProperty(cfgPageDate, DateMath.subtract(this.cfg.getProperty(cfgPageDate), DateMath.YEAR, count));
+ this.resetRenderers();
+ this.changePageEvent.fire();
+ },
+
+ /**
+ * Navigates to the next month page in the calendar widget.
+ * @method nextMonth
+ */
+ nextMonth : function() {
+ this.addMonths(1);
+ },
+
+ /**
+ * Navigates to the previous month page in the calendar widget.
+ * @method previousMonth
+ */
+ previousMonth : function() {
+ this.subtractMonths(1);
+ },
+
+ /**
+ * Navigates to the next year in the currently selected month in the calendar widget.
+ * @method nextYear
+ */
+ nextYear : function() {
+ this.addYears(1);
+ },
+
+ /**
+ * Navigates to the previous year in the currently selected month in the calendar widget.
+ * @method previousYear
+ */
+ previousYear : function() {
+ this.subtractYears(1);
+ },
+
+ // END MONTH NAVIGATION METHODS
+
+ // BEGIN SELECTION METHODS
+
+ /**
+ * Resets the calendar widget to the originally selected month and year, and
+ * sets the calendar to the initial selection(s).
+ * @method reset
+ */
+ reset : function() {
+ this.cfg.resetProperty(DEF_CFG.SELECTED.key);
+ this.cfg.resetProperty(DEF_CFG.PAGEDATE.key);
+ this.resetEvent.fire();
+ },
+
+ /**
+ * Clears the selected dates in the current calendar widget and sets the calendar
+ * to the current month and year.
+ * @method clear
+ */
+ clear : function() {
+ this.cfg.setProperty(DEF_CFG.SELECTED.key, []);
+ this.cfg.setProperty(DEF_CFG.PAGEDATE.key, new Date(this.today.getTime()));
+ this.clearEvent.fire();
+ },
+
+ /**
+ * Selects a date or a collection of dates on the current calendar. This method, by default,
+ * does not call the render method explicitly. Once selection has completed, render must be
+ * called for the changes to be reflected visually.
+ *
+ * Any dates which are OOB (out of bounds, not selectable) will not be selected and the array of
+ * selected dates passed to the selectEvent will not contain OOB dates.
+ *
+ * If all dates are OOB, the no state change will occur; beforeSelect and select events will not be fired.
+ *
+ * @method select
+ * @param {String/Date/Date[]} date The date string of dates to select in the current calendar. Valid formats are
+ * individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006).
+ * Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005).
+ * This method can also take a JavaScript Date object or an array of Date objects.
+ * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected.
+ */
+ select : function(date) {
+
+ var aToBeSelected = this._toFieldArray(date),
+ validDates = [],
+ selected = [],
+ cfgSelected = DEF_CFG.SELECTED.key;
+
+
+ for (var a=0; a < aToBeSelected.length; ++a) {
+ var toSelect = aToBeSelected[a];
+
+ if (!this.isDateOOB(this._toDate(toSelect))) {
+
+ if (validDates.length === 0) {
+ this.beforeSelectEvent.fire();
+ selected = this.cfg.getProperty(cfgSelected);
+ }
+ validDates.push(toSelect);
+
+ if (this._indexOfSelectedFieldArray(toSelect) == -1) {
+ selected[selected.length] = toSelect;
+ }
+ }
+ }
+
+
+ if (validDates.length > 0) {
+ if (this.parent) {
+ this.parent.cfg.setProperty(cfgSelected, selected);
+ } else {
+ this.cfg.setProperty(cfgSelected, selected);
+ }
+ this.selectEvent.fire(validDates);
+ }
+
+ return this.getSelectedDates();
+ },
+
+ /**
+ * Selects a date on the current calendar by referencing the index of the cell that should be selected.
+ * This method is used to easily select a single cell (usually with a mouse click) without having to do
+ * a full render. The selected style is applied to the cell directly.
+ *
+ * If the cell is not marked with the CSS_CELL_SELECTABLE class (as is the case by default for out of month
+ * or out of bounds cells), it will not be selected and in such a case beforeSelect and select events will not be fired.
+ *
+ * @method selectCell
+ * @param {Number} cellIndex The index of the cell to select in the current calendar.
+ * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected.
+ */
+ selectCell : function(cellIndex) {
+
+ var cell = this.cells[cellIndex],
+ cellDate = this.cellDates[cellIndex],
+ dCellDate = this._toDate(cellDate),
+ selectable = Dom.hasClass(cell, this.Style.CSS_CELL_SELECTABLE);
+
+
+ if (selectable) {
+
+ this.beforeSelectEvent.fire();
+
+ var cfgSelected = DEF_CFG.SELECTED.key;
+ var selected = this.cfg.getProperty(cfgSelected);
+
+ var selectDate = cellDate.concat();
+
+ if (this._indexOfSelectedFieldArray(selectDate) == -1) {
+ selected[selected.length] = selectDate;
+ }
+ if (this.parent) {
+ this.parent.cfg.setProperty(cfgSelected, selected);
+ } else {
+ this.cfg.setProperty(cfgSelected, selected);
+ }
+ this.renderCellStyleSelected(dCellDate,cell);
+ this.selectEvent.fire([selectDate]);
+
+ this.doCellMouseOut.call(cell, null, this);
+ }
+
+ return this.getSelectedDates();
+ },
+
+ /**
+ * Deselects a date or a collection of dates on the current calendar. This method, by default,
+ * does not call the render method explicitly. Once deselection has completed, render must be
+ * called for the changes to be reflected visually.
+ *
+ * The method will not attempt to deselect any dates which are OOB (out of bounds, and hence not selectable)
+ * and the array of deselected dates passed to the deselectEvent will not contain any OOB dates.
+ *
+ * If all dates are OOB, beforeDeselect and deselect events will not be fired.
+ *
+ * @method deselect
+ * @param {String/Date/Date[]} date The date string of dates to deselect in the current calendar. Valid formats are
+ * individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006).
+ * Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005).
+ * This method can also take a JavaScript Date object or an array of Date objects.
+ * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected.
+ */
+ deselect : function(date) {
+
+ var aToBeDeselected = this._toFieldArray(date),
+ validDates = [],
+ selected = [],
+ cfgSelected = DEF_CFG.SELECTED.key;
+
+
+ for (var a=0; a < aToBeDeselected.length; ++a) {
+ var toDeselect = aToBeDeselected[a];
+
+ if (!this.isDateOOB(this._toDate(toDeselect))) {
+
+ if (validDates.length === 0) {
+ this.beforeDeselectEvent.fire();
+ selected = this.cfg.getProperty(cfgSelected);
+ }
+
+ validDates.push(toDeselect);
+
+ var index = this._indexOfSelectedFieldArray(toDeselect);
+ if (index != -1) {
+ selected.splice(index,1);
+ }
+ }
+ }
+
+
+ if (validDates.length > 0) {
+ if (this.parent) {
+ this.parent.cfg.setProperty(cfgSelected, selected);
+ } else {
+ this.cfg.setProperty(cfgSelected, selected);
+ }
+ this.deselectEvent.fire(validDates);
+ }
+
+ return this.getSelectedDates();
+ },
+
+ /**
+ * Deselects a date on the current calendar by referencing the index of the cell that should be deselected.
+ * This method is used to easily deselect a single cell (usually with a mouse click) without having to do
+ * a full render. The selected style is removed from the cell directly.
+ *
+ * If the cell is not marked with the CSS_CELL_SELECTABLE class (as is the case by default for out of month
+ * or out of bounds cells), the method will not attempt to deselect it and in such a case, beforeDeselect and
+ * deselect events will not be fired.
+ *
+ * @method deselectCell
+ * @param {Number} cellIndex The index of the cell to deselect in the current calendar.
+ * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected.
+ */
+ deselectCell : function(cellIndex) {
+ var cell = this.cells[cellIndex],
+ cellDate = this.cellDates[cellIndex],
+ cellDateIndex = this._indexOfSelectedFieldArray(cellDate);
+
+ var selectable = Dom.hasClass(cell, this.Style.CSS_CELL_SELECTABLE);
+
+ if (selectable) {
+
+ this.beforeDeselectEvent.fire();
+
+ var selected = this.cfg.getProperty(DEF_CFG.SELECTED.key),
+ dCellDate = this._toDate(cellDate),
+ selectDate = cellDate.concat();
+
+ if (cellDateIndex > -1) {
+ if (this.cfg.getProperty(DEF_CFG.PAGEDATE.key).getMonth() == dCellDate.getMonth() &&
+ this.cfg.getProperty(DEF_CFG.PAGEDATE.key).getFullYear() == dCellDate.getFullYear()) {
+ Dom.removeClass(cell, this.Style.CSS_CELL_SELECTED);
+ }
+ selected.splice(cellDateIndex, 1);
+ }
+
+ if (this.parent) {
+ this.parent.cfg.setProperty(DEF_CFG.SELECTED.key, selected);
+ } else {
+ this.cfg.setProperty(DEF_CFG.SELECTED.key, selected);
+ }
+
+ this.deselectEvent.fire(selectDate);
+ }
+
+ return this.getSelectedDates();
+ },
+
+ /**
+ * Deselects all dates on the current calendar.
+ * @method deselectAll
+ * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected.
+ * Assuming that this function executes properly, the return value should be an empty array.
+ * However, the empty array is returned for the sake of being able to check the selection status
+ * of the calendar.
+ */
+ deselectAll : function() {
+ this.beforeDeselectEvent.fire();
+
+ var cfgSelected = DEF_CFG.SELECTED.key,
+ selected = this.cfg.getProperty(cfgSelected),
+ count = selected.length,
+ sel = selected.concat();
+
+ if (this.parent) {
+ this.parent.cfg.setProperty(cfgSelected, []);
+ } else {
+ this.cfg.setProperty(cfgSelected, []);
+ }
+
+ if (count > 0) {
+ this.deselectEvent.fire(sel);
+ }
+
+ return this.getSelectedDates();
+ },
+
+ // END SELECTION METHODS
+
+ // BEGIN TYPE CONVERSION METHODS
+
+ /**
+ * Converts a date (either a JavaScript Date object, or a date string) to the internal data structure
+ * used to represent dates: [[yyyy,mm,dd],[yyyy,mm,dd]].
+ * @method _toFieldArray
+ * @private
+ * @param {String/Date/Date[]} date The date string of dates to deselect in the current calendar. Valid formats are
+ * individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006).
+ * Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005).
+ * This method can also take a JavaScript Date object or an array of Date objects.
+ * @return {Array[](Number[])} Array of date field arrays
+ */
+ _toFieldArray : function(date) {
+ var returnDate = [];
+
+ if (date instanceof Date) {
+ returnDate = [[date.getFullYear(), date.getMonth()+1, date.getDate()]];
+ } else if (Lang.isString(date)) {
+ returnDate = this._parseDates(date);
+ } else if (Lang.isArray(date)) {
+ for (var i=0;i maxDate.getTime()));
+ },
+
+ /**
+ * Parses a pagedate configuration property value. The value can either be specified as a string of form "mm/yyyy" or a Date object
+ * and is parsed into a Date object normalized to the first day of the month. If no value is passed in, the month and year from today's date are used to create the Date object
+ * @method _parsePageDate
+ * @private
+ * @param {Date|String} date Pagedate value which needs to be parsed
+ * @return {Date} The Date object representing the pagedate
+ */
+ _parsePageDate : function(date) {
+ var parsedDate;
+
+ if (date) {
+ if (date instanceof Date) {
+ parsedDate = DateMath.findMonthStart(date);
+ } else {
+ var month, year, aMonthYear;
+ aMonthYear = date.split(this.cfg.getProperty(DEF_CFG.DATE_FIELD_DELIMITER.key));
+ month = parseInt(aMonthYear[this.cfg.getProperty(DEF_CFG.MY_MONTH_POSITION.key)-1], 10)-1;
+ year = parseInt(aMonthYear[this.cfg.getProperty(DEF_CFG.MY_YEAR_POSITION.key)-1], 10);
+
+ parsedDate = DateMath.getDate(year, month, 1);
+ }
+ } else {
+ parsedDate = DateMath.getDate(this.today.getFullYear(), this.today.getMonth(), 1);
+ }
+ return parsedDate;
+ },
+
+ // END UTILITY METHODS
+
+ // BEGIN EVENT HANDLERS
+
+ /**
+ * Event executed before a date is selected in the calendar widget.
+ * @deprecated Event handlers for this event should be susbcribed to beforeSelectEvent.
+ */
+ onBeforeSelect : function() {
+ if (this.cfg.getProperty(DEF_CFG.MULTI_SELECT.key) === false) {
+ if (this.parent) {
+ this.parent.callChildFunction("clearAllBodyCellStyles", this.Style.CSS_CELL_SELECTED);
+ this.parent.deselectAll();
+ } else {
+ this.clearAllBodyCellStyles(this.Style.CSS_CELL_SELECTED);
+ this.deselectAll();
+ }
+ }
+ },
+
+ /**
+ * Event executed when a date is selected in the calendar widget.
+ * @param {Array} selected An array of date field arrays representing which date or dates were selected. Example: [ [2006,8,6],[2006,8,7],[2006,8,8] ]
+ * @deprecated Event handlers for this event should be susbcribed to selectEvent.
+ */
+ onSelect : function(selected) { },
+
+ /**
+ * Event executed before a date is deselected in the calendar widget.
+ * @deprecated Event handlers for this event should be susbcribed to beforeDeselectEvent.
+ */
+ onBeforeDeselect : function() { },
+
+ /**
+ * Event executed when a date is deselected in the calendar widget.
+ * @param {Array} selected An array of date field arrays representing which date or dates were deselected. Example: [ [2006,8,6],[2006,8,7],[2006,8,8] ]
+ * @deprecated Event handlers for this event should be susbcribed to deselectEvent.
+ */
+ onDeselect : function(deselected) { },
+
+ /**
+ * Event executed when the user navigates to a different calendar page.
+ * @deprecated Event handlers for this event should be susbcribed to changePageEvent.
+ */
+ onChangePage : function() {
+ this.render();
+ },
+
+ /**
+ * Event executed when the calendar widget is rendered.
+ * @deprecated Event handlers for this event should be susbcribed to renderEvent.
+ */
+ onRender : function() { },
+
+ /**
+ * Event executed when the calendar widget is reset to its original state.
+ * @deprecated Event handlers for this event should be susbcribed to resetEvemt.
+ */
+ onReset : function() { this.render(); },
+
+ /**
+ * Event executed when the calendar widget is completely cleared to the current month with no selections.
+ * @deprecated Event handlers for this event should be susbcribed to clearEvent.
+ */
+ onClear : function() { this.render(); },
+
+ /**
+ * Validates the calendar widget. This method has no default implementation
+ * and must be extended by subclassing the widget.
+ * @return Should return true if the widget validates, and false if
+ * it doesn't.
+ * @type Boolean
+ */
+ validate : function() { return true; },
+
+ // END EVENT HANDLERS
+
+ // BEGIN DATE PARSE METHODS
+
+ /**
+ * Converts a date string to a date field array
+ * @private
+ * @param {String} sDate Date string. Valid formats are mm/dd and mm/dd/yyyy.
+ * @return A date field array representing the string passed to the method
+ * @type Array[](Number[])
+ */
+ _parseDate : function(sDate) {
+ var aDate = sDate.split(this.Locale.DATE_FIELD_DELIMITER),
+ rArray;
+
+ if (aDate.length == 2) {
+ rArray = [aDate[this.Locale.MD_MONTH_POSITION-1],aDate[this.Locale.MD_DAY_POSITION-1]];
+ rArray.type = Calendar.MONTH_DAY;
+ } else {
+ rArray = [aDate[this.Locale.MDY_YEAR_POSITION-1],aDate[this.Locale.MDY_MONTH_POSITION-1],aDate[this.Locale.MDY_DAY_POSITION-1]];
+ rArray.type = Calendar.DATE;
+ }
+
+ for (var i=0;i
+*
+*
+*
+* The tables for the calendars ("cal1_0" and "cal1_1") will be inserted into those containers.
+*
+*
+* NOTE: As of 2.4.0, the constructor's ID argument is optional.
+* The CalendarGroup can be constructed by simply providing a container ID string,
+* or a reference to a container DIV HTMLElement (the element needs to exist
+* in the document).
+*
+* E.g.:
+*
+* var c = new YAHOO.widget.CalendarGroup("calContainer", configOptions);
+*
+* or:
+*
+* var containerDiv = YAHOO.util.Dom.get("calContainer");
+* var c = new YAHOO.widget.CalendarGroup(containerDiv, configOptions);
+*
+*
+*
+* If not provided, the ID will be generated from the container DIV ID by adding an "_t" suffix.
+* For example if an ID is not provided, and the container's ID is "calContainer", the CalendarGroup's ID will be set to "calContainer_t".
+*
+*
+* @namespace YAHOO.widget
+* @class CalendarGroup
+* @constructor
+* @param {String} id optional The id of the table element that will represent the CalendarGroup widget. As of 2.4.0, this argument is optional.
+* @param {String | HTMLElement} container The id of the container div element that will wrap the CalendarGroup table, or a reference to a DIV element which exists in the document.
+* @param {Object} config optional The configuration object containing the initial configuration values for the CalendarGroup.
+*/
+function CalendarGroup(id, containerId, config) {
+ if (arguments.length > 0) {
+ this.init.apply(this, arguments);
+ }
+}
+
+/**
+* The set of default Config property keys and values for the CalendarGroup
+* @property YAHOO.widget.CalendarGroup._DEFAULT_CONFIG
+* @final
+* @static
+* @private
+* @type Object
+*/
+CalendarGroup._DEFAULT_CONFIG = Calendar._DEFAULT_CONFIG;
+CalendarGroup._DEFAULT_CONFIG.PAGES = {key:"pages", value:2};
+
+var DEF_CFG = CalendarGroup._DEFAULT_CONFIG;
+
+CalendarGroup.prototype = {
+
+ /**
+ * Initializes the calendar group. All subclasses must call this method in order for the
+ * group to be initialized properly.
+ * @method init
+ * @param {String} id optional The id of the table element that will represent the CalendarGroup widget. As of 2.4.0, this argument is optional.
+ * @param {String | HTMLElement} container The id of the container div element that will wrap the CalendarGroup table, or a reference to a DIV element which exists in the document.
+ * @param {Object} config optional The configuration object containing the initial configuration values for the CalendarGroup.
+ */
+ init : function(id, container, config) {
+
+ // Normalize 2.4.0, pre 2.4.0 args
+ var nArgs = this._parseArgs(arguments);
+
+ id = nArgs.id;
+ container = nArgs.container;
+ config = nArgs.config;
+
+ this.oDomContainer = Dom.get(container);
+
+ if (!this.oDomContainer.id) {
+ this.oDomContainer.id = Dom.generateId();
+ }
+ if (!id) {
+ id = this.oDomContainer.id + "_t";
+ }
+
+ /**
+ * The unique id associated with the CalendarGroup
+ * @property id
+ * @type String
+ */
+ this.id = id;
+
+ /**
+ * The unique id associated with the CalendarGroup container
+ * @property containerId
+ * @type String
+ */
+ this.containerId = this.oDomContainer.id;
+
+ this.initEvents();
+ this.initStyles();
+
+ /**
+ * The collection of Calendar pages contained within the CalendarGroup
+ * @property pages
+ * @type YAHOO.widget.Calendar[]
+ */
+ this.pages = [];
+
+ Dom.addClass(this.oDomContainer, CalendarGroup.CSS_CONTAINER);
+ Dom.addClass(this.oDomContainer, CalendarGroup.CSS_MULTI_UP);
+
+ /**
+ * The Config object used to hold the configuration variables for the CalendarGroup
+ * @property cfg
+ * @type YAHOO.util.Config
+ */
+ this.cfg = new YAHOO.util.Config(this);
+
+ /**
+ * The local object which contains the CalendarGroup's options
+ * @property Options
+ * @type Object
+ */
+ this.Options = {};
+
+ /**
+ * The local object which contains the CalendarGroup's locale settings
+ * @property Locale
+ * @type Object
+ */
+ this.Locale = {};
+
+ this.setupConfig();
+
+ if (config) {
+ this.cfg.applyConfig(config, true);
+ }
+
+ this.cfg.fireQueue();
+
+ // OPERA HACK FOR MISWRAPPED FLOATS
+ if (YAHOO.env.ua.opera){
+ this.renderEvent.subscribe(this._fixWidth, this, true);
+ this.showEvent.subscribe(this._fixWidth, this, true);
+ }
+
+ },
+
+ setupConfig : function() {
+
+ var cfg = this.cfg;
+
+ /**
+ * The number of pages to include in the CalendarGroup. This value can only be set once, in the CalendarGroup's constructor arguments.
+ * @config pages
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.PAGES.key, { value:DEF_CFG.PAGES.value, validator:cfg.checkNumber, handler:this.configPages } );
+
+ /**
+ * The month/year representing the current visible Calendar date (mm/yyyy)
+ * @config pagedate
+ * @type String | Date
+ * @default today's date
+ */
+ cfg.addProperty(DEF_CFG.PAGEDATE.key, { value:new Date(), handler:this.configPageDate } );
+
+ /**
+ * The date or range of dates representing the current Calendar selection
+ *
+ * @config selected
+ * @type String
+ * @default []
+ */
+ cfg.addProperty(DEF_CFG.SELECTED.key, { value:[], handler:this.configSelected } );
+
+ /**
+ * The title to display above the CalendarGroup's month header
+ * @config title
+ * @type String
+ * @default ""
+ */
+ cfg.addProperty(DEF_CFG.TITLE.key, { value:DEF_CFG.TITLE.value, handler:this.configTitle } );
+
+ /**
+ * Whether or not a close button should be displayed for this CalendarGroup
+ * @config close
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.CLOSE.key, { value:DEF_CFG.CLOSE.value, handler:this.configClose } );
+
+ /**
+ * Whether or not an iframe shim should be placed under the Calendar to prevent select boxes from bleeding through in Internet Explorer 6 and below.
+ * This property is enabled by default for IE6 and below. It is disabled by default for other browsers for performance reasons, but can be
+ * enabled if required.
+ *
+ * @config iframe
+ * @type Boolean
+ * @default true for IE6 and below, false for all other browsers
+ */
+ cfg.addProperty(DEF_CFG.IFRAME.key, { value:DEF_CFG.IFRAME.value, handler:this.configIframe, validator:cfg.checkBoolean } );
+
+ /**
+ * The minimum selectable date in the current Calendar (mm/dd/yyyy)
+ * @config mindate
+ * @type String | Date
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.MINDATE.key, { value:DEF_CFG.MINDATE.value, handler:this.delegateConfig } );
+
+ /**
+ * The maximum selectable date in the current Calendar (mm/dd/yyyy)
+ * @config maxdate
+ * @type String | Date
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.MAXDATE.key, { value:DEF_CFG.MAXDATE.value, handler:this.delegateConfig } );
+
+ // Options properties
+
+ /**
+ * True if the Calendar should allow multiple selections. False by default.
+ * @config MULTI_SELECT
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.MULTI_SELECT.key, { value:DEF_CFG.MULTI_SELECT.value, handler:this.delegateConfig, validator:cfg.checkBoolean } );
+
+ /**
+ * The weekday the week begins on. Default is 0 (Sunday).
+ * @config START_WEEKDAY
+ * @type number
+ * @default 0
+ */
+ cfg.addProperty(DEF_CFG.START_WEEKDAY.key, { value:DEF_CFG.START_WEEKDAY.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * True if the Calendar should show weekday labels. True by default.
+ * @config SHOW_WEEKDAYS
+ * @type Boolean
+ * @default true
+ */
+ cfg.addProperty(DEF_CFG.SHOW_WEEKDAYS.key, { value:DEF_CFG.SHOW_WEEKDAYS.value, handler:this.delegateConfig, validator:cfg.checkBoolean } );
+
+ /**
+ * True if the Calendar should show week row headers. False by default.
+ * @config SHOW_WEEK_HEADER
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.SHOW_WEEK_HEADER.key,{ value:DEF_CFG.SHOW_WEEK_HEADER.value, handler:this.delegateConfig, validator:cfg.checkBoolean } );
+
+ /**
+ * True if the Calendar should show week row footers. False by default.
+ * @config SHOW_WEEK_FOOTER
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.SHOW_WEEK_FOOTER.key,{ value:DEF_CFG.SHOW_WEEK_FOOTER.value, handler:this.delegateConfig, validator:cfg.checkBoolean } );
+
+ /**
+ * True if the Calendar should suppress weeks that are not a part of the current month. False by default.
+ * @config HIDE_BLANK_WEEKS
+ * @type Boolean
+ * @default false
+ */
+ cfg.addProperty(DEF_CFG.HIDE_BLANK_WEEKS.key,{ value:DEF_CFG.HIDE_BLANK_WEEKS.value, handler:this.delegateConfig, validator:cfg.checkBoolean } );
+
+ /**
+ * The image that should be used for the left navigation arrow.
+ * @config NAV_ARROW_LEFT
+ * @type String
+ * @deprecated You can customize the image by overriding the default CSS class for the left arrow - "calnavleft"
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.NAV_ARROW_LEFT.key, { value:DEF_CFG.NAV_ARROW_LEFT.value, handler:this.delegateConfig } );
+
+ /**
+ * The image that should be used for the right navigation arrow.
+ * @config NAV_ARROW_RIGHT
+ * @type String
+ * @deprecated You can customize the image by overriding the default CSS class for the right arrow - "calnavright"
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.NAV_ARROW_RIGHT.key, { value:DEF_CFG.NAV_ARROW_RIGHT.value, handler:this.delegateConfig } );
+
+ // Locale properties
+
+ /**
+ * The short month labels for the current locale.
+ * @config MONTHS_SHORT
+ * @type String[]
+ * @default ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
+ */
+ cfg.addProperty(DEF_CFG.MONTHS_SHORT.key, { value:DEF_CFG.MONTHS_SHORT.value, handler:this.delegateConfig } );
+
+ /**
+ * The long month labels for the current locale.
+ * @config MONTHS_LONG
+ * @type String[]
+ * @default ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
+ */
+ cfg.addProperty(DEF_CFG.MONTHS_LONG.key, { value:DEF_CFG.MONTHS_LONG.value, handler:this.delegateConfig } );
+
+ /**
+ * The 1-character weekday labels for the current locale.
+ * @config WEEKDAYS_1CHAR
+ * @type String[]
+ * @default ["S", "M", "T", "W", "T", "F", "S"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_1CHAR.key, { value:DEF_CFG.WEEKDAYS_1CHAR.value, handler:this.delegateConfig } );
+
+ /**
+ * The short weekday labels for the current locale.
+ * @config WEEKDAYS_SHORT
+ * @type String[]
+ * @default ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_SHORT.key, { value:DEF_CFG.WEEKDAYS_SHORT.value, handler:this.delegateConfig } );
+
+ /**
+ * The medium weekday labels for the current locale.
+ * @config WEEKDAYS_MEDIUM
+ * @type String[]
+ * @default ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_MEDIUM.key, { value:DEF_CFG.WEEKDAYS_MEDIUM.value, handler:this.delegateConfig } );
+
+ /**
+ * The long weekday labels for the current locale.
+ * @config WEEKDAYS_LONG
+ * @type String[]
+ * @default ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
+ */
+ cfg.addProperty(DEF_CFG.WEEKDAYS_LONG.key, { value:DEF_CFG.WEEKDAYS_LONG.value, handler:this.delegateConfig } );
+
+ /**
+ * The setting that determines which length of month labels should be used. Possible values are "short" and "long".
+ * @config LOCALE_MONTHS
+ * @type String
+ * @default "long"
+ */
+ cfg.addProperty(DEF_CFG.LOCALE_MONTHS.key, { value:DEF_CFG.LOCALE_MONTHS.value, handler:this.delegateConfig } );
+
+ /**
+ * The setting that determines which length of weekday labels should be used. Possible values are "1char", "short", "medium", and "long".
+ * @config LOCALE_WEEKDAYS
+ * @type String
+ * @default "short"
+ */
+ cfg.addProperty(DEF_CFG.LOCALE_WEEKDAYS.key, { value:DEF_CFG.LOCALE_WEEKDAYS.value, handler:this.delegateConfig } );
+
+ /**
+ * The value used to delimit individual dates in a date string passed to various Calendar functions.
+ * @config DATE_DELIMITER
+ * @type String
+ * @default ","
+ */
+ cfg.addProperty(DEF_CFG.DATE_DELIMITER.key, { value:DEF_CFG.DATE_DELIMITER.value, handler:this.delegateConfig } );
+
+ /**
+ * The value used to delimit date fields in a date string passed to various Calendar functions.
+ * @config DATE_FIELD_DELIMITER
+ * @type String
+ * @default "/"
+ */
+ cfg.addProperty(DEF_CFG.DATE_FIELD_DELIMITER.key,{ value:DEF_CFG.DATE_FIELD_DELIMITER.value, handler:this.delegateConfig } );
+
+ /**
+ * The value used to delimit date ranges in a date string passed to various Calendar functions.
+ * @config DATE_RANGE_DELIMITER
+ * @type String
+ * @default "-"
+ */
+ cfg.addProperty(DEF_CFG.DATE_RANGE_DELIMITER.key,{ value:DEF_CFG.DATE_RANGE_DELIMITER.value, handler:this.delegateConfig } );
+
+ /**
+ * The position of the month in a month/year date string
+ * @config MY_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MY_MONTH_POSITION.key, { value:DEF_CFG.MY_MONTH_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the year in a month/year date string
+ * @config MY_YEAR_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MY_YEAR_POSITION.key, { value:DEF_CFG.MY_YEAR_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the month in a month/day date string
+ * @config MD_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MD_MONTH_POSITION.key, { value:DEF_CFG.MD_MONTH_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the day in a month/year date string
+ * @config MD_DAY_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MD_DAY_POSITION.key, { value:DEF_CFG.MD_DAY_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the month in a month/day/year date string
+ * @config MDY_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MDY_MONTH_POSITION.key, { value:DEF_CFG.MDY_MONTH_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the day in a month/day/year date string
+ * @config MDY_DAY_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MDY_DAY_POSITION.key, { value:DEF_CFG.MDY_DAY_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the year in a month/day/year date string
+ * @config MDY_YEAR_POSITION
+ * @type Number
+ * @default 3
+ */
+ cfg.addProperty(DEF_CFG.MDY_YEAR_POSITION.key, { value:DEF_CFG.MDY_YEAR_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the month in the month year label string used as the Calendar header
+ * @config MY_LABEL_MONTH_POSITION
+ * @type Number
+ * @default 1
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_MONTH_POSITION.key, { value:DEF_CFG.MY_LABEL_MONTH_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The position of the year in the month year label string used as the Calendar header
+ * @config MY_LABEL_YEAR_POSITION
+ * @type Number
+ * @default 2
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_YEAR_POSITION.key, { value:DEF_CFG.MY_LABEL_YEAR_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } );
+
+ /**
+ * The suffix used after the month when rendering the Calendar header
+ * @config MY_LABEL_MONTH_SUFFIX
+ * @type String
+ * @default " "
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_MONTH_SUFFIX.key, { value:DEF_CFG.MY_LABEL_MONTH_SUFFIX.value, handler:this.delegateConfig } );
+
+ /**
+ * The suffix used after the year when rendering the Calendar header
+ * @config MY_LABEL_YEAR_SUFFIX
+ * @type String
+ * @default ""
+ */
+ cfg.addProperty(DEF_CFG.MY_LABEL_YEAR_SUFFIX.key, { value:DEF_CFG.MY_LABEL_YEAR_SUFFIX.value, handler:this.delegateConfig } );
+
+ /**
+ * Configuration for the Month Year Navigation UI. By default it is disabled
+ * @config NAV
+ * @type Object
+ * @default null
+ */
+ cfg.addProperty(DEF_CFG.NAV.key, { value:DEF_CFG.NAV.value, handler:this.configNavigator } );
+
+ /**
+ * The map of UI strings which the CalendarGroup UI uses.
+ *
+ * @config strings
+ * @type {Object}
+ * @default An object with the properties shown below:
+ *
+ *
previousMonth
String : The string to use for the "Previous Month" navigation UI. Defaults to "Previous Month".
+ *
nextMonth
String : The string to use for the "Next Month" navigation UI. Defaults to "Next Month".
+ *
close
String : The string to use for the close button label. Defaults to "Close".
+ *
+ */
+ cfg.addProperty(DEF_CFG.STRINGS.key, {
+ value:DEF_CFG.STRINGS.value,
+ handler:this.configStrings,
+ validator: function(val) {
+ return Lang.isObject(val);
+ },
+ supercedes: DEF_CFG.STRINGS.supercedes
+ });
+ },
+
+ /**
+ * Initializes CalendarGroup's built-in CustomEvents
+ * @method initEvents
+ */
+ initEvents : function() {
+
+ var me = this,
+ strEvent = "Event",
+ CE = YAHOO.util.CustomEvent;
+
+ /**
+ * Proxy subscriber to subscribe to the CalendarGroup's child Calendars' CustomEvents
+ * @method sub
+ * @private
+ * @param {Function} fn The function to subscribe to this CustomEvent
+ * @param {Object} obj The CustomEvent's scope object
+ * @param {Boolean} bOverride Whether or not to apply scope correction
+ */
+ var sub = function(fn, obj, bOverride) {
+ for (var p=0;p 0) ? this.pages[0].cfg.getProperty(cfgSelected) : [];
+ this.cfg.setProperty(cfgSelected, selected, true);
+ },
+
+
+ /**
+ * Delegates a configuration property to the CustomEvents associated with the CalendarGroup's children
+ * @method delegateConfig
+ * @param {String} type The CustomEvent type (usually the property name)
+ * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
+ * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner.
+ */
+ delegateConfig : function(type, args, obj) {
+ var val = args[0];
+ var cal;
+
+ for (var p=0;p0) {
+ year+=1;
+ }
+ cal.setYear(year);
+ }
+ },
+
+ /**
+ * Calls the render function of all child calendars within the group.
+ * @method render
+ */
+ render : function() {
+ this.renderHeader();
+ for (var p=0;p
+ *
If MULTI_SELECT is false, selectCell will select the cell at the specified index for only the last displayed Calendar page.
+ *
If MULTI_SELECT is true, selectCell will select the cell at the specified index, on each displayed Calendar page.
+ *
+ * @method selectCell
+ * @param {Number} cellIndex The index of the cell to be selected.
+ * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected.
+ */
+ selectCell : function(cellIndex) {
+ for (var p=0;p=0;--p) {
+ var cal = this.pages[p];
+ cal.previousMonth();
+ }
+ },
+
+ /**
+ * Navigates to the next year in the currently selected month in the calendar widget.
+ * @method nextYear
+ */
+ nextYear : function() {
+ for (var p=0;p 11)) {
+ var newDate = DateMath.add(date, DateMath.MONTH, iMonth-date.getMonth());
+ date.setTime(newDate.getTime());
+ } else {
+ date.setMonth(iMonth);
+ }
+ },
+
+ /**
+ * Fixes the width of the CalendarGroup container element, to account for miswrapped floats
+ * @method _fixWidth
+ * @private
+ */
+ _fixWidth : function() {
+ var w = 0;
+ for (var p=0;p 0) {
+ this.oDomContainer.style.width = w + "px";
+ }
+ },
+
+ /**
+ * Returns a string representation of the object.
+ * @method toString
+ * @return {String} A string representation of the CalendarGroup object.
+ */
+ toString : function() {
+ return "CalendarGroup " + this.id;
+ },
+
+ /**
+ * Destroys the CalendarGroup instance. The method will remove references
+ * to HTML elements, remove any event listeners added by the CalendarGroup.
+ *
+ * It will also destroy the Config and CalendarNavigator instances created by the
+ * CalendarGroup and the individual Calendar instances created for each page.
+ *
+ * @method destroy
+ */
+ destroy : function() {
+
+ if (this.beforeDestroyEvent.fire()) {
+
+ var cal = this;
+
+ // Child objects
+ if (cal.navigator) {
+ cal.navigator.destroy();
+ }
+
+ if (cal.cfg) {
+ cal.cfg.destroy();
+ }
+
+ // DOM event listeners
+ Event.purgeElement(cal.oDomContainer, true);
+
+ // Generated markup/DOM - Not removing the container DIV since we didn't create it.
+ Dom.removeClass(cal.oDomContainer, CalendarGroup.CSS_CONTAINER);
+ Dom.removeClass(cal.oDomContainer, CalendarGroup.CSS_MULTI_UP);
+
+ for (var i = 0, l = cal.pages.length; i < l; i++) {
+ cal.pages[i].destroy();
+ cal.pages[i] = null;
+ }
+
+ cal.oDomContainer.innerHTML = "";
+
+ // JS-to-DOM references
+ cal.oDomContainer = null;
+
+ this.destroyEvent.fire();
+ }
+ }
+};
+
+/**
+* CSS class representing the container for the calendar
+* @property YAHOO.widget.CalendarGroup.CSS_CONTAINER
+* @static
+* @final
+* @type String
+*/
+CalendarGroup.CSS_CONTAINER = "yui-calcontainer";
+
+/**
+* CSS class representing the container for the calendar
+* @property YAHOO.widget.CalendarGroup.CSS_MULTI_UP
+* @static
+* @final
+* @type String
+*/
+CalendarGroup.CSS_MULTI_UP = "multi";
+
+/**
+* CSS class representing the title for the 2-up calendar
+* @property YAHOO.widget.CalendarGroup.CSS_2UPTITLE
+* @static
+* @final
+* @type String
+*/
+CalendarGroup.CSS_2UPTITLE = "title";
+
+/**
+* CSS class representing the close icon for the 2-up calendar
+* @property YAHOO.widget.CalendarGroup.CSS_2UPCLOSE
+* @static
+* @final
+* @deprecated Along with Calendar.IMG_ROOT and NAV_ARROW_LEFT, NAV_ARROW_RIGHT configuration properties.
+* Calendar's Style.CSS_CLOSE property now represents the CSS class used to render the close icon
+* @type String
+*/
+CalendarGroup.CSS_2UPCLOSE = "close-icon";
+
+YAHOO.lang.augmentProto(CalendarGroup, Calendar, "buildDayLabel",
+ "buildMonthLabel",
+ "renderOutOfBoundsDate",
+ "renderRowHeader",
+ "renderRowFooter",
+ "renderCellDefault",
+ "styleCellDefault",
+ "renderCellStyleHighlight1",
+ "renderCellStyleHighlight2",
+ "renderCellStyleHighlight3",
+ "renderCellStyleHighlight4",
+ "renderCellStyleToday",
+ "renderCellStyleSelected",
+ "renderCellNotThisMonth",
+ "renderBodyCellRestricted",
+ "initStyles",
+ "configTitle",
+ "configClose",
+ "configIframe",
+ "configStrings",
+ "configNavigator",
+ "createTitleBar",
+ "createCloseButton",
+ "removeTitleBar",
+ "removeCloseButton",
+ "hide",
+ "show",
+ "toDate",
+ "_toDate",
+ "_parseArgs",
+ "browser");
+
+YAHOO.widget.CalGrp = CalendarGroup;
+YAHOO.widget.CalendarGroup = CalendarGroup;
+
+/**
+* @class YAHOO.widget.Calendar2up
+* @extends YAHOO.widget.CalendarGroup
+* @deprecated The old Calendar2up class is no longer necessary, since CalendarGroup renders in a 2up view by default.
+*/
+YAHOO.widget.Calendar2up = function(id, containerId, config) {
+ this.init(id, containerId, config);
+};
+
+YAHOO.extend(YAHOO.widget.Calendar2up, CalendarGroup);
+
+/**
+* @deprecated The old Calendar2up class is no longer necessary, since CalendarGroup renders in a 2up view by default.
+*/
+YAHOO.widget.Cal2up = YAHOO.widget.Calendar2up;
+
+})();
+
+/**
+ * The CalendarNavigator is used along with a Calendar/CalendarGroup to
+ * provide a Month/Year popup navigation control, allowing the user to navigate
+ * to a specific month/year in the Calendar/CalendarGroup without having to
+ * scroll through months sequentially
+ *
+ * @namespace YAHOO.widget
+ * @class CalendarNavigator
+ * @constructor
+ * @param {Calendar|CalendarGroup} cal The instance of the Calendar or CalendarGroup to which this CalendarNavigator should be attached.
+ */
+YAHOO.widget.CalendarNavigator = function(cal) {
+ this.init(cal);
+};
+
+(function() {
+ // Setup static properties (inside anon fn, so that we can use shortcuts)
+ var CN = YAHOO.widget.CalendarNavigator;
+
+ /**
+ * YAHOO.widget.CalendarNavigator.CLASSES contains constants
+ * for the class values applied to the CalendarNaviatgator's
+ * DOM elements
+ * @property YAHOO.widget.CalendarNavigator.CLASSES
+ * @type Object
+ * @static
+ */
+ CN.CLASSES = {
+ /**
+ * Class applied to the Calendar Navigator's bounding box
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.NAV
+ * @type String
+ * @static
+ */
+ NAV :"yui-cal-nav",
+ /**
+ * Class applied to the Calendar/CalendarGroup's bounding box to indicate
+ * the Navigator is currently visible
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.NAV_VISIBLE
+ * @type String
+ * @static
+ */
+ NAV_VISIBLE: "yui-cal-nav-visible",
+ /**
+ * Class applied to the Navigator mask's bounding box
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.MASK
+ * @type String
+ * @static
+ */
+ MASK : "yui-cal-nav-mask",
+ /**
+ * Class applied to the year label/control bounding box
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.YEAR
+ * @type String
+ * @static
+ */
+ YEAR : "yui-cal-nav-y",
+ /**
+ * Class applied to the month label/control bounding box
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.MONTH
+ * @type String
+ * @static
+ */
+ MONTH : "yui-cal-nav-m",
+ /**
+ * Class applied to the submit/cancel button's bounding box
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.BUTTONS
+ * @type String
+ * @static
+ */
+ BUTTONS : "yui-cal-nav-b",
+ /**
+ * Class applied to buttons wrapping element
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.BUTTON
+ * @type String
+ * @static
+ */
+ BUTTON : "yui-cal-nav-btn",
+ /**
+ * Class applied to the validation error area's bounding box
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.ERROR
+ * @type String
+ * @static
+ */
+ ERROR : "yui-cal-nav-e",
+ /**
+ * Class applied to the year input control
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.YEAR_CTRL
+ * @type String
+ * @static
+ */
+ YEAR_CTRL : "yui-cal-nav-yc",
+ /**
+ * Class applied to the month input control
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.MONTH_CTRL
+ * @type String
+ * @static
+ */
+ MONTH_CTRL : "yui-cal-nav-mc",
+ /**
+ * Class applied to controls with invalid data (e.g. a year input field with invalid an year)
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.INVALID
+ * @type String
+ * @static
+ */
+ INVALID : "yui-invalid",
+ /**
+ * Class applied to default controls
+ * @property YAHOO.widget.CalendarNavigator.CLASSES.DEFAULT
+ * @type String
+ * @static
+ */
+ DEFAULT : "yui-default"
+ };
+
+ /**
+ * Object literal containing the default configuration values for the CalendarNavigator
+ * The configuration object is expected to follow the format below, with the properties being
+ * case sensitive.
+ *
+ *
strings
+ *
Object : An object with the properties shown below, defining the string labels to use in the Navigator's UI
+ *
+ *
month
String : The string to use for the month label. Defaults to "Month".
+ *
year
String : The string to use for the year label. Defaults to "Year".
+ *
submit
String : The string to use for the submit button label. Defaults to "Okay".
+ *
cancel
String : The string to use for the cancel button label. Defaults to "Cancel".
+ *
invalidYear
String : The string to use for invalid year values. Defaults to "Year needs to be a number".
+ *
+ *
+ *
monthFormat
String : The month format to use. Either YAHOO.widget.Calendar.LONG, or YAHOO.widget.Calendar.SHORT. Defaults to YAHOO.widget.Calendar.LONG
+ *
initialFocus
String : Either "year" or "month" specifying which input control should get initial focus. Defaults to "year"
+ *
+ * @property _DEFAULT_CFG
+ * @protected
+ * @type Object
+ * @static
+ */
+ CN._DEFAULT_CFG = {
+ strings : {
+ month: "Month",
+ year: "Year",
+ submit: "Okay",
+ cancel: "Cancel",
+ invalidYear : "Year needs to be a number"
+ },
+ monthFormat: YAHOO.widget.Calendar.LONG,
+ initialFocus: "year"
+ };
+
+ /**
+ * The suffix added to the Calendar/CalendarGroup's ID, to generate
+ * a unique ID for the Navigator and it's bounding box.
+ * @property YAHOO.widget.CalendarNavigator.ID_SUFFIX
+ * @static
+ * @type String
+ * @final
+ */
+ CN.ID_SUFFIX = "_nav";
+ /**
+ * The suffix added to the Navigator's ID, to generate
+ * a unique ID for the month control.
+ * @property YAHOO.widget.CalendarNavigator.MONTH_SUFFIX
+ * @static
+ * @type String
+ * @final
+ */
+ CN.MONTH_SUFFIX = "_month";
+ /**
+ * The suffix added to the Navigator's ID, to generate
+ * a unique ID for the year control.
+ * @property YAHOO.widget.CalendarNavigator.YEAR_SUFFIX
+ * @static
+ * @type String
+ * @final
+ */
+ CN.YEAR_SUFFIX = "_year";
+ /**
+ * The suffix added to the Navigator's ID, to generate
+ * a unique ID for the error bounding box.
+ * @property YAHOO.widget.CalendarNavigator.ERROR_SUFFIX
+ * @static
+ * @type String
+ * @final
+ */
+ CN.ERROR_SUFFIX = "_error";
+ /**
+ * The suffix added to the Navigator's ID, to generate
+ * a unique ID for the "Cancel" button.
+ * @property YAHOO.widget.CalendarNavigator.CANCEL_SUFFIX
+ * @static
+ * @type String
+ * @final
+ */
+ CN.CANCEL_SUFFIX = "_cancel";
+ /**
+ * The suffix added to the Navigator's ID, to generate
+ * a unique ID for the "Submit" button.
+ * @property YAHOO.widget.CalendarNavigator.SUBMIT_SUFFIX
+ * @static
+ * @type String
+ * @final
+ */
+ CN.SUBMIT_SUFFIX = "_submit";
+
+ /**
+ * The number of digits to which the year input control is to be limited.
+ * @property YAHOO.widget.CalendarNavigator.YR_MAX_DIGITS
+ * @static
+ * @type Number
+ */
+ CN.YR_MAX_DIGITS = 4;
+
+ /**
+ * The amount by which to increment the current year value,
+ * when the arrow up/down key is pressed on the year control
+ * @property YAHOO.widget.CalendarNavigator.YR_MINOR_INC
+ * @static
+ * @type Number
+ */
+ CN.YR_MINOR_INC = 1;
+
+ /**
+ * The amount by which to increment the current year value,
+ * when the page up/down key is pressed on the year control
+ * @property YAHOO.widget.CalendarNavigator.YR_MAJOR_INC
+ * @static
+ * @type Number
+ */
+ CN.YR_MAJOR_INC = 10;
+
+ /**
+ * Artificial delay (in ms) between the time the Navigator is hidden
+ * and the Calendar/CalendarGroup state is updated. Allows the user
+ * the see the Calendar/CalendarGroup page changing. If set to 0
+ * the Calendar/CalendarGroup page will be updated instantly
+ * @property YAHOO.widget.CalendarNavigator.UPDATE_DELAY
+ * @static
+ * @type Number
+ */
+ CN.UPDATE_DELAY = 50;
+
+ /**
+ * Regular expression used to validate the year input
+ * @property YAHOO.widget.CalendarNavigator.YR_PATTERN
+ * @static
+ * @type RegExp
+ */
+ CN.YR_PATTERN = /^\d+$/;
+ /**
+ * Regular expression used to trim strings
+ * @property YAHOO.widget.CalendarNavigator.TRIM
+ * @static
+ * @type RegExp
+ */
+ CN.TRIM = /^\s*(.*?)\s*$/;
+})();
+
+YAHOO.widget.CalendarNavigator.prototype = {
+
+ /**
+ * The unique ID for this CalendarNavigator instance
+ * @property id
+ * @type String
+ */
+ id : null,
+
+ /**
+ * The Calendar/CalendarGroup instance to which the navigator belongs
+ * @property cal
+ * @type {Calendar|CalendarGroup}
+ */
+ cal : null,
+
+ /**
+ * Reference to the HTMLElement used to render the navigator's bounding box
+ * @property navEl
+ * @type HTMLElement
+ */
+ navEl : null,
+
+ /**
+ * Reference to the HTMLElement used to render the navigator's mask
+ * @property maskEl
+ * @type HTMLElement
+ */
+ maskEl : null,
+
+ /**
+ * Reference to the HTMLElement used to input the year
+ * @property yearEl
+ * @type HTMLElement
+ */
+ yearEl : null,
+
+ /**
+ * Reference to the HTMLElement used to input the month
+ * @property monthEl
+ * @type HTMLElement
+ */
+ monthEl : null,
+
+ /**
+ * Reference to the HTMLElement used to display validation errors
+ * @property errorEl
+ * @type HTMLElement
+ */
+ errorEl : null,
+
+ /**
+ * Reference to the HTMLElement used to update the Calendar/Calendar group
+ * with the month/year values
+ * @property submitEl
+ * @type HTMLElement
+ */
+ submitEl : null,
+
+ /**
+ * Reference to the HTMLElement used to hide the navigator without updating the
+ * Calendar/Calendar group
+ * @property cancelEl
+ * @type HTMLElement
+ */
+ cancelEl : null,
+
+ /**
+ * Reference to the first focusable control in the navigator (by default monthEl)
+ * @property firstCtrl
+ * @type HTMLElement
+ */
+ firstCtrl : null,
+
+ /**
+ * Reference to the last focusable control in the navigator (by default cancelEl)
+ * @property lastCtrl
+ * @type HTMLElement
+ */
+ lastCtrl : null,
+
+ /**
+ * The document containing the Calendar/Calendar group instance
+ * @protected
+ * @property _doc
+ * @type HTMLDocument
+ */
+ _doc : null,
+
+ /**
+ * Internal state property for the current year displayed in the navigator
+ * @protected
+ * @property _year
+ * @type Number
+ */
+ _year: null,
+
+ /**
+ * Internal state property for the current month index displayed in the navigator
+ * @protected
+ * @property _month
+ * @type Number
+ */
+ _month: 0,
+
+ /**
+ * Private internal state property which indicates whether or not the
+ * Navigator has been rendered.
+ * @private
+ * @property __rendered
+ * @type Boolean
+ */
+ __rendered: false,
+
+ /**
+ * Init lifecycle method called as part of construction
+ *
+ * @method init
+ * @param {Calendar} cal The instance of the Calendar or CalendarGroup to which this CalendarNavigator should be attached
+ */
+ init : function(cal) {
+ var calBox = cal.oDomContainer;
+
+ this.cal = cal;
+ this.id = calBox.id + YAHOO.widget.CalendarNavigator.ID_SUFFIX;
+ this._doc = calBox.ownerDocument;
+
+ /**
+ * Private flag, to identify IE6/IE7 Quirks
+ * @private
+ * @property __isIEQuirks
+ */
+ var ie = YAHOO.env.ua.ie;
+ this.__isIEQuirks = (ie && ((ie <= 6) || (ie === 7 && this._doc.compatMode == "BackCompat")));
+ },
+
+ /**
+ * Displays the navigator and mask, updating the input controls to reflect the
+ * currently set month and year. The show method will invoke the render method
+ * if the navigator has not been renderered already, allowing for lazy rendering
+ * of the control.
+ *
+ * The show method will fire the Calendar/CalendarGroup's beforeShowNav and showNav events
+ *
+ * @method show
+ */
+ show : function() {
+ var CLASSES = YAHOO.widget.CalendarNavigator.CLASSES;
+
+ if (this.cal.beforeShowNavEvent.fire()) {
+ if (!this.__rendered) {
+ this.render();
+ }
+ this.clearErrors();
+
+ this._updateMonthUI();
+ this._updateYearUI();
+ this._show(this.navEl, true);
+
+ this.setInitialFocus();
+ this.showMask();
+
+ YAHOO.util.Dom.addClass(this.cal.oDomContainer, CLASSES.NAV_VISIBLE);
+ this.cal.showNavEvent.fire();
+ }
+ },
+
+ /**
+ * Hides the navigator and mask
+ *
+ * The show method will fire the Calendar/CalendarGroup's beforeHideNav event and hideNav events
+ * @method hide
+ */
+ hide : function() {
+ var CLASSES = YAHOO.widget.CalendarNavigator.CLASSES;
+
+ if (this.cal.beforeHideNavEvent.fire()) {
+ this._show(this.navEl, false);
+ this.hideMask();
+ YAHOO.util.Dom.removeClass(this.cal.oDomContainer, CLASSES.NAV_VISIBLE);
+ this.cal.hideNavEvent.fire();
+ }
+ },
+
+
+ /**
+ * Displays the navigator's mask element
+ *
+ * @method showMask
+ */
+ showMask : function() {
+ this._show(this.maskEl, true);
+ if (this.__isIEQuirks) {
+ this._syncMask();
+ }
+ },
+
+ /**
+ * Hides the navigator's mask element
+ *
+ * @method hideMask
+ */
+ hideMask : function() {
+ this._show(this.maskEl, false);
+ },
+
+ /**
+ * Returns the current month set on the navigator
+ *
+ * Note: This may not be the month set in the UI, if
+ * the UI contains an invalid value.
+ *
+ * @method getMonth
+ * @return {Number} The Navigator's current month index
+ */
+ getMonth: function() {
+ return this._month;
+ },
+
+ /**
+ * Returns the current year set on the navigator
+ *
+ * Note: This may not be the year set in the UI, if
+ * the UI contains an invalid value.
+ *
+ * @method getYear
+ * @return {Number} The Navigator's current year value
+ */
+ getYear: function() {
+ return this._year;
+ },
+
+ /**
+ * Sets the current month on the Navigator, and updates the UI
+ *
+ * @method setMonth
+ * @param {Number} nMonth The month index, from 0 (Jan) through 11 (Dec).
+ */
+ setMonth : function(nMonth) {
+ if (nMonth >= 0 && nMonth < 12) {
+ this._month = nMonth;
+ }
+ this._updateMonthUI();
+ },
+
+ /**
+ * Sets the current year on the Navigator, and updates the UI. If the
+ * provided year is invalid, it will not be set.
+ *
+ * @method setYear
+ * @param {Number} nYear The full year value to set the Navigator to.
+ */
+ setYear : function(nYear) {
+ var yrPattern = YAHOO.widget.CalendarNavigator.YR_PATTERN;
+ if (YAHOO.lang.isNumber(nYear) && yrPattern.test(nYear+"")) {
+ this._year = nYear;
+ }
+ this._updateYearUI();
+ },
+
+ /**
+ * Renders the HTML for the navigator, adding it to the
+ * document and attaches event listeners if it has not
+ * already been rendered.
+ *
+ * @method render
+ */
+ render: function() {
+ this.cal.beforeRenderNavEvent.fire();
+ if (!this.__rendered) {
+ this.createNav();
+ this.createMask();
+ this.applyListeners();
+ this.__rendered = true;
+ }
+ this.cal.renderNavEvent.fire();
+ },
+
+ /**
+ * Creates the navigator's containing HTMLElement, it's contents, and appends
+ * the containg element to the Calendar/CalendarGroup's container.
+ *
+ * @method createNav
+ */
+ createNav : function() {
+ var NAV = YAHOO.widget.CalendarNavigator;
+ var doc = this._doc;
+
+ var d = doc.createElement("div");
+ d.className = NAV.CLASSES.NAV;
+
+ var htmlBuf = this.renderNavContents([]);
+
+ d.innerHTML = htmlBuf.join('');
+ this.cal.oDomContainer.appendChild(d);
+
+ this.navEl = d;
+
+ this.yearEl = doc.getElementById(this.id + NAV.YEAR_SUFFIX);
+ this.monthEl = doc.getElementById(this.id + NAV.MONTH_SUFFIX);
+ this.errorEl = doc.getElementById(this.id + NAV.ERROR_SUFFIX);
+ this.submitEl = doc.getElementById(this.id + NAV.SUBMIT_SUFFIX);
+ this.cancelEl = doc.getElementById(this.id + NAV.CANCEL_SUFFIX);
+
+ if (YAHOO.env.ua.gecko && this.yearEl && this.yearEl.type == "text") {
+ // Avoid XUL error on focus, select [ https://bugzilla.mozilla.org/show_bug.cgi?id=236791,
+ // supposedly fixed in 1.8.1, but there are reports of it still being around for methods other than blur ]
+ this.yearEl.setAttribute("autocomplete", "off");
+ }
+
+ this._setFirstLastElements();
+ },
+
+ /**
+ * Creates the Mask HTMLElement and appends it to the Calendar/CalendarGroups
+ * container.
+ *
+ * @method createMask
+ */
+ createMask : function() {
+ var C = YAHOO.widget.CalendarNavigator.CLASSES;
+
+ var d = this._doc.createElement("div");
+ d.className = C.MASK;
+
+ this.cal.oDomContainer.appendChild(d);
+ this.maskEl = d;
+ },
+
+ /**
+ * Used to set the width/height of the mask in pixels to match the Calendar Container.
+ * Currently only used for IE6 and IE7 quirks mode. The other A-Grade browser are handled using CSS (width/height 100%).
+ *
+ * The method is also registered as an HTMLElement resize listener on the Calendars container element.
+ *
+ * @protected
+ * @method _syncMask
+ */
+ _syncMask : function() {
+ var c = this.cal.oDomContainer;
+ if (c && this.maskEl) {
+ var r = YAHOO.util.Dom.getRegion(c);
+ YAHOO.util.Dom.setStyle(this.maskEl, "width", r.right - r.left + "px");
+ YAHOO.util.Dom.setStyle(this.maskEl, "height", r.bottom - r.top + "px");
+ }
+ },
+
+ /**
+ * Renders the contents of the navigator
+ *
+ * @method renderNavContents
+ *
+ * @param {Array} html The HTML buffer to append the HTML to.
+ * @return {Array} A reference to the buffer passed in.
+ */
+ renderNavContents : function(html) {
+ var NAV = YAHOO.widget.CalendarNavigator,
+ C = NAV.CLASSES,
+ h = html; // just to use a shorter name
+
+ h[h.length] = '
';
+ this.renderMonth(h);
+ h[h.length] = '
';
+ h[h.length] = '
';
+ this.renderYear(h);
+ h[h.length] = '
';
+ h[h.length] = '
';
+ this.renderButtons(h);
+ h[h.length] = '
';
+ h[h.length] = '';
+
+ return h;
+ },
+
+ /**
+ * Renders the month label and control for the navigator
+ *
+ * @method renderNavContents
+ * @param {Array} html The HTML buffer to append the HTML to.
+ * @return {Array} A reference to the buffer passed in.
+ */
+ renderMonth : function(html) {
+ var NAV = YAHOO.widget.CalendarNavigator,
+ C = NAV.CLASSES;
+
+ var id = this.id + NAV.MONTH_SUFFIX,
+ mf = this.__getCfg("monthFormat"),
+ months = this.cal.cfg.getProperty((mf == YAHOO.widget.Calendar.SHORT) ? "MONTHS_SHORT" : "MONTHS_LONG"),
+ h = html;
+
+ if (months && months.length > 0) {
+ h[h.length] = '';
+ h[h.length] = '';
+ }
+ return h;
+ },
+
+ /**
+ * Renders the year label and control for the navigator
+ *
+ * @method renderYear
+ * @param {Array} html The HTML buffer to append the HTML to.
+ * @return {Array} A reference to the buffer passed in.
+ */
+ renderYear : function(html) {
+ var NAV = YAHOO.widget.CalendarNavigator,
+ C = NAV.CLASSES;
+
+ var id = this.id + NAV.YEAR_SUFFIX,
+ size = NAV.YR_MAX_DIGITS,
+ h = html;
+
+ h[h.length] = '';
+ h[h.length] = '';
+ return h;
+ },
+
+ /**
+ * Renders the submit/cancel buttons for the navigator
+ *
+ * @method renderButton
+ * @return {String} The HTML created for the Button UI
+ */
+ renderButtons : function(html) {
+ var C = YAHOO.widget.CalendarNavigator.CLASSES;
+ var h = html;
+
+ h[h.length] = '';
+ h[h.length] = '';
+ h[h.length] = this.__getCfg("submit", true);
+ h[h.length] = '';
+ h[h.length] = '';
+ h[h.length] = '';
+ h[h.length] = '';
+ h[h.length] = this.__getCfg("cancel", true);
+ h[h.length] = '';
+ h[h.length] = '';
+
+ return h;
+ },
+
+ /**
+ * Attaches DOM event listeners to the rendered elements
+ *
+ * The method will call applyKeyListeners, to setup keyboard specific
+ * listeners
+ *
+ * @method applyListeners
+ */
+ applyListeners : function() {
+ var E = YAHOO.util.Event;
+
+ function yearUpdateHandler() {
+ if (this.validate()) {
+ this.setYear(this._getYearFromUI());
+ }
+ }
+
+ function monthUpdateHandler() {
+ this.setMonth(this._getMonthFromUI());
+ }
+
+ E.on(this.submitEl, "click", this.submit, this, true);
+ E.on(this.cancelEl, "click", this.cancel, this, true);
+ E.on(this.yearEl, "blur", yearUpdateHandler, this, true);
+ E.on(this.monthEl, "change", monthUpdateHandler, this, true);
+
+ if (this.__isIEQuirks) {
+ YAHOO.util.Event.on(this.cal.oDomContainer, "resize", this._syncMask, this, true);
+ }
+
+ this.applyKeyListeners();
+ },
+
+ /**
+ * Removes/purges DOM event listeners from the rendered elements
+ *
+ * @method purgeListeners
+ */
+ purgeListeners : function() {
+ var E = YAHOO.util.Event;
+ E.removeListener(this.submitEl, "click", this.submit);
+ E.removeListener(this.cancelEl, "click", this.cancel);
+ E.removeListener(this.yearEl, "blur");
+ E.removeListener(this.monthEl, "change");
+ if (this.__isIEQuirks) {
+ E.removeListener(this.cal.oDomContainer, "resize", this._syncMask);
+ }
+
+ this.purgeKeyListeners();
+ },
+
+ /**
+ * Attaches DOM listeners for keyboard support.
+ * Tab/Shift-Tab looping, Enter Key Submit on Year element,
+ * Up/Down/PgUp/PgDown year increment on Year element
+ *
+ * NOTE: MacOSX Safari 2.x doesn't let you tab to buttons and
+ * MacOSX Gecko does not let you tab to buttons or select controls,
+ * so for these browsers, Tab/Shift-Tab looping is limited to the
+ * elements which can be reached using the tab key.
+ *
+ * @method applyKeyListeners
+ */
+ applyKeyListeners : function() {
+ var E = YAHOO.util.Event,
+ ua = YAHOO.env.ua;
+
+ // IE/Safari 3.1 doesn't fire keypress for arrow/pg keys (non-char keys)
+ var arrowEvt = (ua.ie || ua.webkit) ? "keydown" : "keypress";
+
+ // - IE/Safari 3.1 doesn't fire keypress for non-char keys
+ // - Opera doesn't allow us to cancel keydown or keypress for tab, but
+ // changes focus successfully on keydown (keypress is too late to change focus - opera's already moved on).
+ var tabEvt = (ua.ie || ua.opera || ua.webkit) ? "keydown" : "keypress";
+
+ // Everyone likes keypress for Enter (char keys) - whoo hoo!
+ E.on(this.yearEl, "keypress", this._handleEnterKey, this, true);
+
+ E.on(this.yearEl, arrowEvt, this._handleDirectionKeys, this, true);
+ E.on(this.lastCtrl, tabEvt, this._handleTabKey, this, true);
+ E.on(this.firstCtrl, tabEvt, this._handleShiftTabKey, this, true);
+ },
+
+ /**
+ * Removes/purges DOM listeners for keyboard support
+ *
+ * @method purgeKeyListeners
+ */
+ purgeKeyListeners : function() {
+ var E = YAHOO.util.Event,
+ ua = YAHOO.env.ua;
+
+ var arrowEvt = (ua.ie || ua.webkit) ? "keydown" : "keypress";
+ var tabEvt = (ua.ie || ua.opera || ua.webkit) ? "keydown" : "keypress";
+
+ E.removeListener(this.yearEl, "keypress", this._handleEnterKey);
+ E.removeListener(this.yearEl, arrowEvt, this._handleDirectionKeys);
+ E.removeListener(this.lastCtrl, tabEvt, this._handleTabKey);
+ E.removeListener(this.firstCtrl, tabEvt, this._handleShiftTabKey);
+ },
+
+ /**
+ * Updates the Calendar/CalendarGroup's pagedate with the currently set month and year if valid.
+ *
+ * If the currently set month/year is invalid, a validation error will be displayed and the
+ * Calendar/CalendarGroup's pagedate will not be updated.
+ *
+ * @method submit
+ */
+ submit : function() {
+ if (this.validate()) {
+ this.hide();
+
+ this.setMonth(this._getMonthFromUI());
+ this.setYear(this._getYearFromUI());
+
+ var cal = this.cal;
+
+ // Artificial delay, just to help the user see something changed
+ var delay = YAHOO.widget.CalendarNavigator.UPDATE_DELAY;
+ if (delay > 0) {
+ var nav = this;
+ window.setTimeout(function(){ nav._update(cal); }, delay);
+ } else {
+ this._update(cal);
+ }
+ }
+ },
+
+ /**
+ * Updates the Calendar rendered state, based on the state of the CalendarNavigator
+ * @method _update
+ * @param cal The Calendar instance to update
+ * @protected
+ */
+ _update : function(cal) {
+ cal.setYear(this.getYear());
+ cal.setMonth(this.getMonth());
+ cal.render();
+ },
+
+ /**
+ * Hides the navigator and mask, without updating the Calendar/CalendarGroup's state
+ *
+ * @method cancel
+ */
+ cancel : function() {
+ this.hide();
+ },
+
+ /**
+ * Validates the current state of the UI controls
+ *
+ * @method validate
+ * @return {Boolean} true, if the current UI state contains valid values, false if not
+ */
+ validate : function() {
+ if (this._getYearFromUI() !== null) {
+ this.clearErrors();
+ return true;
+ } else {
+ this.setYearError();
+ this.setError(this.__getCfg("invalidYear", true));
+ return false;
+ }
+ },
+
+ /**
+ * Displays an error message in the Navigator's error panel
+ * @method setError
+ * @param {String} msg The error message to display
+ */
+ setError : function(msg) {
+ if (this.errorEl) {
+ this.errorEl.innerHTML = msg;
+ this._show(this.errorEl, true);
+ }
+ },
+
+ /**
+ * Clears the navigator's error message and hides the error panel
+ * @method clearError
+ */
+ clearError : function() {
+ if (this.errorEl) {
+ this.errorEl.innerHTML = "";
+ this._show(this.errorEl, false);
+ }
+ },
+
+ /**
+ * Displays the validation error UI for the year control
+ * @method setYearError
+ */
+ setYearError : function() {
+ YAHOO.util.Dom.addClass(this.yearEl, YAHOO.widget.CalendarNavigator.CLASSES.INVALID);
+ },
+
+ /**
+ * Removes the validation error UI for the year control
+ * @method clearYearError
+ */
+ clearYearError : function() {
+ YAHOO.util.Dom.removeClass(this.yearEl, YAHOO.widget.CalendarNavigator.CLASSES.INVALID);
+ },
+
+ /**
+ * Clears all validation and error messages in the UI
+ * @method clearErrors
+ */
+ clearErrors : function() {
+ this.clearError();
+ this.clearYearError();
+ },
+
+ /**
+ * Sets the initial focus, based on the configured value
+ * @method setInitialFocus
+ */
+ setInitialFocus : function() {
+ var el = this.submitEl,
+ f = this.__getCfg("initialFocus");
+
+ if (f && f.toLowerCase) {
+ f = f.toLowerCase();
+ if (f == "year") {
+ el = this.yearEl;
+ try {
+ this.yearEl.select();
+ } catch (selErr) {
+ // Ignore;
+ }
+ } else if (f == "month") {
+ el = this.monthEl;
+ }
+ }
+
+ if (el && YAHOO.lang.isFunction(el.focus)) {
+ try {
+ el.focus();
+ } catch (focusErr) {
+ // TODO: Fall back if focus fails?
+ }
+ }
+ },
+
+ /**
+ * Removes all renderered HTML elements for the Navigator from
+ * the DOM, purges event listeners and clears (nulls) any property
+ * references to HTML references
+ * @method erase
+ */
+ erase : function() {
+ if (this.__rendered) {
+ this.purgeListeners();
+
+ // Clear out innerHTML references
+ this.yearEl = null;
+ this.monthEl = null;
+ this.errorEl = null;
+ this.submitEl = null;
+ this.cancelEl = null;
+ this.firstCtrl = null;
+ this.lastCtrl = null;
+ if (this.navEl) {
+ this.navEl.innerHTML = "";
+ }
+
+ var p = this.navEl.parentNode;
+ if (p) {
+ p.removeChild(this.navEl);
+ }
+ this.navEl = null;
+
+ var pm = this.maskEl.parentNode;
+ if (pm) {
+ pm.removeChild(this.maskEl);
+ }
+ this.maskEl = null;
+ this.__rendered = false;
+ }
+ },
+
+ /**
+ * Destroys the Navigator object and any HTML references
+ * @method destroy
+ */
+ destroy : function() {
+ this.erase();
+ this._doc = null;
+ this.cal = null;
+ this.id = null;
+ },
+
+ /**
+ * Protected implementation to handle how UI elements are
+ * hidden/shown.
+ *
+ * @method _show
+ * @protected
+ */
+ _show : function(el, bShow) {
+ if (el) {
+ YAHOO.util.Dom.setStyle(el, "display", (bShow) ? "block" : "none");
+ }
+ },
+
+ /**
+ * Returns the month value (index), from the month UI element
+ * @protected
+ * @method _getMonthFromUI
+ * @return {Number} The month index, or 0 if a UI element for the month
+ * is not found
+ */
+ _getMonthFromUI : function() {
+ if (this.monthEl) {
+ return this.monthEl.selectedIndex;
+ } else {
+ return 0; // Default to Jan
+ }
+ },
+
+ /**
+ * Returns the year value, from the Navitator's year UI element
+ * @protected
+ * @method _getYearFromUI
+ * @return {Number} The year value set in the UI, if valid. null is returned if
+ * the UI does not contain a valid year value.
+ */
+ _getYearFromUI : function() {
+ var NAV = YAHOO.widget.CalendarNavigator;
+
+ var yr = null;
+ if (this.yearEl) {
+ var value = this.yearEl.value;
+ value = value.replace(NAV.TRIM, "$1");
+
+ if (NAV.YR_PATTERN.test(value)) {
+ yr = parseInt(value, 10);
+ }
+ }
+ return yr;
+ },
+
+ /**
+ * Updates the Navigator's year UI, based on the year value set on the Navigator object
+ * @protected
+ * @method _updateYearUI
+ */
+ _updateYearUI : function() {
+ if (this.yearEl && this._year !== null) {
+ this.yearEl.value = this._year;
+ }
+ },
+
+ /**
+ * Updates the Navigator's month UI, based on the month value set on the Navigator object
+ * @protected
+ * @method _updateMonthUI
+ */
+ _updateMonthUI : function() {
+ if (this.monthEl) {
+ this.monthEl.selectedIndex = this._month;
+ }
+ },
+
+ /**
+ * Sets up references to the first and last focusable element in the Navigator's UI
+ * in terms of tab order (Naviagator's firstEl and lastEl properties). The references
+ * are used to control modality by looping around from the first to the last control
+ * and visa versa for tab/shift-tab navigation.
+ *
+ * @protected
+ * @method _setFirstLastElements
+ */
+ _setFirstLastElements : function() {
+ this.firstCtrl = this.monthEl;
+ this.lastCtrl = this.cancelEl;
+
+ // Special handling for MacOSX.
+ // - Safari 2.x can't focus on buttons
+ // - Gecko can't focus on select boxes or buttons
+ if (this.__isMac) {
+ if (YAHOO.env.ua.webkit && YAHOO.env.ua.webkit < 420){
+ this.firstCtrl = this.monthEl;
+ this.lastCtrl = this.yearEl;
+ }
+ if (YAHOO.env.ua.gecko) {
+ this.firstCtrl = this.yearEl;
+ this.lastCtrl = this.yearEl;
+ }
+ }
+ },
+
+ /**
+ * Default Keyboard event handler to capture Enter
+ * on the Navigator's year control (yearEl)
+ *
+ * @method _handleEnterKey
+ * @protected
+ * @param {Event} e The DOM event being handled
+ */
+ _handleEnterKey : function(e) {
+ var KEYS = YAHOO.util.KeyListener.KEY;
+
+ if (YAHOO.util.Event.getCharCode(e) == KEYS.ENTER) {
+ YAHOO.util.Event.preventDefault(e);
+ this.submit();
+ }
+ },
+
+ /**
+ * Default Keyboard event handler to capture up/down/pgup/pgdown
+ * on the Navigator's year control (yearEl).
+ *
+ * @method _handleDirectionKeys
+ * @protected
+ * @param {Event} e The DOM event being handled
+ */
+ _handleDirectionKeys : function(e) {
+ var E = YAHOO.util.Event,
+ KEYS = YAHOO.util.KeyListener.KEY,
+ NAV = YAHOO.widget.CalendarNavigator;
+
+ var value = (this.yearEl.value) ? parseInt(this.yearEl.value, 10) : null;
+ if (isFinite(value)) {
+ var dir = false;
+ switch(E.getCharCode(e)) {
+ case KEYS.UP:
+ this.yearEl.value = value + NAV.YR_MINOR_INC;
+ dir = true;
+ break;
+ case KEYS.DOWN:
+ this.yearEl.value = Math.max(value - NAV.YR_MINOR_INC, 0);
+ dir = true;
+ break;
+ case KEYS.PAGE_UP:
+ this.yearEl.value = value + NAV.YR_MAJOR_INC;
+ dir = true;
+ break;
+ case KEYS.PAGE_DOWN:
+ this.yearEl.value = Math.max(value - NAV.YR_MAJOR_INC, 0);
+ dir = true;
+ break;
+ default:
+ break;
+ }
+ if (dir) {
+ E.preventDefault(e);
+ try {
+ this.yearEl.select();
+ } catch(err) {
+ // Ignore
+ }
+ }
+ }
+ },
+
+ /**
+ * Default Keyboard event handler to capture Tab
+ * on the last control (lastCtrl) in the Navigator.
+ *
+ * @method _handleTabKey
+ * @protected
+ * @param {Event} e The DOM event being handled
+ */
+ _handleTabKey : function(e) {
+ var E = YAHOO.util.Event,
+ KEYS = YAHOO.util.KeyListener.KEY;
+
+ if (E.getCharCode(e) == KEYS.TAB && !e.shiftKey) {
+ try {
+ E.preventDefault(e);
+ this.firstCtrl.focus();
+ } catch (err) {
+ // Ignore - mainly for focus edge cases
+ }
+ }
+ },
+
+ /**
+ * Default Keyboard event handler to capture Shift-Tab
+ * on the first control (firstCtrl) in the Navigator.
+ *
+ * @method _handleShiftTabKey
+ * @protected
+ * @param {Event} e The DOM event being handled
+ */
+ _handleShiftTabKey : function(e) {
+ var E = YAHOO.util.Event,
+ KEYS = YAHOO.util.KeyListener.KEY;
+
+ if (e.shiftKey && E.getCharCode(e) == KEYS.TAB) {
+ try {
+ E.preventDefault(e);
+ this.lastCtrl.focus();
+ } catch (err) {
+ // Ignore - mainly for focus edge cases
+ }
+ }
+ },
+
+ /**
+ * Retrieve Navigator configuration values from
+ * the parent Calendar/CalendarGroup's config value.
+ *
+ * If it has not been set in the user provided configuration, the method will
+ * return the default value of the configuration property, as set in _DEFAULT_CFG
+ *
+ * @private
+ * @method __getCfg
+ * @param {String} Case sensitive property name.
+ * @param {Boolean} true, if the property is a string property, false if not.
+ * @return The value of the configuration property
+ */
+ __getCfg : function(prop, bIsStr) {
+ var DEF_CFG = YAHOO.widget.CalendarNavigator._DEFAULT_CFG;
+ var cfg = this.cal.cfg.getProperty("navigator");
+
+ if (bIsStr) {
+ return (cfg !== true && cfg.strings && cfg.strings[prop]) ? cfg.strings[prop] : DEF_CFG.strings[prop];
+ } else {
+ return (cfg !== true && cfg[prop]) ? cfg[prop] : DEF_CFG[prop];
+ }
+ },
+
+ /**
+ * Private flag, to identify MacOS
+ * @private
+ * @property __isMac
+ */
+ __isMac : (navigator.userAgent.toLowerCase().indexOf("macintosh") != -1)
+
+};
+
+YAHOO.register("calendar", YAHOO.widget.Calendar, {version: "2.6.0", build: "1321"});
diff --git a/lib/yui/carousel/README b/lib/yui/carousel/README
new file mode 100644
index 0000000000..5096af2a47
--- /dev/null
+++ b/lib/yui/carousel/README
@@ -0,0 +1,5 @@
+Carousel Release Notes
+
+*** version 2.6.0 ***
+
+* Initial release.
diff --git a/lib/yui/carousel/assets/ajax-loader.gif b/lib/yui/carousel/assets/ajax-loader.gif
new file mode 100644
index 0000000000..fe2cd23b3a
Binary files /dev/null and b/lib/yui/carousel/assets/ajax-loader.gif differ
diff --git a/lib/yui/carousel/assets/carousel-core.css b/lib/yui/carousel/assets/carousel-core.css
new file mode 100644
index 0000000000..bc1ff8ead1
--- /dev/null
+++ b/lib/yui/carousel/assets/carousel-core.css
@@ -0,0 +1,82 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.6.0
+*/
+.yui-carousel {
+ visibility: hidden;
+ overflow: hidden;
+ position: relative;
+}
+
+.yui-carousel.yui-carousel-visible {
+ visibility: visible;
+}
+
+.yui-carousel-content {
+ overflow: hidden;
+ position: relative;
+}
+
+.yui-carousel-element {
+ margin: 5px 0;
+ overflow: hidden;
+ padding: 0;
+ position: relative;
+ width: 32000px;
+ z-index: 1;
+}
+
+.yui-carousel-vertical .yui-carousel-element {
+ margin: 0 5px;
+}
+
+.yui-carousel-element li {
+ border: 1px solid #ccc;
+ float: left;
+ list-style: none;
+ margin: 1px;
+ overflow: hidden;
+ padding: 0;
+ text-align: center;
+ /* IE 6 & 7 fix - prevent DOM scroll for focussed elements. */
+ *float: none;
+ *display: inline-block;
+ *zoom: 1;
+ *display: inline;
+}
+
+.yui-carousel .yui-carousel-item-selected {
+ border: 1px dashed #000;
+ margin: 1px;
+}
+
+.yui-carousel-vertical {
+ height: 32000px;
+ margin: 0 5px;
+ width: auto;
+}
+
+.yui-carousel-vertical .yui-carousel-element li {
+ display: block;
+ float: none;
+}
+
+.yui-log .carousel {
+ background: #f2e886;
+}
+
+.yui-carousel-nav {
+ zoom: 1;
+}
+
+.yui-carousel-nav:after {
+ clear: both;
+ content: "";
+ display: block;
+}
+
+.yui-carousel-button-focus {
+ outline: 1px dotted #000;
+}
diff --git a/lib/yui/carousel/assets/skins/sam/carousel-skin.css b/lib/yui/carousel/assets/skins/sam/carousel-skin.css
new file mode 100644
index 0000000000..c095eece7e
--- /dev/null
+++ b/lib/yui/carousel/assets/skins/sam/carousel-skin.css
@@ -0,0 +1,119 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.6.0
+*/
+.yui-skin-sam .yui-carousel,
+.yui-skin-sam .yui-carousel-vertical {
+ border: 1px solid #808080;
+}
+
+.yui-skin-sam .yui-carousel-nav {
+ background: url(../../../../assets/skins/sam/sprite.png) repeat-x 0 0;
+ padding: 3px;
+ text-align: right;
+}
+
+.yui-skin-sam .yui-carousel-button {
+ background: url(../../../../assets/skins/sam/sprite.png) no-repeat 0 -600px;
+ float: right;
+ height: 19px;
+ margin: 5px;
+ overflow: hidden;
+ width: 40px;
+}
+
+.yui-skin-sam .yui-carousel-vertical .yui-carousel-button {
+ background-position: 0 -800px;
+}
+
+.yui-skin-sam .yui-carousel-button-disabled {
+ background-position: 0 -2000px;
+}
+
+.yui-skin-sam .yui-carousel-vertical .yui-carousel-button-disabled {
+ background-position: 0 -2100px;
+}
+
+.yui-skin-sam .yui-carousel-button input {
+ background-color: transparent;
+ border: 0;
+ cursor: pointer;
+ display: block;
+ height: 44px;
+ margin: -2px 0 0 -2px;
+ padding: 0 0 0 50px;
+}
+
+.yui-skin-sam span.yui-carousel-first-button {
+ background-position: 0px -550px;
+ margin-left: -100px;
+ margin-right: 50px;
+ *margin: 5px 5px 5px -90px;
+}
+
+.yui-skin-sam .yui-carousel-vertical span.yui-carousel-first-button {
+ background-position: 0px -750px;
+}
+
+.yui-skin-sam span.yui-carousel-first-button-disabled {
+ background-position: 0 -1950px;
+}
+
+.yui-skin-sam .yui-carousel-vertical span.yui-carousel-first-button-disabled {
+ background-position: 0 -2050px;
+}
+
+.yui-skin-sam .yui-carousel-nav ul {
+ float: right;
+ margin: 0;
+ margin-left: -220px;
+ margin-right: 100px;
+ *margin-left: -160px;
+ *margin-right: 0;
+ padding: 0;
+}
+
+.yui-skin-sam .yui-carousel-nav select {
+ position: relative;
+ *right: 50px;
+ top: 4px;
+}
+
+.yui-skin-sam .yui-carousel-vertical .yui-carousel-nav ul,
+.yui-skin-sam .yui-carousel-vertical .yui-carousel-nav select {
+ float: none;
+ margin: 0;
+ *zoom: 1;
+}
+
+.yui-skin-sam .yui-carousel-nav ul li {
+ float: left;
+ height: 19px;
+ list-style: none;
+}
+
+.yui-skin-sam .yui-carousel-nav ul:after {
+ clear: both;
+ content: "";
+ display: block;
+}
+
+.yui-skin-sam .yui-carousel-nav ul li a {
+ background: url(../../../../assets/skins/sam/sprite.png) no-repeat 0 -650px;
+ display: block;
+ height: 9px;
+ margin: 10px 0 0 5px;
+ overflow: hidden;
+ width: 9px;
+}
+
+.yui-skin-sam .yui-carousel-nav ul li a em {
+ left: -10000px;
+ position: absolute;
+}
+
+.yui-skin-sam .yui-carousel-nav ul li.yui-carousel-nav-page-selected a {
+ background-position: 0 -700px;
+}
diff --git a/lib/yui/carousel/assets/skins/sam/carousel.css b/lib/yui/carousel/assets/skins/sam/carousel.css
new file mode 100644
index 0000000000..30004b6f70
--- /dev/null
+++ b/lib/yui/carousel/assets/skins/sam/carousel.css
@@ -0,0 +1,7 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.6.0
+*/
+.yui-carousel{visibility:hidden;overflow:hidden;position:relative;}.yui-carousel.yui-carousel-visible{visibility:visible;}.yui-carousel-content{overflow:hidden;position:relative;}.yui-carousel-element{margin:5px 0;overflow:hidden;padding:0;position:relative;width:32000px;z-index:1;}.yui-carousel-vertical .yui-carousel-element{margin:0 5px;}.yui-carousel-element li{border:1px solid #ccc;float:left;list-style:none;margin:1px;overflow:hidden;padding:0;text-align:center;*float:none;*display:inline-block;*zoom:1;*display:inline;}.yui-carousel .yui-carousel-item-selected{border:1px dashed #000;margin:1px;}.yui-carousel-vertical{height:32000px;margin:0 5px;width:auto;}.yui-carousel-vertical .yui-carousel-element li{display:block;float:none;}.yui-log .carousel{background:#f2e886;}.yui-carousel-nav{zoom:1;}.yui-carousel-nav:after{clear:both;content:"";display:block;}.yui-carousel-button-focus{outline:1px dotted #000;}.yui-skin-sam .yui-carousel,.yui-skin-sam .yui-carousel-vertical{border:1px solid #808080;}.yui-skin-sam .yui-carousel-nav{background:url(../../../../assets/skins/sam/sprite.png) repeat-x 0 0;padding:3px;text-align:right;}.yui-skin-sam .yui-carousel-button{background:url(../../../../assets/skins/sam/sprite.png) no-repeat 0 -600px;float:right;height:19px;margin:5px;overflow:hidden;width:40px;}.yui-skin-sam .yui-carousel-vertical .yui-carousel-button{background-position:0 -800px;}.yui-skin-sam .yui-carousel-button-disabled{background-position:0 -2000px;}.yui-skin-sam .yui-carousel-vertical .yui-carousel-button-disabled{background-position:0 -2100px;}.yui-skin-sam .yui-carousel-button input{background-color:transparent;border:0;cursor:pointer;display:block;height:44px;margin:-2px 0 0 -2px;padding:0 0 0 50px;}.yui-skin-sam span.yui-carousel-first-button{background-position:0px -550px;margin-left:-100px;margin-right:50px;*margin:5px 5px 5px -90px;}.yui-skin-sam .yui-carousel-vertical span.yui-carousel-first-button{background-position:0px -750px;}.yui-skin-sam span.yui-carousel-first-button-disabled{background-position:0 -1950px;}.yui-skin-sam .yui-carousel-vertical span.yui-carousel-first-button-disabled{background-position:0 -2050px;}.yui-skin-sam .yui-carousel-nav ul{float:right;margin:0;margin-left:-220px;margin-right:100px;*margin-left:-160px;*margin-right:0;padding:0;}.yui-skin-sam .yui-carousel-nav select{position:relative;*right:50px;top:4px;}.yui-skin-sam .yui-carousel-vertical .yui-carousel-nav ul,.yui-skin-sam .yui-carousel-vertical .yui-carousel-nav select{float:none;margin:0;*zoom:1;}.yui-skin-sam .yui-carousel-nav ul li{float:left;height:19px;list-style:none;}.yui-skin-sam .yui-carousel-nav ul:after{clear:both;content:"";display:block;}.yui-skin-sam .yui-carousel-nav ul li a{background:url(../../../../assets/skins/sam/sprite.png) no-repeat 0 -650px;display:block;height:9px;margin:10px 0 0 5px;overflow:hidden;width:9px;}.yui-skin-sam .yui-carousel-nav ul li a em{left:-10000px;position:absolute;}.yui-skin-sam .yui-carousel-nav ul li.yui-carousel-nav-page-selected a{background-position:0 -700px;}
diff --git a/lib/yui/carousel/carousel-beta-debug.js b/lib/yui/carousel/carousel-beta-debug.js
new file mode 100644
index 0000000000..4113b941f5
--- /dev/null
+++ b/lib/yui/carousel/carousel-beta-debug.js
@@ -0,0 +1,2945 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.6.0
+*/
+/**
+ * The Carousel module provides a widget for browsing among a set of like
+ * objects represented pictorially.
+ *
+ * @module carousel
+ * @requires yahoo, dom, event, element
+ * @optional animation
+ * @namespace YAHOO.widget
+ * @title Carousel Widget
+ */
+(function () {
+
+ var WidgetName; // forward declaration
+
+ /**
+ * The Carousel widget.
+ *
+ * @class Carousel
+ * @extends YAHOO.util.Element
+ * @constructor
+ * @param el {HTMLElement | String} The HTML element that represents the
+ * the container that houses the Carousel.
+ * @param cfg {Object} (optional) The configuration values
+ */
+ YAHOO.widget.Carousel = function (el, cfg) {
+ YAHOO.log("Component creation", WidgetName);
+
+ this._navBtns = {};
+ this._pages = {};
+
+ YAHOO.widget.Carousel.superclass.constructor.call(this, el, cfg);
+ };
+
+ /*
+ * Private variables of the Carousel component
+ */
+
+ /* Some abbreviations to avoid lengthy typing and lookups. */
+ var Carousel = YAHOO.widget.Carousel,
+ Dom = YAHOO.util.Dom,
+ Event = YAHOO.util.Event,
+ JS = YAHOO.lang;
+
+ /**
+ * The widget name.
+ * @private
+ * @static
+ */
+ WidgetName = "Carousel";
+
+ /**
+ * The internal table of Carousel instances.
+ * @private
+ * @static
+ */
+ var instances = {};
+
+ /*
+ * Custom events of the Carousel component
+ */
+
+ /**
+ * @event afterScroll
+ * @description Fires when the Carousel has scrolled to the previous or
+ * next page. Passes back the index of the first and last visible items in
+ * the Carousel. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var afterScrollEvent = "afterScroll";
+
+ /**
+ * @event beforeHide
+ * @description Fires before the Carousel is hidden. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var beforeHideEvent = "beforeHide";
+
+ /**
+ * @event beforePageChange
+ * @description Fires when the Carousel is about to scroll to the previous
+ * or next page. Passes back the page number of the current page. Note
+ * that the first page number is zero. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var beforePageChangeEvent = "beforePageChange";
+
+ /**
+ * @event beforeScroll
+ * @description Fires when the Carousel is about to scroll to the previous
+ * or next page. Passes back the index of the first and last visible items
+ * in the Carousel and the direction (backward/forward) of the scroll. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var beforeScrollEvent = "beforeScroll";
+
+ /**
+ * @event beforeShow
+ * @description Fires when the Carousel is about to be shown. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var beforeShowEvent = "beforeShow";
+
+ /**
+ * @event blur
+ * @description Fires when the Carousel loses focus. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var blurEvent = "blur";
+
+ /**
+ * @event focus
+ * @description Fires when the Carousel gains focus. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var focusEvent = "focus";
+
+ /**
+ * @event hide
+ * @description Fires when the Carousel is hidden. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var hideEvent = "hide";
+
+ /**
+ * @event itemAdded
+ * @description Fires when an item has been added to the Carousel. Passes
+ * back the content of the item that would be added, the index at which the
+ * item would be added, and the event itself. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var itemAddedEvent = "itemAdded";
+
+ /**
+ * @event itemRemoved
+ * @description Fires when an item has been removed from the Carousel.
+ * Passes back the content of the item that would be removed, the index
+ * from which the item would be removed, and the event itself. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var itemRemovedEvent = "itemRemoved";
+
+ /**
+ * @event itemSelected
+ * @description Fires when an item has been selected in the Carousel.
+ * Passes back the index of the selected item in the Carousel. Note, that
+ * the index begins from zero. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var itemSelectedEvent = "itemSelected";
+
+ /**
+ * @event loadItems
+ * @description Fires when the Carousel needs more items to be loaded for
+ * displaying them. Passes back the first and last visible items in the
+ * Carousel, and the number of items needed to be loaded. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var loadItemsEvent = "loadItems";
+
+ /**
+ * @event navigationStateChange
+ * @description Fires when the state of either one of the navigation
+ * buttons are changed from enabled to disabled or vice versa. Passes back
+ * the state (true/false) of the previous and next buttons. The value true
+ * signifies the button is enabled, false signifies disabled. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var navigationStateChangeEvent = "navigationStateChange";
+
+ /**
+ * @event pageChange
+ * @description Fires after the Carousel has scrolled to the previous or
+ * next page. Passes back the page number of the current page. Note
+ * that the first page number is zero. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var pageChangeEvent = "pageChange";
+
+ /**
+ * @event render
+ * @description Fires when the Carousel is rendered. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var renderEvent = "render";
+
+ /**
+ * @event show
+ * @description Fires when the Carousel is shown. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var showEvent = "show";
+
+ /**
+ * @event startAutoPlay
+ * @description Fires when the auto play has started in the Carousel. See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var startAutoPlayEvent = "startAutoPlay";
+
+ /**
+ * @event stopAutoPlay
+ * @description Fires when the auto play has been stopped in the Carousel.
+ * See
+ * Element.addListener
+ * for more information on listening for this event.
+ * @type YAHOO.util.CustomEvent
+ */
+ var stopAutoPlayEvent = "stopAutoPlay";
+
+ /*
+ * Private helper functions used by the Carousel component
+ */
+
+ /**
+ * Automatically scroll the contents of the Carousel.
+ * @method autoScroll
+ * @private
+ */
+ function autoScroll() {
+ var currIndex = this._firstItem,
+ index;
+
+ if (currIndex >= this.get("numItems") - 1) {
+ if (this.get("isCircular")) {
+ index = 0;
+ } else {
+ this.stopAutoPlay();
+ }
+ } else {
+ index = currIndex + this.get("numVisible");
+ }
+ this.scrollTo.call(this, index);
+ }
+
+ /**
+ * Create an element, set its class name and optionally install the element
+ * to its parent.
+ * @method createElement
+ * @param el {String} The element to be created
+ * @param attrs {Object} Configuration of parent, class and id attributes.
+ * If the content is specified, it is inserted after creation of the
+ * element. The content can also be an HTML element in which case it would
+ * be appended as a child node of the created element.
+ * @private
+ */
+ function createElement(el, attrs) {
+ var newEl = document.createElement(el);
+
+ attrs = attrs || {};
+ if (attrs.className) {
+ Dom.addClass(newEl, attrs.className);
+ }
+
+ if (attrs.parent) {
+ attrs.parent.appendChild(newEl);
+ }
+
+ if (attrs.id) {
+ newEl.setAttribute("id", attrs.id);
+ }
+
+ if (attrs.content) {
+ if (attrs.content.nodeName) {
+ newEl.appendChild(attrs.content);
+ } else {
+ newEl.innerHTML = attrs.content;
+ }
+ }
+
+ return newEl;
+ }
+
+ /**
+ * Get the computed style of an element.
+ *
+ * @method getStyle
+ * @param el {HTMLElement} The element for which the style needs to be
+ * returned.
+ * @param style {String} The style attribute
+ * @param type {String} "int", "float", etc. (defaults to int)
+ * @private
+ */
+ function getStyle(el, style, type) {
+ var value;
+
+ function getStyleIntVal(el, style) {
+ var val;
+
+ val = parseInt(Dom.getStyle(el, style), 10);
+ return JS.isNumber(val) ? val : 0;
+ }
+
+ function getStyleFloatVal(el, style) {
+ var val;
+
+ val = parseFloat(Dom.getStyle(el, style));
+ return JS.isNumber(val) ? val : 0;
+ }
+
+ if (typeof type == "undefined") {
+ type = "int";
+ }
+
+ switch (style) {
+ case "height":
+ value = el.offsetHeight;
+ if (value > 0) {
+ value += getStyleIntVal(el, "marginTop") +
+ getStyleIntVal(el, "marginBottom");
+ } else {
+ value = getStyleFloatVal(el, "height") +
+ getStyleIntVal(el, "marginTop") +
+ getStyleIntVal(el, "marginBottom") +
+ getStyleIntVal(el, "borderTopWidth") +
+ getStyleIntVal(el, "borderBottomWidth") +
+ getStyleIntVal(el, "paddingTop") +
+ getStyleIntVal(el, "paddingBottom");
+ }
+ break;
+ case "width":
+ value = el.offsetWidth;
+ if (value > 0) {
+ value += getStyleIntVal(el, "marginLeft") +
+ getStyleIntVal(el, "marginRight");
+ } else {
+ value = getStyleFloatVal(el, "width") +
+ getStyleIntVal(el, "marginLeft") +
+ getStyleIntVal(el, "marginRight") +
+ getStyleIntVal(el, "borderLeftWidth") +
+ getStyleIntVal(el, "borderRightWidth") +
+ getStyleIntVal(el, "paddingLeft") +
+ getStyleIntVal(el, "paddingRight");
+ }
+ break;
+ default:
+ if (type == "int") {
+ value = getStyleIntVal(el, style);
+ // XXX: Safari calculates incorrect marginRight for an element
+ // which has its parent element style set to overflow: hidden
+ // https://bugs.webkit.org/show_bug.cgi?id=13343
+ // Let us assume marginLeft == marginRight
+ if (style == "marginRight" && YAHOO.env.ua.webkit) {
+ value = getStyleIntVal(el, "marginLeft");
+ }
+ } else if (type == "float") {
+ value = getStyleFloatVal(el, style);
+ } else {
+ value = Dom.getStyle(el, style);
+ }
+ break;
+ }
+
+ return value;
+ }
+
+ /**
+ * Compute and return the height or width of a single Carousel item
+ * depending upon the orientation.
+ *
+ * @method getCarouselItemSize
+ * @param which {String} "height" or "width" to be returned. If this is
+ * passed explicitly, the calculated size is not cached.
+ * @private
+ */
+ function getCarouselItemSize(which) {
+ var child,
+ size = 0,
+ vertical = false;
+
+ if (this._itemsTable.numItems === 0) {
+ return 0;
+ }
+
+ if (typeof which == "undefined") {
+ if (this._itemsTable.size > 0) {
+ return this._itemsTable.size;
+ }
+ }
+
+ if (JS.isUndefined(this._itemsTable.items[0])) {
+ return 0;
+ }
+
+ child = Dom.get(this._itemsTable.items[0].id);
+
+ if (typeof which == "undefined") {
+ vertical = this.get("isVertical");
+ } else {
+ vertical = which == "height";
+ }
+
+ if (vertical) {
+ size = getStyle(child, "height");
+ } else {
+ size = getStyle(child, "width");
+ }
+
+ if (typeof which == "undefined") {
+ this._itemsTable.size = size; // save the size for later
+ }
+
+ return size;
+ }
+
+ /**
+ * Return the scrolling offset size given the number of elements to
+ * scroll.
+ *
+ * @method getScrollOffset
+ * @param delta {Number} The delta number of elements to scroll by.
+ * @private
+ */
+ function getScrollOffset(delta) {
+ var itemSize = 0,
+ size = 0;
+
+ itemSize = getCarouselItemSize.call(this);
+ size = itemSize * delta;
+
+ // XXX: really, when the orientation is vertical, the scrolling
+ // is not exactly the number of elements into element size.
+ if (this.get("isVertical")) {
+ size -= delta;
+ }
+
+ return size;
+ }
+
+ /**
+ * The load the required set of items that are needed for display.
+ *
+ * @method loadItems
+ * @private
+ */
+ function loadItems() {
+ var first = this.get("firstVisible"),
+ last = 0,
+ numItems = this.get("numItems"),
+ numVisible = this.get("numVisible"),
+ reveal = this.get("revealAmount");
+
+ last = first + numVisible - 1 + (reveal ? 1 : 0);
+ last = last > numItems - 1 ? numItems - 1 : last;
+
+ if (!this.getItem(first) || !this.getItem(last)) {
+ this.fireEvent(loadItemsEvent, {
+ ev: loadItemsEvent,
+ first: first, last: last,
+ num: last - first
+ });
+ }
+ }
+
+ /**
+ * Scroll the Carousel by a page backward.
+ *
+ * @method scrollPageBackward
+ * @param {Event} ev The event object
+ * @param {Object} obj The context object
+ * @private
+ */
+ function scrollPageBackward(ev, obj) {
+ obj.scrollPageBackward();
+ Event.preventDefault(ev);
+ }
+
+ /**
+ * Scroll the Carousel by a page forward.
+ *
+ * @method scrollPageForward
+ * @param {Event} ev The event object
+ * @param {Object} obj The context object
+ * @private
+ */
+ function scrollPageForward(ev, obj) {
+ obj.scrollPageForward();
+ Event.preventDefault(ev);
+ }
+
+ /**
+ * Set the selected item.
+ *
+ * @method setItemSelection
+ * @param {Number} newposition The index of the new position
+ * @param {Number} oldposition The index of the previous position
+ * @private
+ */
+ function setItemSelection(newposition, oldposition) {
+ var backwards,
+ cssClass = this.CLASSES,
+ el,
+ firstItem = this._firstItem,
+ isCircular = this.get("isCircular"),
+ numItems = this.get("numItems"),
+ numVisible = this.get("numVisible"),
+ position = oldposition,
+ sentinel = firstItem + numVisible - 1;
+
+ backwards = numVisible > 1 && !isCircular && position > newposition;
+
+ if (position >= 0 && position < numItems) {
+ if (!JS.isUndefined(this._itemsTable.items[position])) {
+ el = Dom.get(this._itemsTable.items[position].id);
+ if (el) {
+ Dom.removeClass(el, cssClass.SELECTED_ITEM);
+ }
+ }
+ }
+
+ if (JS.isNumber(newposition)) {
+ newposition = parseInt(newposition, 10);
+ newposition = JS.isNumber(newposition) ? newposition : 0;
+ } else {
+ newposition = firstItem;
+ }
+
+ if (JS.isUndefined(this._itemsTable.items[newposition])) {
+ this.scrollTo(newposition); // still loading the item
+ }
+
+ if (!JS.isUndefined(this._itemsTable.items[newposition])) {
+ el = Dom.get(this._itemsTable.items[newposition].id);
+ if (el) {
+ Dom.addClass(el, cssClass.SELECTED_ITEM);
+ }
+ }
+
+ if (newposition < firstItem || newposition > sentinel) {
+ // out of focus
+ if (backwards) {
+ this.scrollTo(firstItem - numVisible, true);
+ } else {
+ this.scrollTo(newposition);
+ }
+ }
+ }
+
+ /**
+ * Fire custom events for enabling/disabling navigation elements.
+ *
+ * @method syncNavigation
+ * @private
+ */
+ function syncNavigation() {
+ var attach = false,
+ cssClass = this.CLASSES,
+ i,
+ navigation,
+ sentinel;
+
+ navigation = this.get("navigation");
+ sentinel = this._firstItem + this.get("numVisible");
+
+ if (navigation.prev) {
+ if (this._firstItem === 0) {
+ if (!this.get("isCircular")) {
+ Event.removeListener(navigation.prev, "click",
+ scrollPageBackward);
+ Dom.addClass(navigation.prev, cssClass.FIRST_NAV_DISABLED);
+ for (i = 0; i < this._navBtns.prev.length; i++) {
+ this._navBtns.prev[i].setAttribute("disabled", "true");
+ }
+ this._prevEnabled = false;
+ } else {
+ attach = !this._prevEnabled;
+ }
+ } else {
+ attach = !this._prevEnabled;
+ }
+
+ if (attach) {
+ Event.on(navigation.prev, "click", scrollPageBackward, this);
+ Dom.removeClass(navigation.prev, cssClass.FIRST_NAV_DISABLED);
+ for (i = 0; i < this._navBtns.prev.length; i++) {
+ this._navBtns.prev[i].removeAttribute("disabled");
+ }
+ this._prevEnabled = true;
+ }
+ }
+
+ attach = false;
+ if (navigation.next) {
+ if (sentinel >= this.get("numItems")) {
+ if (!this.get("isCircular")) {
+ Event.removeListener(navigation.next, "click",
+ scrollPageForward);
+ Dom.addClass(navigation.next, cssClass.DISABLED);
+ for (i = 0; i < this._navBtns.next.length; i++) {
+ this._navBtns.next[i].setAttribute("disabled", "true");
+ }
+ this._nextEnabled = false;
+ } else {
+ attach = !this._nextEnabled;
+ }
+ } else {
+ attach = !this._nextEnabled;
+ }
+
+ if (attach) {
+ Event.on(navigation.next, "click", scrollPageForward, this);
+ Dom.removeClass(navigation.next, cssClass.DISABLED);
+ for (i = 0; i < this._navBtns.next.length; i++) {
+ this._navBtns.next[i].removeAttribute("disabled");
+ }
+ this._nextEnabled = true;
+ }
+ }
+
+ this.fireEvent(navigationStateChangeEvent,
+ { next: this._nextEnabled, prev: this._prevEnabled });
+ }
+
+ /**
+ * Fire custom events for synchronizing the DOM.
+ *
+ * @method syncUI
+ * @param {Object} o The item that needs to be added or removed
+ * @private
+ */
+ function syncUI(o) {
+ var el, i, item, num, oel, pos, sibling;
+
+ if (!JS.isObject(o)) {
+ return;
+ }
+
+ switch (o.ev) {
+ case itemAddedEvent:
+ pos = JS.isUndefined(o.pos) ? this._itemsTable.numItems-1 : o.pos;
+ if (!JS.isUndefined(this._itemsTable.items[pos])) {
+ item = this._itemsTable.items[pos];
+ if (item && !JS.isUndefined(item.id)) {
+ oel = Dom.get(item.id);
+ }
+ }
+ if (!oel) {
+ el = this._createCarouselItem({
+ className : item.className,
+ content : item.item,
+ id : item.id
+ });
+ if (JS.isUndefined(o.pos)) {
+ if (!JS.isUndefined(this._itemsTable.loading[pos])) {
+ oel = this._itemsTable.loading[pos];
+ }
+ if (oel) {
+ this._carouselEl.replaceChild(el, oel);
+ } else {
+ this._carouselEl.appendChild(el);
+ }
+ } else {
+ if (!JS.isUndefined(this._itemsTable.items[o.pos + 1])) {
+ sibling = Dom.get(this._itemsTable.items[o.pos + 1].id);
+ }
+ if (sibling) {
+ this._carouselEl.insertBefore(el, sibling);
+ } else {
+ YAHOO.log("Unable to find sibling","error",WidgetName);
+ }
+ }
+ } else {
+ if (JS.isUndefined(o.pos)) {
+ if (!Dom.isAncestor(this._carouselEl, oel)) {
+ this._carouselEl.appendChild(oel);
+ }
+ } else {
+ if (!Dom.isAncestor(this._carouselEl, oel)) {
+ if (!JS.isUndefined(this._itemsTable.items[o.pos+1])) {
+ this._carouselEl.insertBefore(oel, Dom.get(
+ this._itemsTable.items[o.pos+1].id));
+ }
+ }
+ }
+ }
+
+ if (this._recomputeSize) {
+ this._setClipContainerSize();
+ }
+ break;
+ case itemRemovedEvent:
+ num = this.get("numItems");
+ item = o.item;
+ pos = o.pos;
+
+ if (item && (el = Dom.get(item.id))) {
+ if (el && Dom.isAncestor(this._carouselEl, el)) {
+ Event.purgeElement(el, true);
+ this._carouselEl.removeChild(el);
+ }
+
+ if (this.get("selectedItem") == pos) {
+ pos = pos >= num ? num - 1 : pos;
+ this.set("selectedItem", pos);
+ }
+ } else {
+ YAHOO.log("Unable to find item", "warn", WidgetName);
+ }
+ break;
+ case loadItemsEvent:
+ for (i = o.first; i <= o.last; i++) {
+ el = this._createCarouselItem({
+ content : this.CONFIG.ITEM_LOADING,
+ id : Dom.generateId()
+ });
+ if (el) {
+ if (!JS.isUndefined(this._itemsTable.items[o.last + 1])) {
+ sibling = Dom.get(this._itemsTable.items[o.last+1].id);
+ if (sibling) {
+ this._carouselEl.insertBefore(el, sibling);
+ } else {
+ YAHOO.log("Unable to find sibling", "error",
+ WidgetName);
+ }
+ } else {
+ this._carouselEl.appendChild(el);
+ }
+ }
+ this._itemsTable.loading[i] = el;
+ }
+ break;
+ }
+ }
+
+ /*
+ * Static members and methods of the Carousel component
+ */
+
+ /**
+ * Return the appropriate Carousel object based on the id associated with
+ * the Carousel element or false if none match.
+ * @method getById
+ * @public
+ * @static
+ */
+ Carousel.getById = function (id) {
+ return instances[id] ? instances[id] : false;
+ };
+
+ YAHOO.extend(Carousel, YAHOO.util.Element, {
+
+ /*
+ * Internal variables used within the Carousel component
+ */
+
+ /**
+ * The Carousel element.
+ *
+ * @property _carouselEl
+ * @private
+ */
+ _carouselEl: null,
+
+ /**
+ * The Carousel clipping container element.
+ *
+ * @property _clipEl
+ * @private
+ */
+ _clipEl: null,
+
+ /**
+ * The current first index of the Carousel.
+ *
+ * @property _firstItem
+ * @private
+ */
+ _firstItem: 0,
+
+ /**
+ * Is the animation still in progress?
+ *
+ * @property _isAnimationInProgress
+ * @private
+ */
+ _isAnimationInProgress: false,
+
+ /**
+ * The table of items in the Carousel.
+ * The numItems is the number of items in the Carousel, items being the
+ * array of items in the Carousel. The size is the size of a single
+ * item in the Carousel. It is cached here for efficiency (to avoid
+ * computing the size multiple times).
+ *
+ * @property _itemsTable
+ * @private
+ */
+ _itemsTable: null,
+
+ /**
+ * The Carousel navigation buttons.
+ *
+ * @property _navBtns
+ * @private
+ */
+ _navBtns: null,
+
+ /**
+ * The Carousel navigation.
+ *
+ * @property _navEl
+ * @private
+ */
+ _navEl: null,
+
+ /**
+ * Status of the next navigation item.
+ *
+ * @property _nextEnabled
+ * @private
+ */
+ _nextEnabled: true,
+
+ /**
+ * The Carousel pages structure.
+ * This is an object of the total number of pages and the current page.
+ *
+ * @property _pages
+ * @private
+ */
+ _pages: null,
+
+ /**
+ * Status of the previous navigation item.
+ *
+ * @property _prevEnabled
+ * @private
+ */
+ _prevEnabled: true,
+
+ /**
+ * Whether the Carousel size needs to be recomputed or not?
+ *
+ * @property _recomputeSize
+ * @private
+ */
+ _recomputeSize: true,
+
+ /*
+ * CSS classes used by the Carousel component
+ */
+
+ CLASSES: {
+
+ /**
+ * The class name of the Carousel navigation buttons.
+ *
+ * @property BUTTON
+ * @default "yui-carousel-button"
+ */
+ BUTTON: "yui-carousel-button",
+
+ /**
+ * The class name of the Carousel element.
+ *
+ * @property CAROUSEL
+ * @default "yui-carousel"
+ */
+ CAROUSEL: "yui-carousel",
+
+ /**
+ * The class name of the container of the items in the Carousel.
+ *
+ * @property CAROUSEL_EL
+ * @default "yui-carousel-element"
+ */
+ CAROUSEL_EL: "yui-carousel-element",
+
+ /**
+ * The class name of the Carousel's container element.
+ *
+ * @property CONTAINER
+ * @default "yui-carousel-container"
+ */
+ CONTAINER: "yui-carousel-container",
+
+ /**
+ * The class name of the Carousel's container element.
+ *
+ * @property CONTENT
+ * @default "yui-carousel-content"
+ */
+ CONTENT: "yui-carousel-content",
+
+ /**
+ * The class name of a disabled navigation button.
+ *
+ * @property DISABLED
+ * @default "yui-carousel-button-disabled"
+ */
+ DISABLED: "yui-carousel-button-disabled",
+
+ /**
+ * The class name of the first Carousel navigation button.
+ *
+ * @property FIRST_NAV
+ * @default " yui-carousel-first-button"
+ */
+ FIRST_NAV: " yui-carousel-first-button",
+
+ /**
+ * The class name of a first disabled navigation button.
+ *
+ * @property FIRST_NAV_DISABLED
+ * @default "yui-carousel-first-button-disabled"
+ */
+ FIRST_NAV_DISABLED: "yui-carousel-first-button-disabled",
+
+ /**
+ * The class name of a first page element.
+ *
+ * @property FIRST_PAGE
+ * @default "yui-carousel-nav-first-page"
+ */
+ FIRST_PAGE: "yui-carousel-nav-first-page",
+
+ /**
+ * The class name of the Carousel navigation button that has focus.
+ *
+ * @property FOCUSSED_BUTTON
+ * @default "yui-carousel-button-focus"
+ */
+ FOCUSSED_BUTTON: "yui-carousel-button-focus",
+
+ /**
+ * The class name of a horizontally oriented Carousel.
+ *
+ * @property HORIZONTAL
+ * @default "yui-carousel-horizontal"
+ */
+ HORIZONTAL: "yui-carousel-horizontal",
+
+ /**
+ * The navigation element container class name.
+ *
+ * @property NAVIGATION
+ * @default "yui-carousel-nav"
+ */
+ NAVIGATION: "yui-carousel-nav",
+
+ /**
+ * The class name of the next navigation link. This variable is not
+ * only used for styling, but also for identifying the link within
+ * the Carousel container.
+ *
+ * @property NEXT_PAGE
+ * @default "yui-carousel-next"
+ */
+ NEXT_PAGE: "yui-carousel-next",
+
+ /**
+ * The class name for the navigation container for prev/next.
+ *
+ * @property NAV_CONTAINER
+ * @default "yui-carousel-buttons"
+ */
+ NAV_CONTAINER: "yui-carousel-buttons",
+
+ /**
+ * The class name of the previous navigation link. This variable
+ * is not only used for styling, but also for identifying the link
+ * within the Carousel container.
+ *
+ * @property PREV_PAGE
+ * @default "yui-carousel-prev"
+ */
+ PREV_PAGE: "yui-carousel-prev",
+
+ /**
+ * The class name of the selected item.
+ *
+ * @property SELECTED_ITEM
+ * @default "yui-carousel-item-selected"
+ */
+ SELECTED_ITEM: "yui-carousel-item-selected",
+
+ /**
+ * The class name of the selected paging navigation.
+ *
+ * @property SELECTED_NAV
+ * @default "yui-carousel-nav-page-selected"
+ */
+ SELECTED_NAV: "yui-carousel-nav-page-selected",
+
+ /**
+ * The class name of a vertically oriented Carousel.
+ *
+ * @property VERTICAL
+ * @default "yui-carousel-vertical"
+ */
+ VERTICAL: "yui-carousel-vertical",
+
+ /**
+ * The class name of the (vertical) Carousel's container element.
+ *
+ * @property VERTICAL_CONTAINER
+ * @default "yui-carousel-vertical-container"
+ */
+ VERTICAL_CONTAINER: "yui-carousel-vertical-container",
+
+ /**
+ * The class name of a visible Carousel.
+ *
+ * @property VISIBLE
+ * @default "yui-carousel-visible"
+ */
+ VISIBLE: "yui-carousel-visible"
+
+ },
+
+ /*
+ * Configuration attributes for configuring the Carousel component
+ */
+
+ CONFIG: {
+
+ /**
+ * The offset of the first visible item in the Carousel.
+ *
+ * @property FIRST_VISIBLE
+ * @default 0
+ */
+ FIRST_VISIBLE: 0,
+
+ /**
+ * The element to be used as the progress indicator when the item
+ * is still being loaded.
+ *
+ * @property ITEM_LOADING
+ * @default The progress indicator (spinner) image
+ */
+ ITEM_LOADING: "",
+
+ /**
+ * The tag name of the Carousel item.
+ *
+ * @property ITEM_TAG_NAME
+ * @default "LI"
+ */
+ ITEM_TAG_NAME: "LI",
+
+ /**
+ * The maximum number of pager buttons allowed beyond which the UI
+ * of the pager would be a drop-down of pages instead of buttons.
+ *
+ * @property MAX_PAGER_BUTTONS
+ * @default 5
+ */
+ MAX_PAGER_BUTTONS: 5,
+
+ /**
+ * The minimum width of the Carousel container to support the
+ * navigation buttons.
+ *
+ * @property MIN_WIDTH
+ * @default 99
+ */
+ MIN_WIDTH: 99,
+
+ /**
+ * The number of visible items in the Carousel.
+ *
+ * @property NUM_VISIBLE
+ * @default 3
+ */
+ NUM_VISIBLE: 3,
+
+ /**
+ * The tag name of the Carousel.
+ *
+ * @property TAG_NAME
+ * @default "OL"
+ */
+ TAG_NAME: "OL"
+
+ },
+
+ /*
+ * Internationalizable strings in the Carousel component
+ */
+
+ STRINGS: {
+
+ /**
+ * The next navigation button name/text.
+ *
+ * @property NEXT_BUTTON_TEXT
+ * @default "Next Page"
+ */
+ NEXT_BUTTON_TEXT: "Next Page",
+
+ /**
+ * The prefix text for the pager in case the UI is a drop-down.
+ *
+ * @property PAGER_PREFIX_TEXT
+ * @default "Go to page "
+ */
+ PAGER_PREFIX_TEXT: "Go to page ",
+
+ /**
+ * The previous navigation button name/text.
+ *
+ * @property PREVIOUS_BUTTON_TEXT
+ * @default "Previous Page"
+ */
+ PREVIOUS_BUTTON_TEXT: "Previous Page"
+
+ },
+
+ /*
+ * Public methods of the Carousel component
+ */
+
+ /**
+ * Insert or append an item to the Carousel.
+ *
+ * @method addItem
+ * @public
+ * @param item {String | Object | HTMLElement} The item to be appended
+ * to the Carousel. If the parameter is a string, it is assumed to be
+ * the content of the newly created item. If the parameter is an
+ * object, it is assumed to supply the content and an optional class
+ * and an optional id of the newly created item.
+ * @param index {Number} optional The position to where in the list
+ * (starts from zero).
+ * @return {Boolean} Return true on success, false otherwise
+ */
+ addItem: function (item, index) {
+ var className, content, el, elId, numItems = this.get("numItems");
+
+ if (!item) {
+ return false;
+ }
+
+ if (JS.isString(item) || item.nodeName) {
+ content = item.nodeName ? item.innerHTML : item;
+ } else if (JS.isObject(item)) {
+ content = item.content;
+ } else {
+ YAHOO.log("Invalid argument to addItem", "error", WidgetName);
+ return false;
+ }
+
+ className = item.className || "";
+ elId = item.id ? item.id : Dom.generateId();
+
+ if (JS.isUndefined(index)) {
+ this._itemsTable.items.push({
+ item : content,
+ className : className,
+ id : elId
+ });
+ } else {
+ if (index < 0 || index >= numItems) {
+ YAHOO.log("Index out of bounds", "error", WidgetName);
+ return false;
+ }
+ this._itemsTable.items.splice(index, 0, {
+ item : content,
+ className : className,
+ id : elId
+ });
+ }
+ this._itemsTable.numItems++;
+
+ if (numItems < this._itemsTable.items.length) {
+ this.set("numItems", this._itemsTable.items.length);
+ }
+
+ this.fireEvent(itemAddedEvent, { pos: index, ev: itemAddedEvent });
+
+ return true;
+ },
+
+ /**
+ * Insert or append multiple items to the Carousel.
+ *
+ * @method addItems
+ * @public
+ * @param items {Array} An array of items to be added with each item
+ * representing an item, index pair [{item, index}, ...]
+ * @return {Boolean} Return true on success, false otherwise
+ */
+ addItems: function (items) {
+ var i, n, rv = true;
+
+ if (!JS.isArray(items)) {
+ return false;
+ }
+
+ for (i = 0, n = items.length; i < n; i++) {
+ if (this.addItem(items[i][0], items[i][1]) === false) {
+ rv = false;
+ }
+ }
+
+ return rv;
+ },
+
+ /**
+ * Remove focus from the Carousel.
+ *
+ * @method blur
+ * @public
+ */
+ blur: function () {
+ this._carouselEl.blur();
+ this.fireEvent(blurEvent);
+ },
+
+ /**
+ * Clears the items from Carousel.
+ *
+ * @method clearItems
+ * public
+ */
+ clearItems: function () {
+ var n = this.get("numItems");
+
+ while (n > 0) {
+ this.removeItem(0);
+ n--;
+ }
+ },
+
+ /**
+ * Set focus on the Carousel.
+ *
+ * @method focus
+ * @public
+ */
+ focus: function () {
+ var selItem,
+ numVisible,
+ selectOnScroll,
+ selected,
+ first,
+ last,
+ isSelectionInvisible,
+ focusEl,
+ itemsTable;
+
+ if (this._isAnimationInProgress) {
+ // this messes up real bad!
+ return;
+ }
+
+ selItem = this.get("selectedItem");
+ numVisible = this.get("numVisible");
+ selectOnScroll = this.get("selectOnScroll");
+ selected = this.getItem(selItem);
+ first = this.get("firstVisible");
+ last = first + numVisible - 1;
+ isSelectionInvisible = (selItem < first || selItem > last);
+ focusEl = (selected && selected.id) ?
+ Dom.get(selected.id) : null;
+ itemsTable = this._itemsTable;
+
+ if (!selectOnScroll && isSelectionInvisible) {
+ focusEl = (itemsTable && itemsTable.items &&
+ itemsTable.items[first]) ?
+ Dom.get(itemsTable.items[first].id) : null;
+ }
+
+ if (focusEl) {
+ try {
+ focusEl.focus();
+ } catch (ex) {
+ // ignore focus errors
+ }
+ }
+
+ this.fireEvent(focusEvent);
+ },
+
+ /**
+ * Hide the Carousel.
+ *
+ * @method hide
+ * @public
+ */
+ hide: function () {
+ if (this.fireEvent(beforeHideEvent) !== false) {
+ this.removeClass(this.CLASSES.VISIBLE);
+ this.fireEvent(hideEvent);
+ }
+ },
+
+ /**
+ * Initialize the Carousel.
+ *
+ * @method init
+ * @public
+ * @param el {HTMLElement | String} The html element that represents
+ * the Carousel container.
+ * @param attrs {Object} The set of configuration attributes for
+ * creating the Carousel.
+ */
+ init: function (el, attrs) {
+ var elId = el, // save for a rainy day
+ parse = false;
+
+ if (!el) {
+ YAHOO.log(el + " is neither an HTML element, nor a string",
+ "error", WidgetName);
+ return;
+ }
+
+ this._itemsTable = { loading: {}, numItems: 0, items: [], size: 0 };
+ YAHOO.log("Component initialization", WidgetName);
+
+ if (JS.isString(el)) {
+ el = Dom.get(el);
+ } else if (!el.nodeName) {
+ YAHOO.log(el + " is neither an HTML element, nor a string",
+ "error", WidgetName);
+ return;
+ }
+
+ if (el) {
+ if (!el.id) { // in case the HTML element is passed
+ el.setAttribute("id", Dom.generateId());
+ }
+ this._parseCarousel(el);
+ parse = true;
+ } else {
+ el = this._createCarousel(elId);
+ }
+ elId = el.id;
+
+ Carousel.superclass.init.call(this, el, attrs);
+
+ this.initEvents();
+
+ if (parse) {
+ this._parseCarouselItems();
+ }
+
+ if (!attrs || typeof attrs.isVertical == "undefined") {
+ this.set("isVertical", false);
+ }
+
+ this._parseCarouselNavigation(el);
+ this._navEl = this._setupCarouselNavigation();
+
+ instances[elId] = this;
+
+ loadItems.call(this);
+ },
+
+ /**
+ * Initialize the configuration attributes used to create the Carousel.
+ *
+ * @method initAttributes
+ * @public
+ * @param attrs {Object} The set of configuration attributes for
+ * creating the Carousel.
+ */
+ initAttributes: function (attrs) {
+ attrs = attrs || {};
+ Carousel.superclass.initAttributes.call(this, attrs);
+
+ /**
+ * @attribute currentPage
+ * @description The current page number (read-only.)
+ * @type Number
+ */
+ this.setAttributeConfig("currentPage", {
+ readOnly : true,
+ value : 0
+ });
+
+ /**
+ * @attribute firstVisible
+ * @description The index to start the Carousel from (indexes begin
+ * from zero)
+ * @default 0
+ * @type Number
+ */
+ this.setAttributeConfig("firstVisible", {
+ method : this._setFirstVisible,
+ validator : this._validateFirstVisible,
+ value : attrs.firstVisible || this.CONFIG.FIRST_VISIBLE
+ });
+
+ /**
+ * @attribute selectOnScroll
+ * @description Set this to true to automatically set focus to
+ * follow scrolling in the Carousel.
+ * @default true
+ * @type Boolean
+ */
+ this.setAttributeConfig("selectOnScroll", {
+ validator : JS.isBoolean,
+ value : attrs.selectOnScroll || true
+ });
+
+ /**
+ * @attribute numVisible
+ * @description The number of visible items in the Carousel's
+ * viewport.
+ * @default 3
+ * @type Number
+ */
+ this.setAttributeConfig("numVisible", {
+ method : this._setNumVisible,
+ validator : this._validateNumVisible,
+ value : attrs.numVisible || this.CONFIG.NUM_VISIBLE
+ });
+
+ /**
+ * @attribute numItems
+ * @description The number of items in the Carousel.
+ * @type Number
+ */
+ this.setAttributeConfig("numItems", {
+ method : this._setNumItems,
+ validator : this._validateNumItems,
+ value : this._itemsTable.numItems
+ });
+
+ /**
+ * @attribute scrollIncrement
+ * @description The number of items to scroll by for arrow keys.
+ * @default 1
+ * @type Number
+ */
+ this.setAttributeConfig("scrollIncrement", {
+ validator : this._validateScrollIncrement,
+ value : attrs.scrollIncrement || 1
+ });
+
+ /**
+ * @attribute selectedItem
+ * @description The index of the selected item.
+ * @type Number
+ */
+ this.setAttributeConfig("selectedItem", {
+ method : this._setSelectedItem,
+ validator : JS.isNumber,
+ value : 0
+ });
+
+ /**
+ * @attribute revealAmount
+ * @description The percentage of the item to be revealed on each
+ * side of the Carousel (before and after the first and last item
+ * in the Carousel's viewport.)
+ * @default 0
+ * @type Number
+ */
+ this.setAttributeConfig("revealAmount", {
+ method : this._setRevealAmount,
+ validator : this._validateRevealAmount,
+ value : attrs.revealAmount || 0
+ });
+
+ /**
+ * @attribute isCircular
+ * @description Set this to true to wrap scrolling of the contents
+ * in the Carousel.
+ * @default false
+ * @type Boolean
+ */
+ this.setAttributeConfig("isCircular", {
+ validator : JS.isBoolean,
+ value : attrs.isCircular || false
+ });
+
+ /**
+ * @attribute isVertical
+ * @description True if the orientation of the Carousel is vertical
+ * @default false
+ * @type Boolean
+ */
+ this.setAttributeConfig("isVertical", {
+ method : this._setOrientation,
+ validator : JS.isBoolean,
+ value : attrs.isVertical || false
+ });
+
+ /**
+ * @attribute navigation
+ * @description The set of navigation controls for Carousel
+ * @default
+ * { prev: null, // the previous navigation element
+ * next: null } // the next navigation element
+ * @type Object
+ */
+ this.setAttributeConfig("navigation", {
+ method : this._setNavigation,
+ validator : this._validateNavigation,
+ value : attrs.navigation || {
+ prev: null, next: null, page: null }
+ });
+
+ /**
+ * @attribute animation
+ * @description The optional animation attributes for the Carousel.
+ * @default
+ * { speed: 0, // the animation speed (in seconds)
+ * effect: null } // the animation effect (like
+ * YAHOO.util.Easing.easeOut)
+ * @type Object
+ */
+ this.setAttributeConfig("animation", {
+ validator : this._validateAnimation,
+ value : attrs.animation || { speed: 0, effect: null }
+ });
+
+ /**
+ * @attribute autoPlay
+ * @description Set this to time in milli-seconds to have the
+ * Carousel automatically scroll the contents.
+ * @type Number
+ */
+ this.setAttributeConfig("autoPlay", {
+ validator : JS.isNumber,
+ value : attrs.autoPlay || 0
+ });
+ },
+
+ /**
+ * Initialize and bind the event handlers.
+ *
+ * @method initEvents
+ * @public
+ */
+ initEvents: function () {
+ var cssClass = this.CLASSES;
+
+ this.on("keydown", this._keyboardEventHandler);
+
+ this.subscribe(afterScrollEvent, syncNavigation);
+ this.on(afterScrollEvent, this.focus);
+
+ this.subscribe(itemAddedEvent, syncUI);
+ this.subscribe(itemAddedEvent, syncNavigation);
+
+ this.subscribe(itemRemovedEvent, syncUI);
+ this.subscribe(itemRemovedEvent, syncNavigation);
+
+ this.on(itemSelectedEvent, this.focus);
+
+ this.subscribe(loadItemsEvent, syncUI);
+
+ this.subscribe(pageChangeEvent, this._syncPagerUI);
+
+ this.subscribe(renderEvent, syncNavigation);
+ this.subscribe(renderEvent, this._syncPagerUI);
+
+ this.on("selectedItemChange", function (ev) {
+ setItemSelection.call(this, ev.newValue, ev.prevValue);
+ this._updateTabIndex(this.getElementForItem(ev.newValue));
+ this.fireEvent(itemSelectedEvent, ev.newValue);
+ });
+
+ this.on("firstVisibleChange", function (ev) {
+ if (!this.get("selectOnScroll")) {
+ this._updateTabIndex(this.getElementForItem(ev.newValue));
+ }
+ });
+
+ // Handle item selection on mouse click
+ this.on("click", this._itemClickHandler);
+
+ // Handle page navigation
+ this.on("click", this._pagerClickHandler);
+
+ // Restore the focus on the navigation buttons
+ Event.onFocus(this.get("element"), function (ev, obj) {
+ obj._updateNavButtons(Event.getTarget(ev), true);
+ }, this);
+
+ Event.onBlur(this.get("element"), function (ev, obj) {
+ obj._updateNavButtons(Event.getTarget(ev), false);
+ }, this);
+
+ },
+
+ /**
+ * Return the ITEM_TAG_NAME at index or null if the index is not found.
+ *
+ * @method getElementForItem
+ * @param index {Number} The index of the item to be returned
+ * @return {Element} Return the item at index or null if not found
+ * @public
+ */
+ getElementForItem: function (index) {
+ if (index < 0 || index >= this.get("numItems")) {
+ YAHOO.log("Index out of bounds", "error", WidgetName);
+ return null;
+ }
+
+ // TODO: may be cache the item
+ if (this._itemsTable.numItems > index) {
+ if (!JS.isUndefined(this._itemsTable.items[index])) {
+ return Dom.get(this._itemsTable.items[index].id);
+ }
+ }
+
+ return null;
+ },
+
+ /**
+ * Return the ITEM_TAG_NAME for all items in the Carousel.
+ *
+ * @method getElementForItems
+ * @return {Array} Return all the items
+ * @public
+ */
+ getElementForItems: function () {
+ var els = [], i;
+
+ for (i = 0; i < this._itemsTable.numItems; i++) {
+ els.push(this.getElementForItem(i));
+ }
+
+ return els;
+ },
+
+ /**
+ * Return the item at index or null if the index is not found.
+ *
+ * @method getItem
+ * @param index {Number} The index of the item to be returned
+ * @return {Object} Return the item at index or null if not found
+ * @public
+ */
+ getItem: function (index) {
+ if (index < 0 || index >= this.get("numItems")) {
+ YAHOO.log("Index out of bounds", "error", WidgetName);
+ return null;
+ }
+
+ if (this._itemsTable.numItems > index) {
+ if (!JS.isUndefined(this._itemsTable.items[index])) {
+ return this._itemsTable.items[index];
+ }
+ }
+
+ return null;
+ },
+
+ /**
+ * Return all items as an array.
+ *
+ * @method getItems
+ * @return {Array} Return all items in the Carousel
+ * @public
+ */
+ getItems: function (index) {
+ return this._itemsTable.items;
+ },
+
+ /**
+ * Return the position of the Carousel item that has the id "id", or -1
+ * if the id is not found.
+ *
+ * @method getItemPositionById
+ * @param index {Number} The index of the item to be returned
+ * @public
+ */
+ getItemPositionById: function (id) {
+ var i = 0, n = this._itemsTable.numItems;
+
+ while (i < n) {
+ if (!JS.isUndefined(this._itemsTable.items[i])) {
+ if (this._itemsTable.items[i].id == id) {
+ return i;
+ }
+ }
+ i++;
+ }
+
+ return -1;
+ },
+
+ /**
+ * Remove an item at index from the Carousel.
+ *
+ * @method removeItem
+ * @public
+ * @param index {Number} The position to where in the list (starts from
+ * zero).
+ * @return {Boolean} Return true on success, false otherwise
+ */
+ removeItem: function (index) {
+ var item, num = this.get("numItems");
+
+ if (index < 0 || index >= num) {
+ YAHOO.log("Index out of bounds", "error", WidgetName);
+ return false;
+ }
+
+ item = this._itemsTable.items.splice(index, 1);
+ if (item && item.length == 1) {
+ this.set("numItems", num - 1);
+
+ this.fireEvent(itemRemovedEvent,
+ { item: item[0], pos: index, ev: itemRemovedEvent });
+ return true;
+ }
+
+ return false;
+ },
+
+ /**
+ * Render the Carousel.
+ *
+ * @method render
+ * @public
+ * @param appendTo {HTMLElement | String} The element to which the
+ * Carousel should be appended prior to rendering.
+ * @return {Boolean} Status of the operation
+ */
+ render: function (appendTo) {
+ var config = this.CONFIG,
+ cssClass = this.CLASSES,
+ size;
+
+ this.addClass(cssClass.CAROUSEL);
+
+ if (!this._clipEl) {
+ this._clipEl = this._createCarouselClip();
+ this._clipEl.appendChild(this._carouselEl);
+ }
+
+ if (appendTo) {
+ this.appendChild(this._clipEl);
+ this.appendTo(appendTo);
+ this._setClipContainerSize();
+ } else {
+ if (!Dom.inDocument(this.get("element"))) {
+ YAHOO.log("Nothing to render. The container should be " +
+ "within the document if appendTo is not " +
+ "specified", "error", WidgetName);
+ return false;
+ }
+ this.appendChild(this._clipEl);
+ }
+
+ if (this.get("isVertical")) {
+ size = getCarouselItemSize.call(this);
+ size = size < config.MIN_WIDTH ? config.MIN_WIDTH : size;
+ this.setStyle("width", size + "px");
+ this.addClass(cssClass.VERTICAL);
+ } else {
+ this.addClass(cssClass.HORIZONTAL);
+ }
+
+ if (this.get("numItems") < 1) {
+ YAHOO.log("No items in the Carousel to render", "warn",
+ WidgetName);
+ return false;
+ }
+
+ // Make sure at least one item is selected
+ this.set("selectedItem", this.get("firstVisible"));
+
+ this.fireEvent(renderEvent);
+
+ // By now, the navigation would have been rendered, so calculate
+ // the container height now.
+ this._setContainerSize();
+
+ return true;
+ },
+
+ /**
+ * Scroll the Carousel by an item backward.
+ *
+ * @method scrollBackward
+ * @public
+ */
+ scrollBackward: function () {
+ this.scrollTo(this._firstItem - this.get("scrollIncrement"));
+ },
+
+ /**
+ * Scroll the Carousel by an item forward.
+ *
+ * @method scrollForward
+ * @public
+ */
+ scrollForward: function () {
+ this.scrollTo(this._firstItem + this.get("scrollIncrement"));
+ },
+
+ /**
+ * Scroll the Carousel by a page backward.
+ *
+ * @method scrollPageBackward
+ * @public
+ */
+ scrollPageBackward: function () {
+ this.scrollTo(this._firstItem - this.get("numVisible"));
+ },
+
+ /**
+ * Scroll the Carousel by a page forward.
+ *
+ * @method scrollPageForward
+ * @public
+ */
+ scrollPageForward: function () {
+ this.scrollTo(this._firstItem + this.get("numVisible"));
+ },
+
+ /**
+ * Scroll the Carousel to make the item the first visible item.
+ *
+ * @method scrollTo
+ * @public
+ * @param item Number The index of the element to position at.
+ * @param dontSelect Boolean True if select should be avoided
+ */
+ scrollTo: function (item, dontSelect) {
+ var anim,
+ animate,
+ animAttrs,
+ animCfg = this.get("animation"),
+ isCircular = this.get("isCircular"),
+ delta,
+ direction,
+ firstItem = this._firstItem,
+ newPage,
+ numItems = this.get("numItems"),
+ numPerPage = this.get("numVisible"),
+ offset,
+ page = this.get("currentPage"),
+ rv,
+ sentinel,
+ which;
+
+ if (item == firstItem) {
+ return; // nothing to do!
+ }
+
+ if (this._isAnimationInProgress) {
+ return; // let it take its own sweet time to complete
+ }
+
+ if (item < 0) {
+ if (isCircular) {
+ item = numItems + item;
+ } else {
+ return;
+ }
+ } else if (item > numItems - 1) {
+ if (this.get("isCircular")) {
+ item = numItems - item;
+ } else {
+ return;
+ }
+ }
+
+ direction = (this._firstItem > item) ? "backward" : "forward";
+
+ sentinel = firstItem + numPerPage;
+ sentinel = (sentinel > numItems - 1) ? numItems - 1 : sentinel;
+ rv = this.fireEvent(beforeScrollEvent,
+ { dir: direction, first: firstItem, last: sentinel });
+ if (rv === false) { // scrolling is prevented
+ return;
+ }
+
+ this.fireEvent(beforePageChangeEvent, { page: page });
+
+ delta = firstItem - item; // yes, the delta is reverse
+ this._firstItem = item;
+ this.set("firstVisible", item);
+
+ YAHOO.log("Scrolling to " + item + " delta = " + delta, WidgetName);
+
+ loadItems.call(this); // do we have all the items to display?
+
+ sentinel = item + numPerPage;
+ sentinel = (sentinel > numItems - 1) ? numItems - 1 : sentinel;
+
+ which = this.get("isVertical") ? "top" : "left";
+ offset = getScrollOffset.call(this, delta);
+ YAHOO.log("Scroll offset = " + offset, WidgetName);
+
+ animate = animCfg.speed > 0;
+
+ if (animate) {
+ this._isAnimationInProgress = true;
+ if (this.get("isVertical")) {
+ animAttrs = { points: { by: [0, offset] } };
+ } else {
+ animAttrs = { points: { by: [offset, 0] } };
+ }
+ anim = new YAHOO.util.Motion(this._carouselEl, animAttrs,
+ animCfg.speed, animCfg.effect);
+ anim.onComplete.subscribe(function (ev) {
+ var first = this.get("firstVisible");
+
+ this._isAnimationInProgress = false;
+ this.fireEvent(afterScrollEvent,
+ { first: first, last: sentinel });
+ }, null, this);
+ anim.animate();
+ anim = null;
+ } else {
+ offset += getStyle(this._carouselEl, which);
+ Dom.setStyle(this._carouselEl, which, offset + "px");
+ }
+
+ newPage = parseInt(this._firstItem / numPerPage, 10);
+ if (newPage != page) {
+ this.setAttributeConfig("currentPage", { value: newPage });
+ this.fireEvent(pageChangeEvent, newPage);
+ }
+
+ if (!dontSelect) {
+ if (this.get("selectOnScroll")) {
+ if (item != this._selectedItem) { // out of sync
+ this.set("selectedItem", this._getSelectedItem(item));
+ }
+ }
+ }
+
+ delete this._autoPlayTimer;
+ if (this.get("autoPlay") > 0) {
+ this.startAutoPlay();
+ }
+
+ if (!animate) {
+ this.fireEvent(afterScrollEvent,
+ { first: item, last: sentinel });
+ }
+ },
+
+ /**
+ * Display the Carousel.
+ *
+ * @method show
+ * @public
+ */
+ show: function () {
+ var cssClass = this.CLASSES;
+
+ if (this.fireEvent(beforeShowEvent) !== false) {
+ this.addClass(cssClass.VISIBLE);
+ this.fireEvent(showEvent);
+ }
+ },
+
+ /**
+ * Start auto-playing the Carousel.
+ *
+ * @method startAutoPlay
+ * @public
+ */
+ startAutoPlay: function () {
+ var self = this,
+ timer = this.get("autoPlay");
+
+ if (timer > 0) {
+ if (!JS.isUndefined(this._autoPlayTimer)) {
+ return;
+ }
+ this.fireEvent(startAutoPlayEvent);
+ this._autoPlayTimer = setTimeout(function () {
+ autoScroll.call(self); }, timer);
+ }
+ },
+
+ /**
+ * Stop auto-playing the Carousel.
+ *
+ * @method stopAutoPlay
+ * @public
+ */
+ stopAutoPlay: function () {
+ if (!JS.isUndefined(this._autoPlayTimer)) {
+ clearTimeout(this._autoPlayTimer);
+ delete this._autoPlayTimer;
+ this.set("autoPlay", 0);
+ this.fireEvent(stopAutoPlayEvent);
+ }
+ },
+
+ /**
+ * Return the string representation of the Carousel.
+ *
+ * @method toString
+ * @public
+ * @return {String}
+ */
+ toString: function () {
+ return WidgetName + (this.get ? " (#" + this.get("id") + ")" : "");
+ },
+
+ /*
+ * Protected methods of the Carousel component
+ */
+
+ /**
+ * Create the Carousel.
+ *
+ * @method createCarousel
+ * @param elId {String} The id of the element to be created
+ * @protected
+ */
+ _createCarousel: function (elId) {
+ var cssClass = this.CLASSES;
+
+ var el = createElement("DIV", {
+ className : cssClass.CAROUSEL,
+ id : elId
+ });
+
+ if (!this._carouselEl) {
+ this._carouselEl = createElement(this.CONFIG.TAG_NAME,
+ { className: cssClass.CAROUSEL_EL });
+ }
+
+ return el;
+ },
+
+ /**
+ * Create the Carousel clip container.
+ *
+ * @method createCarouselClip
+ * @protected
+ */
+ _createCarouselClip: function () {
+ var el = createElement("DIV", { className: this.CLASSES.CONTENT });
+ this._setClipContainerSize(el);
+
+ return el;
+ },
+
+ /**
+ * Create the Carousel item.
+ *
+ * @method createCarouselItem
+ * @param obj {Object} The attributes of the element to be created
+ * @protected
+ */
+ _createCarouselItem: function (obj) {
+ return createElement(this.CONFIG.ITEM_TAG_NAME, {
+ className : obj.className,
+ content : obj.content,
+ id : obj.id
+ });
+ },
+
+ /**
+ * Get the value for the selected item.
+ *
+ * @method _getSelectedItem
+ * @param val {Number} The new value for "selected" item
+ * @return {Number} The new value that would be set
+ * @protected
+ */
+ _getSelectedItem: function (val) {
+ var isCircular = this.get("isCircular"),
+ numItems = this.get("numItems"),
+ sentinel = numItems - 1;
+
+ if (val < 0) {
+ if (isCircular) {
+ val = numItems + val;
+ } else {
+ val = this.get("selectedItem");
+ }
+ } else if (val > sentinel) {
+ if (isCircular) {
+ val = val - numItems;
+ } else {
+ val = this.get("selectedItem");
+ }
+ }
+
+ return val;
+ },
+
+ /**
+ * The "click" handler for the item.
+ *
+ * @method _itemClickHandler
+ * @param {Event} ev The event object
+ * @protected
+ */
+ _itemClickHandler: function (ev) {
+ var container = this.get("element"),
+ el,
+ item,
+ target = YAHOO.util.Event.getTarget(ev);
+
+ while (target && target != container &&
+ target.id != this._carouselEl) {
+ el = target.nodeName;
+ if (el.toUpperCase() == this.CONFIG.ITEM_TAG_NAME) {
+ break;
+ }
+ target = target.parentNode;
+ }
+
+ if ((item = this.getItemPositionById(target.id)) >= 0) {
+ YAHOO.log("Setting selection to " + item, WidgetName);
+ this.set("selectedItem", this._getSelectedItem(item));
+ }
+ },
+
+ /**
+ * The keyboard event handler for Carousel.
+ *
+ * @method _keyboardEventHandler
+ * @param ev {Event} The event that is being handled.
+ * @protected
+ */
+ _keyboardEventHandler: function (ev) {
+ var key = Event.getCharCode(ev),
+ prevent = false,
+ position = 0,
+ selItem;
+
+ if (this._isAnimationInProgress) {
+ return; // do not mess while animation is in progress
+ }
+
+ switch (key) {
+ case 0x25: // left arrow
+ case 0x26: // up arrow
+ selItem = this.get("selectedItem");
+ if (selItem == this._firstItem) {
+ position = selItem - this.get("numVisible");
+ this.scrollTo(position);
+ this.set("selectedItem", this._getSelectedItem(selItem-1));
+ } else {
+ position = this.get("selectedItem") -
+ this.get("scrollIncrement");
+ this.set("selectedItem", this._getSelectedItem(position));
+ }
+ prevent = true;
+ break;
+ case 0x27: // right arrow
+ case 0x28: // down arrow
+ position = this.get("selectedItem")+this.get("scrollIncrement");
+ this.set("selectedItem", this._getSelectedItem(position));
+ prevent = true;
+ break;
+ case 0x21: // page-up
+ this.scrollPageBackward();
+ prevent = true;
+ break;
+ case 0x22: // page-down
+ this.scrollPageForward();
+ prevent = true;
+ break;
+ }
+
+ if (prevent) {
+ Event.preventDefault(ev);
+ }
+ },
+
+ /**
+ * The "click" handler for the pager navigation.
+ *
+ * @method _pagerClickHandler
+ * @param {Event} ev The event object
+ * @protected
+ */
+ _pagerClickHandler: function (ev) {
+ var pos, target, val;
+
+ target = Event.getTarget(ev);
+ val = target.href || target.value;
+ if (JS.isString(val) && val) {
+ pos = val.lastIndexOf("#");
+ if (pos != -1) {
+ val = this.getItemPositionById(val.substring(pos + 1));
+ this.scrollTo(val);
+ Event.preventDefault(ev);
+ }
+ }
+ },
+
+ /**
+ * Find the Carousel within a container. The Carousel is identified by
+ * the first element that matches the carousel element tag or the
+ * element that has the Carousel class.
+ *
+ * @method parseCarousel
+ * @param parent {HTMLElement} The parent element to look under
+ * @return {Boolean} True if Carousel is found, false otherwise
+ * @protected
+ */
+ _parseCarousel: function (parent) {
+ var child, cssClass, found, node;
+
+ cssClass = this.CLASSES;
+ found = false;
+
+ for (child = parent.firstChild; child; child = child.nextSibling) {
+ if (child.nodeType == 1) {
+ node = child.nodeName;
+ if (node.toUpperCase() == this.CONFIG.TAG_NAME) {
+ this._carouselEl = child;
+ Dom.addClass(this._carouselEl,this.CLASSES.CAROUSEL_EL);
+ YAHOO.log("Found Carousel - " + node +
+ (child.id ? " (#" + child.id + ")" : ""),
+ WidgetName);
+ found = true;
+ }
+ }
+ }
+
+ return found;
+ },
+
+ /**
+ * Find the items within the Carousel and add them to the items table.
+ * A Carousel item is identified by elements that matches the carousel
+ * item element tag.
+ *
+ * @method parseCarouselItems
+ * @protected
+ */
+ _parseCarouselItems: function () {
+ var child,
+ elId,
+ node,
+ parent = this._carouselEl;
+
+ for (child = parent.firstChild; child; child = child.nextSibling) {
+ if (child.nodeType == 1) {
+ node = child.nodeName;
+ if (node.toUpperCase() == this.CONFIG.ITEM_TAG_NAME) {
+ if (child.id) {
+ elId = child.id;
+ } else {
+ elId = Dom.generateId();
+ child.setAttribute("id", elId);
+ }
+ this.addItem(child);
+ }
+ }
+ }
+ },
+
+ /**
+ * Find the Carousel navigation within a container. The navigation
+ * elements need to match the carousel navigation class names.
+ *
+ * @method parseCarouselNavigation
+ * @param parent {HTMLElement} The parent element to look under
+ * @return {Boolean} True if at least one is found, false otherwise
+ * @protected
+ */
+ _parseCarouselNavigation: function (parent) {
+ var cfg, cssClass = this.CLASSES, el, i, j, nav, rv = false;
+
+ nav = Dom.getElementsByClassName(cssClass.PREV_PAGE, "*", parent);
+ if (nav.length > 0) {
+ for (i in nav) {
+ if (nav.hasOwnProperty(i)) {
+ el = nav[i];
+ YAHOO.log("Found Carousel previous page navigation - " +
+ el + (el.id ? " (#" + el.id + ")" : ""),
+ WidgetName);
+ if (el.nodeName == "INPUT" ||
+ el.nodeName == "BUTTON") {
+ if (typeof this._navBtns.prev == "undefined") {
+ this._navBtns.prev = [];
+ }
+ this._navBtns.prev.push(el);
+ } else {
+ j = el.getElementsByTagName("INPUT");
+ if (JS.isArray(j) && j.length > 0) {
+ this._navBtns.prev.push(j[0]);
+ } else {
+ j = el.getElementsByTagName("BUTTON");
+ if (JS.isArray(j) && j.length > 0) {
+ this._navBtns.prev.push(j[0]);
+ }
+ }
+ }
+ }
+ }
+ cfg = { prev: nav };
+ }
+
+ nav = Dom.getElementsByClassName(cssClass.NEXT_PAGE, "*", parent);
+ if (nav.length > 0) {
+ for (i in nav) {
+ if (nav.hasOwnProperty(i)) {
+ el = nav[i];
+ YAHOO.log("Found Carousel next page navigation - " +
+ el + (el.id ? " (#" + el.id + ")" : ""),
+ WidgetName);
+ if (el.nodeName == "INPUT" ||
+ el.nodeName == "BUTTON") {
+ if (typeof this._navBtns.next == "undefined") {
+ this._navBtns.next = [];
+ }
+ this._navBtns.next.push(el);
+ } else {
+ j = el.getElementsByTagName("INPUT");
+ if (JS.isArray(j) && j.length > 0) {
+ this._navBtns.next.push(j[0]);
+ } else {
+ j = el.getElementsByTagName("BUTTON");
+ if (JS.isArray(j) && j.length > 0) {
+ this._navBtns.next.push(j[0]);
+ }
+ }
+ }
+ }
+ }
+ if (cfg) {
+ cfg.next = nav;
+ } else {
+ cfg = { next: nav };
+ }
+ }
+
+ if (cfg) {
+ this.set("navigation", cfg);
+ rv = true;
+ }
+
+ return rv;
+ },
+
+ /**
+ * Setup/Create the Carousel navigation element (if needed).
+ *
+ * @method _setupCarouselNavigation
+ * @protected
+ */
+ _setupCarouselNavigation: function () {
+ var btn, cfg, cssClass, nav, navContainer, nextButton, pageEl,
+ prevButton;
+
+ cssClass = this.CLASSES;
+
+ navContainer = Dom.getElementsByClassName(cssClass.NAVIGATION,
+ "DIV", this.get("element"));
+
+ if (navContainer.length === 0) {
+ navContainer = createElement("DIV",
+ { className: cssClass.NAVIGATION });
+ this.insertBefore(navContainer,
+ Dom.getFirstChild(this.get("element")));
+ } else {
+ navContainer = navContainer[0];
+ }
+
+ this._pages.el = createElement("UL");
+ navContainer.appendChild(this._pages.el);
+
+ nav = this.get("navigation");
+ if (nav.prev && nav.prev.length > 0) {
+ navContainer.appendChild(nav.prev[0]);
+ } else {
+ // TODO: separate method for creating a navigation button
+ prevButton = createElement("SPAN",
+ { className: cssClass.BUTTON + cssClass.FIRST_NAV });
+ // XXX: for IE 6.x
+ Dom.setStyle(prevButton, "visibility", "visible");
+ btn = Dom.generateId();
+ prevButton.innerHTML = "";
+ navContainer.appendChild(prevButton);
+ btn = Dom.get(btn);
+ this._navBtns.prev = [btn];
+ cfg = { prev: [prevButton] };
+ }
+
+ if (nav.next && nav.next.length > 0) {
+ navContainer.appendChild(nav.next[0]);
+ } else {
+ // TODO: separate method for creating a navigation button
+ nextButton = createElement("SPAN",
+ { className: cssClass.BUTTON });
+ // XXX: for IE 6.x
+ Dom.setStyle(nextButton, "visibility", "visible");
+ btn = Dom.generateId();
+ nextButton.innerHTML = "";
+ navContainer.appendChild(nextButton);
+ btn = Dom.get(btn);
+ this._navBtns.next = [btn];
+ if (cfg) {
+ cfg.next = [nextButton];
+ } else {
+ cfg = { next: [nextButton] };
+ }
+ }
+
+ if (cfg) {
+ this.set("navigation", cfg);
+ }
+
+ return navContainer;
+ },
+
+ /**
+ * Set the clip container size (based on the new numVisible value).
+ *
+ * @method _setClipContainerSize
+ * @param clip {HTMLElement} The clip container element.
+ * @param num {Number} optional The number of items per page.
+ * @protected
+ */
+ _setClipContainerSize: function (clip, num) {
+ var attr, currVal, isVertical, itemSize, reveal, size, which;
+
+ isVertical = this.get("isVertical");
+ reveal = this.get("revealAmount");
+ which = isVertical ? "height" : "width";
+ attr = isVertical ? "top" : "left";
+
+ clip = clip || this._clipEl;
+ if (!clip) {
+ return;
+ }
+
+ num = num || this.get("numVisible");
+ itemSize = getCarouselItemSize.call(this, which);
+ size = itemSize * num;
+
+ this._recomputeSize = (size === 0); // bleh!
+ if (this._recomputeSize) {
+ return; // no use going further, bail out!
+ }
+
+ if (reveal > 0) {
+ reveal = itemSize * (reveal / 100) * 2;
+ size += reveal;
+ // TODO: set the Carousel's initial offset somwehere
+ currVal = parseFloat(Dom.getStyle(this._carouselEl, attr));
+ currVal = JS.isNumber(currVal) ? currVal : 0;
+ Dom.setStyle(this._carouselEl, attr, currVal+(reveal/2)+"px");
+ }
+
+ if (isVertical) {
+ size += getStyle(this._carouselEl, "marginTop") +
+ getStyle(this._carouselEl, "marginBottom") +
+ getStyle(this._carouselEl, "paddingTop") +
+ getStyle(this._carouselEl, "paddingBottom") +
+ getStyle(this._carouselEl, "borderTop") +
+ getStyle(this._carouselEl, "borderBottom");
+ // XXX: for vertical Carousel
+ Dom.setStyle(clip, which, (size - (num - 1)) + "px");
+ } else {
+ size += getStyle(this._carouselEl, "marginLeft") +
+ getStyle(this._carouselEl, "marginRight") +
+ getStyle(this._carouselEl, "paddingLeft") +
+ getStyle(this._carouselEl, "paddingRight") +
+ getStyle(this._carouselEl, "borderLeft") +
+ getStyle(this._carouselEl, "borderRight");
+ Dom.setStyle(clip, which, size + "px");
+ }
+
+ this._setContainerSize(clip); // adjust the container size too
+ },
+
+ /**
+ * Set the container size.
+ *
+ * @method _setContainerSize
+ * @param clip {HTMLElement} The clip container element.
+ * @param attr {String} Either set the height or width.
+ * @protected
+ */
+ _setContainerSize: function (clip, attr) {
+ var isVertical, size;
+
+ isVertical = this.get("isVertical");
+ clip = clip || this._clipEl;
+ attr = attr || (isVertical ? "height" : "width");
+ size = parseFloat(Dom.getStyle(clip, attr), 10);
+
+ size = JS.isNumber(size) ? size : 0;
+
+ size += getStyle(clip, "marginLeft") +
+ getStyle(clip, "marginRight") +
+ getStyle(clip, "paddingLeft") +
+ getStyle(clip, "paddingRight") +
+ getStyle(clip, "borderLeft") +
+ getStyle(clip, "borderRight");
+
+ if (isVertical) {
+ size += getStyle(this._navEl, "height");
+ }
+
+ this.setStyle(attr, size + "px");
+ },
+
+ /**
+ * Set the value for the Carousel's first visible item.
+ *
+ * @method _setFirstVisible
+ * @param val {Number} The new value for firstVisible
+ * @return {Number} The new value that would be set
+ * @protected
+ */
+ _setFirstVisible: function (val) {
+ if (val >= 0 && val < this.get("numItems")) {
+ this.scrollTo(val);
+ } else {
+ val = this.get("firstVisible");
+ }
+ return val;
+ },
+
+ /**
+ * Set the value for the Carousel's navigation.
+ *
+ * @method _setNavigation
+ * @param cfg {Object} The navigation configuration
+ * @return {Object} The new value that would be set
+ * @protected
+ */
+ _setNavigation: function (cfg) {
+ if (cfg.prev) {
+ Event.on(cfg.prev, "click", scrollPageBackward, this);
+ }
+ if (cfg.next) {
+ Event.on(cfg.next, "click", scrollPageForward, this);
+ }
+ },
+
+ /**
+ * Set the value for the number of visible items in the Carousel.
+ *
+ * @method _setNumVisible
+ * @param val {Number} The new value for numVisible
+ * @return {Number} The new value that would be set
+ * @protected
+ */
+ _setNumVisible: function (val) {
+ if (val > 1 && val < this.get("numItems")) {
+ this._setClipContainerSize(this._clipEl, val);
+ } else {
+ val = this.get("numVisible");
+ }
+ return val;
+ },
+
+ /**
+ * Set the number of items in the Carousel.
+ * Warning: Setting this to a lower number than the current removes
+ * items from the end.
+ *
+ * @method _setNumItems
+ * @param val {Number} The new value for numItems
+ * @return {Number} The new value that would be set
+ * @protected
+ */
+ _setNumItems: function (val) {
+ var num = this._itemsTable.numItems;
+
+ if (JS.isArray(this._itemsTable.items)) {
+ if (this._itemsTable.items.length != num) { // out of sync
+ num = this._itemsTable.items.length;
+ this._itemsTable.numItems = num;
+ }
+ }
+
+ if (val < num) {
+ while (num > val) {
+ this.removeItem(num - 1);
+ num--;
+ }
+ }
+
+ return val;
+ },
+
+ /**
+ * Set the orientation of the Carousel.
+ *
+ * @method _setOrientation
+ * @param val {Boolean} The new value for isVertical
+ * @return {Boolean} The new value that would be set
+ * @protected
+ */
+ _setOrientation: function (val) {
+ var cssClass = this.CLASSES;
+
+ if (val) {
+ this.replaceClass(cssClass.HORIZONTAL, cssClass.VERTICAL);
+ } else {
+ this.replaceClass(cssClass.VERTICAL, cssClass.HORIZONTAL);
+ }
+ this._itemsTable.size = 0; // invalidate our size computation cache
+ return val;
+ },
+
+ /**
+ * Set the value for the reveal amount percentage in the Carousel.
+ *
+ * @method _setRevealAmount
+ * @param val {Number} The new value for revealAmount
+ * @return {Number} The new value that would be set
+ * @protected
+ */
+ _setRevealAmount: function (val) {
+ if (val >= 0 && val <= 100) {
+ val = parseInt(val, 10);
+ val = JS.isNumber(val) ? val : 0;
+ this._setClipContainerSize();
+ } else {
+ val = this.get("revealAmount");
+ }
+ return val;
+ },
+
+ /**
+ * Set the value for the selected item.
+ *
+ * @method _setSelectedItem
+ * @param val {Number} The new value for "selected" item
+ * @protected
+ */
+ _setSelectedItem: function (val) {
+ this._selectedItem = val;
+ },
+
+ /**
+ * Synchronize and redraw the Pager UI if necessary.
+ *
+ * @method _syncPagerUI
+ * @protected
+ */
+ _syncPagerUI: function (page) {
+ var a,
+ cssClass = this.CLASSES,
+ i,
+ markup = "",
+ numPages,
+ numVisible = this.get("numVisible");
+
+ page = page || 0;
+ numPages = Math.ceil(this.get("numItems") / numVisible);
+
+ this._pages.num = numPages;
+ this._pages.cur = page;
+
+ if (numPages > this.CONFIG.MAX_PAGER_BUTTONS) {
+ markup = "";
+ }
+
+ this._pages.el.innerHTML = markup;
+ markup = null;
+ },
+
+ /**
+ * Set the correct class for the navigation buttons.
+ *
+ * @method _updateNavButtons
+ * @param el {Object} The target button
+ * @param setFocus {Boolean} True to set focus ring, false otherwise.
+ * @protected
+ */
+ _updateNavButtons: function (el, setFocus) {
+ var children,
+ cssClass = this.CLASSES,
+ grandParent,
+ parent = el.parentNode;
+
+ if (!parent) {
+ return;
+ }
+ grandParent = parent.parentNode;
+
+ if (el.nodeName.toUpperCase() == "INPUT" &&
+ Dom.hasClass(parent, cssClass.BUTTON)) {
+ if (setFocus) {
+ if (grandParent) {
+ children = Dom.getChildren(grandParent);
+ if (children) {
+ Dom.removeClass(children, cssClass.FOCUSSED_BUTTON);
+ }
+ }
+ Dom.addClass(parent, cssClass.FOCUSSED_BUTTON);
+ } else {
+ Dom.removeClass(parent, cssClass.FOCUSSED_BUTTON);
+ }
+ }
+ },
+
+ /**
+ * Set the correct tab index for the Carousel items.
+ *
+ * @method _updateTabIndex
+ * @param el {Object} The element to be focussed
+ * @protected
+ */
+ _updateTabIndex: function (el) {
+ if (el) {
+ if (this._focusableItemEl) {
+ this._focusableItemEl.tabIndex = -1;
+ }
+ this._focusableItemEl = el;
+ el.tabIndex = 0;
+ }
+ },
+
+ /**
+ * Validate animation parameters.
+ *
+ * @method _validateAnimation
+ * @param cfg {Object} The animation configuration
+ * @return {Boolean} The status of the validation
+ * @protected
+ */
+ _validateAnimation: function (cfg) {
+ var rv = true;
+
+ if (JS.isObject(cfg)) {
+ if (cfg.speed) {
+ rv = rv && JS.isNumber(cfg.speed);
+ }
+ if (cfg.effect) {
+ rv = rv && JS.isFunction(cfg.effect);
+ } else if (!JS.isUndefined(YAHOO.util.Easing)) {
+ cfg.effect = YAHOO.util.Easing.easeOut;
+ }
+ } else {
+ rv = false;
+ }
+
+ return rv;
+ },
+
+ /**
+ * Validate the firstVisible value.
+ *
+ * @method _validateFirstVisible
+ * @param val {Number} The first visible value
+ * @return {Boolean} The status of the validation
+ * @protected
+ */
+ _validateFirstVisible: function (val) {
+ var rv = false;
+
+ if (JS.isNumber(val)) {
+ rv = (val >= 0 && val < this.get("numItems"));
+ }
+
+ return rv;
+ },
+
+ /**
+ * Validate and navigation parameters.
+ *
+ * @method _validateNavigation
+ * @param cfg {Object} The navigation configuration
+ * @return {Boolean} The status of the validation
+ * @protected
+ */
+ _validateNavigation : function (cfg) {
+ var i;
+
+ if (!JS.isObject(cfg)) {
+ return false;
+ }
+
+ if (cfg.prev) {
+ if (!JS.isArray(cfg.prev)) {
+ return false;
+ }
+ for (i in cfg.prev) {
+ if (cfg.prev.hasOwnProperty(i)) {
+ if (!JS.isString(cfg.prev[i].nodeName)) {
+ return false;
+ }
+ }
+ }
+ }
+
+ if (cfg.next) {
+ if (!JS.isArray(cfg.next)) {
+ return false;
+ }
+ for (i in cfg.next) {
+ if (cfg.next.hasOwnProperty(i)) {
+ if (!JS.isString(cfg.next[i].nodeName)) {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ },
+
+ /**
+ * Validate the numItems value.
+ *
+ * @method _validateNumItems
+ * @param val {Number} The numItems value
+ * @return {Boolean} The status of the validation
+ * @protected
+ */
+ _validateNumItems: function (val) {
+ var rv = false;
+
+ if (JS.isNumber(val)) {
+ rv = val > 0;
+ }
+
+ return rv;
+ },
+
+ /**
+ * Validate the numVisible value.
+ *
+ * @method _validateNumVisible
+ * @param val {Number} The numVisible value
+ * @return {Boolean} The status of the validation
+ * @protected
+ */
+ _validateNumVisible: function (val) {
+ var rv = false;
+
+ if (JS.isNumber(val)) {
+ rv = val > 0 && val < this.get("numItems");
+ }
+
+ return rv;
+ },
+
+ /**
+ * Validate the revealAmount value.
+ *
+ * @method _validateRevealAmount
+ * @param val {Number} The revealAmount value
+ * @return {Boolean} The status of the validation
+ * @protected
+ */
+ _validateRevealAmount: function (val) {
+ var rv = false;
+
+ if (JS.isNumber(val)) {
+ rv = val >= 0 && val < 100;
+ }
+
+ return rv;
+ },
+
+ /**
+ * Validate the scrollIncrement value.
+ *
+ * @method _validateScrollIncrement
+ * @param val {Number} The scrollIncrement value
+ * @return {Boolean} The status of the validation
+ * @protected
+ */
+ _validateScrollIncrement: function (val) {
+ var rv = false;
+
+ if (JS.isNumber(val)) {
+ rv = (val > 0 && val < this.get("numItems"));
+ }
+
+ return rv;
+ }
+
+ });
+
+})();
+
+YAHOO.register("carousel", YAHOO.widget.Carousel, {version: "2.6.0", build: "1321"});
diff --git a/lib/yui/carousel/carousel-beta-min.js b/lib/yui/carousel/carousel-beta-min.js
new file mode 100644
index 0000000000..375ad2b326
--- /dev/null
+++ b/lib/yui/carousel/carousel-beta-min.js
@@ -0,0 +1,11 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.6.0
+*/
+(function(){var W;YAHOO.widget.Carousel=function(k,j){this._navBtns={};this._pages={};YAHOO.widget.Carousel.superclass.constructor.call(this,k,j);};var e=YAHOO.widget.Carousel,C=YAHOO.util.Dom,i=YAHOO.util.Event,R=YAHOO.lang;W="Carousel";var G={};var h="afterScroll";var F="beforeHide";var f="beforePageChange";var b="beforeScroll";var A="beforeShow";var V="blur";var D="focus";var O="hide";var Q="itemAdded";var J="itemRemoved";var d="itemSelected";var B="loadItems";var E="navigationStateChange";var U="pageChange";var T="render";var I="show";var c="startAutoPlay";var g="stopAutoPlay";function L(){var k=this._firstItem,j;if(k>=this.get("numItems")-1){if(this.get("isCircular")){j=0;}else{this.stopAutoPlay();}}else{j=k+this.get("numVisible");}this.scrollTo.call(this,j);}function a(k,j){var l=document.createElement(k);j=j||{};if(j.className){C.addClass(l,j.className);}if(j.parent){j.parent.appendChild(l);}if(j.id){l.setAttribute("id",j.id);}if(j.content){if(j.content.nodeName){l.appendChild(j.content);}else{l.innerHTML=j.content;}}return l;}function K(l,k,j){var n;function m(q,p){var r;r=parseInt(C.getStyle(q,p),10);return R.isNumber(r)?r:0;}function o(q,p){var r;r=parseFloat(C.getStyle(q,p));return R.isNumber(r)?r:0;}if(typeof j=="undefined"){j="int";}switch(k){case"height":n=l.offsetHeight;if(n>0){n+=m(l,"marginTop")+m(l,"marginBottom");}else{n=o(l,"height")+m(l,"marginTop")+m(l,"marginBottom")+m(l,"borderTopWidth")+m(l,"borderBottomWidth")+m(l,"paddingTop")+m(l,"paddingBottom");}break;case"width":n=l.offsetWidth;if(n>0){n+=m(l,"marginLeft")+m(l,"marginRight");}else{n=o(l,"width")+m(l,"marginLeft")+m(l,"marginRight")+m(l,"borderLeftWidth")+m(l,"borderRightWidth")+m(l,"paddingLeft")+m(l,"paddingRight");}break;default:if(j=="int"){n=m(l,k);if(k=="marginRight"&&YAHOO.env.ua.webkit){n=m(l,"marginLeft");}}else{if(j=="float"){n=o(l,k);}else{n=C.getStyle(l,k);}}break;}return n;}function Y(l){var m,k=0,j=false;if(this._itemsTable.numItems===0){return 0;}if(typeof l=="undefined"){if(this._itemsTable.size>0){return this._itemsTable.size;}}if(R.isUndefined(this._itemsTable.items[0])){return 0;}m=C.get(this._itemsTable.items[0].id);if(typeof l=="undefined"){j=this.get("isVertical");}else{j=l=="height";}if(j){k=K(m,"height");}else{k=K(m,"width");}if(typeof l=="undefined"){this._itemsTable.size=k;}return k;}function S(l){var k=0,j=0;k=Y.call(this);j=k*l;if(this.get("isVertical")){j-=l;}return j;}function H(){var n=this.get("firstVisible"),k=0,j=this.get("numItems"),l=this.get("numVisible"),m=this.get("revealAmount");k=n+l-1+(m?1:0);k=k>j-1?j-1:k;if(!this.getItem(n)||!this.getItem(k)){this.fireEvent(B,{ev:B,first:n,last:k,num:k-n});}}function N(j,k){k.scrollPageBackward();i.preventDefault(j);}function X(j,k){k.scrollPageForward();i.preventDefault(j);}function P(o,j){var r,t=this.CLASSES,k,q=this._firstItem,l=this.get("isCircular"),p=this.get("numItems"),s=this.get("numVisible"),n=j,m=q+s-1;r=s>1&&!l&&n>o;if(n>=0&&n