From d38ed4fba27862986080e176bad4b6508f1d76c9 Mon Sep 17 00:00:00 2001 From: vyshane Date: Thu, 23 Nov 2006 03:10:20 +0000 Subject: [PATCH] Upgraded the YUI libs to version 0.12.0, released 14 Nov 2006. --- lib/yui/README.txt | 3 +- lib/yui/animation/README | 16 +- lib/yui/animation/animation-debug.js | 488 +- lib/yui/animation/animation-min.js | 2 +- lib/yui/animation/animation.js | 488 +- lib/yui/autocomplete/README | 29 + lib/yui/autocomplete/autocomplete-debug.js | 4396 +++++---- lib/yui/autocomplete/autocomplete-min.js | 166 +- lib/yui/autocomplete/autocomplete.js | 4362 +++++---- lib/yui/calendar/README | 95 +- lib/yui/calendar/assets/calendar.css | 86 +- lib/yui/calendar/calendar-debug.js | 5481 +++++++---- lib/yui/calendar/calendar-min.js | 254 +- lib/yui/calendar/calendar.js | 5483 +++++++---- lib/yui/connection/README | 75 +- lib/yui/connection/connection-debug.js | 1779 ++-- lib/yui/connection/connection-min.js | 94 +- lib/yui/connection/connection.js | 1735 ++-- lib/yui/container/README | 103 +- lib/yui/container/assets/container.css | 3 +- lib/yui/container/container-debug.js | 2754 ++++-- lib/yui/container/container-min.js | 321 +- lib/yui/container/container.js | 2751 ++++-- lib/yui/container/container_core-debug.js | 1892 ++-- lib/yui/container/container_core-min.js | 170 +- lib/yui/container/container_core.js | 1888 ++-- lib/yui/dom/README | 29 + lib/yui/dom/dom-debug.js | 1453 ++- lib/yui/dom/dom-min.js | 2 +- lib/yui/dom/dom.js | 1385 ++- lib/yui/dragdrop/README | 50 +- lib/yui/dragdrop/dragdrop-debug.js | 2101 ++-- lib/yui/dragdrop/dragdrop-min.js | 2 +- lib/yui/dragdrop/dragdrop.js | 2015 ++-- lib/yui/event/README | 67 + lib/yui/event/event-debug.js | 1198 ++- lib/yui/event/event-min.js | 2 +- lib/yui/event/event.js | 1062 +- lib/yui/fonts/README | 14 +- lib/yui/fonts/fonts-min.css | 8 +- lib/yui/fonts/fonts.css | 8 +- lib/yui/grids/README | 42 +- lib/yui/grids/grids-min.css | 9 +- lib/yui/grids/grids.css | 182 +- lib/yui/logger/README | 28 + lib/yui/logger/assets/logger.css | 21 +- lib/yui/logger/logger-debug.js | 1475 +-- lib/yui/logger/logger-min.js | 95 +- lib/yui/logger/logger.js | 1475 +-- lib/yui/menu/README | 148 +- lib/yui/menu/assets/menu.css | 27 +- lib/yui/menu/menu-debug.js | 8646 ++++++++++------- lib/yui/menu/menu-min.js | 10 +- lib/yui/menu/menu.js | 8451 +++++++++------- lib/yui/reset-fonts-grids/README | 8 + .../reset-fonts-grids-min.css | 4 + .../reset-fonts-grids/reset-fonts-grids.css | 174 + lib/yui/reset/README | 18 +- lib/yui/reset/reset-min.css | 8 +- lib/yui/reset/reset.css | 9 +- lib/yui/slider/README | 25 + lib/yui/slider/slider-debug.js | 1665 ++-- lib/yui/slider/slider-min.js | 2 +- lib/yui/slider/slider.js | 1535 +-- lib/yui/tabview/README | 6 + lib/yui/tabview/tabview-debug.js | 1951 ++++ lib/yui/tabview/tabview-min.js | 1 + lib/yui/tabview/tabview.js | 1950 ++++ lib/yui/treeview/README | 30 + lib/yui/treeview/assets/tree.css | 24 +- lib/yui/treeview/treeview-debug.js | 1140 ++- lib/yui/treeview/treeview-min.js | 2 +- lib/yui/treeview/treeview.js | 994 +- lib/yui/yahoo-dom-event/README | 23 + lib/yui/yahoo-dom-event/yahoo-dom-event.js | 1 + lib/yui/yahoo/README | 27 + lib/yui/yahoo/yahoo-debug.js | 156 +- lib/yui/yahoo/yahoo-min.js | 2 +- lib/yui/yahoo/yahoo.js | 153 +- 79 files changed, 46200 insertions(+), 28627 deletions(-) create mode 100755 lib/yui/reset-fonts-grids/README create mode 100755 lib/yui/reset-fonts-grids/reset-fonts-grids-min.css create mode 100755 lib/yui/reset-fonts-grids/reset-fonts-grids.css create mode 100755 lib/yui/tabview/README create mode 100755 lib/yui/tabview/tabview-debug.js create mode 100755 lib/yui/tabview/tabview-min.js create mode 100755 lib/yui/tabview/tabview.js create mode 100755 lib/yui/yahoo-dom-event/README create mode 100755 lib/yui/yahoo-dom-event/yahoo-dom-event.js diff --git a/lib/yui/README.txt b/lib/yui/README.txt index e67ccb8228..ea9fdf57e7 100644 --- a/lib/yui/README.txt +++ b/lib/yui/README.txt @@ -5,4 +5,5 @@ from: http://developer.yahoo.com/yui -Added to Moodle 13th July, 2006 +Added to Moodle 13 July 2006 +Updated to YUI 0.12.0, 23 November 2006 diff --git a/lib/yui/animation/README b/lib/yui/animation/README index 0dad5425d1..e0f99516e1 100755 --- a/lib/yui/animation/README +++ b/lib/yui/animation/README @@ -1,5 +1,18 @@ Animation Release Notes +*** 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 @@ -10,7 +23,7 @@ Animation Release Notes *** version 0.10.0 *** -* Scroll now handles relative ("by") animation correctly +* Scroll now handles relative ("by") animation correctly * Now converts "auto" values of "from" to appropriate initial values @@ -18,3 +31,4 @@ Animation Release Notes * Initial release + diff --git a/lib/yui/animation/animation-debug.js b/lib/yui/animation/animation-debug.js index 7b9320dcd0..1a4c89c33d 100755 --- a/lib/yui/animation/animation-debug.js +++ b/lib/yui/animation/animation-debug.js @@ -2,21 +2,27 @@ Copyright (c) 2006, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt -Version: 0.11.0 +version: 0.12.0 */ +/** + * The animation module provides allows effects to be added to HTMLElements. + * @module animation + */ + /** * - * Base class for animated DOM objects. - * @class Base animation class that provides the interface for building animated effects. + * 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 or HTMLElement} el Reference to the element that will be animated + * @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"). @@ -33,8 +39,9 @@ YAHOO.util.Anim = function(el, attributes, duration, method) { YAHOO.util.Anim.prototype = { /** - * toString method - * @return {String} string represenation of anim obj + * Provides a readable name for the Anim instance. + * @method toString + * @return {String} */ toString: function() { var el = this.getEl(); @@ -51,6 +58,7 @@ YAHOO.util.Anim.prototype = { /** * 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. @@ -61,7 +69,8 @@ YAHOO.util.Anim.prototype = { }, /** - * Applies a value to an attribute + * 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. @@ -76,6 +85,7 @@ YAHOO.util.Anim.prototype = { /** * 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. */ @@ -103,7 +113,7 @@ YAHOO.util.Anim.prototype = { /** * Returns the unit to use when none is supplied. - * Applies the "defaultUnit" test to decide whether to use pixels or not + * @method getDefaultUnit * @param {attr} attr The name of the attribute. * @return {String} The default unit to be used. */ @@ -117,6 +127,7 @@ YAHOO.util.Anim.prototype = { /** * Sets the actual values to be used during the animation. + * @method setRuntimeAttribute * Should only be needed for subclass use. * @param {Object} attr The attribute object * @private @@ -160,7 +171,9 @@ YAHOO.util.Anim.prototype = { }, /** - * @param {String or HTMLElement} el Reference to the element that will be animated + * 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"). @@ -171,6 +184,7 @@ YAHOO.util.Anim.prototype = { init: function(el, attributes, duration, method) { /** * Whether or not the animation is running. + * @property isAnimated * @private * @type Boolean */ @@ -178,6 +192,7 @@ YAHOO.util.Anim.prototype = { /** * A Date object that is created when the animation begins. + * @property startTime * @private * @type Date */ @@ -185,6 +200,7 @@ YAHOO.util.Anim.prototype = { /** * The number of frames this animation was able to execute. + * @property actualFrames * @private * @type Int */ @@ -192,6 +208,7 @@ YAHOO.util.Anim.prototype = { /** * The element to be animated. + * @property el * @private * @type HTMLElement */ @@ -203,14 +220,15 @@ YAHOO.util.Anim.prototype = { * 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. - * @member YAHOO#util#Anim * 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 = duration || 1; @@ -218,6 +236,7 @@ YAHOO.util.Anim.prototype = { /** * 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 || YAHOO.util.Easing.easeNone; @@ -225,6 +244,7 @@ YAHOO.util.Anim.prototype = { /** * Whether or not the duration should be treated as seconds. * Defaults to true. + * @property useSeconds * @type Boolean */ this.useSeconds = true; // default to seconds @@ -232,6 +252,7 @@ YAHOO.util.Anim.prototype = { /** * 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; @@ -239,6 +260,7 @@ YAHOO.util.Anim.prototype = { /** * 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 = YAHOO.util.AnimMgr.fps; @@ -246,12 +268,14 @@ YAHOO.util.Anim.prototype = { /** * 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() { @@ -260,6 +284,7 @@ YAHOO.util.Anim.prototype = { /** * Returns the animation start time. + * @method getStartTime * @return {Date} current value of startTime. */ this.getStartTime = function() { @@ -275,6 +300,7 @@ YAHOO.util.Anim.prototype = { /** * Starts the animation by registering it with the animation manager. + * @method animate */ this.animate = function() { if ( this.isAnimated() ) { return false; } @@ -288,13 +314,21 @@ YAHOO.util.Anim.prototype = { /** * 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() { + this.stop = function(finish) { + if (finish) { + this.currentFrame = this.totalFrames; + this._onTween.fire(); + } YAHOO.util.AnimMgr.stop(this); }; var onStart = function() { this.onStart.fire(); + + this.runtimeAttributes = {}; for (var attr in this.attributes) { this.setRuntimeAttribute(attr); } @@ -364,12 +398,14 @@ YAHOO.util.Anim.prototype = { /** * Custom event that fires when animation begins * Listen via subscribe method (e.g. myAnim.onStart.subscribe(someFunction) + * @event onStart */ this.onStart = new YAHOO.util.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 YAHOO.util.CustomEvent('tween', this); @@ -382,6 +418,7 @@ YAHOO.util.Anim.prototype = { /** * Custom event that fires when animation ends * Listen via subscribe method (e.g. myAnim.onComplete.subscribe(someFunction) + * @event onComplete */ this.onComplete = new YAHOO.util.CustomEvent('complete', this); /** @@ -396,20 +433,16 @@ YAHOO.util.Anim.prototype = { } }; -/* -Copyright (c) 2006, Yahoo! Inc. All rights reserved. -Code licensed under the BSD License: -http://developer.yahoo.net/yui/license.txt -Version: 0.10.0 -*/ - /** - * @class Handles animation queueing and threading. + * 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 + * Reference to the animation Interval. + * @property thread * @private * @type Int */ @@ -417,6 +450,7 @@ YAHOO.util.AnimMgr = new function() { /** * The current queue of registered animation objects. + * @property queue * @private * @type Array */ @@ -424,6 +458,7 @@ YAHOO.util.AnimMgr = new function() { /** * The number of active animations. + * @property tweenCount * @private * @type Int */ @@ -432,6 +467,7 @@ YAHOO.util.AnimMgr = new function() { /** * Base frame rate (frames per second). * Arbitrarily high for better x-browser calibration (slower browsers drop more frames). + * @property fps * @type Int * */ @@ -439,6 +475,7 @@ YAHOO.util.AnimMgr = new function() { /** * Interval delay in milliseconds, defaults to fastest possible. + * @property delay * @type Int * */ @@ -447,6 +484,7 @@ YAHOO.util.AnimMgr = new function() { /** * 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) { @@ -456,6 +494,14 @@ YAHOO.util.AnimMgr = new function() { 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) { tween._onComplete.fire(); index = index || getIndex(tween); @@ -467,7 +513,8 @@ YAHOO.util.AnimMgr = new function() { /** * Starts the animation thread. - * Only one thread can run at a time. + * Only one thread can run at a time. + * @method start */ this.start = function() { if (thread === null) { thread = setInterval(this.run, this.delay); } @@ -475,6 +522,7 @@ YAHOO.util.AnimMgr = new function() { /** * 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. */ @@ -497,6 +545,7 @@ YAHOO.util.AnimMgr = new function() { /** * Called per Interval to handle each animation frame. + * @method run */ this.run = function() { for (var i = 0, len = queue.length; i < len; ++i) { @@ -527,6 +576,7 @@ YAHOO.util.AnimMgr = new function() { /** * On the fly frame correction to keep animation on time. + * @method correctFrame * @private * @param {Object} tween The Anim instance being corrected. */ @@ -551,16 +601,10 @@ YAHOO.util.AnimMgr = new function() { } }; }; -/* -Copyright (c) 2006, Yahoo! Inc. All rights reserved. -Code licensed under the BSD License: -http://developer.yahoo.net/yui/license.txt -Version: 0.10.0 -*/ - /** - * - * @class Used to calculate Bezier splines for any number of control points. + * Used to calculate Bezier splines for any number of control points. + * @class Bezier + * @namespace YAHOO.util * */ YAHOO.util.Bezier = new function() @@ -571,6 +615,7 @@ YAHOO.util.Bezier = new function() * 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 @@ -596,9 +641,11 @@ YAHOO.util.Bezier = new function() }; }; /** - * @class ColorAnim subclass for color fading - *

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) + * 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 @@ -606,13 +653,14 @@ YAHOO.util.Bezier = new function() * @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 Y.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a Y.Easing method) + * @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) */ (function() { YAHOO.util.ColorAnim = function(el, attributes, duration, method) { @@ -624,33 +672,27 @@ YAHOO.util.Bezier = new function() // shorthand var Y = YAHOO.util; var superclass = Y.ColorAnim.superclass; - var prototype = Y.ColorAnim.prototype; + var proto = Y.ColorAnim.prototype; - /** - * toString method - * @return {String} string represenation of anim obj - */ - prototype.toString = function() { + proto.toString = function() { var el = this.getEl(); var id = el.id || el.tagName; return ("ColorAnim " + id); }; - /** - * Only certain attributes should be treated as colors. - * @type Object - */ - prototype.patterns.color = /color$/i; - prototype.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i; - prototype.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i; - prototype.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i; + 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. */ - prototype.parseColor = function(s) { + proto.parseColor = function(s) { if (s.length == 3) { return s; } var c = this.patterns.hex.exec(s); @@ -671,25 +713,20 @@ YAHOO.util.Bezier = new function() return null; }; - /** - * Returns current value of the attribute. - * @param {String} attr The name of the attribute. - * @return {Number} val The current value of the attribute. - */ - prototype.getAttribute = function(attr) { + proto.getAttribute = function(attr) { var el = this.getEl(); if ( this.patterns.color.test(attr) ) { var val = YAHOO.util.Dom.getStyle(el, attr); - if (val == 'transparent') { // bgcolor default + if (this.patterns.transparent.test(val)) { // bgcolor default var parent = el.parentNode; // try and get from an ancestor val = Y.Dom.getStyle(parent, attr); - while (parent && val == 'transparent') { + while (parent && this.patterns.transparent.test(val)) { parent = parent.parentNode; val = Y.Dom.getStyle(parent, attr); if (parent.tagName.toUpperCase() == 'HTML') { - val = 'ffffff'; + val = '#fff'; } } } @@ -700,14 +737,7 @@ YAHOO.util.Bezier = new function() return val; }; - /** - * Returns the value computed by the animation's "method". - * @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. - */ - prototype.doMethod = function(attr, start, end) { + proto.doMethod = function(attr, start, end) { var val; if ( this.patterns.color.test(attr) ) { @@ -725,13 +755,7 @@ YAHOO.util.Bezier = new function() return val; }; - /** - * Sets the actual values to be used during the animation. - * Should only be needed for subclass use. - * @param {Object} attr The attribute object - * @private - */ - prototype.setRuntimeAttribute = function(attr) { + proto.setRuntimeAttribute = function(attr) { superclass.setRuntimeAttribute.call(this, attr); if ( this.patterns.color.test(attr) ) { @@ -754,27 +778,33 @@ YAHOO.util.Bezier = new function() })();/* TERMS OF USE - EASING EQUATIONS Open source under the BSD License. -Copyright © 2001 Robert Penner All rights reserved. +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. + * 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. - * @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. + * @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; @@ -782,11 +812,12 @@ YAHOO.util.Easing = { /** * Begins slowly and accelerates towards end. (quadratic) - * @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. + * @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; @@ -794,11 +825,12 @@ YAHOO.util.Easing = { /** * Begins quickly and decelerates towards end. (quadratic) - * @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. + * @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; @@ -806,11 +838,12 @@ YAHOO.util.Easing = { /** * Begins slowly and decelerates towards end. (quadratic) - * @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. + * @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; @@ -819,11 +852,12 @@ YAHOO.util.Easing = { /** * Begins slowly and accelerates towards end. (quartic) - * @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. + * @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; @@ -831,11 +865,12 @@ YAHOO.util.Easing = { /** * Begins quickly and decelerates towards end. (quartic) - * @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. + * @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; @@ -843,11 +878,12 @@ YAHOO.util.Easing = { /** * Begins slowly and decelerates towards end. (quartic) - * @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. + * @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; @@ -855,13 +891,14 @@ YAHOO.util.Easing = { }, /** - * snap in elastic effect - * @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. + * 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} p Period (optional) - * @return {Number} The computed value for the current animation frame. + * @return {Number} The computed value for the current animation frame */ elasticIn: function (t, b, c, d, a, p) { @@ -872,13 +909,14 @@ YAHOO.util.Easing = { }, /** - * snap out elastic effect - * @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. + * 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} p Period (optional) - * @return {Number} The computed value for the current animation frame. + * @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; @@ -888,13 +926,14 @@ YAHOO.util.Easing = { }, /** - * snap both elastic effect - * @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. + * 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} p Period (optional) - * @return {Number} The computed value for the current animation frame. + * @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); @@ -906,13 +945,14 @@ YAHOO.util.Easing = { /** - * back easing in - backtracking slightly, then reversing direction and moving to target - * @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. + * 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; @@ -920,14 +960,14 @@ YAHOO.util.Easing = { }, /** - * back easing out - moving towards target, overshooting it slightly, - * then reversing and coming back to target - * @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. + * 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; @@ -935,14 +975,15 @@ YAHOO.util.Easing = { }, /** - * back easing in/out - backtracking slightly, then reversing direction and moving to target, - * then overshooting target, reversing, and finally coming back to target - * @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. + * 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; @@ -951,24 +992,26 @@ YAHOO.util.Easing = { }, /** - * bounce in - * @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. + * 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; }, /** - * bounce out - * @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. + * 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)) { @@ -983,12 +1026,13 @@ YAHOO.util.Easing = { }, /** - * bounce both - * @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. + * 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; @@ -996,16 +1040,12 @@ YAHOO.util.Easing = { } }; -/* -Copyright (c) 2006, Yahoo! Inc. All rights reserved. -Code licensed under the BSD License: -http://developer.yahoo.net/yui/license.txt -Version: 0.10.0 -*/ - /** - * @class Anim subclass for moving elements along a path defined by the "points" member of "attributes". All "points" are arrays with x, y coordinates. + * 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 @@ -1014,7 +1054,8 @@ Version: 0.10.0 * @requires YAHOO.util.Event * @requires YAHOO.util.CustomEvent * @constructor - * @param {String or HTMLElement} el Reference to the element that will be animated + * @extends YAHOO.util.Anim + * @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"). @@ -1034,27 +1075,17 @@ Version: 0.10.0 // shorthand var Y = YAHOO.util; var superclass = Y.Motion.superclass; - var prototype = Y.Motion.prototype; + var proto = Y.Motion.prototype; - /** - * toString method - * @return {String} string represenation of anim obj - */ - prototype.toString = function() { + proto.toString = function() { var el = this.getEl(); var id = el.id || el.tagName; return ("Motion " + id); }; - prototype.patterns.points = /^points$/i; + proto.patterns.points = /^points$/i; - /** - * Applies a value to an attribute - * @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. - */ - prototype.setAttribute = function(attr, val, unit) { + proto.setAttribute = function(attr, val, unit) { if ( this.patterns.points.test(attr) ) { unit = unit || 'px'; superclass.setAttribute.call(this, 'left', val[0], unit); @@ -1064,12 +1095,7 @@ Version: 0.10.0 } }; - /** - * Sets the default value to be used when "from" is not supplied. - * @param {String} attr The attribute being set. - * @param {Number} val The default value to be applied to the attribute. - */ - prototype.getAttribute = function(attr) { + proto.getAttribute = function(attr) { if ( this.patterns.points.test(attr) ) { var val = [ superclass.getAttribute.call(this, 'left'), @@ -1082,14 +1108,7 @@ Version: 0.10.0 return val; }; - /** - * Returns the value computed by the animation's "method". - * @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. - */ - prototype.doMethod = function(attr, start, end) { + proto.doMethod = function(attr, start, end) { var val = null; if ( this.patterns.points.test(attr) ) { @@ -1101,13 +1120,7 @@ Version: 0.10.0 return val; }; - /** - * Sets the actual values to be used during the animation. - * Should only be needed for subclass use. - * @param {Object} attr The attribute object - * @private - */ - prototype.setRuntimeAttribute = function(attr) { + proto.setRuntimeAttribute = function(attr) { if ( this.patterns.points.test(attr) ) { var el = this.getEl(); var attributes = this.attributes; @@ -1179,16 +1192,12 @@ Version: 0.10.0 return (typeof prop !== 'undefined'); }; })(); -/* -Copyright (c) 2006, Yahoo! Inc. All rights reserved. -Code licensed under the BSD License: -http://developer.yahoo.net/yui/license.txt -Version: 0.10.0 -*/ - /** - * @class 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. + * 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 @@ -1196,6 +1205,7 @@ Version: 0.10.0 * @requires YAHOO.util.Dom * @requires YAHOO.util.Event * @requires YAHOO.util.CustomEvent + * @extends YAHOO.util.Anim * @constructor * @param {String or HTMLElement} el Reference to the element that will be animated * @param {Object} attributes The attribute(s) to be animated. @@ -1217,26 +1227,15 @@ Version: 0.10.0 // shorthand var Y = YAHOO.util; var superclass = Y.Scroll.superclass; - var prototype = Y.Scroll.prototype; + var proto = Y.Scroll.prototype; - /** - * toString method - * @return {String} string represenation of anim obj - */ - prototype.toString = function() { + proto.toString = function() { var el = this.getEl(); var id = el.id || el.tagName; return ("Scroll " + id); }; - /** - * Returns the value computed by the animation's "method". - * @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. - */ - prototype.doMethod = function(attr, start, end) { + proto.doMethod = function(attr, start, end) { var val = null; if (attr == 'scroll') { @@ -1251,12 +1250,7 @@ Version: 0.10.0 return val; }; - /** - * Returns current value of the attribute. - * @param {String} attr The name of the attribute. - * @return {Number} val The current value of the attribute. - */ - prototype.getAttribute = function(attr) { + proto.getAttribute = function(attr) { var val = null; var el = this.getEl(); @@ -1269,13 +1263,7 @@ Version: 0.10.0 return val; }; - /** - * Applies a value to an attribute - * @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. - */ - prototype.setAttribute = function(attr, val, unit) { + proto.setAttribute = function(attr, val, unit) { var el = this.getEl(); if (attr == 'scroll') { diff --git a/lib/yui/animation/animation-min.js b/lib/yui/animation/animation-min.js index bbea1cc643..353f3a3783 100755 --- a/lib/yui/animation/animation-min.js +++ b/lib/yui/animation/animation-min.js @@ -1 +1 @@ -/* Copyright (c) 2006, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt Version: 0.11.0*/YAHOO.util.Anim=function(el,attributes,duration,method){if(el){this.init(el,attributes,duration,method);}};YAHOO.util.Anim.prototype={toString:function(){var el=this.getEl();var id=el.id||el.tagName;return("Anim "+id);},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(attr,start,end){return this.method(this.currentFrame,start,end-start,this.totalFrames);},setAttribute:function(attr,val,unit){if(this.patterns.noNegatives.test(attr)){val=(val>0)?val:0;}YAHOO.util.Dom.setStyle(this.getEl(),attr,val+unit);},getAttribute:function(attr){var el=this.getEl();var val=YAHOO.util.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]);var box=!!(a[2]);if(box||(YAHOO.util.Dom.getStyle(el,'position')=='absolute'&&pos)){val=el['offset'+a[0].charAt(0).toUpperCase()+a[0].substr(1)];}else{val=0;}return val;},getDefaultUnit:function(attr){if(this.patterns.defaultUnit.test(attr)){return'px';}return'';},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;}start=(isset(attributes[attr]['from']))?attributes[attr]['from']:this.getAttribute(attr);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;i0&&isFinite(tweak)){if(tween.currentFrame+tweak>=frames){tweak=frames-(frame+1);}tween.currentFrame+=tweak;}};};YAHOO.util.Bezier=new function(){this.getPosition=function(points,t){var n=points.length;var tmp=[];for(var i=0;i0&&!(control[0]instanceof Array)){control=[control];}else{var tmp=[];for(i=0,len=control.length;i0){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');};})();(function(){YAHOO.util.Scroll=function(el,attributes,duration,method){if(el){YAHOO.util.Scroll.superclass.constructor.call(this,el,attributes,duration,method);}};YAHOO.extend(YAHOO.util.Scroll,YAHOO.util.ColorAnim);var Y=YAHOO.util;var superclass=Y.Scroll.superclass;var prototype=Y.Scroll.prototype;prototype.toString=function(){var el=this.getEl();var id=el.id||el.tagName;return("Scroll "+id);};prototype.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;};prototype.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;};prototype.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);}};})(); +/* Copyright (c) 2006, Yahoo! Inc. All rights reserved.Code licensed under the BSD License:http://developer.yahoo.net/yui/license.txtversion: 0.12.0 */ YAHOO.util.Anim=function(el,attributes,duration,method){if(el){this.init(el,attributes,duration,method);}};YAHOO.util.Anim.prototype={toString:function(){var el=this.getEl();var id=el.id||el.tagName;return("Anim "+id);},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(attr,start,end){return this.method(this.currentFrame,start,end-start,this.totalFrames);},setAttribute:function(attr,val,unit){if(this.patterns.noNegatives.test(attr)){val=(val>0)?val:0;}YAHOO.util.Dom.setStyle(this.getEl(),attr,val+unit);},getAttribute:function(attr){var el=this.getEl();var val=YAHOO.util.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]);var box=!!(a[2]);if(box||(YAHOO.util.Dom.getStyle(el,'position')=='absolute'&&pos)){val=el['offset'+a[0].charAt(0).toUpperCase()+a[0].substr(1)];}else{val=0;}return val;},getDefaultUnit:function(attr){if(this.patterns.defaultUnit.test(attr)){return'px';}return'';},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;}start=(isset(attributes[attr]['from']))?attributes[attr]['from']:this.getAttribute(attr);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;i0&&isFinite(tweak)){if(tween.currentFrame+tweak>=frames){tweak=frames-(frame+1);}tween.currentFrame+=tweak;}};};YAHOO.util.Bezier=new function(){this.getPosition=function(points,t){var n=points.length;var tmp=[];for(var i=0;i0&&!(control[0]instanceof Array)){control=[control];}else{var tmp=[];for(i=0,len=control.length;i0){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');};})();(function(){YAHOO.util.Scroll=function(el,attributes,duration,method){if(el){YAHOO.util.Scroll.superclass.constructor.call(this,el,attributes,duration,method);}};YAHOO.extend(YAHOO.util.Scroll,YAHOO.util.ColorAnim);var Y=YAHOO.util;var superclass=Y.Scroll.superclass;var proto=Y.Scroll.prototype;proto.toString=function(){var el=this.getEl();var id=el.id||el.tagName;return("Scroll "+id);};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);}};})(); \ No newline at end of file diff --git a/lib/yui/animation/animation.js b/lib/yui/animation/animation.js index 5f2f9d14cc..333f946903 100755 --- a/lib/yui/animation/animation.js +++ b/lib/yui/animation/animation.js @@ -2,21 +2,27 @@ Copyright (c) 2006, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt -Version: 0.11.0 +version: 0.12.0 */ +/** + * The animation module provides allows effects to be added to HTMLElements. + * @module animation + */ + /** * - * Base class for animated DOM objects. - * @class Base animation class that provides the interface for building animated effects. + * 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 or HTMLElement} el Reference to the element that will be animated + * @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"). @@ -33,8 +39,9 @@ YAHOO.util.Anim = function(el, attributes, duration, method) { YAHOO.util.Anim.prototype = { /** - * toString method - * @return {String} string represenation of anim obj + * Provides a readable name for the Anim instance. + * @method toString + * @return {String} */ toString: function() { var el = this.getEl(); @@ -51,6 +58,7 @@ YAHOO.util.Anim.prototype = { /** * 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. @@ -61,7 +69,8 @@ YAHOO.util.Anim.prototype = { }, /** - * Applies a value to an attribute + * 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. @@ -76,6 +85,7 @@ YAHOO.util.Anim.prototype = { /** * 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. */ @@ -103,7 +113,7 @@ YAHOO.util.Anim.prototype = { /** * Returns the unit to use when none is supplied. - * Applies the "defaultUnit" test to decide whether to use pixels or not + * @method getDefaultUnit * @param {attr} attr The name of the attribute. * @return {String} The default unit to be used. */ @@ -117,6 +127,7 @@ YAHOO.util.Anim.prototype = { /** * Sets the actual values to be used during the animation. + * @method setRuntimeAttribute * Should only be needed for subclass use. * @param {Object} attr The attribute object * @private @@ -160,7 +171,9 @@ YAHOO.util.Anim.prototype = { }, /** - * @param {String or HTMLElement} el Reference to the element that will be animated + * 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"). @@ -171,6 +184,7 @@ YAHOO.util.Anim.prototype = { init: function(el, attributes, duration, method) { /** * Whether or not the animation is running. + * @property isAnimated * @private * @type Boolean */ @@ -178,6 +192,7 @@ YAHOO.util.Anim.prototype = { /** * A Date object that is created when the animation begins. + * @property startTime * @private * @type Date */ @@ -185,6 +200,7 @@ YAHOO.util.Anim.prototype = { /** * The number of frames this animation was able to execute. + * @property actualFrames * @private * @type Int */ @@ -192,6 +208,7 @@ YAHOO.util.Anim.prototype = { /** * The element to be animated. + * @property el * @private * @type HTMLElement */ @@ -203,14 +220,15 @@ YAHOO.util.Anim.prototype = { * 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. - * @member YAHOO#util#Anim * 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 = duration || 1; @@ -218,6 +236,7 @@ YAHOO.util.Anim.prototype = { /** * 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 || YAHOO.util.Easing.easeNone; @@ -225,6 +244,7 @@ YAHOO.util.Anim.prototype = { /** * Whether or not the duration should be treated as seconds. * Defaults to true. + * @property useSeconds * @type Boolean */ this.useSeconds = true; // default to seconds @@ -232,6 +252,7 @@ YAHOO.util.Anim.prototype = { /** * 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; @@ -239,6 +260,7 @@ YAHOO.util.Anim.prototype = { /** * 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 = YAHOO.util.AnimMgr.fps; @@ -246,12 +268,14 @@ YAHOO.util.Anim.prototype = { /** * 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() { @@ -260,6 +284,7 @@ YAHOO.util.Anim.prototype = { /** * Returns the animation start time. + * @method getStartTime * @return {Date} current value of startTime. */ this.getStartTime = function() { @@ -272,6 +297,7 @@ YAHOO.util.Anim.prototype = { /** * Starts the animation by registering it with the animation manager. + * @method animate */ this.animate = function() { if ( this.isAnimated() ) { return false; } @@ -285,13 +311,21 @@ YAHOO.util.Anim.prototype = { /** * 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() { + this.stop = function(finish) { + if (finish) { + this.currentFrame = this.totalFrames; + this._onTween.fire(); + } YAHOO.util.AnimMgr.stop(this); }; var onStart = function() { this.onStart.fire(); + + this.runtimeAttributes = {}; for (var attr in this.attributes) { this.setRuntimeAttribute(attr); } @@ -361,12 +395,14 @@ YAHOO.util.Anim.prototype = { /** * Custom event that fires when animation begins * Listen via subscribe method (e.g. myAnim.onStart.subscribe(someFunction) + * @event onStart */ this.onStart = new YAHOO.util.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 YAHOO.util.CustomEvent('tween', this); @@ -379,6 +415,7 @@ YAHOO.util.Anim.prototype = { /** * Custom event that fires when animation ends * Listen via subscribe method (e.g. myAnim.onComplete.subscribe(someFunction) + * @event onComplete */ this.onComplete = new YAHOO.util.CustomEvent('complete', this); /** @@ -393,20 +430,16 @@ YAHOO.util.Anim.prototype = { } }; -/* -Copyright (c) 2006, Yahoo! Inc. All rights reserved. -Code licensed under the BSD License: -http://developer.yahoo.net/yui/license.txt -Version: 0.10.0 -*/ - /** - * @class Handles animation queueing and threading. + * 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 + * Reference to the animation Interval. + * @property thread * @private * @type Int */ @@ -414,6 +447,7 @@ YAHOO.util.AnimMgr = new function() { /** * The current queue of registered animation objects. + * @property queue * @private * @type Array */ @@ -421,6 +455,7 @@ YAHOO.util.AnimMgr = new function() { /** * The number of active animations. + * @property tweenCount * @private * @type Int */ @@ -429,6 +464,7 @@ YAHOO.util.AnimMgr = new function() { /** * Base frame rate (frames per second). * Arbitrarily high for better x-browser calibration (slower browsers drop more frames). + * @property fps * @type Int * */ @@ -436,6 +472,7 @@ YAHOO.util.AnimMgr = new function() { /** * Interval delay in milliseconds, defaults to fastest possible. + * @property delay * @type Int * */ @@ -444,6 +481,7 @@ YAHOO.util.AnimMgr = new function() { /** * 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) { @@ -453,6 +491,14 @@ YAHOO.util.AnimMgr = new function() { 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) { tween._onComplete.fire(); index = index || getIndex(tween); @@ -464,7 +510,8 @@ YAHOO.util.AnimMgr = new function() { /** * Starts the animation thread. - * Only one thread can run at a time. + * Only one thread can run at a time. + * @method start */ this.start = function() { if (thread === null) { thread = setInterval(this.run, this.delay); } @@ -472,6 +519,7 @@ YAHOO.util.AnimMgr = new function() { /** * 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. */ @@ -494,6 +542,7 @@ YAHOO.util.AnimMgr = new function() { /** * Called per Interval to handle each animation frame. + * @method run */ this.run = function() { for (var i = 0, len = queue.length; i < len; ++i) { @@ -524,6 +573,7 @@ YAHOO.util.AnimMgr = new function() { /** * On the fly frame correction to keep animation on time. + * @method correctFrame * @private * @param {Object} tween The Anim instance being corrected. */ @@ -548,16 +598,10 @@ YAHOO.util.AnimMgr = new function() { } }; }; -/* -Copyright (c) 2006, Yahoo! Inc. All rights reserved. -Code licensed under the BSD License: -http://developer.yahoo.net/yui/license.txt -Version: 0.10.0 -*/ - /** - * - * @class Used to calculate Bezier splines for any number of control points. + * Used to calculate Bezier splines for any number of control points. + * @class Bezier + * @namespace YAHOO.util * */ YAHOO.util.Bezier = new function() @@ -568,6 +612,7 @@ YAHOO.util.Bezier = new function() * 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 @@ -593,9 +638,11 @@ YAHOO.util.Bezier = new function() }; }; /** - * @class ColorAnim subclass for color fading - *

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) + * 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 @@ -603,13 +650,14 @@ YAHOO.util.Bezier = new function() * @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 Y.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a Y.Easing method) + * @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) */ (function() { YAHOO.util.ColorAnim = function(el, attributes, duration, method) { @@ -621,33 +669,27 @@ YAHOO.util.Bezier = new function() // shorthand var Y = YAHOO.util; var superclass = Y.ColorAnim.superclass; - var prototype = Y.ColorAnim.prototype; + var proto = Y.ColorAnim.prototype; - /** - * toString method - * @return {String} string represenation of anim obj - */ - prototype.toString = function() { + proto.toString = function() { var el = this.getEl(); var id = el.id || el.tagName; return ("ColorAnim " + id); }; - /** - * Only certain attributes should be treated as colors. - * @type Object - */ - prototype.patterns.color = /color$/i; - prototype.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i; - prototype.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i; - prototype.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i; + 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. */ - prototype.parseColor = function(s) { + proto.parseColor = function(s) { if (s.length == 3) { return s; } var c = this.patterns.hex.exec(s); @@ -668,25 +710,20 @@ YAHOO.util.Bezier = new function() return null; }; - /** - * Returns current value of the attribute. - * @param {String} attr The name of the attribute. - * @return {Number} val The current value of the attribute. - */ - prototype.getAttribute = function(attr) { + proto.getAttribute = function(attr) { var el = this.getEl(); if ( this.patterns.color.test(attr) ) { var val = YAHOO.util.Dom.getStyle(el, attr); - if (val == 'transparent') { // bgcolor default + if (this.patterns.transparent.test(val)) { // bgcolor default var parent = el.parentNode; // try and get from an ancestor val = Y.Dom.getStyle(parent, attr); - while (parent && val == 'transparent') { + while (parent && this.patterns.transparent.test(val)) { parent = parent.parentNode; val = Y.Dom.getStyle(parent, attr); if (parent.tagName.toUpperCase() == 'HTML') { - val = 'ffffff'; + val = '#fff'; } } } @@ -697,14 +734,7 @@ YAHOO.util.Bezier = new function() return val; }; - /** - * Returns the value computed by the animation's "method". - * @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. - */ - prototype.doMethod = function(attr, start, end) { + proto.doMethod = function(attr, start, end) { var val; if ( this.patterns.color.test(attr) ) { @@ -722,13 +752,7 @@ YAHOO.util.Bezier = new function() return val; }; - /** - * Sets the actual values to be used during the animation. - * Should only be needed for subclass use. - * @param {Object} attr The attribute object - * @private - */ - prototype.setRuntimeAttribute = function(attr) { + proto.setRuntimeAttribute = function(attr) { superclass.setRuntimeAttribute.call(this, attr); if ( this.patterns.color.test(attr) ) { @@ -751,27 +775,33 @@ YAHOO.util.Bezier = new function() })();/* TERMS OF USE - EASING EQUATIONS Open source under the BSD License. -Copyright © 2001 Robert Penner All rights reserved. +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. + * 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. - * @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. + * @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; @@ -779,11 +809,12 @@ YAHOO.util.Easing = { /** * Begins slowly and accelerates towards end. (quadratic) - * @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. + * @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; @@ -791,11 +822,12 @@ YAHOO.util.Easing = { /** * Begins quickly and decelerates towards end. (quadratic) - * @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. + * @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; @@ -803,11 +835,12 @@ YAHOO.util.Easing = { /** * Begins slowly and decelerates towards end. (quadratic) - * @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. + * @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; @@ -816,11 +849,12 @@ YAHOO.util.Easing = { /** * Begins slowly and accelerates towards end. (quartic) - * @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. + * @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; @@ -828,11 +862,12 @@ YAHOO.util.Easing = { /** * Begins quickly and decelerates towards end. (quartic) - * @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. + * @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; @@ -840,11 +875,12 @@ YAHOO.util.Easing = { /** * Begins slowly and decelerates towards end. (quartic) - * @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. + * @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; @@ -852,13 +888,14 @@ YAHOO.util.Easing = { }, /** - * snap in elastic effect - * @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. + * 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} p Period (optional) - * @return {Number} The computed value for the current animation frame. + * @return {Number} The computed value for the current animation frame */ elasticIn: function (t, b, c, d, a, p) { @@ -869,13 +906,14 @@ YAHOO.util.Easing = { }, /** - * snap out elastic effect - * @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. + * 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} p Period (optional) - * @return {Number} The computed value for the current animation frame. + * @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; @@ -885,13 +923,14 @@ YAHOO.util.Easing = { }, /** - * snap both elastic effect - * @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. + * 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} p Period (optional) - * @return {Number} The computed value for the current animation frame. + * @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); @@ -902,13 +941,14 @@ YAHOO.util.Easing = { }, /** - * back easing in - backtracking slightly, then reversing direction and moving to target - * @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. + * 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; @@ -916,14 +956,14 @@ YAHOO.util.Easing = { }, /** - * back easing out - moving towards target, overshooting it slightly, - * then reversing and coming back to target - * @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. + * 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; @@ -931,14 +971,15 @@ YAHOO.util.Easing = { }, /** - * back easing in/out - backtracking slightly, then reversing direction and moving to target, - * then overshooting target, reversing, and finally coming back to target - * @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. + * 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; @@ -947,24 +988,26 @@ YAHOO.util.Easing = { }, /** - * bounce in - * @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. + * 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; }, /** - * bounce out - * @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. + * 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)) { @@ -979,12 +1022,13 @@ YAHOO.util.Easing = { }, /** - * bounce both - * @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. + * 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; @@ -992,16 +1036,12 @@ YAHOO.util.Easing = { } }; -/* -Copyright (c) 2006, Yahoo! Inc. All rights reserved. -Code licensed under the BSD License: -http://developer.yahoo.net/yui/license.txt -Version: 0.10.0 -*/ - /** - * @class Anim subclass for moving elements along a path defined by the "points" member of "attributes". All "points" are arrays with x, y coordinates. + * 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 @@ -1010,7 +1050,8 @@ Version: 0.10.0 * @requires YAHOO.util.Event * @requires YAHOO.util.CustomEvent * @constructor - * @param {String or HTMLElement} el Reference to the element that will be animated + * @extends YAHOO.util.Anim + * @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"). @@ -1030,27 +1071,17 @@ Version: 0.10.0 // shorthand var Y = YAHOO.util; var superclass = Y.Motion.superclass; - var prototype = Y.Motion.prototype; + var proto = Y.Motion.prototype; - /** - * toString method - * @return {String} string represenation of anim obj - */ - prototype.toString = function() { + proto.toString = function() { var el = this.getEl(); var id = el.id || el.tagName; return ("Motion " + id); }; - prototype.patterns.points = /^points$/i; + proto.patterns.points = /^points$/i; - /** - * Applies a value to an attribute - * @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. - */ - prototype.setAttribute = function(attr, val, unit) { + proto.setAttribute = function(attr, val, unit) { if ( this.patterns.points.test(attr) ) { unit = unit || 'px'; superclass.setAttribute.call(this, 'left', val[0], unit); @@ -1060,12 +1091,7 @@ Version: 0.10.0 } }; - /** - * Sets the default value to be used when "from" is not supplied. - * @param {String} attr The attribute being set. - * @param {Number} val The default value to be applied to the attribute. - */ - prototype.getAttribute = function(attr) { + proto.getAttribute = function(attr) { if ( this.patterns.points.test(attr) ) { var val = [ superclass.getAttribute.call(this, 'left'), @@ -1078,14 +1104,7 @@ Version: 0.10.0 return val; }; - /** - * Returns the value computed by the animation's "method". - * @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. - */ - prototype.doMethod = function(attr, start, end) { + proto.doMethod = function(attr, start, end) { var val = null; if ( this.patterns.points.test(attr) ) { @@ -1097,13 +1116,7 @@ Version: 0.10.0 return val; }; - /** - * Sets the actual values to be used during the animation. - * Should only be needed for subclass use. - * @param {Object} attr The attribute object - * @private - */ - prototype.setRuntimeAttribute = function(attr) { + proto.setRuntimeAttribute = function(attr) { if ( this.patterns.points.test(attr) ) { var el = this.getEl(); var attributes = this.attributes; @@ -1175,16 +1188,12 @@ Version: 0.10.0 return (typeof prop !== 'undefined'); }; })(); -/* -Copyright (c) 2006, Yahoo! Inc. All rights reserved. -Code licensed under the BSD License: -http://developer.yahoo.net/yui/license.txt -Version: 0.10.0 -*/ - /** - * @class 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. + * 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 @@ -1192,6 +1201,7 @@ Version: 0.10.0 * @requires YAHOO.util.Dom * @requires YAHOO.util.Event * @requires YAHOO.util.CustomEvent + * @extends YAHOO.util.Anim * @constructor * @param {String or HTMLElement} el Reference to the element that will be animated * @param {Object} attributes The attribute(s) to be animated. @@ -1213,26 +1223,15 @@ Version: 0.10.0 // shorthand var Y = YAHOO.util; var superclass = Y.Scroll.superclass; - var prototype = Y.Scroll.prototype; + var proto = Y.Scroll.prototype; - /** - * toString method - * @return {String} string represenation of anim obj - */ - prototype.toString = function() { + proto.toString = function() { var el = this.getEl(); var id = el.id || el.tagName; return ("Scroll " + id); }; - /** - * Returns the value computed by the animation's "method". - * @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. - */ - prototype.doMethod = function(attr, start, end) { + proto.doMethod = function(attr, start, end) { var val = null; if (attr == 'scroll') { @@ -1247,12 +1246,7 @@ Version: 0.10.0 return val; }; - /** - * Returns current value of the attribute. - * @param {String} attr The name of the attribute. - * @return {Number} val The current value of the attribute. - */ - prototype.getAttribute = function(attr) { + proto.getAttribute = function(attr) { var val = null; var el = this.getEl(); @@ -1265,13 +1259,7 @@ Version: 0.10.0 return val; }; - /** - * Applies a value to an attribute - * @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. - */ - prototype.setAttribute = function(attr, val, unit) { + proto.setAttribute = function(attr, val, unit) { var el = this.getEl(); if (attr == 'scroll') { diff --git a/lib/yui/autocomplete/README b/lib/yui/autocomplete/README index a3b5c1fb33..4470be23f2 100755 --- a/lib/yui/autocomplete/README +++ b/lib/yui/autocomplete/README @@ -1,5 +1,34 @@ AutoComplete Release Notes +*** 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 diff --git a/lib/yui/autocomplete/autocomplete-debug.js b/lib/yui/autocomplete/autocomplete-debug.js index f78c68f53f..62fd2b73bd 100755 --- a/lib/yui/autocomplete/autocomplete-debug.js +++ b/lib/yui/autocomplete/autocomplete-debug.js @@ -2,1857 +2,2077 @@ Copyright (c) 2006, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.txt -version: 0.11.0 +version: 0.12.0 */ + /** + * The AutoComplete control provides the front-end logic for text-entry suggestion and + * completion functionality. + * + * @module autocomplete + * @requires yahoo, dom, event, datasource + * @optional animation, connection, json + * @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 {Object} Instance of YAHOO.widget.DataSource for query/results + * @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 && (oDataSource instanceof YAHOO.widget.DataSource)) { + this.dataSource = oDataSource; + } + else { + YAHOO.log("Could not instantiate AutoComplete due to an invalid DataSource", "error", this.toString()); + return; + } + + // Validate input element + if(YAHOO.util.Dom.inDocument(elInput)) { + if(typeof elInput == "string") { + this._sName = "instance" + YAHOO.widget.AutoComplete._nIndex + " " + elInput; + this._oTextbox = document.getElementById(elInput); + } + else { + this._sName = (elInput.id) ? + "instance" + YAHOO.widget.AutoComplete._nIndex + " " + elInput.id: + "instance" + YAHOO.widget.AutoComplete._nIndex; + this._oTextbox = elInput; + } + } + 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(typeof elContainer == "string") { + this._oContainer = document.getElementById(elContainer); + } + else { + this._oContainer = elContainer; + } + if(this._oContainer.style.display == "none") { + YAHOO.log("The container may not display properly if display is set to \"none\" in CSS", "warn", this.toString()); + } + } + else { + YAHOO.log("Could not instantiate AutoComplete due to an invalid container element", "error", this.toString()); + return; + } + + // Set any config params passed in to override defaults + if (typeof oConfigs == "object") { + for(var sConfig in oConfigs) { + if (sConfig) { + this[sConfig] = oConfigs[sConfig]; + } + } + } + + // Initialization sequence + this._initContainer(); + this._initProps(); + this._initList(); + this._initContainerHelpers(); + + // Set up events + var oSelf = this; + var oTextbox = this._oTextbox; + // Events are actually for the content module within the container + var oContent = this._oContainer._oContent; + + // Dom events + YAHOO.util.Event.addListener(oTextbox,"keyup",oSelf._onTextboxKeyUp,oSelf); + YAHOO.util.Event.addListener(oTextbox,"keydown",oSelf._onTextboxKeyDown,oSelf); + YAHOO.util.Event.addListener(oTextbox,"focus",oSelf._onTextboxFocus,oSelf); + YAHOO.util.Event.addListener(oTextbox,"blur",oSelf._onTextboxBlur,oSelf); + YAHOO.util.Event.addListener(oContent,"mouseover",oSelf._onContainerMouseover,oSelf); + YAHOO.util.Event.addListener(oContent,"mouseout",oSelf._onContainerMouseout,oSelf); + YAHOO.util.Event.addListener(oContent,"scroll",oSelf._onContainerScroll,oSelf); + YAHOO.util.Event.addListener(oContent,"resize",oSelf._onContainerResize,oSelf); + if(oTextbox.form) { + YAHOO.util.Event.addListener(oTextbox.form,"submit",oSelf._onFormSubmit,oSelf); + } + YAHOO.util.Event.addListener(oTextbox,"keypress",oSelf._onTextboxKeyPress,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.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); + + // Finish up + oTextbox.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 Object + */ +YAHOO.widget.AutoComplete.prototype.dataSource = null; + +/** + * 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. + * + * @property queryDelay + * @type Number + * @default 0.5 + */ +YAHOO.widget.AutoComplete.prototype.queryDelay = 0.5; + +/** + * Class name of a highlighted item within results container. + * + * @property highlighClassName + * @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; + +/** + * Whether or not the input field should be automatically updated + * with the first query result as the user types, auto-selecting the substring + * that the user has not 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; + +/** + * Whether or not the results container should always be displayed. + * Enabling this feature displays the container when the widget is instantiated + * and prevents the toggling of the container to a collapsed state. + * + * @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; + +///////////////////////////////////////////////////////////////////////////// +// +// 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 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 internal array of DOM <li> elements that + * display query results within the results container. + * + * @method getListItems + * @return {HTMLElement[]} Array of <li> elements within the results container. + */ +YAHOO.widget.AutoComplete.prototype.getListItems = function() { + return this._aListItems; +}; + +/** + * Public accessor to the data held in an <li> element of the + * results container. + * + * @method getListItemData + * @return {Object | Array} Object or array of result data or null + */ +YAHOO.widget.AutoComplete.prototype.getListItemData = function(oListItem) { + if(oListItem._oResultData) { + return oListItem._oResultData; + } + else { + return false; + } +}; + +/** + * Sets HTML markup for the results container header. This markup will be + * inserted within a <div> tag with a class of "ac_hd". + * + * @method setHeader + * @param sHeader {String} HTML markup for results container header. + */ +YAHOO.widget.AutoComplete.prototype.setHeader = function(sHeader) { + if(sHeader) { + if(this._oContainer._oContent._oHeader) { + this._oContainer._oContent._oHeader.innerHTML = sHeader; + this._oContainer._oContent._oHeader.style.display = "block"; + } + } + else { + this._oContainer._oContent._oHeader.innerHTML = ""; + this._oContainer._oContent._oHeader.style.display = "none"; + } +}; + +/** + * Sets HTML markup for the results container footer. This markup will be + * inserted within a <div> tag with a class of "ac_ft". + * + * @method setFooter + * @param sFooter {String} HTML markup for results container footer. + */ +YAHOO.widget.AutoComplete.prototype.setFooter = function(sFooter) { + if(sFooter) { + if(this._oContainer._oContent._oFooter) { + this._oContainer._oContent._oFooter.innerHTML = sFooter; + this._oContainer._oContent._oFooter.style.display = "block"; + } + } + else { + this._oContainer._oContent._oFooter.innerHTML = ""; + this._oContainer._oContent._oFooter.style.display = "none"; + } +}; + +/** + * Sets HTML markup for the results container body. This markup will be + * inserted within a <div> tag with a class of "ac_bd". + * + * @method setBody + * @param sHeader {String} HTML markup for results container body. + */ +YAHOO.widget.AutoComplete.prototype.setBody = function(sBody) { + if(sBody) { + if(this._oContainer._oContent._oBody) { + this._oContainer._oContent._oBody.innerHTML = sBody; + this._oContainer._oContent._oBody.style.display = "block"; + this._oContainer._oContent.style.display = "block"; + } + } + else { + this._oContainer._oContent._oBody.innerHTML = ""; + this._oContainer._oContent.style.display = "none"; + } + this._maxResultsDisplayed = 0; +}; + +/** + * Overridable method that converts a result item object into HTML markup + * for display. Return data values are accessible via the oResultItem object, + * and the key return value will always be oResultItem[0]. Markup will be + * displayed within <li> element tags in the container. + * + * @method formatResult + * @param oResultItem {Object} Result item representing one query result. Data is held in an array. + * @param sQuery {String} The current query string. + * @return {String} HTML markup of formatted result data. + */ +YAHOO.widget.AutoComplete.prototype.formatResult = function(oResultItem, sQuery) { + var sResult = oResultItem[0]; + if(sResult) { + return sResult; + } + else { + return ""; + } +}; + +/** + * Overridable method called before container expands allows implementers to access data + * and DOM elements. + * + * @method doBeforeExpandContainer + * @return {Boolean} Return true to continue expanding container, false to cancel the expand. + */ +YAHOO.widget.AutoComplete.prototype.doBeforeExpandContainer = function(oResultItem, sQuery) { + return true; +}; + +/** + * Makes query request to the DataSource. + * + * @method sendQuery + * @param sQuery {String} Query string. + */ +YAHOO.widget.AutoComplete.prototype.sendQuery = function(sQuery) { + this._sendQuery(sQuery); +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Public events +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Fired when the input field receives focus. + * + * @event textboxFocusEvent + * @param oSelf {Object} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.textboxFocusEvent = null; + +/** + * Fired when the input field receives key input. + * + * @event textboxKeyEvent + * @param oSelf {Object} The AutoComplete instance. + * @param nKeycode {Number} The keycode number. + */ +YAHOO.widget.AutoComplete.prototype.textboxKeyEvent = null; + +/** + * Fired when the AutoComplete instance makes a query to the DataSource. + * + * @event dataRequestEvent + * @param oSelf {Object} The AutoComplete instance. + * @param sQuery {String} The query string. + */ +YAHOO.widget.AutoComplete.prototype.dataRequestEvent = null; + +/** + * Fired when the AutoComplete instance receives query results from the data + * source. + * + * @event dataReturnEvent + * @param oSelf {Object} The AutoComplete instance. + * @param sQuery {String} The query string. + * @param aResults {Array} 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 {Object} The AutoComplete instance. + * @param sQuery {String} The query string. + */ +YAHOO.widget.AutoComplete.prototype.dataErrorEvent = null; + +/** + * Fired when the results container is expanded. + * + * @event containerExpandEvent + * @param oSelf {Object} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.containerExpandEvent = null; + +/** + * Fired when the input field has been prefilled by the type-ahead + * feature. + * + * @event typeAheadEvent + * @param oSelf {Object} 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 {Object} 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 {Object} 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 {Object} 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 {Object} 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 {Object} 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. + * Note that this event may not behave as expected when delimiter characters + * have been defined. + * + * @event unmatchedItemSelectEvent + * @param oSelf {Object} The AutoComplete instance. + * @param sQuery {String} The user-typed query 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 {Object} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.selectionEnforceEvent = null; + +/** + * Fired when the results container is collapsed. + * + * @event containerCollapseEvent + * @param oSelf {Object} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.containerCollapseEvent = null; + +/** + * Fired when the input field loses focus. + * + * @event textboxBlurEvent + * @param oSelf {Object} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.textboxBlurEvent = 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 _oTextbox + * @type HTMLElement + * @private + */ +YAHOO.widget.AutoComplete.prototype._oTextbox = 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 = true; + +/** + * Animation instance for container expand/collapse. + * + * @property _oAnim + * @type Boolean + * @private + */ +YAHOO.widget.AutoComplete.prototype._oAnim = null; + +/** + * Container DOM element. + * + * @property _oContainer + * @type HTMLElement + * @private + */ +YAHOO.widget.AutoComplete.prototype._oContainer = 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; + +/** + * Array of <li> elements references that contain query results within the + * results container. + * + * @property _aListItems + * @type Array + * @private + */ +YAHOO.widget.AutoComplete.prototype._aListItems = 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; + +/** + * Past queries this session (for saving delimited queries). + * + * @property _sSavedQuery + * @type String + * @private + */ +YAHOO.widget.AutoComplete.prototype._sSavedQuery = null; + +/** + * Pointer to the currently highlighted <li> element in the container. + * + * @property _oCurItem + * @type HTMLElement + * @private + */ +YAHOO.widget.AutoComplete.prototype._oCurItem = 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; + +/** + * 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(isNaN(minQueryLength) || (minQueryLength < 1)) { + minQueryLength = 1; + } + var maxResultsDisplayed = this.maxResultsDisplayed; + if(isNaN(this.maxResultsDisplayed) || (this.maxResultsDisplayed < 1)) { + this.maxResultsDisplayed = 10; + } + var queryDelay = this.queryDelay; + if(isNaN(this.queryDelay) || (this.queryDelay < 0)) { + this.queryDelay = 0.5; + } + var aDelimChar = (this.delimChar) ? this.delimChar : null; + if(aDelimChar) { + if(typeof aDelimChar == "string") { + this.delimChar = [aDelimChar]; + } + else if(aDelimChar.constructor != Array) { + this.delimChar = null; + } + } + var animSpeed = this.animSpeed; + if((this.animHoriz || this.animVert) && YAHOO.util.Anim) { + if(isNaN(animSpeed) || (animSpeed < 0)) { + animSpeed = 0.3; + } + if(!this._oAnim ) { + oAnim = new YAHOO.util.Anim(this._oContainer._oContent, {}, this.animSpeed); + this._oAnim = oAnim; + } + else { + this._oAnim.duration = animSpeed; + } + } + if(this.forceSelection && this.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 _initContainerHelpers + * @private + */ +YAHOO.widget.AutoComplete.prototype._initContainerHelpers = function() { + if(this.useShadow && !this._oContainer._oShadow) { + var oShadow = document.createElement("div"); + oShadow.className = "yui-ac-shadow"; + this._oContainer._oShadow = this._oContainer.appendChild(oShadow); + } + if(this.useIFrame && !this._oContainer._oIFrame) { + var oIFrame = document.createElement("iframe"); + oIFrame.src = this._iFrameSrc; + oIFrame.frameBorder = 0; + oIFrame.scrolling = "no"; + oIFrame.style.position = "absolute"; + oIFrame.style.width = "100%"; + oIFrame.style.height = "100%"; + oIFrame.tabIndex = -1; + this._oContainer._oIFrame = this._oContainer.appendChild(oIFrame); + } +}; + +/** + * Initializes the results container once at object creation + * + * @method _initContainer + * @private + */ +YAHOO.widget.AutoComplete.prototype._initContainer = function() { + if(!this._oContainer._oContent) { + // The oContent div helps size the iframe and shadow properly + var oContent = document.createElement("div"); + oContent.className = "yui-ac-content"; + oContent.style.display = "none"; + this._oContainer._oContent = this._oContainer.appendChild(oContent); + + var oHeader = document.createElement("div"); + oHeader.className = "yui-ac-hd"; + oHeader.style.display = "none"; + this._oContainer._oContent._oHeader = this._oContainer._oContent.appendChild(oHeader); + + var oBody = document.createElement("div"); + oBody.className = "yui-ac-bd"; + this._oContainer._oContent._oBody = this._oContainer._oContent.appendChild(oBody); + + var oFooter = document.createElement("div"); + oFooter.className = "yui-ac-ft"; + oFooter.style.display = "none"; + this._oContainer._oContent._oFooter = this._oContainer._oContent.appendChild(oFooter); + } + 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 _initList + * @private + */ +YAHOO.widget.AutoComplete.prototype._initList = function() { + this._aListItems = []; + while(this._oContainer._oContent._oBody.hasChildNodes()) { + var oldListItems = this.getListItems(); + if(oldListItems) { + for(var oldi = oldListItems.length-1; oldi >= 0; i--) { + oldListItems[oldi] = null; + } + } + this._oContainer._oContent._oBody.innerHTML = ""; + } + + var oList = document.createElement("ul"); + oList = this._oContainer._oContent._oBody.appendChild(oList); + for(var i=0; i= 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 >= 44 && nKeyCode <= 45)) { // print screen,insert + 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 == -1) { + this._toggleContainer(false); + return; + } + // Delimiter has been enabled + var aDelimChar = (this.delimChar) ? this.delimChar : null; + if(aDelimChar) { + // Loop through all possible delimiters and find the latest one + // 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 so extract the latest query + 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._sSavedQuery = sQuery.substring(0,nQueryStart); + // Here is the query itself + sQuery = sQuery.substr(nQueryStart); + } + else if(sQuery.indexOf(this._sSavedQuery) < 0){ + this._sSavedQuery = null; + } + } + + // 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); + return; + } + + sQuery = encodeURIComponent(sQuery); + this._nDelayID = -1; // Reset timeout ID because request has been made + this.dataRequestEvent.fire(this, sQuery); + this.dataSource.getResults(this._populateList, sQuery, this); +}; + +/** + * Populates the array of <li> elements in the container with query + * results. This method is passed to YAHOO.widget.DataSource#getResults as a + * callback function so results from the DataSource instance are returned to the + * AutoComplete instance. + * + * @method _populateList + * @param sQuery {String} The query string. + * @param aResults {Array} An array of query result objects from the DataSource. + * @param oSelf {Object} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._populateList = function(sQuery, aResults, oSelf) { + if(aResults === null) { + oSelf.dataErrorEvent.fire(oSelf, sQuery); + } + if (!oSelf._bFocused || !aResults) { + return; + } + + var isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1); + var contentStyle = oSelf._oContainer._oContent.style; + contentStyle.width = (!isOpera) ? null : ""; + contentStyle.height = (!isOpera) ? null : ""; + + var sCurQuery = decodeURIComponent(sQuery); + oSelf._sCurQuery = sCurQuery; + oSelf._bItemSelected = false; + + if(oSelf._maxResultsDisplayed != oSelf.maxResultsDisplayed) { + oSelf._initList(); + } + + var nItems = Math.min(aResults.length,oSelf.maxResultsDisplayed); + oSelf._nDisplayedItems = nItems; + if (nItems > 0) { + oSelf._initContainerHelpers(); + var aItems = oSelf._aListItems; + + // Fill items with data + for(var i = nItems-1; i >= 0; i--) { + var oItemi = aItems[i]; + var oResultItemi = aResults[i]; + oItemi.innerHTML = oSelf.formatResult(oResultItemi, sCurQuery); + oItemi.style.display = "list-item"; + oItemi._sResultKey = oResultItemi[0]; + oItemi._oResultData = oResultItemi; + + } + + // Empty out remaining items if any + for(var j = aItems.length-1; j >= nItems ; j--) { + var oItemj = aItems[j]; + oItemj.innerHTML = null; + oItemj.style.display = "none"; + oItemj._sResultKey = null; + oItemj._oResultData = null; + } + + if(oSelf.autoHighlight) { + // Go to the first item + var oFirstItem = aItems[0]; + oSelf._toggleHighlight(oFirstItem,"to"); + oSelf.itemArrowToEvent.fire(oSelf, oFirstItem); + oSelf._typeAhead(oFirstItem,sQuery); + } + else { + oSelf._oCurItem = null; + } + + // Expand the container + var ok = oSelf.doBeforeExpandContainer(oSelf._oTextbox, oSelf._oContainer, sQuery, aResults); + oSelf._toggleContainer(ok); + } + else { + oSelf._toggleContainer(false); + } + oSelf.dataReturnEvent.fire(oSelf, sQuery, aResults); +}; + +/** + * 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._oTextbox.value; + var sChar = (this.delimChar) ? this.delimChar[0] : null; + var nIndex = (sChar) ? sValue.lastIndexOf(sChar, sValue.length-2) : -1; + if(nIndex > -1) { + this._oTextbox.value = sValue.substring(0,nIndex); + } + else { + this._oTextbox.value = ""; + } + this._sSavedQuery = this._oTextbox.value; + + // Fire custom event + this.selectionEnforceEvent.fire(this); +}; + +/** + * Whether or not user-typed value in the text input box matches any of the + * query results. + * + * @method _textMatchesOption + * @return {Boolean} True if user-input text matches a result, false otherwise. + * @private + */ +YAHOO.widget.AutoComplete.prototype._textMatchesOption = function() { + var foundMatch = false; + + for(var i = this._nDisplayedItems-1; i >= 0 ; i--) { + var oItem = this._aListItems[i]; + var sMatch = oItem._sResultKey.toLowerCase(); + if (sMatch == this._sCurQuery.toLowerCase()) { + foundMatch = true; + break; + } + } + return(foundMatch); +}; + +/** + * 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 oItem {HTMLElement} The <li> element item whose data populates the input field. + * @param sQuery {String} Query string. + * @private + */ +YAHOO.widget.AutoComplete.prototype._typeAhead = function(oItem, sQuery) { + // Don't update if turned off + if (!this.typeAhead) { + return; + } + + var oTextbox = this._oTextbox; + var sValue = this._oTextbox.value; // any saved queries plus what user has typed + + // Don't update with type-ahead if text selection is not supported + if(!oTextbox.setSelectionRange && !oTextbox.createTextRange) { + return; + } + + // Select the portion of text that the user has not typed + var nStart = sValue.length; + this._updateValue(oItem); + var nEnd = oTextbox.value.length; + this._selectText(oTextbox,nStart,nEnd); + var sPrefill = oTextbox.value.substr(nStart,nEnd); + this.typeAheadEvent.fire(this,sQuery,sPrefill); +}; + +/** + * Selects text in the input field. + * + * @method _selectText + * @param oTextbox {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(oTextbox, nStart, nEnd) { + if (oTextbox.setSelectionRange) { // For Mozilla + oTextbox.setSelectionRange(nStart,nEnd); + } + else if (oTextbox.createTextRange) { // For IE + var oTextRange = oTextbox.createTextRange(); + oTextRange.moveStart("character", nStart); + oTextRange.moveEnd("character", nEnd-oTextbox.value.length); + oTextRange.select(); + } + else { + oTextbox.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 bFireEvent = false; + var width = this._oContainer._oContent.offsetWidth + "px"; + var height = this._oContainer._oContent.offsetHeight + "px"; + + if(this.useIFrame && this._oContainer._oIFrame) { + bFireEvent = true; + if(bShow) { + this._oContainer._oIFrame.style.width = width; + this._oContainer._oIFrame.style.height = height; + } + else { + this._oContainer._oIFrame.style.width = 0; + this._oContainer._oIFrame.style.height = 0; + } + } + if(this.useShadow && this._oContainer._oShadow) { + bFireEvent = true; + if(bShow) { + this._oContainer._oShadow.style.width = width; + this._oContainer._oShadow.style.height = height; + } + else { + this._oContainer._oShadow.style.width = 0; + this._oContainer._oShadow.style.height = 0; + } + } +}; + +/** + * 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 oContainer = this._oContainer; + + // Implementer has container always open so don't mess with it + if(this.alwaysShowContainer && this._bContainerOpen) { + return; + } + + // Clear contents of container + if(!bShow) { + this._oContainer._oContent.scrollTop = 0; + var aItems = this._aListItems; + + if(aItems && (aItems.length > 0)) { + for(var i = aItems.length-1; i >= 0 ; i--) { + aItems[i].style.display = "none"; + } + } + + if (this._oCurItem) { + this._toggleHighlight(this._oCurItem,"from"); + } + + this._oCurItem = null; + this._nDisplayedItems = 0; + this._sCurQuery = null; + } + + // Container is already closed + if (!bShow && !this._bContainerOpen) { + oContainer._oContent.style.display = "none"; + return; + } + + // If animation is enabled... + var oAnim = this._oAnim; + if (oAnim && oAnim.getEl() && (this.animHoriz || this.animVert)) { + // If helpers need to be collapsed, do it right away... + // but if helpers need to be expanded, wait until after the container expands + if(!bShow) { + this._toggleContainerHelpers(bShow); + } + + if(oAnim.isAnimated()) { + oAnim.stop(); + } + + // Clone container to grab current size offscreen + var oClone = oContainer._oContent.cloneNode(true); + oContainer.appendChild(oClone); + oClone.style.top = "-9000px"; + oClone.style.display = "block"; + + // 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) { + oContainer._oContent.style.width = wColl+"px"; + oContainer._oContent.style.height = hColl+"px"; + } + // Else, set it to its last known size. + else { + oContainer._oContent.style.width = wExp+"px"; + oContainer._oContent.style.height = hExp+"px"; + } + + oContainer.removeChild(oClone); + oClone = null; + + var oSelf = this; + var onAnimComplete = function() { + // Finish the collapse + oAnim.onComplete.unsubscribeAll(); + + if(bShow) { + oSelf.containerExpandEvent.fire(oSelf); + } + else { + oContainer._oContent.style.display = "none"; + oSelf.containerCollapseEvent.fire(oSelf); + } + oSelf._toggleContainerHelpers(bShow); + }; + + // Display container and animate it + oContainer._oContent.style.display = "block"; + oAnim.onComplete.subscribe(onAnimComplete); + oAnim.animate(); + this._bContainerOpen = bShow; + } + // Else don't animate, just show or hide + else { + if(bShow) { + oContainer._oContent.style.display = "block"; + this.containerExpandEvent.fire(this); + } + else { + oContainer._oContent.style.display = "none"; + this.containerCollapseEvent.fire(this); + } + this._toggleContainerHelpers(bShow); + this._bContainerOpen = bShow; + } + +}; + +/** + * Toggles the highlight on or off for an item in the container, and also cleans + * up highlighting of any previous item. + * + * @method _toggleHighlight + * @param oNewItem {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(oNewItem, sType) { + var sHighlight = this.highlightClassName; + if(this._oCurItem) { + // Remove highlight from old item + YAHOO.util.Dom.removeClass(this._oCurItem, sHighlight); + } + + if((sType == "to") && sHighlight) { + // Apply highlight to new item + YAHOO.util.Dom.addClass(oNewItem, sHighlight); + this._oCurItem = oNewItem; + } +}; + +/** + * Toggles the pre-highlight on or off for an item in the container. + * + * @method _togglePrehighlight + * @param oNewItem {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(oNewItem, sType) { + if(oNewItem == this._oCurItem) { + return; + } + + var sPrehighlight = this.prehighlightClassName; + if((sType == "mouseover") && sPrehighlight) { + // Apply prehighlight to new item + YAHOO.util.Dom.addClass(oNewItem, sPrehighlight); + } + else { + // Remove prehighlight from old item + YAHOO.util.Dom.removeClass(oNewItem, 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 oItem {HTMLElement} The <li> element item with which to update the value. + * @private + */ +YAHOO.widget.AutoComplete.prototype._updateValue = function(oItem) { + var oTextbox = this._oTextbox; + var sDelimChar = (this.delimChar) ? (this.delimChar[0] || this.delimChar) : null; + var sSavedQuery = this._sSavedQuery; + var sResultKey = oItem._sResultKey; + oTextbox.focus(); + + // First clear text field + oTextbox.value = ""; + // Grab data to put into text field + if(sDelimChar) { + if(sSavedQuery) { + oTextbox.value = sSavedQuery; + } + oTextbox.value += sResultKey + sDelimChar; + if(sDelimChar != " ") { + oTextbox.value += " "; + } + } + else { oTextbox.value = sResultKey; } + + // scroll to bottom of textarea if necessary + if(oTextbox.type == "textarea") { + oTextbox.scrollTop = oTextbox.scrollHeight; + } + + // move cursor to end + var end = oTextbox.value.length; + this._selectText(oTextbox,end,end); + + this._oCurItem = oItem; +}; + +/** + * Selects a result item from the container + * + * @method _selectItem + * @param oItem {HTMLElement} The selected <li> element item. + * @private + */ +YAHOO.widget.AutoComplete.prototype._selectItem = function(oItem) { + this._bItemSelected = true; + this._updateValue(oItem); + this._cancelIntervalDetection(this); + this.itemSelectEvent.fire(this, oItem, oItem._oResultData); + this._toggleContainer(false); +}; + +/** + * For values updated by type-ahead, the right arrow key jumps to the end + * of the textbox, otherwise the container is closed. + * + * @method _jumpSelection + * @private + */ +YAHOO.widget.AutoComplete.prototype._jumpSelection = function() { + if(!this.typeAhead) { + return; + } + 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 oCurItem = this._oCurItem; + var nCurItemIndex = -1; + + if (oCurItem) { + nCurItemIndex = oCurItem._nItemIndex; + } + + var nNewItemIndex = (nKeyCode == 40) ? + (nCurItemIndex + 1) : (nCurItemIndex - 1); + + // Out of bounds + if (nNewItemIndex < -2 || nNewItemIndex >= this._nDisplayedItems) { + return; + } + + if (oCurItem) { + // Unhighlight current item + this._toggleHighlight(oCurItem, "from"); + this.itemArrowFromEvent.fire(this, oCurItem); + } + if (nNewItemIndex == -1) { + // Go back to query (remove type-ahead string) + if(this.delimChar && this._sSavedQuery) { + if (!this._textMatchesOption()) { + this._oTextbox.value = this._sSavedQuery; + } + else { + this._oTextbox.value = this._sSavedQuery + this._sCurQuery; + } + } + else { + this._oTextbox.value = this._sCurQuery; + } + this._oCurItem = null; + return; + } + if (nNewItemIndex == -2) { + // Close container + this._toggleContainer(false); + return; + } + + var oNewItem = this._aListItems[nNewItemIndex]; + + // Scroll the container if necessary + var oContent = this._oContainer._oContent; + var scrollOn = ((YAHOO.util.Dom.getStyle(oContent,"overflow") == "auto") || + (YAHOO.util.Dom.getStyle(oContent,"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((oNewItem.offsetTop+oNewItem.offsetHeight) > (oContent.scrollTop + oContent.offsetHeight)) { + // Set bottom of scroll area to bottom of selected item + oContent.scrollTop = (oNewItem.offsetTop+oNewItem.offsetHeight) - oContent.offsetHeight; + } + // Bottom of selected item is above scroll area... + else if((oNewItem.offsetTop+oNewItem.offsetHeight) < oContent.scrollTop) { + // Set top of selected item to top of scroll area + oContent.scrollTop = oNewItem.offsetTop; + + } + } + // User is keying up + else { + // Top of selected item is above scroll area + if(oNewItem.offsetTop < oContent.scrollTop) { + // Set top of scroll area to top of selected item + this._oContainer._oContent.scrollTop = oNewItem.offsetTop; + } + // Top of selected item is below scroll area + else if(oNewItem.offsetTop > (oContent.scrollTop + oContent.offsetHeight)) { + // Set bottom of selected item to bottom of scroll area + this._oContainer._oContent.scrollTop = (oNewItem.offsetTop+oNewItem.offsetHeight) - oContent.offsetHeight; + } + } + } + + this._toggleHighlight(oNewItem, "to"); + this.itemArrowToEvent.fire(this, oNewItem); + if(this.typeAhead) { + this._updateValue(oNewItem); + } + } +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Private event handlers +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Handles <li> element mouseover events in the container. + * + * @method _onItemMouseover + * @param v {HTMLEvent} The mouseover event. + * @param oSelf {Object} 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); +}; + +/** + * Handles <li> element mouseout events in the container. + * + * @method _onItemMouseout + * @param v {HTMLEvent} The mouseout event. + * @param oSelf {Object} 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); +}; + +/** + * Handles <li> element click events in the container. + * + * @method _onItemMouseclick + * @param v {HTMLEvent} The click event. + * @param oSelf {Object} 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 {Object} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onContainerMouseover = function(v,oSelf) { + oSelf._bOverContainer = true; +}; + +/** + * Handles container mouseout events. + * + * @method _onContainerMouseout + * @param v {HTMLEvent} The mouseout event. + * @param oSelf {Object} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onContainerMouseout = function(v,oSelf) { + oSelf._bOverContainer = false; + // If container is still active + if(oSelf._oCurItem) { + oSelf._toggleHighlight(oSelf._oCurItem,"to"); + } +}; + +/** + * Handles container scroll events. + * + * @method _onContainerScroll + * @param v {HTMLEvent} The scroll event. + * @param oSelf {Object} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onContainerScroll = function(v,oSelf) { + oSelf._oTextbox.focus(); +}; + +/** + * Handles container resize events. + * + * @method _onContainerResize + * @param v {HTMLEvent} The resize event. + * @param oSelf {Object} 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 {object} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxKeyDown = function(v,oSelf) { + var nKeyCode = v.keyCode; + + switch (nKeyCode) { + case 9: // tab + if(oSelf.delimChar && (oSelf._nKeyCode != nKeyCode)) { + if(oSelf._bContainerOpen) { + YAHOO.util.Event.stopEvent(v); + } + } + // select an item or clear out + if(oSelf._oCurItem) { + oSelf._selectItem(oSelf._oCurItem); + } + else { + oSelf._toggleContainer(false); + } + break; + case 13: // enter + if(oSelf._nKeyCode != nKeyCode) { + if(oSelf._bContainerOpen) { + YAHOO.util.Event.stopEvent(v); + } + } + if(oSelf._oCurItem) { + oSelf._selectItem(oSelf._oCurItem); + } + else { + oSelf._toggleContainer(false); + } + break; + case 27: // esc + oSelf._toggleContainer(false); + return; + case 39: // right + oSelf._jumpSelection(); + break; + case 38: // up + YAHOO.util.Event.stopEvent(v); + oSelf._moveSelection(nKeyCode); + break; + case 40: // down + YAHOO.util.Event.stopEvent(v); + oSelf._moveSelection(nKeyCode); + break; + default: + break; + } +}; + +/** + * Handles textbox keypress events. + * @method _onTextboxKeyPress + * @param v {HTMLEvent} The keypress event. + * @param oSelf {Object} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxKeyPress = function(v,oSelf) { + var nKeyCode = v.keyCode; + + //Expose only to Mac browsers, where stopEvent is ineffective on keydown events (bug 790337) + var isMac = (navigator.userAgent.toLowerCase().indexOf("mac") != -1); + if(isMac) { + switch (nKeyCode) { + case 9: // tab + if(oSelf.delimChar && (oSelf._nKeyCode != nKeyCode)) { + if(oSelf._bContainerOpen) { + YAHOO.util.Event.stopEvent(v); + } + } + break; + case 13: // enter + if(oSelf._nKeyCode != nKeyCode) { + if(oSelf._bContainerOpen) { + YAHOO.util.Event.stopEvent(v); + } + } + break; + case 38: // up + case 40: // down + YAHOO.util.Event.stopEvent(v); + 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._queryInterval = setInterval(function() { oSelf._onIMEDetected(oSelf); },500); + } +}; + +/** + * Handles textbox keyup events that trigger queries. + * + * @method _onTextboxKeyUp + * @param v {HTMLEvent} The keyup event. + * @param oSelf {Object} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxKeyUp = function(v,oSelf) { + // Check to see if any of the public properties have been updated + oSelf._initProps(); + + var nKeyCode = v.keyCode; + oSelf._nKeyCode = nKeyCode; + var sText = this.value; //string in textbox + + // Filter out chars that don't trigger queries + if (oSelf._isIgnoreKey(nKeyCode) || (sText.toLowerCase() == oSelf._sCurQuery)) { + return; + } + else { + oSelf.textboxKeyEvent.fire(oSelf, nKeyCode); + } + + // Set timeout on the request + if (oSelf.queryDelay > 0) { + var nDelayID = + setTimeout(function(){oSelf._sendQuery(sText);},(oSelf.queryDelay * 1000)); + + if (oSelf._nDelayID != -1) { + clearTimeout(oSelf._nDelayID); + } + + oSelf._nDelayID = 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 {Object} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxFocus = function (v,oSelf) { + oSelf._oTextbox.setAttribute("autocomplete","off"); + oSelf._bFocused = true; + oSelf.textboxFocusEvent.fire(oSelf); +}; + +/** + * Handles text input box losing focus. + * + * @method _onTextboxBlur + * @param v {HTMLEvent} The focus event. + * @param oSelf {Object} 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 + if(!oSelf._bItemSelected) { + if(!oSelf._bContainerOpen || (oSelf._bContainerOpen && !oSelf._textMatchesOption())) { + if(oSelf.forceSelection) { + oSelf._clearSelection(); + } + else { + oSelf.unmatchedItemSelectEvent.fire(oSelf, oSelf._sCurQuery); + } + } + } + + if(oSelf._bContainerOpen) { + oSelf._toggleContainer(false); + } + oSelf._cancelIntervalDetection(oSelf); + oSelf._bFocused = false; + oSelf.textboxBlurEvent.fire(oSelf); + } +}; + +/** + * Handles form submission event. + * + * @method _onFormSubmit + * @param v {HTMLEvent} The submit event. + * @param oSelf {Object} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onFormSubmit = function(v,oSelf) { + if(oSelf.allowBrowserAutocomplete) { + oSelf._oTextbox.setAttribute("autocomplete","on"); + } + else { + oSelf._oTextbox.setAttribute("autocomplete","off"); + } +}; /****************************************************************************/ /****************************************************************************/ /****************************************************************************/ /** - * Class providing the customizable functionality of a plug-and-play DHTML - * auto complete 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
  • - *
- * - * requires YAHOO.util.Dom Dom utility - * requires YAHOO.util.Event Event utility - * requires YAHOO.widget.DataSource Data source class - * see YAHOO.util.Animation Animation utility - * see JSON JSON library - * - * @constructor - * @param {element | string} inputEl DOM element reference or string ID of the auto complete input field - * @param {element | string} containerEl DOM element reference or string ID of the auto complete <div> - * container - * @param {object} oDataSource Instance of YAHOO.widget.DataSource for query/results - * @param {object} oConfigs Optional object literal of config params - */ -YAHOO.widget.AutoComplete = function(inputEl,containerEl,oDataSource,oConfigs) { - if(inputEl && containerEl && oDataSource) { - // Validate data source - if (oDataSource && (oDataSource instanceof YAHOO.widget.DataSource)) { - this.dataSource = oDataSource; - } - else { - YAHOO.log("Could not instantiate AutoComplete due to an invalid DataSource", "error", this.toString()); - return; - } - - // Validate input element - if(YAHOO.util.Dom.inDocument(inputEl)) { - if(typeof inputEl == "string") { - this._sName = "instance" + YAHOO.widget.AutoComplete._nIndex + " " + inputEl; - this._oTextbox = document.getElementById(inputEl); - } - else { - this._sName = (inputEl.id) ? - "instance" + YAHOO.widget.AutoComplete._nIndex + " " + inputEl.id: - "instance" + YAHOO.widget.AutoComplete._nIndex; - this._oTextbox = inputEl; - } - } - 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(containerEl)) { - if(typeof containerEl == "string") { - this._oContainer = document.getElementById(containerEl); - } - else { - this._oContainer = containerEl; - } - if(this._oContainer.style.display == "none") { - YAHOO.log("The container may not display properly if display is set to \"none\" in CSS", "warn", this.toString()); - } - } - else { - YAHOO.log("Could not instantiate AutoComplete due to an invalid container element", "error", this.toString()); - return; - } - - // Set any config params passed in to override defaults - if (typeof oConfigs == "object") { - for(var sConfig in oConfigs) { - if (sConfig) { - this[sConfig] = oConfigs[sConfig]; - } - } - } - - // Initialization sequence - this._initContainer(); - this._initProps(); - this._initList(); - this._initContainerHelpers(); - - // Set up events - var oSelf = this; - var oTextbox = this._oTextbox; - // Events are actually for the content module within the container - var oContent = this._oContainer._oContent; - - // Dom events - YAHOO.util.Event.addListener(oTextbox,"keyup",oSelf._onTextboxKeyUp,oSelf); - YAHOO.util.Event.addListener(oTextbox,"keydown",oSelf._onTextboxKeyDown,oSelf); - YAHOO.util.Event.addListener(oTextbox,"keypress",oSelf._onTextboxKeyPress,oSelf); - YAHOO.util.Event.addListener(oTextbox,"focus",oSelf._onTextboxFocus,oSelf); - YAHOO.util.Event.addListener(oTextbox,"blur",oSelf._onTextboxBlur,oSelf); - YAHOO.util.Event.addListener(oContent,"mouseover",oSelf._onContainerMouseover,oSelf); - YAHOO.util.Event.addListener(oContent,"mouseout",oSelf._onContainerMouseout,oSelf); - YAHOO.util.Event.addListener(oContent,"scroll",oSelf._onContainerScroll,oSelf); - YAHOO.util.Event.addListener(oContent,"resize",oSelf._onContainerResize,oSelf); - if(oTextbox.form) { - YAHOO.util.Event.addListener(oTextbox.form,"submit",oSelf._onFormSubmit,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.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); - - // Finish up - oTextbox.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 data source object that encapsulates the data used for auto completion. - * This object should be an inherited object from YAHOO.widget.DataSource. - * - * @type object - */ -YAHOO.widget.AutoComplete.prototype.dataSource = null; - -/** - * Number of characters that must be entered before querying for results. - * Default: 1. - * - * @type number - */ -YAHOO.widget.AutoComplete.prototype.minQueryLength = 1; - -/** - * Maximum number of results to display in auto complete container. Default: 10. - * - * @type number - */ -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. - * Default: 0.5. - * - * @type number - */ -YAHOO.widget.AutoComplete.prototype.queryDelay = 0.5; - -/** - * Class name of a highlighted item within the auto complete container. - * Default: "yui-ac-highlight". - * - * @type string - */ -YAHOO.widget.AutoComplete.prototype.highlightClassName = "yui-ac-highlight"; - -/** - * Class name of a pre-highlighted item within the auto complete container. - * Default: null. - * - * @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. Default: null. - * - * @type string or array - */ -YAHOO.widget.AutoComplete.prototype.delimChar = null; - -/** - * Whether or not the first item in the auto complete container should be - * automatically highlighted on expand. Default: true. - * - * @type boolean - */ -YAHOO.widget.AutoComplete.prototype.autoHighlight = true; - -/** - * Whether or not the auto complete input field should be automatically updated - * with the first query result as the user types, auto-selecting the substring - * that the user has not typed. Default: false. - * - * @type boolean - */ -YAHOO.widget.AutoComplete.prototype.typeAhead = false; - -/** - * Whether or not to animate the expansion/collapse of the auto complete - * container in the horizontal direction. Default: false. - * - * @type boolean - */ -YAHOO.widget.AutoComplete.prototype.animHoriz = false; - -/** - * Whether or not to animate the expansion/collapse of the auto complete - * container in the vertical direction. Default: true. - * - * @type boolean - */ -YAHOO.widget.AutoComplete.prototype.animVert = true; - -/** - * Speed of container expand/collapse animation, in seconds. Default: 0.3. - * - * @type number - */ -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 auto complete form - * input field into a <select> field. This feature is not recommended - * with delimiter character(s) defined. Default: false. - * - * @type boolean - */ -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 auto complete 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. - * Default: true. - * - * @type boolean - */ -YAHOO.widget.AutoComplete.prototype.allowBrowserAutocomplete = true; - -/** - * Whether or not the auto complete container should always be displayed. - * Enabling this feature prevents the toggling of the container to a collapsed - * state. Default: false. - * - * @type boolean - */ -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 auto complete 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). Default:false. - * - * @type boolean - */ -YAHOO.widget.AutoComplete.prototype.useIFrame = false; - -/** - * Configurable iFrame src used when useIFrame = true. Implementations over SSL - * should set this parameter to an appropriate https location in order to avoid - * security-related browser errors. Default:"about:blank". - * - * @type boolean - */ -YAHOO.widget.AutoComplete.prototype.iFrameSrc = "about:blank"; - -/** - * Whether or not the auto complete container should have a shadow. Default:false. - * - * @type boolean - */ -YAHOO.widget.AutoComplete.prototype.useShadow = false; - -/*************************************************************************** - * Public methods - ***************************************************************************/ - /** - * Public accessor to the unique name of the auto complete instance. - * - * @return {string} Unique name of the auto complete instance - */ -YAHOO.widget.AutoComplete.prototype.getName = function() { - return this._sName; -}; - - /** - * Public accessor to the unique name of the auto complete instance. - * - * @return {string} Unique name of the auto complete instance - */ -YAHOO.widget.AutoComplete.prototype.toString = function() { - return "AutoComplete " + this._sName; -}; - -/** - * Public accessor to the internal array of DOM <li> elements that - * display query results within the auto complete container. - * - * @return {array} Array of <li> elements within the auto complete - * container - */ -YAHOO.widget.AutoComplete.prototype.getListItems = function() { - return this._aListItems; -}; - -/** - * Public accessor to the data held in an <li> element of the - * auto complete container. - * - * @return {object or array} Object or array of result data or null - */ -YAHOO.widget.AutoComplete.prototype.getListItemData = function(oListItem) { - if(oListItem._oResultData) { - return oListItem._oResultData; - } - else { - return false; - } -}; - -/** - * Sets HTML markup for the auto complete container header. This markup will be - * inserted within a <div> tag with a class of "ac_hd". - * - * @param {string} sHeader HTML markup for container header - */ -YAHOO.widget.AutoComplete.prototype.setHeader = function(sHeader) { - if(sHeader) { - if(this._oContainer._oContent._oHeader) { - this._oContainer._oContent._oHeader.innerHTML = sHeader; - this._oContainer._oContent._oHeader.style.display = "block"; - } - } - else { - this._oContainer._oContent._oHeader.innerHTML = ""; - this._oContainer._oContent._oHeader.style.display = "none"; - } -}; - -/** - * Sets HTML markup for the auto complete container footer. This markup will be - * inserted within a <div> tag with a class of "ac_ft". - * - * @param {string} sFooter HTML markup for container footer - */ -YAHOO.widget.AutoComplete.prototype.setFooter = function(sFooter) { - if(sFooter) { - if(this._oContainer._oContent._oFooter) { - this._oContainer._oContent._oFooter.innerHTML = sFooter; - this._oContainer._oContent._oFooter.style.display = "block"; - } - } - else { - this._oContainer._oContent._oFooter.innerHTML = ""; - this._oContainer._oContent._oFooter.style.display = "none"; - } -}; - -/** - * Sets HTML markup for the auto complete container body. This markup will be - * inserted within a <div> tag with a class of "ac_bd". - * - * @param {string} sHeader HTML markup for container body - */ -YAHOO.widget.AutoComplete.prototype.setBody = function(sBody) { - if(sBody) { - if(this._oContainer._oContent._oBody) { - this._oContainer._oContent._oBody.innerHTML = sBody; - this._oContainer._oContent._oBody.style.display = "block"; - this._oContainer._oContent.style.display = "block"; - } - } - else { - this._oContainer._oContent._oBody.innerHTML = ""; - this._oContainer._oContent.style.display = "none"; - } - this._maxResultsDisplayed = 0; -}; - -/** - * Overridable method that converts a result item object into HTML markup - * for display. Return data values are accessible via the oResultItem object, - * and the key return value will always be oResultItem[0]. Markup will be - * displayed within <li> element tags in the container. - * - * @param {object} oResultItem Result item object representing one query result - * @param {string} sQuery The current query string - * @return {string} HTML markup of formatted result data - */ -YAHOO.widget.AutoComplete.prototype.formatResult = function(oResultItem, sQuery) { - var sResult = oResultItem[0]; - if(sResult) { - return sResult; - } - else { - return ""; - } -}; - -/** - * Makes query request to the data source. - * - * @param {string} sQuery Query string. - */ -YAHOO.widget.AutoComplete.prototype.sendQuery = function(sQuery) { - if(sQuery) { - this._sendQuery(sQuery); - } - else { - YAHOO.log("Query could not be sent because the string value was empty or null.","warn",this.toString()); - return; - } -}; - -/*************************************************************************** - * Events - ***************************************************************************/ -/** - * Fired when the auto complete text input box receives focus. Subscribers - * receive the following array:
- * - args[0] The auto complete object instance - */ -YAHOO.widget.AutoComplete.prototype.textboxFocusEvent = null; - -/** - * Fired when the auto complete text input box receives key input. Subscribers - * receive the following array:
- * - args[0] The auto complete object instance - * - args[1] The keycode number - */ -YAHOO.widget.AutoComplete.prototype.textboxKeyEvent = null; - -/** - * Fired when the auto complete instance makes a query to the data source. - * Subscribers receive the following array:
- * - args[0] The auto complete object instance - * - args[1] The query string - */ -YAHOO.widget.AutoComplete.prototype.dataRequestEvent = null; - -/** - * Fired when the auto complete instance receives query results from the data - * source. Subscribers receive the following array:
- * - args[0] The auto complete object instance - * - args[1] The query string - * - args[2] Results array - */ -YAHOO.widget.AutoComplete.prototype.dataReturnEvent = null; - -/** - * Fired when the auto complete instance does not receive query results from the - * data source due to an error. Subscribers receive the following array:
- * - args[0] The auto complete object instance - * - args[1] The query string - */ -YAHOO.widget.AutoComplete.prototype.dataErrorEvent = null; - -/** - * Fired when the auto complete container is expanded. If alwaysShowContainer is - * enabled, then containerExpandEvent will be fired when the container is - * populated with results. Subscribers receive the following array:
- * - args[0] The auto complete object instance - */ -YAHOO.widget.AutoComplete.prototype.containerExpandEvent = null; - -/** - * Fired when the auto complete textbox has been prefilled by the type-ahead - * feature. Subscribers receive the following array:
- * - args[0] The auto complete object instance - * - args[1] The query string - * - args[2] The prefill string - */ -YAHOO.widget.AutoComplete.prototype.typeAheadEvent = null; - -/** - * Fired when result item has been moused over. Subscribers receive the following - * array:
- * - args[0] The auto complete object instance - * - args[1] The <li> element item moused to - */ -YAHOO.widget.AutoComplete.prototype.itemMouseOverEvent = null; - -/** - * Fired when result item has been moused out. Subscribers receive the - * following array:
- * - args[0] The auto complete object instance - * - args[1] The <li> element item moused from - */ -YAHOO.widget.AutoComplete.prototype.itemMouseOutEvent = null; - -/** - * Fired when result item has been arrowed to. Subscribers receive the following - * array:
- * - args[0] The auto complete object instance - * - args[1] The <li> element item arrowed to - */ -YAHOO.widget.AutoComplete.prototype.itemArrowToEvent = null; - -/** - * Fired when result item has been arrowed away from. Subscribers receive the - * following array:
- * - args[0] The auto complete object instance - * - args[1] 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. - * Subscribers receive the following array:
- * - args[0] The auto complete object instance - * - args[1] The selected <li> element item - * - args[2] 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 an user selection does not match any of the displayed result items. - * Note that this event may not behave as expected when delimiter characters - * have been defined. Subscribers receive the following array:
- * - args[0] The auto complete object instance - * - args[1] The user selection - */ -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. Subscribers - * receive the following array:
- * - args[0] The auto complete object instance - */ -YAHOO.widget.AutoComplete.prototype.selectionEnforceEvent = null; - -/** - * Fired when the auto complete container is collapsed. If alwaysShowContainer is - * enabled, then containerCollapseEvent will be fired when the container is - * cleared of results. Subscribers receive the following array:
- * - args[0] The auto complete object instance - */ -YAHOO.widget.AutoComplete.prototype.containerCollapseEvent = null; - -/** - * Fired when the auto complete text input box loses focus. Subscribers receive - * an array of the following array:
- * - args[0] The auto complete object instance - */ -YAHOO.widget.AutoComplete.prototype.textboxBlurEvent = null; - -/*************************************************************************** - * Private member variables - ***************************************************************************/ -/** - * Internal class variable to index multiple auto complete instances. - * - * @type number - * @private - */ -YAHOO.widget.AutoComplete._nIndex = 0; - -/** - * Name of auto complete instance. - * - * @type string - * @private - */ -YAHOO.widget.AutoComplete.prototype._sName = null; - -/** - * Text input box DOM element. - * - * @type object - * @private - */ -YAHOO.widget.AutoComplete.prototype._oTextbox = null; - -/** - * Whether or not the textbox is currently in focus. If query results come back - * but the user has already moved on, do not proceed with auto complete behavior. - * - * @type boolean - * @private - */ -YAHOO.widget.AutoComplete.prototype._bFocused = true; - -/** - * Animation instance for container expand/collapse. - * - * @type boolean - * @private - */ -YAHOO.widget.AutoComplete.prototype._oAnim = null; - -/** - * Container DOM element. - * - * @type object - * @private - */ -YAHOO.widget.AutoComplete.prototype._oContainer = null; - -/** - * Whether or not the auto complete container is currently open. - * - * @type boolean - * @private - */ -YAHOO.widget.AutoComplete.prototype._bContainerOpen = false; - -/** - * Whether or not the mouse is currently over the auto complete - * container. This is necessary in order to prevent clicks on container items - * from being text input box blur events. - * - * @type boolean - * @private - */ -YAHOO.widget.AutoComplete.prototype._bOverContainer = false; - -/** - * Array of <li> elements references that contain query results within the - * auto complete container. - * - * @type array - * @private - */ -YAHOO.widget.AutoComplete.prototype._aListItems = null; - -/** - * Number of <li> elements currently displayed in auto complete container. - * - * @type number - * @private - */ -YAHOO.widget.AutoComplete.prototype._nDisplayedItems = 0; - -/** - * Internal count of <li> elements displayed and hidden in auto complete container. - * - * @type number - * @private - */ -YAHOO.widget.AutoComplete.prototype._maxResultsDisplayed = 0; - -/** - * Current query string - * - * @type string - * @private - */ -YAHOO.widget.AutoComplete.prototype._sCurQuery = null; - -/** - * Past queries this session (for saving delimited queries). - * - * @type string - * @private - */ -YAHOO.widget.AutoComplete.prototype._sSavedQuery = null; - -/** - * Pointer to the currently highlighted <li> element in the container. - * - * @type object - * @private - */ -YAHOO.widget.AutoComplete.prototype._oCurItem = 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. - * - * @type boolean - * @private - */ -YAHOO.widget.AutoComplete.prototype._bItemSelected = false; - -/** - * Key code of the last key pressed in textbox. - * - * @type number - * @private - */ -YAHOO.widget.AutoComplete.prototype._nKeyCode = null; - -/** - * Delay timeout ID. - * - * @type number - * @private - */ -YAHOO.widget.AutoComplete.prototype._nDelayID = -1; - -/*************************************************************************** - * Private methods - ***************************************************************************/ -/** - * Updates and validates latest public config properties. - * - * @private - */ -YAHOO.widget.AutoComplete.prototype._initProps = function() { - // Correct any invalid values - var minQueryLength = this.minQueryLength; - if(isNaN(minQueryLength) || (minQueryLength < 1)) { - minQueryLength = 1; - } - var maxResultsDisplayed = this.maxResultsDisplayed; - if(isNaN(this.maxResultsDisplayed) || (this.maxResultsDisplayed < 1)) { - this.maxResultsDisplayed = 10; - } - var queryDelay = this.queryDelay; - if(isNaN(this.queryDelay) || (this.queryDelay < 0)) { - this.queryDelay = 0.5; - } - var aDelimChar = (this.delimChar) ? this.delimChar : null; - if(aDelimChar) { - if(typeof aDelimChar == "string") { - this.delimChar = [aDelimChar]; - } - else if(aDelimChar.constructor != Array) { - this.delimChar = null; - } - } - var animSpeed = this.animSpeed; - if((this.animHoriz || this.animVert) && YAHOO.util.Anim) { - if(isNaN(animSpeed) || (animSpeed < 0)) { - animSpeed = 0.3; - } - if(!this._oAnim ) { - oAnim = new YAHOO.util.Anim(this._oContainer._oContent, {}, this.animSpeed); - this._oAnim = oAnim; - } - else { - this._oAnim.duration = animSpeed; - } - } - if(this.forceSelection && this.delimChar) { - YAHOO.log("The forceSelection feature has been enabled with delimChar defined.","warn", this.toString()); - } - if(this.alwaysShowContainer && (this.useShadow || this.useIFrame)) { - YAHOO.log("The features useShadow and useIFrame are not compatible with the alwaysShowContainer feature.","warn", this.toString()); - } - - if(this.alwaysShowContainer) { - this._bContainerOpen = true; - } -}; - -/** - * Initializes the auto complete container helpers if they are enabled and do - * not exist - * - * @private - */ -YAHOO.widget.AutoComplete.prototype._initContainerHelpers = function() { - if(this.useShadow && !this._oContainer._oShadow) { - var oShadow = document.createElement("div"); - oShadow.className = "yui-ac-shadow"; - this._oContainer._oShadow = this._oContainer.appendChild(oShadow); - } - if(this.useIFrame && !this._oContainer._oIFrame) { - var oIFrame = document.createElement("iframe"); - oIFrame.src = this.iFrameSrc; - oIFrame.frameBorder = 0; - oIFrame.scrolling = "no"; - oIFrame.style.position = "absolute"; - oIFrame.style.width = "100%"; - oIFrame.style.height = "100%"; - this._oContainer._oIFrame = this._oContainer.appendChild(oIFrame); - } -}; - -/** - * Initializes the auto complete container once at object creation - * - * @private - */ -YAHOO.widget.AutoComplete.prototype._initContainer = function() { - if(!this._oContainer._oContent) { - // The oContent div helps size the iframe and shadow properly - var oContent = document.createElement("div"); - oContent.className = "yui-ac-content"; - oContent.style.display = "none"; - this._oContainer._oContent = this._oContainer.appendChild(oContent); - - var oHeader = document.createElement("div"); - oHeader.className = "yui-ac-hd"; - oHeader.style.display = "none"; - this._oContainer._oContent._oHeader = this._oContainer._oContent.appendChild(oHeader); - - var oBody = document.createElement("div"); - oBody.className = "yui-ac-bd"; - this._oContainer._oContent._oBody = this._oContainer._oContent.appendChild(oBody); - - var oFooter = document.createElement("div"); - oFooter.className = "yui-ac-ft"; - oFooter.style.display = "none"; - this._oContainer._oContent._oFooter = this._oContainer._oContent.appendChild(oFooter); - } - 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. - * - * @private - */ -YAHOO.widget.AutoComplete.prototype._initList = function() { - this._aListItems = []; - while(this._oContainer._oContent._oBody.hasChildNodes()) { - var oldListItems = this.getListItems(); - if(oldListItems) { - for(var oldi = oldListItems.length-1; oldi >= 0; i--) { - oldListItems[oldi] = null; - } - } - this._oContainer._oContent._oBody.innerHTML = ""; - } - - var oList = document.createElement("ul"); - oList = this._oContainer._oContent._oBody.appendChild(oList); - for(var i=0; i 0) { - var nDelayID = - setTimeout(function(){oSelf._sendQuery(sText);},(oSelf.queryDelay * 1000)); - - if (oSelf._nDelayID != -1) { - clearTimeout(oSelf._nDelayID); - } - - oSelf._nDelayID = nDelayID; - } - else { - // No delay so send request immediately - oSelf._sendQuery(sText); - } -}; - -/** - * 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. - * - * @param {number} nKeycode Code of key pressed - * @return {boolean} Whether or not to be ignore key - * @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 >= 44 && nKeyCode <= 45)) { // print screen,insert - return true; - } - return false; -}; - -/** - * Handles text input box receiving focus. - * - * @param {event} v The focus event - * @param {object} oSelf The auto complete instance - * @private - */ -YAHOO.widget.AutoComplete.prototype._onTextboxFocus = function (v,oSelf) { - oSelf._oTextbox.setAttribute("autocomplete","off"); - oSelf._bFocused = true; - oSelf.textboxFocusEvent.fire(oSelf); -}; - -/** - * Handles text input box losing focus. - * - * @param {event} v The focus event - * @param {object} oSelf The auto complete 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 - if(!oSelf._bItemSelected) { - if(!oSelf._bContainerOpen || (oSelf._bContainerOpen && !oSelf._textMatchesOption())) { - if(oSelf.forceSelection) { - oSelf._clearSelection(); - } - else { - oSelf.unmatchedItemSelectEvent.fire(oSelf, oSelf._sCurQuery); - } - } - } - - if(oSelf._bContainerOpen) { - oSelf._clearList(); - } - oSelf._bFocused = false; - oSelf.textboxBlurEvent.fire(oSelf); - } -}; - -/** - * Handles form submission event. - * - * @param {event} v The submit event - * @param {object} oSelf The auto complete instance - * @private - */ -YAHOO.widget.AutoComplete.prototype._onFormSubmit = function(v,oSelf) { - if(oSelf.allowBrowserAutocomplete) { - oSelf._oTextbox.setAttribute("autocomplete","on"); - } - else { - oSelf._oTextbox.setAttribute("autocomplete","off"); - } -}; - -/** - * Makes query request to the data source. - * - * @param {string} sQuery Query string. - * @private - */ -YAHOO.widget.AutoComplete.prototype._sendQuery = function(sQuery) { - // Delimiter has been enabled - var aDelimChar = (this.delimChar) ? this.delimChar : null; - if(aDelimChar) { - // Loop through all possible delimiters and find the latest one - // 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 so extract the latest query - 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._sSavedQuery = sQuery.substring(0,nQueryStart); - // Here is the query itself - sQuery = sQuery.substr(nQueryStart); - } - else if(sQuery.indexOf(this._sSavedQuery) < 0){ - this._sSavedQuery = null; - } - } - - // Don't search queries that are too short - if (sQuery.length < this.minQueryLength) { - if (this._nDelayID != -1) { - clearTimeout(this._nDelayID); - } - this._clearList(); - return; - } - - sQuery = encodeURIComponent(sQuery); - this._nDelayID = -1; // Reset timeout ID because request has been made - this.dataRequestEvent.fire(this, sQuery); - this.dataSource.getResults(this._populateList, sQuery, this); -}; - -/** - * Hides all visuals related to the array of <li> elements in the container. - * - * @private - */ -YAHOO.widget.AutoComplete.prototype._clearList = function() { - this._oContainer._oContent.scrollTop = 0; - var aItems = this._aListItems; - - if(aItems && (aItems.length > 0)) { - for(var i = aItems.length-1; i >= 0 ; i--) { - aItems[i].style.display = "none"; - } - } - - if (this._oCurItem) { - this._toggleHighlight(this._oCurItem,"from"); - } - - this._oCurItem = null; - this._nDisplayedItems = 0; - this._sCurQuery = null; - this._toggleContainer(false); -}; - -/** - * Populates the array of <li> elements in the container with query - * results. This method is passed to YAHOO.widget.DataSource#getResults as a - * callback function so results from the datasource are returned to the - * auto complete instance. - * - * @param {string} sQuery The query string - * @param {object} aResults An array of query result objects from the data source - * @param {string} oSelf The auto complete instance - * @private - */ -YAHOO.widget.AutoComplete.prototype._populateList = function(sQuery, aResults, oSelf) { - if(aResults === null) { - oSelf.dataErrorEvent.fire(oSelf, sQuery); - } - if (!oSelf._bFocused || !aResults) { - return; - } - - var isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1); - var contentStyle = oSelf._oContainer._oContent.style; - contentStyle.width = (!isOpera) ? null : ""; - contentStyle.height = (!isOpera) ? null : ""; - - var sCurQuery = decodeURIComponent(sQuery); - oSelf._sCurQuery = sCurQuery; - oSelf._bItemSelected = false; - - if(oSelf._maxResultsDisplayed != oSelf.maxResultsDisplayed) { - oSelf._initList(); - } - - var nItems = Math.min(aResults.length,oSelf.maxResultsDisplayed); - oSelf._nDisplayedItems = nItems; - if (nItems > 0) { - oSelf._initContainerHelpers(); - var aItems = oSelf._aListItems; - - // Fill items with data - for(var i = nItems-1; i >= 0; i--) { - var oItemi = aItems[i]; - var oResultItemi = aResults[i]; - oItemi.innerHTML = oSelf.formatResult(oResultItemi, sCurQuery); - oItemi.style.display = "list-item"; - oItemi._sResultKey = oResultItemi[0]; - oItemi._oResultData = oResultItemi; - - } - - // Empty out remaining items if any - for(var j = aItems.length-1; j >= nItems ; j--) { - var oItemj = aItems[j]; - oItemj.innerHTML = null; - oItemj.style.display = "none"; - oItemj._sResultKey = null; - oItemj._oResultData = null; - } - - if(oSelf.autoHighlight) { - // Go to the first item - var oFirstItem = aItems[0]; - oSelf._toggleHighlight(oFirstItem,"to"); - oSelf.itemArrowToEvent.fire(oSelf, oFirstItem); - oSelf._typeAhead(oFirstItem,sQuery); - } - else { - oSelf._oCurItem = null; - } - - // Expand the container - oSelf._toggleContainer(true); - } - else { - oSelf._clearList(); - } - oSelf.dataReturnEvent.fire(oSelf, sQuery, aResults); -}; - -/** - * When YAHOO.widget.AutoComplete#bForceSelection is true and the user attempts - * leave the text input box without selecting an item from the query results, - * the user selection is cleared. - * - * @private - */ -YAHOO.widget.AutoComplete.prototype._clearSelection = function() { - var sValue = this._oTextbox.value; - var sChar = (this.delimChar) ? this.delimChar[0] : null; - var nIndex = (sChar) ? sValue.lastIndexOf(sChar, sValue.length-2) : -1; - if(nIndex > -1) { - this._oTextbox.value = sValue.substring(0,nIndex); - } - else { - this._oTextbox.value = ""; - } - this._sSavedQuery = this._oTextbox.value; - - // Fire custom event - this.selectionEnforceEvent.fire(this); -}; - -/** - * Whether or not user-typed value in the text input box matches any of the - * query results. - * - * @private - */ -YAHOO.widget.AutoComplete.prototype._textMatchesOption = function() { - var foundMatch = false; - - for(var i = this._nDisplayedItems-1; i >= 0 ; i--) { - var oItem = this._aListItems[i]; - var sMatch = oItem._sResultKey.toLowerCase(); - if (sMatch == this._sCurQuery.toLowerCase()) { - foundMatch = true; - break; - } - } - return(foundMatch); -}; - -/** - * Updates in the text input box with the first query result as the user types, - * selecting the substring that the user has not typed. - * - * @param {object} oItem The <li> element item whose data populates the input field - * @param {string} sQuery Query string - * @private - */ -YAHOO.widget.AutoComplete.prototype._typeAhead = function(oItem, sQuery) { - // Don't update if turned off - if (!this.typeAhead) { - return; - } - - var oTextbox = this._oTextbox; - var sValue = this._oTextbox.value; // any saved queries plus what user has typed - - // Don't update with type-ahead if text selection is not supported - if(!oTextbox.setSelectionRange && !oTextbox.createTextRange) { - return; - } - - // Select the portion of text that the user has not typed - var nStart = sValue.length; - this._updateValue(oItem); - var nEnd = oTextbox.value.length; - this._selectText(oTextbox,nStart,nEnd); - var sPrefill = oTextbox.value.substr(nStart,nEnd); - this.typeAheadEvent.fire(this,sQuery,sPrefill); -}; - -/** - * Selects text in a text input box. - * - * @param {object} oTextbox Text input box element in which to select text - * @param {number} nStart Starting index of text string to select - * @param {number} nEnd Ending index of text selection - * @private - */ -YAHOO.widget.AutoComplete.prototype._selectText = function(oTextbox, nStart, nEnd) { - if (oTextbox.setSelectionRange) { // For Mozilla - oTextbox.setSelectionRange(nStart,nEnd); - } - else if (oTextbox.createTextRange) { // For IE - var oTextRange = oTextbox.createTextRange(); - oTextRange.moveStart("character", nStart); - oTextRange.moveEnd("character", nEnd-oTextbox.value.length); - oTextRange.select(); - } - else { - oTextbox.select(); - } -}; - -/** - * Syncs auto complete container with its helpers. - * - * @param {boolean} bShow True if container is expanded, false if collapsed - * @private - */ -YAHOO.widget.AutoComplete.prototype._toggleContainerHelpers = function(bShow) { - var bFireEvent = false; - var width = this._oContainer._oContent.offsetWidth + "px"; - var height = this._oContainer._oContent.offsetHeight + "px"; - - if(this.useIFrame && this._oContainer._oIFrame) { - bFireEvent = true; - if(this.alwaysShowContainer || bShow) { - this._oContainer._oIFrame.style.width = width; - this._oContainer._oIFrame.style.height = height; - } - else { - this._oContainer._oIFrame.style.width = 0; - this._oContainer._oIFrame.style.height = 0; - } - } - if(this.useShadow && this._oContainer._oShadow) { - bFireEvent = true; - if(this.alwaysShowContainer || bShow) { - this._oContainer._oShadow.style.width = width; - this._oContainer._oShadow.style.height = height; - } - else { - this._oContainer._oShadow.style.width = 0; - this._oContainer._oShadow.style.height = 0; - } - } -}; - -/** - * Animates expansion or collapse of the container. - * - * @param {boolean} bShow True if container should be expanded, false if - * container should be collapsed - * @private - */ -YAHOO.widget.AutoComplete.prototype._toggleContainer = function(bShow) { - // Implementer has container always open so don't mess with it - if(this.alwaysShowContainer) { - // Fire these events to give implementers a hook into the container - // being populated and being emptied - if(bShow) { - this.containerExpandEvent.fire(this); - } - else { - this.containerCollapseEvent.fire(this); - } - this._bContainerOpen = bShow; - return; - } - - var oContainer = this._oContainer; - // Container is already closed - if (!bShow && !this._bContainerOpen) { - oContainer._oContent.style.display = "none"; - return; - } - - // If animation is enabled... - var oAnim = this._oAnim; - if (oAnim && oAnim.getEl() && (this.animHoriz || this.animVert)) { - // If helpers need to be collapsed, do it right away... - // but if helpers need to be expanded, wait until after the container expands - if(!bShow) { - this._toggleContainerHelpers(bShow); - } - - if(oAnim.isAnimated()) { - oAnim.stop(); - } - - // Clone container to grab current size offscreen - var oClone = oContainer._oContent.cloneNode(true); - oContainer.appendChild(oClone); - oClone.style.top = "-9000px"; - oClone.style.display = "block"; - - // 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) { - oContainer._oContent.style.width = wColl+"px"; - oContainer._oContent.style.height = hColl+"px"; - } - // Else, set it to its last known size. - else { - oContainer._oContent.style.width = wExp+"px"; - oContainer._oContent.style.height = hExp+"px"; - } - - oContainer.removeChild(oClone); - oClone = null; - - var oSelf = this; - var onAnimComplete = function() { - // Finish the collapse - oAnim.onComplete.unsubscribeAll(); - - if(bShow) { - oSelf.containerExpandEvent.fire(oSelf); - } - else { - oContainer._oContent.style.display = "none"; - oSelf.containerCollapseEvent.fire(oSelf); - } - oSelf._toggleContainerHelpers(bShow); - }; - - // Display container and animate it - oContainer._oContent.style.display = "block"; - oAnim.onComplete.subscribe(onAnimComplete); - oAnim.animate(); - this._bContainerOpen = bShow; - } - // Else don't animate, just show or hide - else { - if(bShow) { - oContainer._oContent.style.display = "block"; - this.containerExpandEvent.fire(this); - } - else { - oContainer._oContent.style.display = "none"; - this.containerCollapseEvent.fire(this); - } - this._toggleContainerHelpers(bShow); - this._bContainerOpen = bShow; - } - -}; - -/** - * Toggles the highlight on or off for an item in the container, and also cleans - * up highlighting of any previous item. - * - * @param {object} oNewItem New The <li> element item to receive highlight - * behavior - * @param {string} sType "mouseover" will toggle highlight on, and "mouseout" - * will toggle highlight off. - * @private - */ -YAHOO.widget.AutoComplete.prototype._toggleHighlight = function(oNewItem, sType) { - var sHighlight = this.highlightClassName; - if(this._oCurItem) { - // Remove highlight from old item - YAHOO.util.Dom.removeClass(this._oCurItem, sHighlight); - } - - if((sType == "to") && sHighlight) { - // Apply highlight to new item - YAHOO.util.Dom.addClass(oNewItem, sHighlight); - this._oCurItem = oNewItem; - } -}; - -/** - * Toggles the pre-highlight on or off for an item in the container. - * - * @param {object} oNewItem New The <li> element item to receive highlight - * behavior - * @param {string} sType "mouseover" will toggle highlight on, and "mouseout" - * will toggle highlight off. - * @private - */ -YAHOO.widget.AutoComplete.prototype._togglePrehighlight = function(oNewItem, sType) { - if(oNewItem == this._oCurItem) { - return; - } - - var sPrehighlight = this.prehighlightClassName; - if((sType == "mouseover") && sPrehighlight) { - // Apply prehighlight to new item - YAHOO.util.Dom.addClass(oNewItem, sPrehighlight); - } - else { - // Remove prehighlight from old item - YAHOO.util.Dom.removeClass(oNewItem, 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. - * - * @param {object} oItem The <li> element item with which to update the value - * @private - */ -YAHOO.widget.AutoComplete.prototype._updateValue = function(oItem) { - var oTextbox = this._oTextbox; - var sDelimChar = (this.delimChar) ? this.delimChar[0] : null; - var sSavedQuery = this._sSavedQuery; - var sResultKey = oItem._sResultKey; - oTextbox.focus(); - - // First clear text field - oTextbox.value = ""; - // Grab data to put into text field - if(sDelimChar) { - if(sSavedQuery) { - oTextbox.value = sSavedQuery; - } - oTextbox.value += sResultKey + sDelimChar; - if(sDelimChar != " ") { - oTextbox.value += " "; - } - } - else { oTextbox.value = sResultKey; } - - // scroll to bottom of textarea if necessary - if(oTextbox.type == "textarea") { - oTextbox.scrollTop = oTextbox.scrollHeight; - } - - // move cursor to end - var end = oTextbox.value.length; - this._selectText(oTextbox,end,end); - - this._oCurItem = oItem; -}; - -/** - * Selects a result item from the container - * - * @param {object} oItem The selected <li> element item - * @private - */ -YAHOO.widget.AutoComplete.prototype._selectItem = function(oItem) { - this._bItemSelected = true; - this._updateValue(oItem); - this.itemSelectEvent.fire(this, oItem, oItem._oResultData); - this._clearList(); -}; - -/** - * For values updated by type-ahead, the right arrow key jumps to the end - * of the textbox, otherwise the container is closed. - * - * @private - */ -YAHOO.widget.AutoComplete.prototype._jumpSelection = function() { - if(!this.typeAhead) { - return; - } - else { - this._clearList(); - } -}; - -/** - * Triggered by up and down arrow keys, changes the current highlighted - * <li> element item. Scrolls container if necessary. - * - * @param {number} nKeyCode Code of key pressed - * @private - */ -YAHOO.widget.AutoComplete.prototype._moveSelection = function(nKeyCode) { - if(this._bContainerOpen) { - // Determine current item's id number - var oCurItem = this._oCurItem; - var nCurItemIndex = -1; - - if (oCurItem) { - nCurItemIndex = oCurItem._nItemIndex; - } - - var nNewItemIndex = (nKeyCode == 40) ? - (nCurItemIndex + 1) : (nCurItemIndex - 1); - - // Out of bounds - if (nNewItemIndex < -2 || nNewItemIndex >= this._nDisplayedItems) { - return; - } - - if (oCurItem) { - // Unhighlight current item - this._toggleHighlight(oCurItem, "from"); - this.itemArrowFromEvent.fire(this, oCurItem); - } - if (nNewItemIndex == -1) { - // Go back to query (remove type-ahead string) - if(this.delimChar && this._sSavedQuery) { - if (!this._textMatchesOption()) { - this._oTextbox.value = this._sSavedQuery; - } - else { - this._oTextbox.value = this._sSavedQuery + this._sCurQuery; - } - } - else { - this._oTextbox.value = this._sCurQuery; - } - this._oCurItem = null; - return; - } - if (nNewItemIndex == -2) { - // Close container - this._clearList(); - return; - } - - var oNewItem = this._aListItems[nNewItemIndex]; - - // Scroll the container if necessary - if((YAHOO.util.Dom.getStyle(this._oContainer._oContent,"overflow") == "auto") && - (nNewItemIndex > -1) && (nNewItemIndex < this._nDisplayedItems)) { - // User is keying down - if(nKeyCode == 40) { - // Bottom of selected item is below scroll area... - if((oNewItem.offsetTop+oNewItem.offsetHeight) > (this._oContainer._oContent.scrollTop + this._oContainer._oContent.offsetHeight)) { - // Set bottom of scroll area to bottom of selected item - this._oContainer._oContent.scrollTop = (oNewItem.offsetTop+oNewItem.offsetHeight) - this._oContainer._oContent.offsetHeight; - } - // Bottom of selected item is above scroll area... - else if((oNewItem.offsetTop+oNewItem.offsetHeight) < this._oContainer._oContent.scrollTop) { - // Set top of selected item to top of scroll area - this._oContainer._oContent.scrollTop = oNewItem.offsetTop; - - } - } - // User is keying up - else { - // Top of selected item is above scroll area - if(oNewItem.offsetTop < this._oContainer._oContent.scrollTop) { - // Set top of scroll area to top of selected item - this._oContainer._oContent.scrollTop = oNewItem.offsetTop; - } - // Top of selected item is below scroll area - else if(oNewItem.offsetTop > (this._oContainer._oContent.scrollTop + this._oContainer._oContent.offsetHeight)) { - // Set bottom of selected item to bottom of scroll area - this._oContainer._oContent.scrollTop = (oNewItem.offsetTop+oNewItem.offsetHeight) - this._oContainer._oContent.offsetHeight; - } - } - } - - this._toggleHighlight(oNewItem, "to"); - this.itemArrowToEvent.fire(this, oNewItem); - if(this.typeAhead) { - this._updateValue(oNewItem); - } - } -}; - -/****************************************************************************/ -/****************************************************************************/ -/****************************************************************************/ - -/** - * Class providing encapsulation of a data source. + * The DataSource classes manages sending a request and returning response from a live + * database. Supported data include local JavaScript arrays and objects and databases + * accessible via XHR connections. Supported response formats include JavaScript arrays, + * JSON, XML, and flat-file textual data. * + * @class DataSource * @constructor - * */ YAHOO.widget.DataSource = function() { /* abstract class */ }; -/*************************************************************************** - * Public constants - ***************************************************************************/ +///////////////////////////////////////////////////////////////////////////// +// +// Public constants +// +///////////////////////////////////////////////////////////////////////////// + /** * Error message for null data responses. * - * @type constant + * @property ERROR_DATANULL + * @type String + * @static * @final */ -YAHOO.widget.DataSource.prototype.ERROR_DATANULL = "Response data was null"; +YAHOO.widget.DataSource.ERROR_DATANULL = "Response data was null"; /** * Error message for data responses with parsing errors. * - * @type constant + * @property ERROR_DATAPARSE + * @type String + * @static * @final */ -YAHOO.widget.DataSource.prototype.ERROR_DATAPARSE = "Response data could not be parsed"; +YAHOO.widget.DataSource.ERROR_DATAPARSE = "Response data could not be parsed"; -/*************************************************************************** - * Public member variables - ***************************************************************************/ +///////////////////////////////////////////////////////////////////////////// +// +// Public member variables +// +///////////////////////////////////////////////////////////////////////////// + /** * Max size of the local cache. Set to 0 to turn off caching. Caching is * useful to reduce the number of server connections. Recommended only for data * sources that return comprehensive results for queries or when stale data is - * not an issue. Default: 15. + * not an issue. * - * @type number + * @property maxCacheEntries + * @type Number + * @default 15 */ YAHOO.widget.DataSource.prototype.maxCacheEntries = 15; @@ -1861,50 +2081,52 @@ YAHOO.widget.DataSource.prototype.maxCacheEntries = 15; * data source. If caching is on and queryMatchContains is true, the cache * returns results that "contain" the query string. By default, * queryMatchContains is set to false, meaning the cache only returns results - * that "start with" the query string. Default: false. + * that "start with" the query string. * - * @type boolean + * @property queryMatchContains + * @type Boolean + * @default false */ YAHOO.widget.DataSource.prototype.queryMatchContains = false; /** - * Data source query subset matching. If caching is on and queryMatchSubset is + * Enables query subset matching. If caching is on 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 data sources that return comprehensive results - * for queries with very few characters. Default: false. + * source. Recommended only for DataSources that return comprehensive results + * for queries with very few characters. + * + * @property queryMatchSubset + * @type Boolean + * @default false * - * @type boolean */ YAHOO.widget.DataSource.prototype.queryMatchSubset = false; /** - * Data source query case-sensitivity matching. If caching is on and + * Enables query case-sensitivity matching. If caching is on and * queryMatchCase is true, queries will only return results for case-sensitive - * matches. Default: false. + * matches. * - * @type boolean + * @property queryMatchCase + * @type Boolean + * @default false */ YAHOO.widget.DataSource.prototype.queryMatchCase = false; -/*************************************************************************** - * Public methods - ***************************************************************************/ - /** - * Public accessor to the unique name of the data source instance. - * - * @return {string} Unique name of the data source instance - */ -YAHOO.widget.DataSource.prototype.getName = function() { - return this._sName; -}; +///////////////////////////////////////////////////////////////////////////// +// +// Public methods +// +///////////////////////////////////////////////////////////////////////////// /** - * Public accessor to the unique name of the data source instance. + * Public accessor to the unique name of the DataSource instance. * - * @return {string} Unique name of the data source instance + * @method toString + * @return {String} Unique name of the DataSource instance */ YAHOO.widget.DataSource.prototype.toString = function() { return "DataSource " + this._sName; @@ -1914,10 +2136,10 @@ YAHOO.widget.DataSource.prototype.toString = function() { * Retrieves query results, first checking the local cache, then making the * query request to the live data source as defined by the function doQuery. * - * @param {object} oCallbackFn Callback function defined by oParent object to - * which to return results - * @param {string} sQuery Query string - * @param {object} oParent The object instance that has requested data + * @method getResults + * @param oCallbackFn {HTMLFunction} Callback function defined by oParent object to which to return results. + * @param sQuery {String} Query string. + * @param oParent {Object} The object instance that has requested data. */ YAHOO.widget.DataSource.prototype.getResults = function(oCallbackFn, sQuery, oParent) { @@ -1936,10 +2158,10 @@ YAHOO.widget.DataSource.prototype.getResults = function(oCallbackFn, sQuery, oPa * source. Must call the callback function with the response returned from the * query. Populates cache (if enabled). * - * @param {object} oCallbackFn Callback function implemented by oParent to - * which to return results - * @param {string} sQuery Query string - * @param {object} oParent The object instance that has requested data + * @method doQuery + * @param oCallbackFn {HTMLFunction} Callback function implemented by oParent to which to return results. + * @param sQuery {String} Query string. + * @param oParent {Object} The object instance that has requested data. */ YAHOO.widget.DataSource.prototype.doQuery = function(oCallbackFn, sQuery, oParent) { /* override this */ @@ -1947,6 +2169,8 @@ YAHOO.widget.DataSource.prototype.doQuery = function(oCallbackFn, sQuery, oParen /** * Flushes cache. + * + * @method flushCache */ YAHOO.widget.DataSource.prototype.flushCache = function() { if(this._aCache) { @@ -1958,79 +2182,94 @@ YAHOO.widget.DataSource.prototype.flushCache = function() { this.cacheFlushEvent.fire(this); }; -/*************************************************************************** - * Events - ***************************************************************************/ +///////////////////////////////////////////////////////////////////////////// +// +// Public events +// +///////////////////////////////////////////////////////////////////////////// + /** - * Fired when a query is made to the live data source. Subscribers receive the - * following array:
- * - args[0] The data source instance - * - args[1] The requesting object - * - args[2] The query string + * Fired when a query is made to the live data source. + * + * @event queryEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. */ YAHOO.widget.DataSource.prototype.queryEvent = null; /** - * Fired when a query is made to the local cache. Subscribers receive the - * following array:
- * - args[0] The data source instance - * - args[1] The requesting object - * - args[2] The query string + * Fired when a query is made to the local cache. + * + * @event cacheQueryEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. */ YAHOO.widget.DataSource.prototype.cacheQueryEvent = null; /** - * Fired when data is retrieved from the live data source. Subscribers receive - * the following array:
- * - args[0] The data source instance - * - args[1] The requesting object - * - args[2] The query string - * - args[3] Array of result objects + * Fired when data is retrieved from the live data source. + * + * @event getResultsEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. + * @param aResults {Object[]} Array of result objects. */ YAHOO.widget.DataSource.prototype.getResultsEvent = null; /** - * Fired when data is retrieved from the local cache. Subscribers receive the - * following array :
- * - args[0] The data source instance - * - args[1] The requesting object - * - args[2] The query string - * - args[3] Array of result objects + * Fired when data is retrieved from the local cache. + * + * @event getCachedResultsEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. + * @param aResults {Object[]} Array of result objects. */ YAHOO.widget.DataSource.prototype.getCachedResultsEvent = null; /** - * Fired when an error is encountered with the live data source. Subscribers - * receive the following array:
- * - args[0] The data source instance - * - args[1] The requesting object - * - args[2] The query string - * - args[3] Error message string + * Fired when an error is encountered with the live data source. + * + * @event dataErrorEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. + * @param sMsg {String} Error message string */ YAHOO.widget.DataSource.prototype.dataErrorEvent = null; /** - * Fired when the local cache is flushed. Subscribers receive the following - * array :
- * - args[0] The data source instance + * Fired when the local cache is flushed. + * + * @event cacheFlushEvent + * @param oSelf {Object} The DataSource instance */ YAHOO.widget.DataSource.prototype.cacheFlushEvent = null; -/*************************************************************************** - * Private member variables - ***************************************************************************/ +///////////////////////////////////////////////////////////////////////////// +// +// Private member variables +// +///////////////////////////////////////////////////////////////////////////// + /** - * Internal class variable to index multiple data source instances. + * Internal class variable to index multiple DataSource instances. * - * @type number + * @property _nIndex + * @type Number * @private + * @static */ YAHOO.widget.DataSource._nIndex = 0; /** - * Name of data source instance. + * Name of DataSource instance. * - * @type string + * @property _sName + * @type String * @private */ YAHOO.widget.DataSource.prototype._sName = null; @@ -2038,18 +2277,23 @@ YAHOO.widget.DataSource.prototype._sName = null; /** * Local cache of data result objects indexed chronologically. * - * @type array + * @property _aCache + * @type Object[] * @private */ YAHOO.widget.DataSource.prototype._aCache = null; -/*************************************************************************** - * Private methods - ***************************************************************************/ +///////////////////////////////////////////////////////////////////////////// +// +// Private methods +// +///////////////////////////////////////////////////////////////////////////// + /** - * Initializes data source instance. + * Initializes DataSource instance. * + * @method _init * @private */ YAHOO.widget.DataSource.prototype._init = function() { @@ -2079,14 +2323,14 @@ YAHOO.widget.DataSource.prototype._init = function() { * cache is full. Newer items will have higher indexes, the oldest item will have * index of 0. * - * @param {object} resultObj Object literal of data results, including internal - * properties and an array of result objects + * @method _addCacheElem + * @param oResult {Object} Data result object, including array of results. * @private */ -YAHOO.widget.DataSource.prototype._addCacheElem = function(resultObj) { +YAHOO.widget.DataSource.prototype._addCacheElem = function(oResult) { var aCache = this._aCache; // Don't add if anything important is missing. - if(!aCache || !resultObj || !resultObj.query || !resultObj.results) { + if(!aCache || !oResult || !oResult.query || !oResult.results) { return; } @@ -2096,7 +2340,7 @@ YAHOO.widget.DataSource.prototype._addCacheElem = function(resultObj) { } // Add to cache, at the end of the array - aCache.push(resultObj); + aCache.push(oResult); }; /** @@ -2104,12 +2348,11 @@ YAHOO.widget.DataSource.prototype._addCacheElem = function(resultObj) { * function is called with the results, and the cached is refreshed so that it * is now the newest element. * - * @param {object} oCallbackFn Callback function defined by oParent object to - * which to return results - * @param {string} sQuery Query string - * @param {object} oParent The object instance that has requested data - * @return {array} aResults Result object from local cache if found, otherwise - * null + * @method _doQueryCache + * @param oCallbackFn {HTMLFunction} Callback function defined by oParent object to which to return results. + * @param sQuery {String} Query string. + * @param oParent {Object} The object instance that has requested data. + * @return aResults {Object[]} Array of results from local cache if found, otherwise null. * @private */ YAHOO.widget.DataSource.prototype._doQueryCache = function(oCallbackFn, sQuery, oParent) { @@ -2134,7 +2377,7 @@ YAHOO.widget.DataSource.prototype._doQueryCache = function(oCallbackFn, sQuery, var aAllResultItems = resultObj.results; // If case is unimportant, normalize match key for comparison var matchKey = (!this.queryMatchCase) ? - encodeURIComponent(resultObj.query.toLowerCase()): + encodeURIComponent(resultObj.query).toLowerCase(): encodeURIComponent(resultObj.query); // If a cached match key exactly matches the query... @@ -2211,14 +2454,15 @@ YAHOO.widget.DataSource.prototype._doQueryCache = function(oCallbackFn, sQuery, /** * Implementation of YAHOO.widget.DataSource using XML HTTP requests that return * query results. - * requires YAHOO.util.Connect XMLHTTPRequest library - * extends YAHOO.widget.DataSource * + * @class DS_XHR + * @extends YAHOO.widget.DataSource + * @requires connection * @constructor - * @param {string} sScriptURI Absolute or relative URI to script that returns - * query results as JSON, XML, or delimited flat data - * @param {array} aSchema Data schema definition of results - * @param {object} oConfigs Optional object literal of config params + * @param sScriptURI {String} Absolute or relative URI to script that returns query + * results as JSON, XML, or delimited flat-file data. + * @param aSchema {String[]} Data schema definition of results. + * @param oConfigs {Object} (optional) Object literal of config params. */ YAHOO.widget.DS_XHR = function(sScriptURI, aSchema, oConfigs) { // Set any config params passed in to override defaults @@ -2243,71 +2487,95 @@ YAHOO.widget.DS_XHR = function(sScriptURI, aSchema, oConfigs) { YAHOO.widget.DS_XHR.prototype = new YAHOO.widget.DataSource(); -/*************************************************************************** - * Public constants - ***************************************************************************/ +///////////////////////////////////////////////////////////////////////////// +// +// Public constants +// +///////////////////////////////////////////////////////////////////////////// + /** - * JSON data type + * JSON data type. * - * @type constant + * @property TYPE_JSON + * @type Number + * @static * @final */ -YAHOO.widget.DS_XHR.prototype.TYPE_JSON = 0; +YAHOO.widget.DS_XHR.TYPE_JSON = 0; /** - * XML data type + * XML data type. * - * @type constant + * @property TYPE_XML + * @type Number + * @static * @final */ -YAHOO.widget.DS_XHR.prototype.TYPE_XML = 1; +YAHOO.widget.DS_XHR.TYPE_XML = 1; /** - * Flat file data type + * Flat-file data type. * - * @type constant + * @property TYPE_FLAT + * @type Number + * @static * @final */ -YAHOO.widget.DS_XHR.prototype.TYPE_FLAT = 2; +YAHOO.widget.DS_XHR.TYPE_FLAT = 2; /** * Error message for XHR failure. * - * @type constant + * @property ERROR_DATAXHR + * @type String + * @static * @final */ -YAHOO.widget.DS_XHR.prototype.ERROR_DATAXHR = "XHR response failed"; +YAHOO.widget.DS_XHR.ERROR_DATAXHR = "XHR response failed"; + +///////////////////////////////////////////////////////////////////////////// +// +// Public member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Alias to YUI Connection Manager. Allows implementers to specify their own + * subclasses of the YUI Connection Manager utility. + * + * @property connMgr + * @type Object + * @default YAHOO.util.Connect + */ +YAHOO.widget.DS_XHR.prototype.connMgr = YAHOO.util.Connect; -/*************************************************************************** - * Public member variables - ***************************************************************************/ /** * Number of milliseconds the XHR connection will wait for a server response. A * a value of zero indicates the XHR connection will wait forever. Any value * greater than zero will use the Connection utility's Auto-Abort feature. - * Default: 0. * - * @type number + * @property connTimeout + * @type Number + * @default 0 */ YAHOO.widget.DS_XHR.prototype.connTimeout = 0; - /** * Absolute or relative URI to script that returns query results. For instance, - * queries will be sent to - * ?=userinput + * queries will be sent to <scriptURI>?<scriptQueryParam>=userinput * - * @type string + * @property scriptURI + * @type String */ YAHOO.widget.DS_XHR.prototype.scriptURI = null; /** * Query string parameter name sent to scriptURI. For instance, queries will be - * sent to - * ?=userinput - * Default: "query". + * sent to <scriptURI>?<scriptQueryParam>=userinput * - * @type string + * @property scriptQueryParam + * @type String + * @default "query" */ YAHOO.widget.DS_XHR.prototype.scriptQueryParam = "query"; @@ -2315,53 +2583,61 @@ YAHOO.widget.DS_XHR.prototype.scriptQueryParam = "query"; * String of key/value pairs to append to requests made to scriptURI. Define * this string when you want to send additional query parameters to your script. * When defined, queries will be sent to - * ?=userinput& - * Default: "". + * <scriptURI>?<scriptQueryParam>=userinput&<scriptQueryAppend> * - * @type string + * @property scriptQueryAppend + * @type String + * @default "" */ YAHOO.widget.DS_XHR.prototype.scriptQueryAppend = ""; /** - * XHR response data type. Other types that may be defined are TYPE_XML and - * TYPE_FLAT. Default: TYPE_JSON. + * XHR response data type. Other types that may be defined are YAHOO.widget.DS_XHR.TYPE_XML + * and YAHOO.widget.DS_XHR.TYPE_FLAT. * - * @type type + * @property responseType + * @type String + * @default YAHOO.widget.DS_XHR.TYPE_JSON */ -YAHOO.widget.DS_XHR.prototype.responseType = YAHOO.widget.DS_XHR.prototype.TYPE_JSON; +YAHOO.widget.DS_XHR.prototype.responseType = YAHOO.widget.DS_XHR.TYPE_JSON; /** * String after which to strip results. If the results from the XHR are sent * back as HTML, the gzip HTML comment appears at the end of the data and should - * be ignored. Default: "\n<!--" + * be ignored. * - * @type string + * @property responseStripAfter + * @type String + * @default "\n<!-" */ -YAHOO.widget.DS_XHR.prototype.responseStripAfter = "\n