/* Copyright (c) 2009, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 2.7.0 */ /** * The YAHOO object is the single global object used by YUI Library. It * contains utility function for setting up namespaces, inheritance, and * logging. YAHOO.util, YAHOO.widget, and YAHOO.example are namespaces * created automatically for and used by the library. * @module yahoo * @title YAHOO Global */ /** * YAHOO_config is not included as part of the library. Instead it is an * object that can be defined by the implementer immediately before * including the YUI library. The properties included in this object * will be used to configure global properties needed as soon as the * library begins to load. * @class YAHOO_config * @static */ /** * A reference to a function that will be executed every time a YAHOO module * is loaded. As parameter, this function will receive the version * information for the module. See * YAHOO.env.getVersion for the description of the version data structure. * @property listener * @type Function * @static * @default undefined */ /** * Set to true if the library will be dynamically loaded after window.onload. * Defaults to false * @property injecting * @type boolean * @static * @default undefined */ /** * Instructs the yuiloader component to dynamically load yui components and * their dependencies. See the yuiloader documentation for more information * about dynamic loading * @property load * @static * @default undefined * @see yuiloader */ /** * Forces the use of the supplied locale where applicable in the library * @property locale * @type string * @static * @default undefined */ if (typeof YAHOO == "undefined" || !YAHOO) { /** * The YAHOO global namespace object. If YAHOO is already defined, the * existing YAHOO object will not be overwritten so that defined * namespaces are preserved. * @class YAHOO * @static */ var YAHOO = {}; } /** * Returns the namespace specified and creates it if it doesn't exist *
 * YAHOO.namespace("property.package");
 * YAHOO.namespace("YAHOO.property.package");
 * 
* Either of the above would create YAHOO.property, then * YAHOO.property.package * * Be careful when naming packages. Reserved words may work in some browsers * and not others. For instance, the following will fail in Safari: *
 * YAHOO.namespace("really.long.nested.namespace");
 * 
* This fails because "long" is a future reserved word in ECMAScript * * For implementation code that uses YUI, do not create your components * in the namespaces created by the library. defined by YUI -- create * your own (YAHOO.util, YAHOO.widget, YAHOO.lang, YAHOO.env) * * @method namespace * @static * @param {String*} arguments 1-n namespaces to create * @return {Object} A reference to the last namespace object created */ YAHOO.namespace = function() { var a=arguments, o=null, i, j, d; for (i=0; i *
name:
The name of the module
*
version:
The version in use
*
build:
The build number in use
*
versions:
All versions that were registered
*
builds:
All builds that were registered.
*
mainClass:
An object that was was stamped with the * current version and build. If * mainClass.VERSION != version or mainClass.BUILD != build, * multiple versions of pieces of the library have been * loaded, potentially causing issues.
* * * @method getVersion * @static * @param {String} name the name of the module (event, slider, etc) * @return {Object} The version info */ YAHOO.env.getVersion = function(name) { return YAHOO.env.modules[name] || null; }; /** * Do not fork for a browser if it can be avoided. Use feature detection when * you can. Use the user agent as a last resort. YAHOO.env.ua stores a version * number for the browser engine, 0 otherwise. This value may or may not map * to the version number of the browser using the engine. The value is * presented as a float so that it can easily be used for boolean evaluation * as well as for looking for a particular range of versions. Because of this, * some of the granularity of the version info may be lost (e.g., Gecko 1.8.0.9 * reports 1.8). * @class YAHOO.env.ua * @static */ YAHOO.env.ua = function() { var o={ /** * Internet Explorer version number or 0. Example: 6 * @property ie * @type float */ ie:0, /** * Opera version number or 0. Example: 9.2 * @property opera * @type float */ opera:0, /** * Gecko engine revision number. Will evaluate to 1 if Gecko * is detected but the revision could not be found. Other browsers * will be 0. Example: 1.8 *
         * Firefox 1.0.0.4: 1.7.8   <-- Reports 1.7
         * Firefox 1.5.0.9: 1.8.0.9 <-- Reports 1.8
         * Firefox 2.0.0.3: 1.8.1.3 <-- Reports 1.8
         * Firefox 3 alpha: 1.9a4   <-- Reports 1.9
         * 
* @property gecko * @type float */ gecko:0, /** * AppleWebKit version. KHTML browsers that are not WebKit browsers * will evaluate to 1, other browsers 0. Example: 418.9.1 *
         * Safari 1.3.2 (312.6): 312.8.1 <-- Reports 312.8 -- currently the 
         *                                   latest available for Mac OSX 10.3.
         * Safari 2.0.2:         416     <-- hasOwnProperty introduced
         * Safari 2.0.4:         418     <-- preventDefault fixed
         * Safari 2.0.4 (419.3): 418.9.1 <-- One version of Safari may run
         *                                   different versions of webkit
         * Safari 2.0.4 (419.3): 419     <-- Tiger installations that have been
         *                                   updated, but not updated
         *                                   to the latest patch.
         * Webkit 212 nightly:   522+    <-- Safari 3.0 precursor (with native SVG
         *                                   and many major issues fixed).  
         * 3.x yahoo.com, flickr:422     <-- Safari 3.x hacks the user agent
         *                                   string when hitting yahoo.com and 
         *                                   flickr.com.
         * Safari 3.0.4 (523.12):523.12  <-- First Tiger release - automatic update
         *                                   from 2.x via the 10.4.11 OS patch
         * Webkit nightly 1/2008:525+    <-- Supports DOMContentLoaded event.
         *                                   yahoo.com user agent hack removed.
         *                                   
         * 
* http://developer.apple.com/internet/safari/uamatrix.html * @property webkit * @type float */ webkit: 0, /** * The mobile property will be set to a string containing any relevant * user agent information when a modern mobile browser is detected. * Currently limited to Safari on the iPhone/iPod Touch, Nokia N-series * devices with the WebKit-based browser, and Opera Mini. * @property mobile * @type string */ mobile: null, /** * Adobe AIR version number or 0. Only populated if webkit is detected. * Example: 1.0 * @property air * @type float */ air: 0, /** * Google Caja version number or 0. * @property caja * @type float */ caja: 0 }, ua = navigator.userAgent, m; // Modern KHTML browsers should qualify as Safari X-Grade if ((/KHTML/).test(ua)) { o.webkit=1; } // Modern WebKit browsers are at least X-Grade m=ua.match(/AppleWebKit\/([^\s]*)/); if (m&&m[1]) { o.webkit=parseFloat(m[1]); // Mobile browser check if (/ Mobile\//.test(ua)) { o.mobile = "Apple"; // iPhone or iPod Touch } else { m=ua.match(/NokiaN[^\/]*/); if (m) { o.mobile = m[0]; // Nokia N-series, ex: NokiaN95 } } m=ua.match(/AdobeAIR\/([^\s]*)/); if (m) { o.air = m[0]; // Adobe AIR 1.0 or better } } if (!o.webkit) { // not webkit // @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr) m=ua.match(/Opera[\s\/]([^\s]*)/); if (m&&m[1]) { o.opera=parseFloat(m[1]); m=ua.match(/Opera Mini[^;]*/); if (m) { o.mobile = m[0]; // ex: Opera Mini/2.0.4509/1316 } } else { // not opera or webkit m=ua.match(/MSIE\s([^;]*)/); if (m&&m[1]) { o.ie=parseFloat(m[1]); } else { // not opera, webkit, or ie m=ua.match(/Gecko\/([^\s]*)/); if (m) { o.gecko=1; // Gecko detected, look for revision m=ua.match(/rv:([^\s\)]*)/); if (m&&m[1]) { o.gecko=parseFloat(m[1]); } } } } } m=ua.match(/Caja\/([^\s]*)/); if (m&&m[1]) { o.caja=parseFloat(m[1]); } return o; }(); /* * Initializes the global by creating the default namespaces and applying * any new configuration information that is detected. This is the setup * for env. * @method init * @static * @private */ (function() { YAHOO.namespace("util", "widget", "example"); /*global YAHOO_config*/ if ("undefined" !== typeof YAHOO_config) { var l=YAHOO_config.listener,ls=YAHOO.env.listeners,unique=true,i; if (l) { // if YAHOO is loaded multiple times we need to check to see if // this is a new config object. If it is, add the new component // load listener to the stack for (i=0;i 0) ? L.dump(o[i], d-1) : OBJ); } else { s.push(o[i]); } s.push(COMMA); } if (s.length > 1) { s.pop(); } s.push("]"); // objects {k1 => v1, k2 => v2} } else { s.push("{"); for (i in o) { if (L.hasOwnProperty(o, i)) { s.push(i + ARROW); if (L.isObject(o[i])) { s.push((d > 0) ? L.dump(o[i], d-1) : OBJ); } else { s.push(o[i]); } s.push(COMMA); } } if (s.length > 1) { s.pop(); } s.push("}"); } return s.join(""); }, /** * Does variable substitution on a string. It scans through the string * looking for expressions enclosed in { } braces. If an expression * is found, it is used a key on the object. If there is a space in * the key, the first word is used for the key and the rest is provided * to an optional function to be used to programatically determine the * value (the extra information might be used for this decision). If * the value for the key in the object, or what is returned from the * function has a string value, number value, or object value, it is * substituted for the bracket expression and it repeats. If this * value is an object, it uses the Object's toString() if this has * been overridden, otherwise it does a shallow dump of the key/value * pairs. * @method substitute * @since 2.3.0 * @param s {String} The string that will be modified. * @param o {Object} An object containing the replacement values * @param f {Function} An optional function that can be used to * process each match. It receives the key, * value, and any extra metadata included with * the key inside of the braces. * @return {String} the substituted string */ substitute: function (s, o, f) { var i, j, k, key, v, meta, saved=[], token, DUMP='dump', SPACE=' ', LBRACE='{', RBRACE='}', dump; for (;;) { i = s.lastIndexOf(LBRACE); if (i < 0) { break; } j = s.indexOf(RBRACE, i); if (i + 1 >= j) { break; } //Extract key and meta info token = s.substring(i + 1, j); key = token; meta = null; k = key.indexOf(SPACE); if (k > -1) { meta = key.substring(k + 1); key = key.substring(0, k); } // lookup the value v = o[key]; // if a substitution function was provided, execute it if (f) { v = f(key, v, meta); } if (L.isObject(v)) { if (L.isArray(v)) { v = L.dump(v, parseInt(meta, 10)); } else { meta = meta || ""; // look for the keyword 'dump', if found force obj dump dump = meta.indexOf(DUMP); if (dump > -1) { meta = meta.substring(4); } // use the toString if it is not the Object toString // and the 'dump' meta info was not found if (v.toString===OP.toString || dump>-1) { v = L.dump(v, parseInt(meta, 10)); } else { v = v.toString(); } } } else if (!L.isString(v) && !L.isNumber(v)) { // This {block} has no replace string. Save it for later. v = "~-" + saved.length + "-~"; saved[saved.length] = token; // break; } s = s.substring(0, i) + v + s.substring(j + 1); } // restore saved {block}s for (i=saved.length-1; i>=0; i=i-1) { s = s.replace(new RegExp("~-" + i + "-~"), "{" + saved[i] + "}", "g"); } return s; }, /** * Returns a string without any leading or trailing whitespace. If * the input is not a string, the input will be returned untouched. * @method trim * @since 2.3.0 * @param s {string} the string to trim * @return {string} the trimmed string */ trim: function(s){ try { return s.replace(/^\s+|\s+$/g, ""); } catch(e) { return s; } }, /** * Returns a new object containing all of the properties of * all the supplied objects. The properties from later objects * will overwrite those in earlier objects. * @method merge * @since 2.3.0 * @param arguments {Object*} the objects to merge * @return the new merged object */ merge: function() { var o={}, a=arguments, l=a.length, i; for (i=0; i * var A = function() {}; * A.prototype.foo = 'foo'; * var a = new A(); * a.foo = 'foo'; * alert(a.hasOwnProperty('foo')); // true * alert(YAHOO.lang.hasOwnProperty(a, 'foo')); // false when using fallback * * @method hasOwnProperty * @param {any} o The object being testing * @param prop {string} the name of the property to test * @return {boolean} the result */ L.hasOwnProperty = (OP.hasOwnProperty) ? function(o, prop) { return o && o.hasOwnProperty(prop); } : function(o, prop) { return !L.isUndefined(o[prop]) && o.constructor.prototype[prop] !== o[prop]; }; // new lang wins OB.augmentObject(L, OB, true); /* * An alias for YAHOO.lang * @class YAHOO.util.Lang */ YAHOO.util.Lang = L; /** * Same as YAHOO.lang.augmentObject, except it only applies prototype * properties. This is an alias for augmentProto. * @see YAHOO.lang.augmentObject * @method augment * @static * @param {Function} r the object to receive the augmentation * @param {Function} s the object that supplies the properties to augment * @param {String*|boolean} arguments zero or more properties methods to * augment the receiver with. If none specified, everything * in the supplier will be used unless it would * overwrite an existing property in the receiver. if true * is specified as the third parameter, all properties will * be applied and will overwrite an existing property in * the receiver */ L.augment = L.augmentProto; /** * An alias for YAHOO.lang.augment * @for YAHOO * @method augment * @static * @param {Function} r the object to receive the augmentation * @param {Function} s the object that supplies the properties to augment * @param {String*} arguments zero or more properties methods to * augment the receiver with. If none specified, everything * in the supplier will be used unless it would * overwrite an existing property in the receiver */ YAHOO.augment = L.augmentProto; /** * An alias for YAHOO.lang.extend * @method extend * @static * @param {Function} subc the object to modify * @param {Function} superc the object to inherit * @param {Object} overrides additional properties/methods to add to the * subclass prototype. These will override the * matching items obtained from the superclass if present. */ YAHOO.extend = L.extend; })(); YAHOO.register("yahoo", YAHOO, {version: "2.7.0", build: "1799"}); /* Copyright (c) 2009, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 2.7.0 */ /** * The CustomEvent class lets you define events for your application * that can be subscribed to by one or more independent component. * * @param {String} type The type of event, which is passed to the callback * when the event fires * @param {Object} context The context the event will fire from. "this" will * refer to this object in the callback. Default value: * the window object. The listener can override this. * @param {boolean} silent pass true to prevent the event from writing to * the debugsystem * @param {int} signature the signature that the custom event subscriber * will receive. YAHOO.util.CustomEvent.LIST or * YAHOO.util.CustomEvent.FLAT. The default is * YAHOO.util.CustomEvent.LIST. * @namespace YAHOO.util * @class CustomEvent * @constructor */ YAHOO.util.CustomEvent = function(type, context, silent, signature) { /** * The type of event, returned to subscribers when the event fires * @property type * @type string */ this.type = type; /** * The context the the event will fire from by default. Defaults to the window * obj * @property scope * @type object */ this.scope = context || window; /** * By default all custom events are logged in the debug build, set silent * to true to disable debug outpu for this event. * @property silent * @type boolean */ this.silent = silent; /** * Custom events support two styles of arguments provided to the event * subscribers. *
    *
  • YAHOO.util.CustomEvent.LIST: *
      *
    • param1: event name
    • *
    • param2: array of arguments sent to fire
    • *
    • param3: a custom object supplied by the subscriber
    • *
    *
  • *
  • YAHOO.util.CustomEvent.FLAT *
      *
    • param1: the first argument passed to fire. If you need to * pass multiple parameters, use and array or object literal
    • *
    • param2: a custom object supplied by the subscriber
    • *
    *
  • *
* @property signature * @type int */ this.signature = signature || YAHOO.util.CustomEvent.LIST; /** * The subscribers to this event * @property subscribers * @type Subscriber[] */ this.subscribers = []; if (!this.silent) { } var onsubscribeType = "_YUICEOnSubscribe"; // Only add subscribe events for events that are not generated by // CustomEvent if (type !== onsubscribeType) { /** * Custom events provide a custom event that fires whenever there is * a new subscriber to the event. This provides an opportunity to * handle the case where there is a non-repeating event that has * already fired has a new subscriber. * * @event subscribeEvent * @type YAHOO.util.CustomEvent * @param {Function} fn The function to execute * @param {Object} obj An object to be passed along when the event * fires defaults to the custom event * @param {boolean|Object} override If true, the obj passed in becomes * the execution context of the listener. * if an object, that object becomes the * the execution context. defaults to * the custom event */ this.subscribeEvent = new YAHOO.util.CustomEvent(onsubscribeType, this, true); } /** * In order to make it possible to execute the rest of the subscriber * stack when one thows an exception, the subscribers exceptions are * caught. The most recent exception is stored in this property * @property lastError * @type Error */ this.lastError = null; }; /** * Subscriber listener sigature constant. The LIST type returns three * parameters: the event type, the array of args passed to fire, and * the optional custom object * @property YAHOO.util.CustomEvent.LIST * @static * @type int */ YAHOO.util.CustomEvent.LIST = 0; /** * Subscriber listener sigature constant. The FLAT type returns two * parameters: the first argument passed to fire and the optional * custom object * @property YAHOO.util.CustomEvent.FLAT * @static * @type int */ YAHOO.util.CustomEvent.FLAT = 1; YAHOO.util.CustomEvent.prototype = { /** * Subscribes the caller to this event * @method subscribe * @param {Function} fn The function to execute * @param {Object} obj An object to be passed along when the event * fires * @param {boolean|Object} overrideContext If true, the obj passed in becomes * the execution context of the listener. * if an object, that object becomes the * the execution context. */ subscribe: function(fn, obj, overrideContext) { if (!fn) { throw new Error("Invalid callback for subscriber to '" + this.type + "'"); } if (this.subscribeEvent) { this.subscribeEvent.fire(fn, obj, overrideContext); } this.subscribers.push( new YAHOO.util.Subscriber(fn, obj, overrideContext) ); }, /** * Unsubscribes subscribers. * @method unsubscribe * @param {Function} fn The subscribed function to remove, if not supplied * all will be removed * @param {Object} obj The custom object passed to subscribe. This is * optional, but if supplied will be used to * disambiguate multiple listeners that are the same * (e.g., you subscribe many object using a function * that lives on the prototype) * @return {boolean} True if the subscriber was found and detached. */ unsubscribe: function(fn, obj) { if (!fn) { return this.unsubscribeAll(); } var found = false; for (var i=0, len=this.subscribers.length; i *
  • The type of event
  • *
  • All of the arguments fire() was executed with as an array
  • *
  • The custom object (if any) that was passed into the subscribe() * method
  • * * @method fire * @param {Object*} arguments an arbitrary set of parameters to pass to * the handler. * @return {boolean} false if one of the subscribers returned false, * true otherwise */ fire: function() { this.lastError = null; var errors = [], len=this.subscribers.length; if (!len && this.silent) { return true; } var args=[].slice.call(arguments, 0), ret=true, i, rebuild=false; if (!this.silent) { } // make a copy of the subscribers so that there are // no index problems if one subscriber removes another. var subs = this.subscribers.slice(), throwErrors = YAHOO.util.Event.throwErrors; for (i=0; i 0) { param = args[0]; } try { ret = s.fn.call(scope, param, s.obj); } catch(e) { this.lastError = e; // errors.push(e); if (throwErrors) { throw e; } } } else { try { ret = s.fn.call(scope, this.type, args, s.obj); } catch(ex) { this.lastError = ex; if (throwErrors) { throw ex; } } } if (false === ret) { if (!this.silent) { } break; // return false; } } } return (ret !== false); }, /** * Removes all listeners * @method unsubscribeAll * @return {int} The number of listeners unsubscribed */ unsubscribeAll: function() { var l = this.subscribers.length, i; for (i=l-1; i>-1; i--) { this._delete(i); } this.subscribers=[]; return l; }, /** * @method _delete * @private */ _delete: function(index) { var s = this.subscribers[index]; if (s) { delete s.fn; delete s.obj; } // this.subscribers[index]=null; this.subscribers.splice(index, 1); }, /** * @method toString */ toString: function() { return "CustomEvent: " + "'" + this.type + "', " + "context: " + this.scope; } }; ///////////////////////////////////////////////////////////////////// /** * Stores the subscriber information to be used when the event fires. * @param {Function} fn The function to execute * @param {Object} obj An object to be passed along when the event fires * @param {boolean} overrideContext If true, the obj passed in becomes the execution * context of the listener * @class Subscriber * @constructor */ YAHOO.util.Subscriber = function(fn, obj, overrideContext) { /** * The callback that will be execute when the event fires * @property fn * @type function */ this.fn = fn; /** * An optional custom object that will passed to the callback when * the event fires * @property obj * @type object */ this.obj = YAHOO.lang.isUndefined(obj) ? null : obj; /** * The default execution context for the event listener is defined when the * event is created (usually the object which contains the event). * By setting overrideContext to true, the execution context becomes the custom * object passed in by the subscriber. If overrideContext is an object, that * object becomes the context. * @property overrideContext * @type boolean|object */ this.overrideContext = overrideContext; }; /** * Returns the execution context for this listener. If overrideContext was set to true * the custom obj will be the context. If overrideContext is an object, that is the * context, otherwise the default context will be used. * @method getScope * @param {Object} defaultScope the context to use if this listener does not * override it. */ YAHOO.util.Subscriber.prototype.getScope = function(defaultScope) { if (this.overrideContext) { if (this.overrideContext === true) { return this.obj; } else { return this.overrideContext; } } return defaultScope; }; /** * Returns true if the fn and obj match this objects properties. * Used by the unsubscribe method to match the right subscriber. * * @method contains * @param {Function} fn the function to execute * @param {Object} obj an object to be passed along when the event fires * @return {boolean} true if the supplied arguments match this * subscriber's signature. */ YAHOO.util.Subscriber.prototype.contains = function(fn, obj) { if (obj) { return (this.fn == fn && this.obj == obj); } else { return (this.fn == fn); } }; /** * @method toString */ YAHOO.util.Subscriber.prototype.toString = function() { return "Subscriber { obj: " + this.obj + ", overrideContext: " + (this.overrideContext || "no") + " }"; }; /** * The Event Utility provides utilities for managing DOM Events and tools * for building event systems * * @module event * @title Event Utility * @namespace YAHOO.util * @requires yahoo */ // The first instance of Event will win if it is loaded more than once. // @TODO this needs to be changed so that only the state data that needs to // be preserved is kept, while methods are overwritten/added as needed. // This means that the module pattern can't be used. if (!YAHOO.util.Event) { /** * The event utility provides functions to add and remove event listeners, * event cleansing. It also tries to automatically remove listeners it * registers during the unload event. * * @class Event * @static */ YAHOO.util.Event = function() { /** * True after the onload event has fired * @property loadComplete * @type boolean * @static * @private */ var loadComplete = false; /** * Cache of wrapped listeners * @property listeners * @type array * @static * @private */ var listeners = []; /** * User-defined unload function that will be fired before all events * are detached * @property unloadListeners * @type array * @static * @private */ var unloadListeners = []; /** * Cache of DOM0 event handlers to work around issues with DOM2 events * in Safari * @property legacyEvents * @static * @private */ var legacyEvents = []; /** * Listener stack for DOM0 events * @property legacyHandlers * @static * @private */ var legacyHandlers = []; /** * The number of times to poll after window.onload. This number is * increased if additional late-bound handlers are requested after * the page load. * @property retryCount * @static * @private */ var retryCount = 0; /** * onAvailable listeners * @property onAvailStack * @static * @private */ var onAvailStack = []; /** * Lookup table for legacy events * @property legacyMap * @static * @private */ var legacyMap = []; /** * Counter for auto id generation * @property counter * @static * @private */ var counter = 0; /** * Normalized keycodes for webkit/safari * @property webkitKeymap * @type {int: int} * @private * @static * @final */ var webkitKeymap = { 63232: 38, // up 63233: 40, // down 63234: 37, // left 63235: 39, // right 63276: 33, // page up 63277: 34, // page down 25: 9 // SHIFT-TAB (Safari provides a different key code in // this case, even though the shiftKey modifier is set) }; // String constants used by the addFocusListener and removeFocusListener methods var _FOCUS = YAHOO.env.ua.ie ? "focusin" : "focus"; var _BLUR = YAHOO.env.ua.ie ? "focusout" : "blur"; return { /** * The number of times we should look for elements that are not * in the DOM at the time the event is requested after the document * has been loaded. The default is 2000@amp;20 ms, so it will poll * for 40 seconds or until all outstanding handlers are bound * (whichever comes first). * @property POLL_RETRYS * @type int * @static * @final */ POLL_RETRYS: 2000, /** * The poll interval in milliseconds * @property POLL_INTERVAL * @type int * @static * @final */ POLL_INTERVAL: 20, /** * Element to bind, int constant * @property EL * @type int * @static * @final */ EL: 0, /** * Type of event, int constant * @property TYPE * @type int * @static * @final */ TYPE: 1, /** * Function to execute, int constant * @property FN * @type int * @static * @final */ FN: 2, /** * Function wrapped for context correction and cleanup, int constant * @property WFN * @type int * @static * @final */ WFN: 3, /** * Object passed in by the user that will be returned as a * parameter to the callback, int constant. Specific to * unload listeners * @property OBJ * @type int * @static * @final */ UNLOAD_OBJ: 3, /** * Adjusted context, either the element we are registering the event * on or the custom object passed in by the listener, int constant * @property ADJ_SCOPE * @type int * @static * @final */ ADJ_SCOPE: 4, /** * The original obj passed into addListener * @property OBJ * @type int * @static * @final */ OBJ: 5, /** * The original context parameter passed into addListener * @property OVERRIDE * @type int * @static * @final */ OVERRIDE: 6, /** * addListener/removeListener can throw errors in unexpected scenarios. * These errors are suppressed, the method returns false, and this property * is set * @property lastError * @static * @type Error */ lastError: null, /** * Safari detection * @property isSafari * @private * @static * @deprecated use YAHOO.env.ua.webkit */ isSafari: YAHOO.env.ua.webkit, /** * webkit version * @property webkit * @type string * @private * @static * @deprecated use YAHOO.env.ua.webkit */ webkit: YAHOO.env.ua.webkit, /** * IE detection * @property isIE * @private * @static * @deprecated use YAHOO.env.ua.ie */ isIE: YAHOO.env.ua.ie, /** * poll handle * @property _interval * @static * @private */ _interval: null, /** * document readystate poll handle * @property _dri * @static * @private */ _dri: null, /** * True when the document is initially usable * @property DOMReady * @type boolean * @static */ DOMReady: false, /** * Errors thrown by subscribers of custom events are caught * and the error message is written to the debug console. If * this property is set to true, it will also re-throw the * error. * @property throwErrors * @type boolean * @default false */ throwErrors: false, /** * @method startInterval * @static * @private */ startInterval: function() { if (!this._interval) { var self = this; var callback = function() { self._tryPreloadAttach(); }; this._interval = setInterval(callback, this.POLL_INTERVAL); } }, /** * Executes the supplied callback when the item with the supplied * id is found. This is meant to be used to execute behavior as * soon as possible as the page loads. If you use this after the * initial page load it will poll for a fixed time for the element. * The number of times it will poll and the frequency are * configurable. By default it will poll for 10 seconds. * *

    The callback is executed with a single parameter: * the custom object parameter, if provided.

    * * @method onAvailable * * @param {string||string[]} id the id of the element, or an array * of ids to look for. * @param {function} fn what to execute when the element is found. * @param {object} obj an optional object to be passed back as * a parameter to fn. * @param {boolean|object} overrideContext If set to true, fn will execute * in the context of obj, if set to an object it * will execute in the context of that object * @param checkContent {boolean} check child node readiness (onContentReady) * @static */ onAvailable: function(id, fn, obj, overrideContext, checkContent) { var a = (YAHOO.lang.isString(id)) ? [id] : id; for (var i=0; iThe callback is executed with a single parameter: * the custom object parameter, if provided.

    * * @method onContentReady * * @param {string} id the id of the element to look for. * @param {function} fn what to execute when the element is ready. * @param {object} obj an optional object to be passed back as * a parameter to fn. * @param {boolean|object} overrideContext If set to true, fn will execute * in the context of obj. If an object, fn will * exectute in the context of that object * * @static */ onContentReady: function(id, fn, obj, overrideContext) { this.onAvailable(id, fn, obj, overrideContext, true); }, /** * Executes the supplied callback when the DOM is first usable. This * will execute immediately if called after the DOMReady event has * fired. @todo the DOMContentReady event does not fire when the * script is dynamically injected into the page. This means the * DOMReady custom event will never fire in FireFox or Opera when the * library is injected. It _will_ fire in Safari, and the IE * implementation would allow for us to fire it if the defered script * is not available. We want this to behave the same in all browsers. * Is there a way to identify when the script has been injected * instead of included inline? Is there a way to know whether the * window onload event has fired without having had a listener attached * to it when it did so? * *

    The callback is a CustomEvent, so the signature is:

    *

    type <string>, args <array>, customobject <object>

    *

    For DOMReady events, there are no fire argments, so the * signature is:

    *

    "DOMReady", [], obj

    * * * @method onDOMReady * * @param {function} fn what to execute when the element is found. * @param {object} obj an optional object to be passed back as * a parameter to fn. * @param {boolean|object} overrideContext If set to true, fn will execute * in the context of obj, if set to an object it * will execute in the context of that object * * @static */ onDOMReady: function(fn, obj, overrideContext) { if (this.DOMReady) { setTimeout(function() { var s = window; if (overrideContext) { if (overrideContext === true) { s = obj; } else { s = overrideContext; } } fn.call(s, "DOMReady", [], obj); }, 0); } else { this.DOMReadyEvent.subscribe(fn, obj, overrideContext); } }, /** * Appends an event handler * * @method _addListener * * @param {String|HTMLElement|Array|NodeList} el An id, an element * reference, or a collection of ids and/or elements to assign the * listener to. * @param {String} sType The type of event to append * @param {Function} fn The method the event invokes * @param {Object} obj An arbitrary object that will be * passed as a parameter to the handler * @param {Boolean|object} overrideContext If true, the obj passed in becomes * the execution context of the listener. If an * object, this object becomes the execution * context. * @param {boolen} capture capture or bubble phase * @return {Boolean} True if the action was successful or defered, * false if one or more of the elements * could not have the listener attached, * or if the operation throws an exception. * @private * @static */ _addListener: function(el, sType, fn, obj, overrideContext, bCapture) { if (!fn || !fn.call) { return false; } // The el argument can be an array of elements or element ids. if ( this._isValidCollection(el)) { var ok = true; for (var i=0,len=el.length; i-1; i--) { ok = ( this.removeListener(el[i], sType, fn) && ok ); } return ok; } if (!fn || !fn.call) { //return false; return this.purgeElement(el, false, sType); } if ("unload" == sType) { for (i=unloadListeners.length-1; i>-1; i--) { li = unloadListeners[i]; if (li && li[0] == el && li[1] == sType && li[2] == fn) { unloadListeners.splice(i, 1); // unloadListeners[i]=null; return true; } } return false; } var cacheItem = null; // The index is a hidden parameter; needed to remove it from // the method signature because it was tempting users to // try and take advantage of it, which is not possible. var index = arguments[3]; if ("undefined" === typeof index) { index = this._getCacheIndex(el, sType, fn); } if (index >= 0) { cacheItem = listeners[index]; } if (!el || !cacheItem) { return false; } if (this.useLegacyEvent(el, sType)) { var legacyIndex = this.getLegacyIndex(el, sType); var llist = legacyHandlers[legacyIndex]; if (llist) { for (i=0, len=llist.length; i 0 && onAvailStack.length > 0); } // onAvailable var notAvail = []; var executeItem = function (el, item) { var context = el; if (item.overrideContext) { if (item.overrideContext === true) { context = item.obj; } else { context = item.overrideContext; } } item.fn.call(context, item.obj); }; var i, len, item, el, ready=[]; // onAvailable onContentReady for (i=0, len=onAvailStack.length; i-1; i--) { item = onAvailStack[i]; if (!item || !item.id) { onAvailStack.splice(i, 1); } } this.startInterval(); } else { if (this._interval) { clearInterval(this._interval); this._interval = null; } } this.locked = false; }, /** * Removes all listeners attached to the given element via addListener. * Optionally, the node's children can also be purged. * Optionally, you can specify a specific type of event to remove. * @method purgeElement * @param {HTMLElement} el the element to purge * @param {boolean} recurse recursively purge this element's children * as well. Use with caution. * @param {string} sType optional type of listener to purge. If * left out, all listeners will be removed * @static */ purgeElement: function(el, recurse, sType) { var oEl = (YAHOO.lang.isString(el)) ? this.getEl(el) : el; var elListeners = this.getListeners(oEl, sType), i, len; if (elListeners) { for (i=elListeners.length-1; i>-1; i--) { var l = elListeners[i]; this.removeListener(oEl, l.type, l.fn); } } if (recurse && oEl && oEl.childNodes) { for (i=0,len=oEl.childNodes.length; i 0) { // 2.5.0 listeners are removed for all browsers again. FireFox preserves // at least some listeners between page refreshes, potentially causing // errors during page load (mouseover listeners firing before they // should if the user moves the mouse at the correct moment). if (listeners) { for (j=listeners.length-1; j>-1; j--) { l = listeners[j]; if (l) { EU.removeListener(l[EU.EL], l[EU.TYPE], l[EU.FN], j); } } l=null; } legacyEvents = null; EU._simpleRemove(window, "unload", EU._unload); }, /** * Returns scrollLeft * @method _getScrollLeft * @static * @private */ _getScrollLeft: function() { return this._getScroll()[1]; }, /** * Returns scrollTop * @method _getScrollTop * @static * @private */ _getScrollTop: function() { return this._getScroll()[0]; }, /** * Returns the scrollTop and scrollLeft. Used to calculate the * pageX and pageY in Internet Explorer * @method _getScroll * @static * @private */ _getScroll: function() { var dd = document.documentElement, db = document.body; if (dd && (dd.scrollTop || dd.scrollLeft)) { return [dd.scrollTop, dd.scrollLeft]; } else if (db) { return [db.scrollTop, db.scrollLeft]; } else { return [0, 0]; } }, /** * Used by old versions of CustomEvent, restored for backwards * compatibility * @method regCE * @private * @static * @deprecated still here for backwards compatibility */ regCE: function() { // does nothing }, /** * Adds a DOM event directly without the caching, cleanup, context adj, etc * * @method _simpleAdd * @param {HTMLElement} el the element to bind the handler to * @param {string} sType the type of event handler * @param {function} fn the callback to invoke * @param {boolen} capture capture or bubble phase * @static * @private */ _simpleAdd: function () { if (window.addEventListener) { return function(el, sType, fn, capture) { el.addEventListener(sType, fn, (capture)); }; } else if (window.attachEvent) { return function(el, sType, fn, capture) { el.attachEvent("on" + sType, fn); }; } else { return function(){}; } }(), /** * Basic remove listener * * @method _simpleRemove * @param {HTMLElement} el the element to bind the handler to * @param {string} sType the type of event handler * @param {function} fn the callback to invoke * @param {boolen} capture capture or bubble phase * @static * @private */ _simpleRemove: function() { if (window.removeEventListener) { return function (el, sType, fn, capture) { el.removeEventListener(sType, fn, (capture)); }; } else if (window.detachEvent) { return function (el, sType, fn) { el.detachEvent("on" + sType, fn); }; } else { return function(){}; } }() }; }(); (function() { var EU = YAHOO.util.Event; /** * YAHOO.util.Event.on is an alias for addListener * @method on * @see addListener * @static */ EU.on = EU.addListener; /** * YAHOO.util.Event.onFocus is an alias for addFocusListener * @method on * @see addFocusListener * @static */ EU.onFocus = EU.addFocusListener; /** * YAHOO.util.Event.onBlur is an alias for addBlurListener * @method onBlur * @see addBlurListener * @static */ EU.onBlur = EU.addBlurListener; /*! DOMReady: based on work by: Dean Edwards/John Resig/Matthias Miller */ // Internet Explorer: use the readyState of a defered script. // This isolates what appears to be a safe moment to manipulate // the DOM prior to when the document's readyState suggests // it is safe to do so. if (EU.isIE) { // Process onAvailable/onContentReady items when the // DOM is ready. YAHOO.util.Event.onDOMReady( YAHOO.util.Event._tryPreloadAttach, YAHOO.util.Event, true); var n = document.createElement('p'); EU._dri = setInterval(function() { try { // throws an error if doc is not ready n.doScroll('left'); clearInterval(EU._dri); EU._dri = null; EU._ready(); n = null; } catch (ex) { } }, EU.POLL_INTERVAL); // The document's readyState in Safari currently will // change to loaded/complete before images are loaded. } else if (EU.webkit && EU.webkit < 525) { EU._dri = setInterval(function() { var rs=document.readyState; if ("loaded" == rs || "complete" == rs) { clearInterval(EU._dri); EU._dri = null; EU._ready(); } }, EU.POLL_INTERVAL); // FireFox and Opera: These browsers provide a event for this // moment. The latest WebKit releases now support this event. } else { EU._simpleAdd(document, "DOMContentLoaded", EU._ready); } ///////////////////////////////////////////////////////////// EU._simpleAdd(window, "load", EU._load); EU._simpleAdd(window, "unload", EU._unload); EU._tryPreloadAttach(); })(); } /** * EventProvider is designed to be used with YAHOO.augment to wrap * CustomEvents in an interface that allows events to be subscribed to * and fired by name. This makes it possible for implementing code to * subscribe to an event that either has not been created yet, or will * not be created at all. * * @Class EventProvider */ YAHOO.util.EventProvider = function() { }; YAHOO.util.EventProvider.prototype = { /** * Private storage of custom events * @property __yui_events * @type Object[] * @private */ __yui_events: null, /** * Private storage of custom event subscribers * @property __yui_subscribers * @type Object[] * @private */ __yui_subscribers: null, /** * Subscribe to a CustomEvent by event type * * @method subscribe * @param p_type {string} the type, or name of the event * @param p_fn {function} the function to exectute when the event fires * @param p_obj {Object} An object to be passed along when the event * fires * @param overrideContext {boolean} If true, the obj passed in becomes the * execution scope of the listener */ subscribe: function(p_type, p_fn, p_obj, overrideContext) { this.__yui_events = this.__yui_events || {}; var ce = this.__yui_events[p_type]; if (ce) { ce.subscribe(p_fn, p_obj, overrideContext); } else { this.__yui_subscribers = this.__yui_subscribers || {}; var subs = this.__yui_subscribers; if (!subs[p_type]) { subs[p_type] = []; } subs[p_type].push( { fn: p_fn, obj: p_obj, overrideContext: overrideContext } ); } }, /** * Unsubscribes one or more listeners the from the specified event * @method unsubscribe * @param p_type {string} The type, or name of the event. If the type * is not specified, it will attempt to remove * the listener from all hosted events. * @param p_fn {Function} The subscribed function to unsubscribe, if not * supplied, all subscribers will be removed. * @param p_obj {Object} The custom object passed to subscribe. This is * optional, but if supplied will be used to * disambiguate multiple listeners that are the same * (e.g., you subscribe many object using a function * that lives on the prototype) * @return {boolean} true if the subscriber was found and detached. */ unsubscribe: function(p_type, p_fn, p_obj) { this.__yui_events = this.__yui_events || {}; var evts = this.__yui_events; if (p_type) { var ce = evts[p_type]; if (ce) { return ce.unsubscribe(p_fn, p_obj); } } else { var ret = true; for (var i in evts) { if (YAHOO.lang.hasOwnProperty(evts, i)) { ret = ret && evts[i].unsubscribe(p_fn, p_obj); } } return ret; } return false; }, /** * Removes all listeners from the specified event. If the event type * is not specified, all listeners from all hosted custom events will * be removed. * @method unsubscribeAll * @param p_type {string} The type, or name of the event */ unsubscribeAll: function(p_type) { return this.unsubscribe(p_type); }, /** * Creates a new custom event of the specified type. If a custom event * by that name already exists, it will not be re-created. In either * case the custom event is returned. * * @method createEvent * * @param p_type {string} the type, or name of the event * @param p_config {object} optional config params. Valid properties are: * *
      *
    • * scope: defines the default execution scope. If not defined * the default scope will be this instance. *
    • *
    • * silent: if true, the custom event will not generate log messages. * This is false by default. *
    • *
    • * onSubscribeCallback: specifies a callback to execute when the * event has a new subscriber. This will fire immediately for * each queued subscriber if any exist prior to the creation of * the event. *
    • *
    * * @return {CustomEvent} the custom event * */ createEvent: function(p_type, p_config) { this.__yui_events = this.__yui_events || {}; var opts = p_config || {}; var events = this.__yui_events; if (events[p_type]) { } else { var scope = opts.scope || this; var silent = (opts.silent); var ce = new YAHOO.util.CustomEvent(p_type, scope, silent, YAHOO.util.CustomEvent.FLAT); events[p_type] = ce; if (opts.onSubscribeCallback) { ce.subscribeEvent.subscribe(opts.onSubscribeCallback); } this.__yui_subscribers = this.__yui_subscribers || {}; var qs = this.__yui_subscribers[p_type]; if (qs) { for (var i=0; i *
  • The first argument fire() was executed with
  • *
  • The custom object (if any) that was passed into the subscribe() * method
  • * * @method fireEvent * @param p_type {string} the type, or name of the event * @param arguments {Object*} an arbitrary set of parameters to pass to * the handler. * @return {boolean} the return value from CustomEvent.fire * */ fireEvent: function(p_type, arg1, arg2, etc) { this.__yui_events = this.__yui_events || {}; var ce = this.__yui_events[p_type]; if (!ce) { return null; } var args = []; for (var i=1; i 519) ? true : false); // TODO: worth refactoring for TOP/LEFT only? while ((parentNode = parentNode[OFFSET_PARENT])) { xy[0] += parentNode[OFFSET_LEFT]; xy[1] += parentNode[OFFSET_TOP]; if (bCheck) { xy = Y.Dom._calcBorders(parentNode, xy); } } // account for any scrolled ancestors if (Y.Dom._getStyle(node, POSITION) !== FIXED) { parentNode = node; while ((parentNode = parentNode[PARENT_NODE]) && parentNode[TAG_NAME]) { scrollTop = parentNode[SCROLL_TOP]; scrollLeft = parentNode[SCROLL_LEFT]; //Firefox does something funky with borders when overflow is not visible. if (isGecko && (Y.Dom._getStyle(parentNode, 'overflow') !== 'visible')) { xy = Y.Dom._calcBorders(parentNode, xy); } if (scrollTop || scrollLeft) { xy[0] -= scrollLeft; xy[1] -= scrollTop; } } xy[0] += docScrollLeft; xy[1] += docScrollTop; } else { //Fix FIXED position -- add scrollbars if (isOpera) { xy[0] -= docScrollLeft; xy[1] -= docScrollTop; } else if (isSafari || isGecko) { xy[0] += docScrollLeft; xy[1] += docScrollTop; } } //Round the numbers so we get sane data back xy[0] = Math.floor(xy[0]); xy[1] = Math.floor(xy[1]); } else { } return xy; }; } }(), // NOTE: Executing for loadtime branching /** * Gets the current X position of an element based on page coordinates. The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). * @method getX * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements * @return {Number | Array} The X position of the element(s) */ getX: function(el) { var f = function(el) { return Y.Dom.getXY(el)[0]; }; return Y.Dom.batch(el, f, Y.Dom, true); }, /** * Gets the current Y position of an element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). * @method getY * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements * @return {Number | Array} The Y position of the element(s) */ getY: function(el) { var f = function(el) { return Y.Dom.getXY(el)[1]; }; return Y.Dom.batch(el, f, Y.Dom, true); }, /** * Set the position of an html element in page coordinates, regardless of how the element is positioned. * The element(s) must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). * @method setXY * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements * @param {Array} pos Contains X & Y values for new position (coordinates are page-based) * @param {Boolean} noRetry By default we try and set the position a second time if the first fails */ setXY: function(el, pos, noRetry) { Y.Dom.batch(el, Y.Dom._setXY, { pos: pos, noRetry: noRetry }); }, _setXY: function(node, args) { var pos = Y.Dom._getStyle(node, POSITION), setStyle = Y.Dom.setStyle, xy = args.pos, noRetry = args.noRetry, delta = [ // assuming pixels; if not we will have to retry parseInt( Y.Dom.getComputedStyle(node, LEFT), 10 ), parseInt( Y.Dom.getComputedStyle(node, TOP), 10 ) ], currentXY, newXY; if (pos == 'static') { // default to relative pos = RELATIVE; setStyle(node, POSITION, pos); } currentXY = Y.Dom._getXY(node); if (!xy || currentXY === false) { // has to be part of doc to have xy return false; } if ( isNaN(delta[0]) ) {// in case of 'auto' delta[0] = (pos == RELATIVE) ? 0 : node[OFFSET_LEFT]; } if ( isNaN(delta[1]) ) { // in case of 'auto' delta[1] = (pos == RELATIVE) ? 0 : node[OFFSET_TOP]; } if (xy[0] !== null) { // from setX setStyle(node, LEFT, xy[0] - currentXY[0] + delta[0] + 'px'); } if (xy[1] !== null) { // from setY setStyle(node, TOP, xy[1] - currentXY[1] + delta[1] + 'px'); } if (!noRetry) { newXY = Y.Dom._getXY(node); // if retry is true, try one more time if we miss if ( (xy[0] !== null && newXY[0] != xy[0]) || (xy[1] !== null && newXY[1] != xy[1]) ) { Y.Dom._setXY(node, { pos: xy, noRetry: true }); } } }, /** * Set the X position of an html element in page coordinates, regardless of how the element is positioned. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). * @method setX * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements. * @param {Int} x The value to use as the X coordinate for the element(s). */ setX: function(el, x) { Y.Dom.setXY(el, [x, null]); }, /** * Set the Y position of an html element in page coordinates, regardless of how the element is positioned. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). * @method setY * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements. * @param {Int} x To use as the Y coordinate for the element(s). */ setY: function(el, y) { Y.Dom.setXY(el, [null, y]); }, /** * Returns the region position of the given element. * The element must be part of the DOM tree to have a region (display:none or elements not appended return false). * @method getRegion * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements. * @return {Region | Array} A Region or array of Region instances containing "top, left, bottom, right" member data. */ getRegion: function(el) { var f = function(el) { var region = false; if ( Y.Dom._canPosition(el) ) { region = Y.Region.getRegion(el); } else { } return region; }; return Y.Dom.batch(el, f, Y.Dom, true); }, /** * Returns the width of the client (viewport). * @method getClientWidth * @deprecated Now using getViewportWidth. This interface left intact for back compat. * @return {Int} The width of the viewable area of the page. */ getClientWidth: function() { return Y.Dom.getViewportWidth(); }, /** * Returns the height of the client (viewport). * @method getClientHeight * @deprecated Now using getViewportHeight. This interface left intact for back compat. * @return {Int} The height of the viewable area of the page. */ getClientHeight: function() { return Y.Dom.getViewportHeight(); }, /** * Returns a array of HTMLElements with the given class. * For optimized performance, include a tag and/or root node when possible. * Note: This method operates against a live collection, so modifying the * collection in the callback (removing/appending nodes, etc.) will have * side effects. Instead you should iterate the returned nodes array, * as you would with the native "getElementsByTagName" method. * @method getElementsByClassName * @param {String} className The class name to match against * @param {String} tag (optional) The tag name of the elements being collected * @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point * @param {Function} apply (optional) A function to apply to each element when found * @param {Any} o (optional) An optional arg that is passed to the supplied method * @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o" * @return {Array} An array of elements that have the given class name */ getElementsByClassName: function(className, tag, root, apply, o, overrides) { className = lang.trim(className); tag = tag || '*'; root = (root) ? Y.Dom.get(root) : null || document; if (!root) { return []; } var nodes = [], elements = root.getElementsByTagName(tag), hasClass = Y.Dom.hasClass; for (var i = 0, len = elements.length; i < len; ++i) { if ( hasClass(elements[i], className) ) { nodes[nodes.length] = elements[i]; } } if (apply) { Y.Dom.batch(nodes, apply, o, overrides); } return nodes; }, /** * Determines whether an HTMLElement has the given className. * @method hasClass * @param {String | HTMLElement | Array} el The element or collection to test * @param {String} className the class name to search for * @return {Boolean | Array} A boolean value or array of boolean values */ hasClass: function(el, className) { return Y.Dom.batch(el, Y.Dom._hasClass, className); }, _hasClass: function(el, className) { var ret = false, current; if (el && className) { current = Y.Dom.getAttribute(el, CLASS_NAME) || EMPTY; if (className.exec) { ret = className.test(current); } else { ret = className && (SPACE + current + SPACE). indexOf(SPACE + className + SPACE) > -1; } } else { } return ret; }, /** * Adds a class name to a given element or collection of elements. * @method addClass * @param {String | HTMLElement | Array} el The element or collection to add the class to * @param {String} className the class name to add to the class attribute * @return {Boolean | Array} A pass/fail boolean or array of booleans */ addClass: function(el, className) { return Y.Dom.batch(el, Y.Dom._addClass, className); }, _addClass: function(el, className) { var ret = false, current; if (el && className) { current = Y.Dom.getAttribute(el, CLASS_NAME) || EMPTY; if ( !Y.Dom._hasClass(el, className) ) { Y.Dom.setAttribute(el, CLASS_NAME, trim(current + SPACE + className)); ret = true; } } else { } return ret; }, /** * Removes a class name from a given element or collection of elements. * @method removeClass * @param {String | HTMLElement | Array} el The element or collection to remove the class from * @param {String} className the class name to remove from the class attribute * @return {Boolean | Array} A pass/fail boolean or array of booleans */ removeClass: function(el, className) { return Y.Dom.batch(el, Y.Dom._removeClass, className); }, _removeClass: function(el, className) { var ret = false, current, newClass, attr; if (el && className) { current = Y.Dom.getAttribute(el, CLASS_NAME) || EMPTY; Y.Dom.setAttribute(el, CLASS_NAME, current.replace(Y.Dom._getClassRegex(className), EMPTY)); newClass = Y.Dom.getAttribute(el, CLASS_NAME); if (current !== newClass) { // else nothing changed Y.Dom.setAttribute(el, CLASS_NAME, trim(newClass)); // trim after comparing to current class ret = true; if (Y.Dom.getAttribute(el, CLASS_NAME) === '') { // remove class attribute if empty attr = (el.hasAttribute && el.hasAttribute(_CLASS)) ? _CLASS : CLASS_NAME; el.removeAttribute(attr); } } } else { } return ret; }, /** * Replace a class with another class for a given element or collection of elements. * If no oldClassName is present, the newClassName is simply added. * @method replaceClass * @param {String | HTMLElement | Array} el The element or collection to remove the class from * @param {String} oldClassName the class name to be replaced * @param {String} newClassName the class name that will be replacing the old class name * @return {Boolean | Array} A pass/fail boolean or array of booleans */ replaceClass: function(el, oldClassName, newClassName) { return Y.Dom.batch(el, Y.Dom._replaceClass, { from: oldClassName, to: newClassName }); }, _replaceClass: function(el, classObj) { var className, from, to, ret = false, current; if (el && classObj) { from = classObj.from; to = classObj.to; if (!to) { ret = false; } else if (!from) { // just add if no "from" ret = Y.Dom._addClass(el, classObj.to); } else if (from !== to) { // else nothing to replace // May need to lead with DBLSPACE? current = Y.Dom.getAttribute(el, CLASS_NAME) || EMPTY; className = (SPACE + current.replace(Y.Dom._getClassRegex(from), SPACE + to)). split(Y.Dom._getClassRegex(to)); // insert to into what would have been the first occurrence slot className.splice(1, 0, SPACE + to); Y.Dom.setAttribute(el, CLASS_NAME, trim(className.join(EMPTY))); ret = true; } } else { } return ret; }, /** * Returns an ID and applies it to the element "el", if provided. * @method generateId * @param {String | HTMLElement | Array} el (optional) An optional element array of elements to add an ID to (no ID is added if one is already present). * @param {String} prefix (optional) an optional prefix to use (defaults to "yui-gen"). * @return {String | Array} The generated ID, or array of generated IDs (or original ID if already present on an element) */ generateId: function(el, prefix) { prefix = prefix || 'yui-gen'; var f = function(el) { if (el && el.id) { // do not override existing ID return el.id; } var id = prefix + YAHOO.env._id_counter++; if (el) { if (el[OWNER_DOCUMENT].getElementById(id)) { // in case one already exists // use failed id plus prefix to help ensure uniqueness return Y.Dom.generateId(el, id + prefix); } el.id = id; } return id; }; // batch fails when no element, so just generate and return single ID return Y.Dom.batch(el, f, Y.Dom, true) || f.apply(Y.Dom, arguments); }, /** * Determines whether an HTMLElement is an ancestor of another HTML element in the DOM hierarchy. * @method isAncestor * @param {String | HTMLElement} haystack The possible ancestor * @param {String | HTMLElement} needle The possible descendent * @return {Boolean} Whether or not the haystack is an ancestor of needle */ isAncestor: function(haystack, needle) { haystack = Y.Dom.get(haystack); needle = Y.Dom.get(needle); var ret = false; if ( (haystack && needle) && (haystack[NODE_TYPE] && needle[NODE_TYPE]) ) { if (haystack.contains && haystack !== needle) { // contains returns true when equal ret = haystack.contains(needle); } else if (haystack.compareDocumentPosition) { // gecko ret = !!(haystack.compareDocumentPosition(needle) & 16); } } else { } return ret; }, /** * Determines whether an HTMLElement is present in the current document. * @method inDocument * @param {String | HTMLElement} el The element to search for * @param {Object} doc An optional document to search, defaults to element's owner document * @return {Boolean} Whether or not the element is present in the current document */ inDocument: function(el, doc) { return Y.Dom._inDoc(Y.Dom.get(el), doc); }, _inDoc: function(el, doc) { var ret = false; if (el && el[TAG_NAME]) { doc = doc || el[OWNER_DOCUMENT]; ret = Y.Dom.isAncestor(doc[DOCUMENT_ELEMENT], el); } else { } return ret; }, /** * Returns a array of HTMLElements that pass the test applied by supplied boolean method. * For optimized performance, include a tag and/or root node when possible. * Note: This method operates against a live collection, so modifying the * collection in the callback (removing/appending nodes, etc.) will have * side effects. Instead you should iterate the returned nodes array, * as you would with the native "getElementsByTagName" method. * @method getElementsBy * @param {Function} method - A boolean method for testing elements which receives the element as its only argument. * @param {String} tag (optional) The tag name of the elements being collected * @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point * @param {Function} apply (optional) A function to apply to each element when found * @param {Any} o (optional) An optional arg that is passed to the supplied method * @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o" * @return {Array} Array of HTMLElements */ getElementsBy: function(method, tag, root, apply, o, overrides, firstOnly) { tag = tag || '*'; root = (root) ? Y.Dom.get(root) : null || document; if (!root) { return []; } var nodes = [], elements = root.getElementsByTagName(tag); for (var i = 0, len = elements.length; i < len; ++i) { if ( method(elements[i]) ) { if (firstOnly) { nodes = elements[i]; break; } else { nodes[nodes.length] = elements[i]; } } } if (apply) { Y.Dom.batch(nodes, apply, o, overrides); } return nodes; }, /** * Returns the first HTMLElement that passes the test applied by the supplied boolean method. * @method getElementBy * @param {Function} method - A boolean method for testing elements which receives the element as its only argument. * @param {String} tag (optional) The tag name of the elements being collected * @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point * @return {HTMLElement} */ getElementBy: function(method, tag, root) { return Y.Dom.getElementsBy(method, tag, root, null, null, null, true); }, /** * Runs the supplied method against each item in the Collection/Array. * The method is called with the element(s) as the first arg, and the optional param as the second ( method(el, o) ). * @method batch * @param {String | HTMLElement | Array} el (optional) An element or array of elements to apply the method to * @param {Function} method The method to apply to the element(s) * @param {Any} o (optional) An optional arg that is passed to the supplied method * @param {Boolean} overrides (optional) Whether or not to override the scope of "method" with "o" * @return {Any | Array} The return value(s) from the supplied method */ batch: function(el, method, o, overrides) { var collection = [], scope = (overrides) ? o : window; el = (el && (el[TAG_NAME] || el.item)) ? el : Y.Dom.get(el); // skip get() when possible if (el && method) { if (el[TAG_NAME] || el.length === undefined) { // element or not array-like return method.call(scope, el, o); } for (var i = 0; i < el.length; ++i) { collection[collection.length] = method.call(scope, el[i], o); } } else { return false; } return collection; }, /** * Returns the height of the document. * @method getDocumentHeight * @return {Int} The height of the actual document (which includes the body and its margin). */ getDocumentHeight: function() { var scrollHeight = (document[COMPAT_MODE] != CSS1_COMPAT || isSafari) ? document.body.scrollHeight : documentElement.scrollHeight, h = Math.max(scrollHeight, Y.Dom.getViewportHeight()); return h; }, /** * Returns the width of the document. * @method getDocumentWidth * @return {Int} The width of the actual document (which includes the body and its margin). */ getDocumentWidth: function() { var scrollWidth = (document[COMPAT_MODE] != CSS1_COMPAT || isSafari) ? document.body.scrollWidth : documentElement.scrollWidth, w = Math.max(scrollWidth, Y.Dom.getViewportWidth()); return w; }, /** * Returns the current height of the viewport. * @method getViewportHeight * @return {Int} The height of the viewable area of the page (excludes scrollbars). */ getViewportHeight: function() { var height = self.innerHeight, // Safari, Opera mode = document[COMPAT_MODE]; if ( (mode || isIE) && !isOpera ) { // IE, Gecko height = (mode == CSS1_COMPAT) ? documentElement.clientHeight : // Standards document.body.clientHeight; // Quirks } return height; }, /** * Returns the current width of the viewport. * @method getViewportWidth * @return {Int} The width of the viewable area of the page (excludes scrollbars). */ getViewportWidth: function() { var width = self.innerWidth, // Safari mode = document[COMPAT_MODE]; if (mode || isIE) { // IE, Gecko, Opera width = (mode == CSS1_COMPAT) ? documentElement.clientWidth : // Standards document.body.clientWidth; // Quirks } return width; }, /** * Returns the nearest ancestor that passes the test applied by supplied boolean method. * For performance reasons, IDs are not accepted and argument validation omitted. * @method getAncestorBy * @param {HTMLElement} node The HTMLElement to use as the starting point * @param {Function} method - A boolean method for testing elements which receives the element as its only argument. * @return {Object} HTMLElement or null if not found */ getAncestorBy: function(node, method) { while ( (node = node[PARENT_NODE]) ) { // NOTE: assignment if ( Y.Dom._testElement(node, method) ) { return node; } } return null; }, /** * Returns the nearest ancestor with the given className. * @method getAncestorByClassName * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point * @param {String} className * @return {Object} HTMLElement */ getAncestorByClassName: function(node, className) { node = Y.Dom.get(node); if (!node) { return null; } var method = function(el) { return Y.Dom.hasClass(el, className); }; return Y.Dom.getAncestorBy(node, method); }, /** * Returns the nearest ancestor with the given tagName. * @method getAncestorByTagName * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point * @param {String} tagName * @return {Object} HTMLElement */ getAncestorByTagName: function(node, tagName) { node = Y.Dom.get(node); if (!node) { return null; } var method = function(el) { return el[TAG_NAME] && el[TAG_NAME].toUpperCase() == tagName.toUpperCase(); }; return Y.Dom.getAncestorBy(node, method); }, /** * Returns the previous sibling that is an HTMLElement. * For performance reasons, IDs are not accepted and argument validation omitted. * Returns the nearest HTMLElement sibling if no method provided. * @method getPreviousSiblingBy * @param {HTMLElement} node The HTMLElement to use as the starting point * @param {Function} method A boolean function used to test siblings * that receives the sibling node being tested as its only argument * @return {Object} HTMLElement or null if not found */ getPreviousSiblingBy: function(node, method) { while (node) { node = node.previousSibling; if ( Y.Dom._testElement(node, method) ) { return node; } } return null; }, /** * Returns the previous sibling that is an HTMLElement * @method getPreviousSibling * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point * @return {Object} HTMLElement or null if not found */ getPreviousSibling: function(node) { node = Y.Dom.get(node); if (!node) { return null; } return Y.Dom.getPreviousSiblingBy(node); }, /** * Returns the next HTMLElement sibling that passes the boolean method. * For performance reasons, IDs are not accepted and argument validation omitted. * Returns the nearest HTMLElement sibling if no method provided. * @method getNextSiblingBy * @param {HTMLElement} node The HTMLElement to use as the starting point * @param {Function} method A boolean function used to test siblings * that receives the sibling node being tested as its only argument * @return {Object} HTMLElement or null if not found */ getNextSiblingBy: function(node, method) { while (node) { node = node.nextSibling; if ( Y.Dom._testElement(node, method) ) { return node; } } return null; }, /** * Returns the next sibling that is an HTMLElement * @method getNextSibling * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point * @return {Object} HTMLElement or null if not found */ getNextSibling: function(node) { node = Y.Dom.get(node); if (!node) { return null; } return Y.Dom.getNextSiblingBy(node); }, /** * Returns the first HTMLElement child that passes the test method. * @method getFirstChildBy * @param {HTMLElement} node The HTMLElement to use as the starting point * @param {Function} method A boolean function used to test children * that receives the node being tested as its only argument * @return {Object} HTMLElement or null if not found */ getFirstChildBy: function(node, method) { var child = ( Y.Dom._testElement(node.firstChild, method) ) ? node.firstChild : null; return child || Y.Dom.getNextSiblingBy(node.firstChild, method); }, /** * Returns the first HTMLElement child. * @method getFirstChild * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point * @return {Object} HTMLElement or null if not found */ getFirstChild: function(node, method) { node = Y.Dom.get(node); if (!node) { return null; } return Y.Dom.getFirstChildBy(node); }, /** * Returns the last HTMLElement child that passes the test method. * @method getLastChildBy * @param {HTMLElement} node The HTMLElement to use as the starting point * @param {Function} method A boolean function used to test children * that receives the node being tested as its only argument * @return {Object} HTMLElement or null if not found */ getLastChildBy: function(node, method) { if (!node) { return null; } var child = ( Y.Dom._testElement(node.lastChild, method) ) ? node.lastChild : null; return child || Y.Dom.getPreviousSiblingBy(node.lastChild, method); }, /** * Returns the last HTMLElement child. * @method getLastChild * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point * @return {Object} HTMLElement or null if not found */ getLastChild: function(node) { node = Y.Dom.get(node); return Y.Dom.getLastChildBy(node); }, /** * Returns an array of HTMLElement childNodes that pass the test method. * @method getChildrenBy * @param {HTMLElement} node The HTMLElement to start from * @param {Function} method A boolean function used to test children * that receives the node being tested as its only argument * @return {Array} A static array of HTMLElements */ getChildrenBy: function(node, method) { var child = Y.Dom.getFirstChildBy(node, method), children = child ? [child] : []; Y.Dom.getNextSiblingBy(child, function(node) { if ( !method || method(node) ) { children[children.length] = node; } return false; // fail test to collect all children }); return children; }, /** * Returns an array of HTMLElement childNodes. * @method getChildren * @param {String | HTMLElement} node The HTMLElement or an ID to use as the starting point * @return {Array} A static array of HTMLElements */ getChildren: function(node) { node = Y.Dom.get(node); if (!node) { } return Y.Dom.getChildrenBy(node); }, /** * Returns the left scroll value of the document * @method getDocumentScrollLeft * @param {HTMLDocument} document (optional) The document to get the scroll value of * @return {Int} The amount that the document is scrolled to the left */ getDocumentScrollLeft: function(doc) { doc = doc || document; return Math.max(doc[DOCUMENT_ELEMENT].scrollLeft, doc.body.scrollLeft); }, /** * Returns the top scroll value of the document * @method getDocumentScrollTop * @param {HTMLDocument} document (optional) The document to get the scroll value of * @return {Int} The amount that the document is scrolled to the top */ getDocumentScrollTop: function(doc) { doc = doc || document; return Math.max(doc[DOCUMENT_ELEMENT].scrollTop, doc.body.scrollTop); }, /** * Inserts the new node as the previous sibling of the reference node * @method insertBefore * @param {String | HTMLElement} newNode The node to be inserted * @param {String | HTMLElement} referenceNode The node to insert the new node before * @return {HTMLElement} The node that was inserted (or null if insert fails) */ insertBefore: function(newNode, referenceNode) { newNode = Y.Dom.get(newNode); referenceNode = Y.Dom.get(referenceNode); if (!newNode || !referenceNode || !referenceNode[PARENT_NODE]) { return null; } return referenceNode[PARENT_NODE].insertBefore(newNode, referenceNode); }, /** * Inserts the new node as the next sibling of the reference node * @method insertAfter * @param {String | HTMLElement} newNode The node to be inserted * @param {String | HTMLElement} referenceNode The node to insert the new node after * @return {HTMLElement} The node that was inserted (or null if insert fails) */ insertAfter: function(newNode, referenceNode) { newNode = Y.Dom.get(newNode); referenceNode = Y.Dom.get(referenceNode); if (!newNode || !referenceNode || !referenceNode[PARENT_NODE]) { return null; } if (referenceNode.nextSibling) { return referenceNode[PARENT_NODE].insertBefore(newNode, referenceNode.nextSibling); } else { return referenceNode[PARENT_NODE].appendChild(newNode); } }, /** * Creates a Region based on the viewport relative to the document. * @method getClientRegion * @return {Region} A Region object representing the viewport which accounts for document scroll */ getClientRegion: function() { var t = Y.Dom.getDocumentScrollTop(), l = Y.Dom.getDocumentScrollLeft(), r = Y.Dom.getViewportWidth() + l, b = Y.Dom.getViewportHeight() + t; return new Y.Region(t, r, b, l); }, /** * Provides a normalized attribute interface. * @method setAttibute * @param {String | HTMLElement} el The target element for the attribute. * @param {String} attr The attribute to set. * @param {String} val The value of the attribute. */ setAttribute: function(el, attr, val) { attr = Y.Dom.CUSTOM_ATTRIBUTES[attr] || attr; el.setAttribute(attr, val); }, /** * Provides a normalized attribute interface. * @method getAttibute * @param {String | HTMLElement} el The target element for the attribute. * @param {String} attr The attribute to get. * @return {String} The current value of the attribute. */ getAttribute: function(el, attr) { attr = Y.Dom.CUSTOM_ATTRIBUTES[attr] || attr; return el.getAttribute(attr); }, _toCamel: function(property) { var c = propertyCache; function tU(x,l) { return l.toUpperCase(); } return c[property] || (c[property] = property.indexOf('-') === -1 ? property : property.replace( /-([a-z])/gi, tU )); }, _getClassRegex: function(className) { var re; if (className !== undefined) { // allow empty string to pass if (className.exec) { // already a RegExp re = className; } else { re = reCache[className]; if (!re) { // escape special chars (".", "[", etc.) className = className.replace(Y.Dom._patterns.CLASS_RE_TOKENS, '\\$1'); re = reCache[className] = new RegExp(C_START + className + C_END, G); } } } return re; }, _patterns: { ROOT_TAG: /^body|html$/i, // body for quirks mode, html for standards, CLASS_RE_TOKENS: /([\.\(\)\^\$\*\+\?\|\[\]\{\}])/g }, _testElement: function(node, method) { return node && node[NODE_TYPE] == 1 && ( !method || method(node) ); }, _calcBorders: function(node, xy2) { var t = parseInt(Y.Dom[GET_COMPUTED_STYLE](node, BORDER_TOP_WIDTH), 10) || 0, l = parseInt(Y.Dom[GET_COMPUTED_STYLE](node, BORDER_LEFT_WIDTH), 10) || 0; if (isGecko) { if (RE_TABLE.test(node[TAG_NAME])) { t = 0; l = 0; } } xy2[0] += l; xy2[1] += t; return xy2; } }; var _getComputedStyle = Y.Dom[GET_COMPUTED_STYLE]; // fix opera computedStyle default color unit (convert to rgb) if (UA.opera) { Y.Dom[GET_COMPUTED_STYLE] = function(node, att) { var val = _getComputedStyle(node, att); if (RE_COLOR.test(att)) { val = Y.Dom.Color.toRGB(val); } return val; }; } // safari converts transparent to rgba(), others use "transparent" if (UA.webkit) { Y.Dom[GET_COMPUTED_STYLE] = function(node, att) { var val = _getComputedStyle(node, att); if (val === 'rgba(0, 0, 0, 0)') { val = 'transparent'; } return val; }; } })(); /** * A region is a representation of an object on a grid. It is defined * by the top, right, bottom, left extents, so is rectangular by default. If * other shapes are required, this class could be extended to support it. * @namespace YAHOO.util * @class Region * @param {Int} t the top extent * @param {Int} r the right extent * @param {Int} b the bottom extent * @param {Int} l the left extent * @constructor */ YAHOO.util.Region = function(t, r, b, l) { /** * The region's top extent * @property top * @type Int */ this.top = t; /** * The region's top extent * @property y * @type Int */ this.y = t; /** * The region's top extent as index, for symmetry with set/getXY * @property 1 * @type Int */ this[1] = t; /** * The region's right extent * @property right * @type int */ this.right = r; /** * The region's bottom extent * @property bottom * @type Int */ this.bottom = b; /** * The region's left extent * @property left * @type Int */ this.left = l; /** * The region's left extent * @property x * @type Int */ this.x = l; /** * The region's left extent as index, for symmetry with set/getXY * @property 0 * @type Int */ this[0] = l; /** * The region's total width * @property width * @type Int */ this.width = this.right - this.left; /** * The region's total height * @property height * @type Int */ this.height = this.bottom - this.top; }; /** * Returns true if this region contains the region passed in * @method contains * @param {Region} region The region to evaluate * @return {Boolean} True if the region is contained with this region, * else false */ YAHOO.util.Region.prototype.contains = function(region) { return ( region.left >= this.left && region.right <= this.right && region.top >= this.top && region.bottom <= this.bottom ); }; /** * Returns the area of the region * @method getArea * @return {Int} the region's area */ YAHOO.util.Region.prototype.getArea = function() { return ( (this.bottom - this.top) * (this.right - this.left) ); }; /** * Returns the region where the passed in region overlaps with this one * @method intersect * @param {Region} region The region that intersects * @return {Region} The overlap region, or null if there is no overlap */ YAHOO.util.Region.prototype.intersect = function(region) { var t = Math.max( this.top, region.top ), r = Math.min( this.right, region.right ), b = Math.min( this.bottom, region.bottom ), l = Math.max( this.left, region.left ); if (b >= t && r >= l) { return new YAHOO.util.Region(t, r, b, l); } else { return null; } }; /** * Returns the region representing the smallest region that can contain both * the passed in region and this region. * @method union * @param {Region} region The region that to create the union with * @return {Region} The union region */ YAHOO.util.Region.prototype.union = function(region) { var t = Math.min( this.top, region.top ), r = Math.max( this.right, region.right ), b = Math.max( this.bottom, region.bottom ), l = Math.min( this.left, region.left ); return new YAHOO.util.Region(t, r, b, l); }; /** * toString * @method toString * @return string the region properties */ YAHOO.util.Region.prototype.toString = function() { return ( "Region {" + "top: " + this.top + ", right: " + this.right + ", bottom: " + this.bottom + ", left: " + this.left + ", height: " + this.height + ", width: " + this.width + "}" ); }; /** * Returns a region that is occupied by the DOM element * @method getRegion * @param {HTMLElement} el The element * @return {Region} The region that the element occupies * @static */ YAHOO.util.Region.getRegion = function(el) { var p = YAHOO.util.Dom.getXY(el), t = p[1], r = p[0] + el.offsetWidth, b = p[1] + el.offsetHeight, l = p[0]; return new YAHOO.util.Region(t, r, b, l); }; ///////////////////////////////////////////////////////////////////////////// /** * A point is a region that is special in that it represents a single point on * the grid. * @namespace YAHOO.util * @class Point * @param {Int} x The X position of the point * @param {Int} y The Y position of the point * @constructor * @extends YAHOO.util.Region */ YAHOO.util.Point = function(x, y) { if (YAHOO.lang.isArray(x)) { // accept input from Dom.getXY, Event.getXY, etc. y = x[1]; // dont blow away x yet x = x[0]; } YAHOO.util.Point.superclass.constructor.call(this, y, x, y, x); }; YAHOO.extend(YAHOO.util.Point, YAHOO.util.Region); (function() { /** * Add style management functionality to DOM. * @module dom * @for Dom */ var Y = YAHOO.util, CLIENT_TOP = 'clientTop', CLIENT_LEFT = 'clientLeft', PARENT_NODE = 'parentNode', RIGHT = 'right', HAS_LAYOUT = 'hasLayout', PX = 'px', OPACITY = 'opacity', AUTO = 'auto', BORDER_LEFT_WIDTH = 'borderLeftWidth', BORDER_TOP_WIDTH = 'borderTopWidth', BORDER_RIGHT_WIDTH = 'borderRightWidth', BORDER_BOTTOM_WIDTH = 'borderBottomWidth', VISIBLE = 'visible', TRANSPARENT = 'transparent', HEIGHT = 'height', WIDTH = 'width', STYLE = 'style', CURRENT_STYLE = 'currentStyle', // IE getComputedStyle // TODO: unit-less lineHeight (e.g. 1.22) re_size = /^width|height$/, re_unit = /^(\d[.\d]*)+(em|ex|px|gd|rem|vw|vh|vm|ch|mm|cm|in|pt|pc|deg|rad|ms|s|hz|khz|%){1}?/i, ComputedStyle = { get: function(el, property) { var value = '', current = el[CURRENT_STYLE][property]; if (property === OPACITY) { value = Y.Dom.getStyle(el, OPACITY); } else if (!current || (current.indexOf && current.indexOf(PX) > -1)) { // no need to convert value = current; } else if (Y.Dom.IE_COMPUTED[property]) { // use compute function value = Y.Dom.IE_COMPUTED[property](el, property); } else if (re_unit.test(current)) { // convert to pixel value = Y.Dom.IE.ComputedStyle.getPixel(el, property); } else { value = current; } return value; }, getOffset: function(el, prop) { var current = el[CURRENT_STYLE][prop], // value of "width", "top", etc. capped = prop.charAt(0).toUpperCase() + prop.substr(1), // "Width", "Top", etc. offset = 'offset' + capped, // "offsetWidth", "offsetTop", etc. pixel = 'pixel' + capped, // "pixelWidth", "pixelTop", etc. value = '', actual; if (current == AUTO) { actual = el[offset]; // offsetHeight/Top etc. if (actual === undefined) { // likely "right" or "bottom" value = 0; } value = actual; if (re_size.test(prop)) { // account for box model diff el[STYLE][prop] = actual; if (el[offset] > actual) { // the difference is padding + border (works in Standards & Quirks modes) value = actual - (el[offset] - actual); } el[STYLE][prop] = AUTO; // revert to auto } } else { // convert units to px if (!el[STYLE][pixel] && !el[STYLE][prop]) { // need to map style.width to currentStyle (no currentStyle.pixelWidth) el[STYLE][prop] = current; // no style.pixelWidth if no style.width } value = el[STYLE][pixel]; } return value + PX; }, getBorderWidth: function(el, property) { // clientHeight/Width = paddingBox (e.g. offsetWidth - borderWidth) // clientTop/Left = borderWidth var value = null; if (!el[CURRENT_STYLE][HAS_LAYOUT]) { // TODO: unset layout? el[STYLE].zoom = 1; // need layout to measure client } switch(property) { case BORDER_TOP_WIDTH: value = el[CLIENT_TOP]; break; case BORDER_BOTTOM_WIDTH: value = el.offsetHeight - el.clientHeight - el[CLIENT_TOP]; break; case BORDER_LEFT_WIDTH: value = el[CLIENT_LEFT]; break; case BORDER_RIGHT_WIDTH: value = el.offsetWidth - el.clientWidth - el[CLIENT_LEFT]; break; } return value + PX; }, getPixel: function(node, att) { // use pixelRight to convert to px var val = null, styleRight = node[CURRENT_STYLE][RIGHT], current = node[CURRENT_STYLE][att]; node[STYLE][RIGHT] = current; val = node[STYLE].pixelRight; node[STYLE][RIGHT] = styleRight; // revert return val + PX; }, getMargin: function(node, att) { var val; if (node[CURRENT_STYLE][att] == AUTO) { val = 0 + PX; } else { val = Y.Dom.IE.ComputedStyle.getPixel(node, att); } return val; }, getVisibility: function(node, att) { var current; while ( (current = node[CURRENT_STYLE]) && current[att] == 'inherit') { // NOTE: assignment in test node = node[PARENT_NODE]; } return (current) ? current[att] : VISIBLE; }, getColor: function(node, att) { return Y.Dom.Color.toRGB(node[CURRENT_STYLE][att]) || TRANSPARENT; }, getBorderColor: function(node, att) { var current = node[CURRENT_STYLE], val = current[att] || current.color; return Y.Dom.Color.toRGB(Y.Dom.Color.toHex(val)); } }, //fontSize: getPixelFont, IEComputed = {}; IEComputed.top = IEComputed.right = IEComputed.bottom = IEComputed.left = IEComputed[WIDTH] = IEComputed[HEIGHT] = ComputedStyle.getOffset; IEComputed.color = ComputedStyle.getColor; IEComputed[BORDER_TOP_WIDTH] = IEComputed[BORDER_RIGHT_WIDTH] = IEComputed[BORDER_BOTTOM_WIDTH] = IEComputed[BORDER_LEFT_WIDTH] = ComputedStyle.getBorderWidth; IEComputed.marginTop = IEComputed.marginRight = IEComputed.marginBottom = IEComputed.marginLeft = ComputedStyle.getMargin; IEComputed.visibility = ComputedStyle.getVisibility; IEComputed.borderColor = IEComputed.borderTopColor = IEComputed.borderRightColor = IEComputed.borderBottomColor = IEComputed.borderLeftColor = ComputedStyle.getBorderColor; Y.Dom.IE_COMPUTED = IEComputed; Y.Dom.IE_ComputedStyle = ComputedStyle; })(); (function() { /** * Add style management functionality to DOM. * @module dom * @for Dom */ var TO_STRING = 'toString', PARSE_INT = parseInt, RE = RegExp, Y = YAHOO.util; Y.Dom.Color = { KEYWORDS: { black: '000', silver: 'c0c0c0', gray: '808080', white: 'fff', maroon: '800000', red: 'f00', purple: '800080', fuchsia: 'f0f', green: '008000', lime: '0f0', olive: '808000', yellow: 'ff0', navy: '000080', blue: '00f', teal: '008080', aqua: '0ff' }, re_RGB: /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i, re_hex: /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i, re_hex3: /([0-9A-F])/gi, toRGB: function(val) { if (!Y.Dom.Color.re_RGB.test(val)) { val = Y.Dom.Color.toHex(val); } if(Y.Dom.Color.re_hex.exec(val)) { val = 'rgb(' + [ PARSE_INT(RE.$1, 16), PARSE_INT(RE.$2, 16), PARSE_INT(RE.$3, 16) ].join(', ') + ')'; } return val; }, toHex: function(val) { val = Y.Dom.Color.KEYWORDS[val] || val; if (Y.Dom.Color.re_RGB.exec(val)) { var r = (RE.$1.length === 1) ? '0' + RE.$1 : Number(RE.$1), g = (RE.$2.length === 1) ? '0' + RE.$2 : Number(RE.$2), b = (RE.$3.length === 1) ? '0' + RE.$3 : Number(RE.$3); val = [ r[TO_STRING](16), g[TO_STRING](16), b[TO_STRING](16) ].join(''); } if (val.length < 6) { val = val.replace(Y.Dom.Color.re_hex3, '$1$1'); } if (val !== 'transparent' && val.indexOf('#') < 0) { val = '#' + val; } return val.toLowerCase(); } }; }()); YAHOO.register("dom", YAHOO.util.Dom, {version: "2.7.0", build: "1799"}); /* Copyright (c) 2009, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 2.7.0 */ /** * The Connection Manager provides a simplified interface to the XMLHttpRequest * object. It handles cross-browser instantiantion of XMLHttpRequest, negotiates the * interactive states and server response, returning the results to a pre-defined * callback you create. * * @namespace YAHOO.util * @module connection * @requires yahoo * @requires event */ /** * The Connection Manager singleton provides methods for creating and managing * asynchronous transactions. * * @class Connect */ YAHOO.util.Connect = { /** * @description Array of MSFT ActiveX ids for XMLHttpRequest. * @property _msxml_progid * @private * @static * @type array */ _msxml_progid:[ 'Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP' ], /** * @description Object literal of HTTP header(s) * @property _http_header * @private * @static * @type object */ _http_headers:{}, /** * @description Determines if HTTP headers are set. * @property _has_http_headers * @private * @static * @type boolean */ _has_http_headers:false, /** * @description Determines if a default header of * Content-Type of 'application/x-www-form-urlencoded' * will be added to any client HTTP headers sent for POST * transactions. * @property _use_default_post_header * @private * @static * @type boolean */ _use_default_post_header:true, /** * @description The default header used for POST transactions. * @property _default_post_header * @private * @static * @type boolean */ _default_post_header:'application/x-www-form-urlencoded; charset=UTF-8', /** * @description The default header used for transactions involving the * use of HTML forms. * @property _default_form_header * @private * @static * @type boolean */ _default_form_header:'application/x-www-form-urlencoded', /** * @description Determines if a default header of * 'X-Requested-With: XMLHttpRequest' * will be added to each transaction. * @property _use_default_xhr_header * @private * @static * @type boolean */ _use_default_xhr_header:true, /** * @description The default header value for the label * "X-Requested-With". This is sent with each * transaction, by default, to identify the * request as being made by YUI Connection Manager. * @property _default_xhr_header * @private * @static * @type boolean */ _default_xhr_header:'XMLHttpRequest', /** * @description Determines if custom, default headers * are set for each transaction. * @property _has_default_header * @private * @static * @type boolean */ _has_default_headers:true, /** * @description Determines if custom, default headers * are set for each transaction. * @property _has_default_header * @private * @static * @type boolean */ _default_headers:{}, /** * @description Property modified by setForm() to determine if the data * should be submitted as an HTML form. * @property _isFormSubmit * @private * @static * @type boolean */ _isFormSubmit:false, /** * @description Property modified by setForm() to determine if a file(s) * upload is expected. * @property _isFileUpload * @private * @static * @type boolean */ _isFileUpload:false, /** * @description Property modified by setForm() to set a reference to the HTML * form node if the desired action is file upload. * @property _formNode * @private * @static * @type object */ _formNode:null, /** * @description Property modified by setForm() to set the HTML form data * for each transaction. * @property _sFormData * @private * @static * @type string */ _sFormData:null, /** * @description Collection of polling references to the polling mechanism in handleReadyState. * @property _poll * @private * @static * @type object */ _poll:{}, /** * @description Queue of timeout values for each transaction callback with a defined timeout value. * @property _timeOut * @private * @static * @type object */ _timeOut:{}, /** * @description The polling frequency, in milliseconds, for HandleReadyState. * when attempting to determine a transaction's XHR readyState. * The default is 50 milliseconds. * @property _polling_interval * @private * @static * @type int */ _polling_interval:50, /** * @description A transaction counter that increments the transaction id for each transaction. * @property _transaction_id * @private * @static * @type int */ _transaction_id:0, /** * @description Tracks the name-value pair of the "clicked" submit button if multiple submit * buttons are present in an HTML form; and, if YAHOO.util.Event is available. * @property _submitElementValue * @private * @static * @type string */ _submitElementValue:null, /** * @description Determines whether YAHOO.util.Event is available and returns true or false. * If true, an event listener is bound at the document level to trap click events that * resolve to a target type of "Submit". This listener will enable setForm() to determine * the clicked "Submit" value in a multi-Submit button, HTML form. * @property _hasSubmitListener * @private * @static */ _hasSubmitListener:(function() { if(YAHOO.util.Event){ YAHOO.util.Event.addListener( document, 'click', function(e){ var obj = YAHOO.util.Event.getTarget(e), name = obj.nodeName.toLowerCase(); if((name === 'input' || name === 'button') && (obj.type && obj.type.toLowerCase() == 'submit')){ YAHOO.util.Connect._submitElementValue = encodeURIComponent(obj.name) + "=" + encodeURIComponent(obj.value); } }); return true; } return false; })(), /** * @description Custom event that fires at the start of a transaction * @property startEvent * @private * @static * @type CustomEvent */ startEvent: new YAHOO.util.CustomEvent('start'), /** * @description Custom event that fires when a transaction response has completed. * @property completeEvent * @private * @static * @type CustomEvent */ completeEvent: new YAHOO.util.CustomEvent('complete'), /** * @description Custom event that fires when handleTransactionResponse() determines a * response in the HTTP 2xx range. * @property successEvent * @private * @static * @type CustomEvent */ successEvent: new YAHOO.util.CustomEvent('success'), /** * @description Custom event that fires when handleTransactionResponse() determines a * response in the HTTP 4xx/5xx range. * @property failureEvent * @private * @static * @type CustomEvent */ failureEvent: new YAHOO.util.CustomEvent('failure'), /** * @description Custom event that fires when handleTransactionResponse() determines a * response in the HTTP 4xx/5xx range. * @property failureEvent * @private * @static * @type CustomEvent */ uploadEvent: new YAHOO.util.CustomEvent('upload'), /** * @description Custom event that fires when a transaction is successfully aborted. * @property abortEvent * @private * @static * @type CustomEvent */ abortEvent: new YAHOO.util.CustomEvent('abort'), /** * @description A reference table that maps callback custom events members to its specific * event name. * @property _customEvents * @private * @static * @type object */ _customEvents: { onStart:['startEvent', 'start'], onComplete:['completeEvent', 'complete'], onSuccess:['successEvent', 'success'], onFailure:['failureEvent', 'failure'], onUpload:['uploadEvent', 'upload'], onAbort:['abortEvent', 'abort'] }, /** * @description Member to add an ActiveX id to the existing xml_progid array. * In the event(unlikely) a new ActiveX id is introduced, it can be added * without internal code modifications. * @method setProgId * @public * @static * @param {string} id The ActiveX id to be added to initialize the XHR object. * @return void */ setProgId:function(id) { this._msxml_progid.unshift(id); }, /** * @description Member to override the default POST header. * @method setDefaultPostHeader * @public * @static * @param {boolean} b Set and use default header - true or false . * @return void */ setDefaultPostHeader:function(b) { if(typeof b == 'string'){ this._default_post_header = b; } else if(typeof b == 'boolean'){ this._use_default_post_header = b; } }, /** * @description Member to override the default transaction header.. * @method setDefaultXhrHeader * @public * @static * @param {boolean} b Set and use default header - true or false . * @return void */ setDefaultXhrHeader:function(b) { if(typeof b == 'string'){ this._default_xhr_header = b; } else{ this._use_default_xhr_header = b; } }, /** * @description Member to modify the default polling interval. * @method setPollingInterval * @public * @static * @param {int} i The polling interval in milliseconds. * @return void */ setPollingInterval:function(i) { if(typeof i == 'number' && isFinite(i)){ this._polling_interval = i; } }, /** * @description Instantiates a XMLHttpRequest object and returns an object with two properties: * the XMLHttpRequest instance and the transaction id. * @method createXhrObject * @private * @static * @param {int} transactionId Property containing the transaction id for this transaction. * @return object */ createXhrObject:function(transactionId) { var obj,http; try { // Instantiates XMLHttpRequest in non-IE browsers and assigns to http. http = new XMLHttpRequest(); // Object literal with http and tId properties obj = { conn:http, tId:transactionId }; } catch(e) { for(var i=0; i= 200 && httpStatus < 300 || httpStatus === 1223){ responseObject = this.createResponseObject(o, args); if(callback && callback.success){ if(!callback.scope){ callback.success(responseObject); } else{ // If a scope property is defined, the callback will be fired from // the context of the object. callback.success.apply(callback.scope, [responseObject]); } } // Fire global custom event -- successEvent this.successEvent.fire(responseObject); if(o.successEvent){ // Fire transaction custom event -- successEvent o.successEvent.fire(responseObject); } } else{ switch(httpStatus){ // The following cases are wininet.dll error codes that may be encountered. case 12002: // Server timeout case 12029: // 12029 to 12031 correspond to dropped connections. case 12030: case 12031: case 12152: // Connection closed by server. case 13030: // See above comments for variable status. responseObject = this.createExceptionObject(o.tId, args, (isAbort?isAbort:false)); if(callback && callback.failure){ if(!callback.scope){ callback.failure(responseObject); } else{ callback.failure.apply(callback.scope, [responseObject]); } } break; default: responseObject = this.createResponseObject(o, args); if(callback && callback.failure){ if(!callback.scope){ callback.failure(responseObject); } else{ callback.failure.apply(callback.scope, [responseObject]); } } } // Fire global custom event -- failureEvent this.failureEvent.fire(responseObject); if(o.failureEvent){ // Fire transaction custom event -- failureEvent o.failureEvent.fire(responseObject); } } this.releaseObject(o); responseObject = null; }, /** * @description This method evaluates the server response, creates and returns the results via * its properties. Success and failure cases will differ in the response * object's property values. * @method createResponseObject * @private * @static * @param {object} o The connection object * @param {callbackArg} callbackArg The user-defined argument or arguments to be passed to the callback * @return {object} */ createResponseObject:function(o, callbackArg) { var obj = {}; var headerObj = {}; try { var headerStr = o.conn.getAllResponseHeaders(); var header = headerStr.split('\n'); for(var i=0; i -1) { opt = oElement.options[oElement.selectedIndex]; data[item++] = oName + encodeURIComponent( (opt.attributes.value && opt.attributes.value.specified) ? opt.value : opt.text); } break; case 'select-multiple': if (oElement.selectedIndex > -1) { for(j=oElement.selectedIndex, jlen=oElement.options.length; j'); // IE will throw a security exception in an SSL environment if the // iframe source is undefined. if(typeof secureUri == 'boolean'){ io.src = 'javascript:false'; } } else{ io = document.createElement('iframe'); io.id = frameId; io.name = frameId; } io.style.position = 'absolute'; io.style.top = '-1000px'; io.style.left = '-1000px'; document.body.appendChild(io); }, /** * @description Parses the POST data and creates hidden form elements * for each key-value, and appends them to the HTML form object. * @method appendPostData * @private * @static * @param {string} postData The HTTP POST data * @return {array} formElements Collection of hidden fields. */ appendPostData:function(postData) { var formElements = [], postMessage = postData.split('&'), i, delimitPos; for(i=0; i < postMessage.length; i++){ delimitPos = postMessage[i].indexOf('='); if(delimitPos != -1){ formElements[i] = document.createElement('input'); formElements[i].type = 'hidden'; formElements[i].name = decodeURIComponent(postMessage[i].substring(0,delimitPos)); formElements[i].value = decodeURIComponent(postMessage[i].substring(delimitPos+1)); this._formNode.appendChild(formElements[i]); } } return formElements; }, /** * @description Uploads HTML form, inclusive of files/attachments, using the * iframe created in createFrame to facilitate the transaction. * @method uploadFile * @private * @static * @param {int} id The transaction id. * @param {object} callback User-defined callback object. * @param {string} uri Fully qualified path of resource. * @param {string} postData POST data to be submitted in addition to HTML form. * @return {void} */ uploadFile:function(o, callback, uri, postData){ // Each iframe has an id prefix of "yuiIO" followed // by the unique transaction id. var frameId = 'yuiIO' + o.tId, uploadEncoding = 'multipart/form-data', io = document.getElementById(frameId), oConn = this, args = (callback && callback.argument)?callback.argument:null, oElements,i,prop,obj; // Track original HTML form attribute values. var rawFormAttributes = { action:this._formNode.getAttribute('action'), method:this._formNode.getAttribute('method'), target:this._formNode.getAttribute('target') }; // Initialize the HTML form properties in case they are // not defined in the HTML form. this._formNode.setAttribute('action', uri); this._formNode.setAttribute('method', 'POST'); this._formNode.setAttribute('target', frameId); if(YAHOO.env.ua.ie){ // IE does not respect property enctype for HTML forms. // Instead it uses the property - "encoding". this._formNode.setAttribute('encoding', uploadEncoding); } else{ this._formNode.setAttribute('enctype', uploadEncoding); } if(postData){ oElements = this.appendPostData(postData); } // Start file upload. this._formNode.submit(); // Fire global custom event -- startEvent this.startEvent.fire(o, args); if(o.startEvent){ // Fire transaction custom event -- startEvent o.startEvent.fire(o, args); } // Start polling if a callback is present and the timeout // property has been defined. if(callback && callback.timeout){ this._timeOut[o.tId] = window.setTimeout(function(){ oConn.abort(o, callback, true); }, callback.timeout); } // Remove HTML elements created by appendPostData if(oElements && oElements.length > 0){ for(i=0; i < oElements.length; i++){ this._formNode.removeChild(oElements[i]); } } // Restore HTML form attributes to their original // values prior to file upload. for(prop in rawFormAttributes){ if(YAHOO.lang.hasOwnProperty(rawFormAttributes, prop)){ if(rawFormAttributes[prop]){ this._formNode.setAttribute(prop, rawFormAttributes[prop]); } else{ this._formNode.removeAttribute(prop); } } } // Reset HTML form state properties. this.resetFormState(); // Create the upload callback handler that fires when the iframe // receives the load event. Subsequently, the event handler is detached // and the iframe removed from the document. var uploadCallback = function() { if(callback && callback.timeout){ window.clearTimeout(oConn._timeOut[o.tId]); delete oConn._timeOut[o.tId]; } // Fire global custom event -- completeEvent oConn.completeEvent.fire(o, args); if(o.completeEvent){ // Fire transaction custom event -- completeEvent o.completeEvent.fire(o, args); } obj = { tId : o.tId, argument : callback.argument }; try { // responseText and responseXML will be populated with the same data from the iframe. // Since the HTTP headers cannot be read from the iframe obj.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:io.contentWindow.document.documentElement.textContent; obj.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document; } catch(e){} if(callback && callback.upload){ if(!callback.scope){ callback.upload(obj); } else{ callback.upload.apply(callback.scope, [obj]); } } // Fire global custom event -- uploadEvent oConn.uploadEvent.fire(obj); if(o.uploadEvent){ // Fire transaction custom event -- uploadEvent o.uploadEvent.fire(obj); } YAHOO.util.Event.removeListener(io, "load", uploadCallback); setTimeout( function(){ document.body.removeChild(io); oConn.releaseObject(o); }, 100); }; // Bind the onload handler to the iframe to detect the file upload response. YAHOO.util.Event.addListener(io, "load", uploadCallback); }, /** * @description Method to terminate a transaction, if it has not reached readyState 4. * @method abort * @public * @static * @param {object} o The connection object returned by asyncRequest. * @param {object} callback User-defined callback object. * @param {string} isTimeout boolean to indicate if abort resulted from a callback timeout. * @return {boolean} */ abort:function(o, callback, isTimeout) { var abortStatus; var args = (callback && callback.argument)?callback.argument:null; if(o && o.conn){ if(this.isCallInProgress(o)){ // Issue abort request o.conn.abort(); window.clearInterval(this._poll[o.tId]); delete this._poll[o.tId]; if(isTimeout){ window.clearTimeout(this._timeOut[o.tId]); delete this._timeOut[o.tId]; } abortStatus = true; } } else if(o && o.isUpload === true){ var frameId = 'yuiIO' + o.tId; var io = document.getElementById(frameId); if(io){ // Remove all listeners on the iframe prior to // its destruction. YAHOO.util.Event.removeListener(io, "load"); // Destroy the iframe facilitating the transaction. document.body.removeChild(io); if(isTimeout){ window.clearTimeout(this._timeOut[o.tId]); delete this._timeOut[o.tId]; } abortStatus = true; } } else{ abortStatus = false; } if(abortStatus === true){ // Fire global custom event -- abortEvent this.abortEvent.fire(o, args); if(o.abortEvent){ // Fire transaction custom event -- abortEvent o.abortEvent.fire(o, args); } this.handleTransactionResponse(o, callback, true); } return abortStatus; }, /** * @description Determines if the transaction is still being processed. * @method isCallInProgress * @public * @static * @param {object} o The connection object returned by asyncRequest * @return {boolean} */ isCallInProgress:function(o) { // if the XHR object assigned to the transaction has not been dereferenced, // then check its readyState status. Otherwise, return false. if(o && o.conn){ return o.conn.readyState !== 4 && o.conn.readyState !== 0; } else if(o && o.isUpload === true){ var frameId = 'yuiIO' + o.tId; return document.getElementById(frameId)?true:false; } else{ return false; } }, /** * @description Dereference the XHR instance and the connection object after the transaction is completed. * @method releaseObject * @private * @static * @param {object} o The connection object * @return {void} */ releaseObject:function(o) { if(o && o.conn){ //dereference the XHR instance. o.conn = null; //dereference the connection object. o = null; } } }; YAHOO.register("connection", YAHOO.util.Connect, {version: "2.7.0", build: "1799"}); /* Copyright (c) 2009, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 2.7.0 */ (function() { var Y = YAHOO.util; /* Copyright (c) 2006, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt */ /** * The animation module provides allows effects to be added to HTMLElements. * @module animation * @requires yahoo, event, dom */ /** * * Base animation class that provides the interface for building animated effects. *

    Usage: var myAnim = new YAHOO.util.Anim(el, { width: { from: 10, to: 100 } }, 1, YAHOO.util.Easing.easeOut);

    * @class Anim * @namespace YAHOO.util * @requires YAHOO.util.AnimMgr * @requires YAHOO.util.Easing * @requires YAHOO.util.Dom * @requires YAHOO.util.Event * @requires YAHOO.util.CustomEvent * @constructor * @param {String | HTMLElement} el Reference to the element that will be animated * @param {Object} attributes The attribute(s) to be animated. * Each attribute is an object with at minimum a "to" or "by" member defined. * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). * All attribute names use camelCase. * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) */ var Anim = function(el, attributes, duration, method) { if (!el) { } this.init(el, attributes, duration, method); }; Anim.NAME = 'Anim'; Anim.prototype = { /** * Provides a readable name for the Anim instance. * @method toString * @return {String} */ toString: function() { var el = this.getEl() || {}; var id = el.id || el.tagName; return (this.constructor.NAME + ': ' + id); }, patterns: { // cached for performance noNegatives: /width|height|opacity|padding/i, // keep at zero or above offsetAttribute: /^((width|height)|(top|left))$/, // use offsetValue as default defaultUnit: /width|height|top$|bottom$|left$|right$/i, // use 'px' by default offsetUnit: /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i // IE may return these, so convert these to offset }, /** * Returns the value computed by the animation's "method". * @method doMethod * @param {String} attr The name of the attribute. * @param {Number} start The value this attribute should start from for this animation. * @param {Number} end The value this attribute should end at for this animation. * @return {Number} The Value to be applied to the attribute. */ doMethod: function(attr, start, end) { return this.method(this.currentFrame, start, end - start, this.totalFrames); }, /** * Applies a value to an attribute. * @method setAttribute * @param {String} attr The name of the attribute. * @param {Number} val The value to be applied to the attribute. * @param {String} unit The unit ('px', '%', etc.) of the value. */ setAttribute: function(attr, val, unit) { var el = this.getEl(); if ( this.patterns.noNegatives.test(attr) ) { val = (val > 0) ? val : 0; } if ('style' in el) { Y.Dom.setStyle(el, attr, val + unit); } else if (attr in el) { el[attr] = val; } }, /** * Returns current value of the attribute. * @method getAttribute * @param {String} attr The name of the attribute. * @return {Number} val The current value of the attribute. */ getAttribute: function(attr) { var el = this.getEl(); var val = Y.Dom.getStyle(el, attr); if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) { return parseFloat(val); } var a = this.patterns.offsetAttribute.exec(attr) || []; var pos = !!( a[3] ); // top or left var box = !!( a[2] ); // width or height if ('style' in el) { // use offsets for width/height and abs pos top/left if ( box || (Y.Dom.getStyle(el, 'position') == 'absolute' && pos) ) { val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)]; } else { // default to zero for other 'auto' val = 0; } } else if (attr in el) { val = el[attr]; } return val; }, /** * Returns the unit to use when none is supplied. * @method getDefaultUnit * @param {attr} attr The name of the attribute. * @return {String} The default unit to be used. */ getDefaultUnit: function(attr) { if ( this.patterns.defaultUnit.test(attr) ) { return 'px'; } return ''; }, /** * Sets the actual values to be used during the animation. Should only be needed for subclass use. * @method setRuntimeAttribute * @param {Object} attr The attribute object * @private */ setRuntimeAttribute: function(attr) { var start; var end; var attributes = this.attributes; this.runtimeAttributes[attr] = {}; var isset = function(prop) { return (typeof prop !== 'undefined'); }; if ( !isset(attributes[attr]['to']) && !isset(attributes[attr]['by']) ) { return false; // note return; nothing to animate to } start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr); // To beats by, per SMIL 2.1 spec if ( isset(attributes[attr]['to']) ) { end = attributes[attr]['to']; } else if ( isset(attributes[attr]['by']) ) { if (start.constructor == Array) { end = []; for (var i = 0, len = start.length; i < len; ++i) { end[i] = start[i] + attributes[attr]['by'][i] * 1; // times 1 to cast "by" } } else { end = start + attributes[attr]['by'] * 1; } } this.runtimeAttributes[attr].start = start; this.runtimeAttributes[attr].end = end; // set units if needed this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? attributes[attr]['unit'] : this.getDefaultUnit(attr); return true; }, /** * Constructor for Anim instance. * @method init * @param {String | HTMLElement} el Reference to the element that will be animated * @param {Object} attributes The attribute(s) to be animated. * Each attribute is an object with at minimum a "to" or "by" member defined. * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). * All attribute names use camelCase. * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) */ init: function(el, attributes, duration, method) { /** * Whether or not the animation is running. * @property isAnimated * @private * @type Boolean */ var isAnimated = false; /** * A Date object that is created when the animation begins. * @property startTime * @private * @type Date */ var startTime = null; /** * The number of frames this animation was able to execute. * @property actualFrames * @private * @type Int */ var actualFrames = 0; /** * The element to be animated. * @property el * @private * @type HTMLElement */ el = Y.Dom.get(el); /** * The collection of attributes to be animated. * Each attribute must have at least a "to" or "by" defined in order to animate. * If "to" is supplied, the animation will end with the attribute at that value. * If "by" is supplied, the animation will end at that value plus its starting value. * If both are supplied, "to" is used, and "by" is ignored. * Optional additional member include "from" (the value the attribute should start animating from, defaults to current value), and "unit" (the units to apply to the values). * @property attributes * @type Object */ this.attributes = attributes || {}; /** * The length of the animation. Defaults to "1" (second). * @property duration * @type Number */ this.duration = !YAHOO.lang.isUndefined(duration) ? duration : 1; /** * The method that will provide values to the attribute(s) during the animation. * Defaults to "YAHOO.util.Easing.easeNone". * @property method * @type Function */ this.method = method || Y.Easing.easeNone; /** * Whether or not the duration should be treated as seconds. * Defaults to true. * @property useSeconds * @type Boolean */ this.useSeconds = true; // default to seconds /** * The location of the current animation on the timeline. * In time-based animations, this is used by AnimMgr to ensure the animation finishes on time. * @property currentFrame * @type Int */ this.currentFrame = 0; /** * The total number of frames to be executed. * In time-based animations, this is used by AnimMgr to ensure the animation finishes on time. * @property totalFrames * @type Int */ this.totalFrames = Y.AnimMgr.fps; /** * Changes the animated element * @method setEl */ this.setEl = function(element) { el = Y.Dom.get(element); }; /** * Returns a reference to the animated element. * @method getEl * @return {HTMLElement} */ this.getEl = function() { return el; }; /** * Checks whether the element is currently animated. * @method isAnimated * @return {Boolean} current value of isAnimated. */ this.isAnimated = function() { return isAnimated; }; /** * Returns the animation start time. * @method getStartTime * @return {Date} current value of startTime. */ this.getStartTime = function() { return startTime; }; this.runtimeAttributes = {}; /** * Starts the animation by registering it with the animation manager. * @method animate */ this.animate = function() { if ( this.isAnimated() ) { return false; } this.currentFrame = 0; this.totalFrames = ( this.useSeconds ) ? Math.ceil(Y.AnimMgr.fps * this.duration) : this.duration; if (this.duration === 0 && this.useSeconds) { // jump to last frame if zero second duration this.totalFrames = 1; } Y.AnimMgr.registerElement(this); return true; }; /** * Stops the animation. Normally called by AnimMgr when animation completes. * @method stop * @param {Boolean} finish (optional) If true, animation will jump to final frame. */ this.stop = function(finish) { if (!this.isAnimated()) { // nothing to stop return false; } if (finish) { this.currentFrame = this.totalFrames; this._onTween.fire(); } Y.AnimMgr.stop(this); }; var onStart = function() { this.onStart.fire(); this.runtimeAttributes = {}; for (var attr in this.attributes) { this.setRuntimeAttribute(attr); } isAnimated = true; actualFrames = 0; startTime = new Date(); }; /** * Feeds the starting and ending values for each animated attribute to doMethod once per frame, then applies the resulting value to the attribute(s). * @private */ var onTween = function() { var data = { duration: new Date() - this.getStartTime(), currentFrame: this.currentFrame }; data.toString = function() { return ( 'duration: ' + data.duration + ', currentFrame: ' + data.currentFrame ); }; this.onTween.fire(data); var runtimeAttributes = this.runtimeAttributes; for (var attr in runtimeAttributes) { this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit); } actualFrames += 1; }; var onComplete = function() { var actual_duration = (new Date() - startTime) / 1000 ; var data = { duration: actual_duration, frames: actualFrames, fps: actualFrames / actual_duration }; data.toString = function() { return ( 'duration: ' + data.duration + ', frames: ' + data.frames + ', fps: ' + data.fps ); }; isAnimated = false; actualFrames = 0; this.onComplete.fire(data); }; /** * Custom event that fires after onStart, useful in subclassing * @private */ this._onStart = new Y.CustomEvent('_start', this, true); /** * Custom event that fires when animation begins * Listen via subscribe method (e.g. myAnim.onStart.subscribe(someFunction) * @event onStart */ this.onStart = new Y.CustomEvent('start', this); /** * Custom event that fires between each frame * Listen via subscribe method (e.g. myAnim.onTween.subscribe(someFunction) * @event onTween */ this.onTween = new Y.CustomEvent('tween', this); /** * Custom event that fires after onTween * @private */ this._onTween = new Y.CustomEvent('_tween', this, true); /** * Custom event that fires when animation ends * Listen via subscribe method (e.g. myAnim.onComplete.subscribe(someFunction) * @event onComplete */ this.onComplete = new Y.CustomEvent('complete', this); /** * Custom event that fires after onComplete * @private */ this._onComplete = new Y.CustomEvent('_complete', this, true); this._onStart.subscribe(onStart); this._onTween.subscribe(onTween); this._onComplete.subscribe(onComplete); } }; Y.Anim = Anim; })(); /** * Handles animation queueing and threading. * Used by Anim and subclasses. * @class AnimMgr * @namespace YAHOO.util */ YAHOO.util.AnimMgr = new function() { /** * Reference to the animation Interval. * @property thread * @private * @type Int */ var thread = null; /** * The current queue of registered animation objects. * @property queue * @private * @type Array */ var queue = []; /** * The number of active animations. * @property tweenCount * @private * @type Int */ var tweenCount = 0; /** * Base frame rate (frames per second). * Arbitrarily high for better x-browser calibration (slower browsers drop more frames). * @property fps * @type Int * */ this.fps = 1000; /** * Interval delay in milliseconds, defaults to fastest possible. * @property delay * @type Int * */ this.delay = 1; /** * Adds an animation instance to the animation queue. * All animation instances must be registered in order to animate. * @method registerElement * @param {object} tween The Anim instance to be be registered */ this.registerElement = function(tween) { queue[queue.length] = tween; tweenCount += 1; tween._onStart.fire(); this.start(); }; /** * removes an animation instance from the animation queue. * All animation instances must be registered in order to animate. * @method unRegister * @param {object} tween The Anim instance to be be registered * @param {Int} index The index of the Anim instance * @private */ this.unRegister = function(tween, index) { index = index || getIndex(tween); if (!tween.isAnimated() || index == -1) { return false; } tween._onComplete.fire(); queue.splice(index, 1); tweenCount -= 1; if (tweenCount <= 0) { this.stop(); } return true; }; /** * Starts the animation thread. * Only one thread can run at a time. * @method start */ this.start = function() { if (thread === null) { thread = setInterval(this.run, this.delay); } }; /** * Stops the animation thread or a specific animation instance. * @method stop * @param {object} tween A specific Anim instance to stop (optional) * If no instance given, Manager stops thread and all animations. */ this.stop = function(tween) { if (!tween) { clearInterval(thread); for (var i = 0, len = queue.length; i < len; ++i) { this.unRegister(queue[0], 0); } queue = []; thread = null; tweenCount = 0; } else { this.unRegister(tween); } }; /** * Called per Interval to handle each animation frame. * @method run */ this.run = function() { for (var i = 0, len = queue.length; i < len; ++i) { var tween = queue[i]; if ( !tween || !tween.isAnimated() ) { continue; } if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null) { tween.currentFrame += 1; if (tween.useSeconds) { correctFrame(tween); } tween._onTween.fire(); } else { YAHOO.util.AnimMgr.stop(tween, i); } } }; var getIndex = function(anim) { for (var i = 0, len = queue.length; i < len; ++i) { if (queue[i] == anim) { return i; // note return; } } return -1; }; /** * On the fly frame correction to keep animation on time. * @method correctFrame * @private * @param {Object} tween The Anim instance being corrected. */ var correctFrame = function(tween) { var frames = tween.totalFrames; var frame = tween.currentFrame; var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames); var elapsed = (new Date() - tween.getStartTime()); var tweak = 0; if (elapsed < tween.duration * 1000) { // check if falling behind tweak = Math.round((elapsed / expected - 1) * tween.currentFrame); } else { // went over duration, so jump to end tweak = frames - (frame + 1); } if (tweak > 0 && isFinite(tweak)) { // adjust if needed if (tween.currentFrame + tweak >= frames) {// dont go past last frame tweak = frames - (frame + 1); } tween.currentFrame += tweak; } }; }; /** * Used to calculate Bezier splines for any number of control points. * @class Bezier * @namespace YAHOO.util * */ YAHOO.util.Bezier = new function() { /** * Get the current position of the animated element based on t. * Each point is an array of "x" and "y" values (0 = x, 1 = y) * At least 2 points are required (start and end). * First point is start. Last point is end. * Additional control points are optional. * @method getPosition * @param {Array} points An array containing Bezier points * @param {Number} t A number between 0 and 1 which is the basis for determining current position * @return {Array} An array containing int x and y member data */ this.getPosition = function(points, t) { var n = points.length; var tmp = []; for (var i = 0; i < n; ++i){ tmp[i] = [points[i][0], points[i][1]]; // save input } for (var j = 1; j < n; ++j) { for (i = 0; i < n - j; ++i) { tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0]; tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1]; } } return [ tmp[0][0], tmp[0][1] ]; }; }; (function() { /** * Anim subclass for color transitions. *

    Usage: var myAnim = new Y.ColorAnim(el, { backgroundColor: { from: '#FF0000', to: '#FFFFFF' } }, 1, Y.Easing.easeOut); Color values can be specified with either 112233, #112233, * [255,255,255], or rgb(255,255,255)

    * @class ColorAnim * @namespace YAHOO.util * @requires YAHOO.util.Anim * @requires YAHOO.util.AnimMgr * @requires YAHOO.util.Easing * @requires YAHOO.util.Bezier * @requires YAHOO.util.Dom * @requires YAHOO.util.Event * @constructor * @extends YAHOO.util.Anim * @param {HTMLElement | String} el Reference to the element that will be animated * @param {Object} attributes The attribute(s) to be animated. * Each attribute is an object with at minimum a "to" or "by" member defined. * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). * All attribute names use camelCase. * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) */ var ColorAnim = function(el, attributes, duration, method) { ColorAnim.superclass.constructor.call(this, el, attributes, duration, method); }; ColorAnim.NAME = 'ColorAnim'; ColorAnim.DEFAULT_BGCOLOR = '#fff'; // shorthand var Y = YAHOO.util; YAHOO.extend(ColorAnim, Y.Anim); var superclass = ColorAnim.superclass; var proto = ColorAnim.prototype; proto.patterns.color = /color$/i; proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i; proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i; proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i; proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/; // need rgba for safari /** * Attempts to parse the given string and return a 3-tuple. * @method parseColor * @param {String} s The string to parse. * @return {Array} The 3-tuple of rgb values. */ proto.parseColor = function(s) { if (s.length == 3) { return s; } var c = this.patterns.hex.exec(s); if (c && c.length == 4) { return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ]; } c = this.patterns.rgb.exec(s); if (c && c.length == 4) { return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ]; } c = this.patterns.hex3.exec(s); if (c && c.length == 4) { return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ]; } return null; }; proto.getAttribute = function(attr) { var el = this.getEl(); if (this.patterns.color.test(attr) ) { var val = YAHOO.util.Dom.getStyle(el, attr); var that = this; if (this.patterns.transparent.test(val)) { // bgcolor default var parent = YAHOO.util.Dom.getAncestorBy(el, function(node) { return !that.patterns.transparent.test(val); }); if (parent) { val = Y.Dom.getStyle(parent, attr); } else { val = ColorAnim.DEFAULT_BGCOLOR; } } } else { val = superclass.getAttribute.call(this, attr); } return val; }; proto.doMethod = function(attr, start, end) { var val; if ( this.patterns.color.test(attr) ) { val = []; for (var i = 0, len = start.length; i < len; ++i) { val[i] = superclass.doMethod.call(this, attr, start[i], end[i]); } val = 'rgb('+Math.floor(val[0])+','+Math.floor(val[1])+','+Math.floor(val[2])+')'; } else { val = superclass.doMethod.call(this, attr, start, end); } return val; }; proto.setRuntimeAttribute = function(attr) { superclass.setRuntimeAttribute.call(this, attr); if ( this.patterns.color.test(attr) ) { var attributes = this.attributes; var start = this.parseColor(this.runtimeAttributes[attr].start); var end = this.parseColor(this.runtimeAttributes[attr].end); // fix colors if going "by" if ( typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined' ) { end = this.parseColor(attributes[attr].by); for (var i = 0, len = start.length; i < len; ++i) { end[i] = start[i] + end[i]; } } this.runtimeAttributes[attr].start = start; this.runtimeAttributes[attr].end = end; } }; Y.ColorAnim = ColorAnim; })(); /*! TERMS OF USE - EASING EQUATIONS Open source under the BSD License. Copyright 2001 Robert Penner All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * Singleton that determines how an animation proceeds from start to end. * @class Easing * @namespace YAHOO.util */ YAHOO.util.Easing = { /** * Uniform speed between points. * @method easeNone * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @return {Number} The computed value for the current animation frame */ easeNone: function (t, b, c, d) { return c*t/d + b; }, /** * Begins slowly and accelerates towards end. * @method easeIn * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @return {Number} The computed value for the current animation frame */ easeIn: function (t, b, c, d) { return c*(t/=d)*t + b; }, /** * Begins quickly and decelerates towards end. * @method easeOut * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @return {Number} The computed value for the current animation frame */ easeOut: function (t, b, c, d) { return -c *(t/=d)*(t-2) + b; }, /** * Begins slowly and decelerates towards end. * @method easeBoth * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @return {Number} The computed value for the current animation frame */ easeBoth: function (t, b, c, d) { if ((t/=d/2) < 1) { return c/2*t*t + b; } return -c/2 * ((--t)*(t-2) - 1) + b; }, /** * Begins slowly and accelerates towards end. * @method easeInStrong * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @return {Number} The computed value for the current animation frame */ easeInStrong: function (t, b, c, d) { return c*(t/=d)*t*t*t + b; }, /** * Begins quickly and decelerates towards end. * @method easeOutStrong * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @return {Number} The computed value for the current animation frame */ easeOutStrong: function (t, b, c, d) { return -c * ((t=t/d-1)*t*t*t - 1) + b; }, /** * Begins slowly and decelerates towards end. * @method easeBothStrong * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @return {Number} The computed value for the current animation frame */ easeBothStrong: function (t, b, c, d) { if ((t/=d/2) < 1) { return c/2*t*t*t*t + b; } return -c/2 * ((t-=2)*t*t*t - 2) + b; }, /** * Snap in elastic effect. * @method elasticIn * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @param {Number} a Amplitude (optional) * @param {Number} p Period (optional) * @return {Number} The computed value for the current animation frame */ elasticIn: function (t, b, c, d, a, p) { if (t == 0) { return b; } if ( (t /= d) == 1 ) { return b+c; } if (!p) { p=d*.3; } if (!a || a < Math.abs(c)) { a = c; var s = p/4; } else { var s = p/(2*Math.PI) * Math.asin (c/a); } return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; }, /** * Snap out elastic effect. * @method elasticOut * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @param {Number} a Amplitude (optional) * @param {Number} p Period (optional) * @return {Number} The computed value for the current animation frame */ elasticOut: function (t, b, c, d, a, p) { if (t == 0) { return b; } if ( (t /= d) == 1 ) { return b+c; } if (!p) { p=d*.3; } if (!a || a < Math.abs(c)) { a = c; var s = p / 4; } else { var s = p/(2*Math.PI) * Math.asin (c/a); } return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b; }, /** * Snap both elastic effect. * @method elasticBoth * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @param {Number} a Amplitude (optional) * @param {Number} p Period (optional) * @return {Number} The computed value for the current animation frame */ elasticBoth: function (t, b, c, d, a, p) { if (t == 0) { return b; } if ( (t /= d/2) == 2 ) { return b+c; } if (!p) { p = d*(.3*1.5); } if ( !a || a < Math.abs(c) ) { a = c; var s = p/4; } else { var s = p/(2*Math.PI) * Math.asin (c/a); } if (t < 1) { return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; } return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b; }, /** * Backtracks slightly, then reverses direction and moves to end. * @method backIn * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @param {Number} s Overshoot (optional) * @return {Number} The computed value for the current animation frame */ backIn: function (t, b, c, d, s) { if (typeof s == 'undefined') { s = 1.70158; } return c*(t/=d)*t*((s+1)*t - s) + b; }, /** * Overshoots end, then reverses and comes back to end. * @method backOut * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @param {Number} s Overshoot (optional) * @return {Number} The computed value for the current animation frame */ backOut: function (t, b, c, d, s) { if (typeof s == 'undefined') { s = 1.70158; } return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; }, /** * Backtracks slightly, then reverses direction, overshoots end, * then reverses and comes back to end. * @method backBoth * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @param {Number} s Overshoot (optional) * @return {Number} The computed value for the current animation frame */ backBoth: function (t, b, c, d, s) { if (typeof s == 'undefined') { s = 1.70158; } if ((t /= d/2 ) < 1) { return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; } return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; }, /** * Bounce off of start. * @method bounceIn * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @return {Number} The computed value for the current animation frame */ bounceIn: function (t, b, c, d) { return c - YAHOO.util.Easing.bounceOut(d-t, 0, c, d) + b; }, /** * Bounces off end. * @method bounceOut * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @return {Number} The computed value for the current animation frame */ bounceOut: function (t, b, c, d) { if ((t/=d) < (1/2.75)) { return c*(7.5625*t*t) + b; } else if (t < (2/2.75)) { return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; } else if (t < (2.5/2.75)) { return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; } return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; }, /** * Bounces off start and end. * @method bounceBoth * @param {Number} t Time value used to compute current value * @param {Number} b Starting value * @param {Number} c Delta between start and end values * @param {Number} d Total length of animation * @return {Number} The computed value for the current animation frame */ bounceBoth: function (t, b, c, d) { if (t < d/2) { return YAHOO.util.Easing.bounceIn(t*2, 0, c, d) * .5 + b; } return YAHOO.util.Easing.bounceOut(t*2-d, 0, c, d) * .5 + c*.5 + b; } }; (function() { /** * Anim subclass for moving elements along a path defined by the "points" * member of "attributes". All "points" are arrays with x, y coordinates. *

    Usage: var myAnim = new YAHOO.util.Motion(el, { points: { to: [800, 800] } }, 1, YAHOO.util.Easing.easeOut);

    * @class Motion * @namespace YAHOO.util * @requires YAHOO.util.Anim * @requires YAHOO.util.AnimMgr * @requires YAHOO.util.Easing * @requires YAHOO.util.Bezier * @requires YAHOO.util.Dom * @requires YAHOO.util.Event * @requires YAHOO.util.CustomEvent * @constructor * @extends YAHOO.util.ColorAnim * @param {String | HTMLElement} el Reference to the element that will be animated * @param {Object} attributes The attribute(s) to be animated. * Each attribute is an object with at minimum a "to" or "by" member defined. * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). * All attribute names use camelCase. * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) */ var Motion = function(el, attributes, duration, method) { if (el) { // dont break existing subclasses not using YAHOO.extend Motion.superclass.constructor.call(this, el, attributes, duration, method); } }; Motion.NAME = 'Motion'; // shorthand var Y = YAHOO.util; YAHOO.extend(Motion, Y.ColorAnim); var superclass = Motion.superclass; var proto = Motion.prototype; proto.patterns.points = /^points$/i; proto.setAttribute = function(attr, val, unit) { if ( this.patterns.points.test(attr) ) { unit = unit || 'px'; superclass.setAttribute.call(this, 'left', val[0], unit); superclass.setAttribute.call(this, 'top', val[1], unit); } else { superclass.setAttribute.call(this, attr, val, unit); } }; proto.getAttribute = function(attr) { if ( this.patterns.points.test(attr) ) { var val = [ superclass.getAttribute.call(this, 'left'), superclass.getAttribute.call(this, 'top') ]; } else { val = superclass.getAttribute.call(this, attr); } return val; }; proto.doMethod = function(attr, start, end) { var val = null; if ( this.patterns.points.test(attr) ) { var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100; val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t); } else { val = superclass.doMethod.call(this, attr, start, end); } return val; }; proto.setRuntimeAttribute = function(attr) { if ( this.patterns.points.test(attr) ) { var el = this.getEl(); var attributes = this.attributes; var start; var control = attributes['points']['control'] || []; var end; var i, len; if (control.length > 0 && !(control[0] instanceof Array) ) { // could be single point or array of points control = [control]; } else { // break reference to attributes.points.control var tmp = []; for (i = 0, len = control.length; i< len; ++i) { tmp[i] = control[i]; } control = tmp; } if (Y.Dom.getStyle(el, 'position') == 'static') { // default to relative Y.Dom.setStyle(el, 'position', 'relative'); } if ( isset(attributes['points']['from']) ) { Y.Dom.setXY(el, attributes['points']['from']); // set position to from point } else { Y.Dom.setXY( el, Y.Dom.getXY(el) ); } // set it to current position start = this.getAttribute('points'); // get actual top & left // TO beats BY, per SMIL 2.1 spec if ( isset(attributes['points']['to']) ) { end = translateValues.call(this, attributes['points']['to'], start); var pageXY = Y.Dom.getXY(this.getEl()); for (i = 0, len = control.length; i < len; ++i) { control[i] = translateValues.call(this, control[i], start); } } else if ( isset(attributes['points']['by']) ) { end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ]; for (i = 0, len = control.length; i < len; ++i) { control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ]; } } this.runtimeAttributes[attr] = [start]; if (control.length > 0) { this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control); } this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end; } else { superclass.setRuntimeAttribute.call(this, attr); } }; var translateValues = function(val, start) { var pageXY = Y.Dom.getXY(this.getEl()); val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ]; return val; }; var isset = function(prop) { return (typeof prop !== 'undefined'); }; Y.Motion = Motion; })(); (function() { /** * Anim subclass for scrolling elements to a position defined by the "scroll" * member of "attributes". All "scroll" members are arrays with x, y scroll positions. *

    Usage: var myAnim = new YAHOO.util.Scroll(el, { scroll: { to: [0, 800] } }, 1, YAHOO.util.Easing.easeOut);

    * @class Scroll * @namespace YAHOO.util * @requires YAHOO.util.Anim * @requires YAHOO.util.AnimMgr * @requires YAHOO.util.Easing * @requires YAHOO.util.Bezier * @requires YAHOO.util.Dom * @requires YAHOO.util.Event * @requires YAHOO.util.CustomEvent * @extends YAHOO.util.ColorAnim * @constructor * @param {String or HTMLElement} el Reference to the element that will be animated * @param {Object} attributes The attribute(s) to be animated. * Each attribute is an object with at minimum a "to" or "by" member defined. * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). * All attribute names use camelCase. * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) */ var Scroll = function(el, attributes, duration, method) { if (el) { // dont break existing subclasses not using YAHOO.extend Scroll.superclass.constructor.call(this, el, attributes, duration, method); } }; Scroll.NAME = 'Scroll'; // shorthand var Y = YAHOO.util; YAHOO.extend(Scroll, Y.ColorAnim); var superclass = Scroll.superclass; var proto = Scroll.prototype; proto.doMethod = function(attr, start, end) { var val = null; if (attr == 'scroll') { val = [ this.method(this.currentFrame, start[0], end[0] - start[0], this.totalFrames), this.method(this.currentFrame, start[1], end[1] - start[1], this.totalFrames) ]; } else { val = superclass.doMethod.call(this, attr, start, end); } return val; }; proto.getAttribute = function(attr) { var val = null; var el = this.getEl(); if (attr == 'scroll') { val = [ el.scrollLeft, el.scrollTop ]; } else { val = superclass.getAttribute.call(this, attr); } return val; }; proto.setAttribute = function(attr, val, unit) { var el = this.getEl(); if (attr == 'scroll') { el.scrollLeft = val[0]; el.scrollTop = val[1]; } else { superclass.setAttribute.call(this, attr, val, unit); } }; Y.Scroll = Scroll; })(); YAHOO.register("animation", YAHOO.util.Anim, {version: "2.7.0", build: "1799"}); /* Copyright (c) 2009, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 2.7.0 */ /** * The drag and drop utility provides a framework for building drag and drop * applications. In addition to enabling drag and drop for specific elements, * the drag and drop elements are tracked by the manager class, and the * interactions between the various elements are tracked during the drag and * the implementing code is notified about these important moments. * @module dragdrop * @title Drag and Drop * @requires yahoo,dom,event * @namespace YAHOO.util */ // Only load the library once. Rewriting the manager class would orphan // existing drag and drop instances. if (!YAHOO.util.DragDropMgr) { /** * DragDropMgr is a singleton that tracks the element interaction for * all DragDrop items in the window. Generally, you will not call * this class directly, but it does have helper methods that could * be useful in your DragDrop implementations. * @class DragDropMgr * @static */ YAHOO.util.DragDropMgr = function() { var Event = YAHOO.util.Event, Dom = YAHOO.util.Dom; return { /** * This property is used to turn on global use of the shim element on all DragDrop instances, defaults to false for backcompat. (Use: YAHOO.util.DDM.useShim = true) * @property useShim * @type Boolean * @static */ useShim: false, /** * This property is used to determine if the shim is active over the screen, default false. * @private * @property _shimActive * @type Boolean * @static */ _shimActive: false, /** * This property is used when useShim is set on a DragDrop object to store the current state of DDM.useShim so it can be reset when a drag operation is done. * @private * @property _shimState * @type Boolean * @static */ _shimState: false, /** * This property is used when useShim is set to true, it will set the opacity on the shim to .5 for debugging. Use: (YAHOO.util.DDM._debugShim = true;) * @private * @property _debugShim * @type Boolean * @static */ _debugShim: false, /** * This method will create a shim element (giving it the id of yui-ddm-shim), it also attaches the mousemove and mouseup listeners to it and attaches a scroll listener on the window * @private * @method _sizeShim * @static */ _createShim: function() { var s = document.createElement('div'); s.id = 'yui-ddm-shim'; if (document.body.firstChild) { document.body.insertBefore(s, document.body.firstChild); } else { document.body.appendChild(s); } s.style.display = 'none'; s.style.backgroundColor = 'red'; s.style.position = 'absolute'; s.style.zIndex = '99999'; Dom.setStyle(s, 'opacity', '0'); this._shim = s; Event.on(s, "mouseup", this.handleMouseUp, this, true); Event.on(s, "mousemove", this.handleMouseMove, this, true); Event.on(window, 'scroll', this._sizeShim, this, true); }, /** * This method will size the shim, called from activate and on window scroll event * @private * @method _sizeShim * @static */ _sizeShim: function() { if (this._shimActive) { var s = this._shim; s.style.height = Dom.getDocumentHeight() + 'px'; s.style.width = Dom.getDocumentWidth() + 'px'; s.style.top = '0'; s.style.left = '0'; } }, /** * This method will create the shim element if needed, then show the shim element, size the element and set the _shimActive property to true * @private * @method _activateShim * @static */ _activateShim: function() { if (this.useShim) { if (!this._shim) { this._createShim(); } this._shimActive = true; var s = this._shim, o = '0'; if (this._debugShim) { o = '.5'; } Dom.setStyle(s, 'opacity', o); this._sizeShim(); s.style.display = 'block'; } }, /** * This method will hide the shim element and set the _shimActive property to false * @private * @method _deactivateShim * @static */ _deactivateShim: function() { this._shim.style.display = 'none'; this._shimActive = false; }, /** * The HTML element created to use as a shim over the document to track mouse movements * @private * @property _shim * @type HTMLElement * @static */ _shim: null, /** * Two dimensional Array of registered DragDrop objects. The first * dimension is the DragDrop item group, the second the DragDrop * object. * @property ids * @type {string: string} * @private * @static */ ids: {}, /** * Array of element ids defined as drag handles. Used to determine * if the element that generated the mousedown event is actually the * handle and not the html element itself. * @property handleIds * @type {string: string} * @private * @static */ handleIds: {}, /** * the DragDrop object that is currently being dragged * @property dragCurrent * @type DragDrop * @private * @static **/ dragCurrent: null, /** * the DragDrop object(s) that are being hovered over * @property dragOvers * @type Array * @private * @static */ dragOvers: {}, /** * the X distance between the cursor and the object being dragged * @property deltaX * @type int * @private * @static */ deltaX: 0, /** * the Y distance between the cursor and the object being dragged * @property deltaY * @type int * @private * @static */ deltaY: 0, /** * Flag to determine if we should prevent the default behavior of the * events we define. By default this is true, but this can be set to * false if you need the default behavior (not recommended) * @property preventDefault * @type boolean * @static */ preventDefault: true, /** * Flag to determine if we should stop the propagation of the events * we generate. This is true by default but you may want to set it to * false if the html element contains other features that require the * mouse click. * @property stopPropagation * @type boolean * @static */ stopPropagation: true, /** * Internal flag that is set to true when drag and drop has been * initialized * @property initialized * @private * @static */ initialized: false, /** * All drag and drop can be disabled. * @property locked * @private * @static */ locked: false, /** * Provides additional information about the the current set of * interactions. Can be accessed from the event handlers. It * contains the following properties: * * out: onDragOut interactions * enter: onDragEnter interactions * over: onDragOver interactions * drop: onDragDrop interactions * point: The location of the cursor * draggedRegion: The location of dragged element at the time * of the interaction * sourceRegion: The location of the source elemtn at the time * of the interaction * validDrop: boolean * @property interactionInfo * @type object * @static */ interactionInfo: null, /** * Called the first time an element is registered. * @method init * @private * @static */ init: function() { this.initialized = true; }, /** * In point mode, drag and drop interaction is defined by the * location of the cursor during the drag/drop * @property POINT * @type int * @static * @final */ POINT: 0, /** * In intersect mode, drag and drop interaction is defined by the * cursor position or the amount of overlap of two or more drag and * drop objects. * @property INTERSECT * @type int * @static * @final */ INTERSECT: 1, /** * In intersect mode, drag and drop interaction is defined only by the * overlap of two or more drag and drop objects. * @property STRICT_INTERSECT * @type int * @static * @final */ STRICT_INTERSECT: 2, /** * The current drag and drop mode. Default: POINT * @property mode * @type int * @static */ mode: 0, /** * Runs method on all drag and drop objects * @method _execOnAll * @private * @static */ _execOnAll: function(sMethod, args) { for (var i in this.ids) { for (var j in this.ids[i]) { var oDD = this.ids[i][j]; if (! this.isTypeOfDD(oDD)) { continue; } oDD[sMethod].apply(oDD, args); } } }, /** * Drag and drop initialization. Sets up the global event handlers * @method _onLoad * @private * @static */ _onLoad: function() { this.init(); Event.on(document, "mouseup", this.handleMouseUp, this, true); Event.on(document, "mousemove", this.handleMouseMove, this, true); Event.on(window, "unload", this._onUnload, this, true); Event.on(window, "resize", this._onResize, this, true); // Event.on(window, "mouseout", this._test); }, /** * Reset constraints on all drag and drop objs * @method _onResize * @private * @static */ _onResize: function(e) { this._execOnAll("resetConstraints", []); }, /** * Lock all drag and drop functionality * @method lock * @static */ lock: function() { this.locked = true; }, /** * Unlock all drag and drop functionality * @method unlock * @static */ unlock: function() { this.locked = false; }, /** * Is drag and drop locked? * @method isLocked * @return {boolean} True if drag and drop is locked, false otherwise. * @static */ isLocked: function() { return this.locked; }, /** * Location cache that is set for all drag drop objects when a drag is * initiated, cleared when the drag is finished. * @property locationCache * @private * @static */ locationCache: {}, /** * Set useCache to false if you want to force object the lookup of each * drag and drop linked element constantly during a drag. * @property useCache * @type boolean * @static */ useCache: true, /** * The number of pixels that the mouse needs to move after the * mousedown before the drag is initiated. Default=3; * @property clickPixelThresh * @type int * @static */ clickPixelThresh: 3, /** * The number of milliseconds after the mousedown event to initiate the * drag if we don't get a mouseup event. Default=1000 * @property clickTimeThresh * @type int * @static */ clickTimeThresh: 1000, /** * Flag that indicates that either the drag pixel threshold or the * mousdown time threshold has been met * @property dragThreshMet * @type boolean * @private * @static */ dragThreshMet: false, /** * Timeout used for the click time threshold * @property clickTimeout * @type Object * @private * @static */ clickTimeout: null, /** * The X position of the mousedown event stored for later use when a * drag threshold is met. * @property startX * @type int * @private * @static */ startX: 0, /** * The Y position of the mousedown event stored for later use when a * drag threshold is met. * @property startY * @type int * @private * @static */ startY: 0, /** * Flag to determine if the drag event was fired from the click timeout and * not the mouse move threshold. * @property fromTimeout * @type boolean * @private * @static */ fromTimeout: false, /** * Each DragDrop instance must be registered with the DragDropMgr. * This is executed in DragDrop.init() * @method regDragDrop * @param {DragDrop} oDD the DragDrop object to register * @param {String} sGroup the name of the group this element belongs to * @static */ regDragDrop: function(oDD, sGroup) { if (!this.initialized) { this.init(); } if (!this.ids[sGroup]) { this.ids[sGroup] = {}; } this.ids[sGroup][oDD.id] = oDD; }, /** * Removes the supplied dd instance from the supplied group. Executed * by DragDrop.removeFromGroup, so don't call this function directly. * @method removeDDFromGroup * @private * @static */ removeDDFromGroup: function(oDD, sGroup) { if (!this.ids[sGroup]) { this.ids[sGroup] = {}; } var obj = this.ids[sGroup]; if (obj && obj[oDD.id]) { delete obj[oDD.id]; } }, /** * Unregisters a drag and drop item. This is executed in * DragDrop.unreg, use that method instead of calling this directly. * @method _remove * @private * @static */ _remove: function(oDD) { for (var g in oDD.groups) { if (g) { var item = this.ids[g]; if (item && item[oDD.id]) { delete item[oDD.id]; } } } delete this.handleIds[oDD.id]; }, /** * Each DragDrop handle element must be registered. This is done * automatically when executing DragDrop.setHandleElId() * @method regHandle * @param {String} sDDId the DragDrop id this element is a handle for * @param {String} sHandleId the id of the element that is the drag * handle * @static */ regHandle: function(sDDId, sHandleId) { if (!this.handleIds[sDDId]) { this.handleIds[sDDId] = {}; } this.handleIds[sDDId][sHandleId] = sHandleId; }, /** * Utility function to determine if a given element has been * registered as a drag drop item. * @method isDragDrop * @param {String} id the element id to check * @return {boolean} true if this element is a DragDrop item, * false otherwise * @static */ isDragDrop: function(id) { return ( this.getDDById(id) ) ? true : false; }, /** * Returns the drag and drop instances that are in all groups the * passed in instance belongs to. * @method getRelated * @param {DragDrop} p_oDD the obj to get related data for * @param {boolean} bTargetsOnly if true, only return targetable objs * @return {DragDrop[]} the related instances * @static */ getRelated: function(p_oDD, bTargetsOnly) { var oDDs = []; for (var i in p_oDD.groups) { for (var j in this.ids[i]) { var dd = this.ids[i][j]; if (! this.isTypeOfDD(dd)) { continue; } if (!bTargetsOnly || dd.isTarget) { oDDs[oDDs.length] = dd; } } } return oDDs; }, /** * Returns true if the specified dd target is a legal target for * the specifice drag obj * @method isLegalTarget * @param {DragDrop} the drag obj * @param {DragDrop} the target * @return {boolean} true if the target is a legal target for the * dd obj * @static */ isLegalTarget: function (oDD, oTargetDD) { var targets = this.getRelated(oDD, true); for (var i=0, len=targets.length;i this.clickPixelThresh || diffY > this.clickPixelThresh) { this.startDrag(this.startX, this.startY); } } if (this.dragThreshMet) { if (dc && dc.events.b4Drag) { dc.b4Drag(e); dc.fireEvent('b4DragEvent', { e: e}); } if (dc && dc.events.drag) { dc.onDrag(e); dc.fireEvent('dragEvent', { e: e}); } if (dc) { this.fireEvents(e, false); } } this.stopEvent(e); } }, /** * Iterates over all of the DragDrop elements to find ones we are * hovering over or dropping on * @method fireEvents * @param {Event} e the event * @param {boolean} isDrop is this a drop op or a mouseover op? * @private * @static */ fireEvents: function(e, isDrop) { var dc = this.dragCurrent; // If the user did the mouse up outside of the window, we could // get here even though we have ended the drag. // If the config option dragOnly is true, bail out and don't fire the events if (!dc || dc.isLocked() || dc.dragOnly) { return; } var x = YAHOO.util.Event.getPageX(e), y = YAHOO.util.Event.getPageY(e), pt = new YAHOO.util.Point(x,y), pos = dc.getTargetCoord(pt.x, pt.y), el = dc.getDragEl(), events = ['out', 'over', 'drop', 'enter'], curRegion = new YAHOO.util.Region( pos.y, pos.x + el.offsetWidth, pos.y + el.offsetHeight, pos.x ), oldOvers = [], // cache the previous dragOver array inGroupsObj = {}, inGroups = [], data = { outEvts: [], overEvts: [], dropEvts: [], enterEvts: [] }; // Check to see if the object(s) we were hovering over is no longer // being hovered over so we can fire the onDragOut event for (var i in this.dragOvers) { var ddo = this.dragOvers[i]; if (! this.isTypeOfDD(ddo)) { continue; } if (! this.isOverTarget(pt, ddo, this.mode, curRegion)) { data.outEvts.push( ddo ); } oldOvers[i] = true; delete this.dragOvers[i]; } for (var sGroup in dc.groups) { if ("string" != typeof sGroup) { continue; } for (i in this.ids[sGroup]) { var oDD = this.ids[sGroup][i]; if (! this.isTypeOfDD(oDD)) { continue; } if (oDD.isTarget && !oDD.isLocked() && oDD != dc) { if (this.isOverTarget(pt, oDD, this.mode, curRegion)) { inGroupsObj[sGroup] = true; // look for drop interactions if (isDrop) { data.dropEvts.push( oDD ); // look for drag enter and drag over interactions } else { // initial drag over: dragEnter fires if (!oldOvers[oDD.id]) { data.enterEvts.push( oDD ); // subsequent drag overs: dragOver fires } else { data.overEvts.push( oDD ); } this.dragOvers[oDD.id] = oDD; } } } } } this.interactionInfo = { out: data.outEvts, enter: data.enterEvts, over: data.overEvts, drop: data.dropEvts, point: pt, draggedRegion: curRegion, sourceRegion: this.locationCache[dc.id], validDrop: isDrop }; for (var inG in inGroupsObj) { inGroups.push(inG); } // notify about a drop that did not find a target if (isDrop && !data.dropEvts.length) { this.interactionInfo.validDrop = false; if (dc.events.invalidDrop) { dc.onInvalidDrop(e); dc.fireEvent('invalidDropEvent', { e: e }); } } for (i = 0; i < events.length; i++) { var tmp = null; if (data[events[i] + 'Evts']) { tmp = data[events[i] + 'Evts']; } if (tmp && tmp.length) { var type = events[i].charAt(0).toUpperCase() + events[i].substr(1), ev = 'onDrag' + type, b4 = 'b4Drag' + type, cev = 'drag' + type + 'Event', check = 'drag' + type; if (this.mode) { if (dc.events[b4]) { dc[b4](e, tmp, inGroups); dc.fireEvent(b4 + 'Event', { event: e, info: tmp, group: inGroups }); } if (dc.events[check]) { dc[ev](e, tmp, inGroups); dc.fireEvent(cev, { event: e, info: tmp, group: inGroups }); } } else { for (var b = 0, len = tmp.length; b < len; ++b) { if (dc.events[b4]) { dc[b4](e, tmp[b].id, inGroups[0]); dc.fireEvent(b4 + 'Event', { event: e, info: tmp[b].id, group: inGroups[0] }); } if (dc.events[check]) { dc[ev](e, tmp[b].id, inGroups[0]); dc.fireEvent(cev, { event: e, info: tmp[b].id, group: inGroups[0] }); } } } } } }, /** * Helper function for getting the best match from the list of drag * and drop objects returned by the drag and drop events when we are * in INTERSECT mode. It returns either the first object that the * cursor is over, or the object that has the greatest overlap with * the dragged element. * @method getBestMatch * @param {DragDrop[]} dds The array of drag and drop objects * targeted * @return {DragDrop} The best single match * @static */ getBestMatch: function(dds) { var winner = null; var len = dds.length; if (len == 1) { winner = dds[0]; } else { // Loop through the targeted items for (var i=0; i * YAHOO.util.DragDropMgr.refreshCache(ddinstance.groups); * * Alternatively: * * YAHOO.util.DragDropMgr.refreshCache({group1:true, group2:true}); * * @TODO this really should be an indexed array. Alternatively this * method could accept both. * @method refreshCache * @param {Object} groups an associative array of groups to refresh * @static */ refreshCache: function(groups) { // refresh everything if group array is not provided var g = groups || this.ids; for (var sGroup in g) { if ("string" != typeof sGroup) { continue; } for (var i in this.ids[sGroup]) { var oDD = this.ids[sGroup][i]; if (this.isTypeOfDD(oDD)) { var loc = this.getLocation(oDD); if (loc) { this.locationCache[oDD.id] = loc; } else { delete this.locationCache[oDD.id]; } } } } }, /** * This checks to make sure an element exists and is in the DOM. The * main purpose is to handle cases where innerHTML is used to remove * drag and drop objects from the DOM. IE provides an 'unspecified * error' when trying to access the offsetParent of such an element * @method verifyEl * @param {HTMLElement} el the element to check * @return {boolean} true if the element looks usable * @static */ verifyEl: function(el) { try { if (el) { var parent = el.offsetParent; if (parent) { return true; } } } catch(e) { } return false; }, /** * Returns a Region object containing the drag and drop element's position * and size, including the padding configured for it * @method getLocation * @param {DragDrop} oDD the drag and drop object to get the * location for * @return {YAHOO.util.Region} a Region object representing the total area * the element occupies, including any padding * the instance is configured for. * @static */ getLocation: function(oDD) { if (! this.isTypeOfDD(oDD)) { return null; } var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l; try { pos= YAHOO.util.Dom.getXY(el); } catch (e) { } if (!pos) { return null; } x1 = pos[0]; x2 = x1 + el.offsetWidth; y1 = pos[1]; y2 = y1 + el.offsetHeight; t = y1 - oDD.padding[0]; r = x2 + oDD.padding[1]; b = y2 + oDD.padding[2]; l = x1 - oDD.padding[3]; return new YAHOO.util.Region( t, r, b, l ); }, /** * Checks the cursor location to see if it over the target * @method isOverTarget * @param {YAHOO.util.Point} pt The point to evaluate * @param {DragDrop} oTarget the DragDrop object we are inspecting * @param {boolean} intersect true if we are in intersect mode * @param {YAHOO.util.Region} pre-cached location of the dragged element * @return {boolean} true if the mouse is over the target * @private * @static */ isOverTarget: function(pt, oTarget, intersect, curRegion) { // use cache if available var loc = this.locationCache[oTarget.id]; if (!loc || !this.useCache) { loc = this.getLocation(oTarget); this.locationCache[oTarget.id] = loc; } if (!loc) { return false; } oTarget.cursorIsOver = loc.contains( pt ); // DragDrop is using this as a sanity check for the initial mousedown // in this case we are done. In POINT mode, if the drag obj has no // contraints, we are done. Otherwise we need to evaluate the // region the target as occupies to determine if the dragged element // overlaps with it. var dc = this.dragCurrent; if (!dc || (!intersect && !dc.constrainX && !dc.constrainY)) { //if (oTarget.cursorIsOver) { //} return oTarget.cursorIsOver; } oTarget.overlap = null; // Get the current location of the drag element, this is the // location of the mouse event less the delta that represents // where the original mousedown happened on the element. We // need to consider constraints and ticks as well. if (!curRegion) { var pos = dc.getTargetCoord(pt.x, pt.y); var el = dc.getDragEl(); curRegion = new YAHOO.util.Region( pos.y, pos.x + el.offsetWidth, pos.y + el.offsetHeight, pos.x ); } var overlap = curRegion.intersect(loc); if (overlap) { oTarget.overlap = overlap; return (intersect) ? true : oTarget.cursorIsOver; } else { return false; } }, /** * unload event handler * @method _onUnload * @private * @static */ _onUnload: function(e, me) { this.unregAll(); }, /** * Cleans up the drag and drop events and objects. * @method unregAll * @private * @static */ unregAll: function() { if (this.dragCurrent) { this.stopDrag(); this.dragCurrent = null; } this._execOnAll("unreg", []); //for (var i in this.elementCache) { //delete this.elementCache[i]; //} //this.elementCache = {}; this.ids = {}; }, /** * A cache of DOM elements * @property elementCache * @private * @static * @deprecated elements are not cached now */ elementCache: {}, /** * Get the wrapper for the DOM element specified * @method getElWrapper * @param {String} id the id of the element to get * @return {YAHOO.util.DDM.ElementWrapper} the wrapped element * @private * @deprecated This wrapper isn't that useful * @static */ getElWrapper: function(id) { var oWrapper = this.elementCache[id]; if (!oWrapper || !oWrapper.el) { oWrapper = this.elementCache[id] = new this.ElementWrapper(YAHOO.util.Dom.get(id)); } return oWrapper; }, /** * Returns the actual DOM element * @method getElement * @param {String} id the id of the elment to get * @return {Object} The element * @deprecated use YAHOO.util.Dom.get instead * @static */ getElement: function(id) { return YAHOO.util.Dom.get(id); }, /** * Returns the style property for the DOM element (i.e., * document.getElById(id).style) * @method getCss * @param {String} id the id of the elment to get * @return {Object} The style property of the element * @deprecated use YAHOO.util.Dom instead * @static */ getCss: function(id) { var el = YAHOO.util.Dom.get(id); return (el) ? el.style : null; }, /** * Inner class for cached elements * @class DragDropMgr.ElementWrapper * @for DragDropMgr * @private * @deprecated */ ElementWrapper: function(el) { /** * The element * @property el */ this.el = el || null; /** * The element id * @property id */ this.id = this.el && el.id; /** * A reference to the style property * @property css */ this.css = this.el && el.style; }, /** * Returns the X position of an html element * @method getPosX * @param el the element for which to get the position * @return {int} the X coordinate * @for DragDropMgr * @deprecated use YAHOO.util.Dom.getX instead * @static */ getPosX: function(el) { return YAHOO.util.Dom.getX(el); }, /** * Returns the Y position of an html element * @method getPosY * @param el the element for which to get the position * @return {int} the Y coordinate * @deprecated use YAHOO.util.Dom.getY instead * @static */ getPosY: function(el) { return YAHOO.util.Dom.getY(el); }, /** * Swap two nodes. In IE, we use the native method, for others we * emulate the IE behavior * @method swapNode * @param n1 the first node to swap * @param n2 the other node to swap * @static */ swapNode: function(n1, n2) { if (n1.swapNode) { n1.swapNode(n2); } else { var p = n2.parentNode; var s = n2.nextSibling; if (s == n1) { p.insertBefore(n1, n2); } else if (n2 == n1.nextSibling) { p.insertBefore(n2, n1); } else { n1.parentNode.replaceChild(n2, n1); p.insertBefore(n1, s); } } }, /** * Returns the current scroll position * @method getScroll * @private * @static */ getScroll: function () { var t, l, dde=document.documentElement, db=document.body; if (dde && (dde.scrollTop || dde.scrollLeft)) { t = dde.scrollTop; l = dde.scrollLeft; } else if (db) { t = db.scrollTop; l = db.scrollLeft; } else { } return { top: t, left: l }; }, /** * Returns the specified element style property * @method getStyle * @param {HTMLElement} el the element * @param {string} styleProp the style property * @return {string} The value of the style property * @deprecated use YAHOO.util.Dom.getStyle * @static */ getStyle: function(el, styleProp) { return YAHOO.util.Dom.getStyle(el, styleProp); }, /** * Gets the scrollTop * @method getScrollTop * @return {int} the document's scrollTop * @static */ getScrollTop: function () { return this.getScroll().top; }, /** * Gets the scrollLeft * @method getScrollLeft * @return {int} the document's scrollTop * @static */ getScrollLeft: function () { return this.getScroll().left; }, /** * Sets the x/y position of an element to the location of the * target element. * @method moveToEl * @param {HTMLElement} moveEl The element to move * @param {HTMLElement} targetEl The position reference element * @static */ moveToEl: function (moveEl, targetEl) { var aCoord = YAHOO.util.Dom.getXY(targetEl); YAHOO.util.Dom.setXY(moveEl, aCoord); }, /** * Gets the client height * @method getClientHeight * @return {int} client height in px * @deprecated use YAHOO.util.Dom.getViewportHeight instead * @static */ getClientHeight: function() { return YAHOO.util.Dom.getViewportHeight(); }, /** * Gets the client width * @method getClientWidth * @return {int} client width in px * @deprecated use YAHOO.util.Dom.getViewportWidth instead * @static */ getClientWidth: function() { return YAHOO.util.Dom.getViewportWidth(); }, /** * Numeric array sort function * @method numericSort * @static */ numericSort: function(a, b) { return (a - b); }, /** * Internal counter * @property _timeoutCount * @private * @static */ _timeoutCount: 0, /** * Trying to make the load order less important. Without this we get * an error if this file is loaded before the Event Utility. * @method _addListeners * @private * @static */ _addListeners: function() { var DDM = YAHOO.util.DDM; if ( YAHOO.util.Event && document ) { DDM._onLoad(); } else { if (DDM._timeoutCount > 2000) { } else { setTimeout(DDM._addListeners, 10); if (document && document.body) { DDM._timeoutCount += 1; } } } }, /** * Recursively searches the immediate parent and all child nodes for * the handle element in order to determine wheter or not it was * clicked. * @method handleWasClicked * @param node the html element to inspect * @static */ handleWasClicked: function(node, id) { if (this.isHandle(id, node.id)) { return true; } else { // check to see if this is a text node child of the one we want var p = node.parentNode; while (p) { if (this.isHandle(id, p.id)) { return true; } else { p = p.parentNode; } } } return false; } }; }(); // shorter alias, save a few bytes YAHOO.util.DDM = YAHOO.util.DragDropMgr; YAHOO.util.DDM._addListeners(); } (function() { var Event=YAHOO.util.Event; var Dom=YAHOO.util.Dom; /** * Defines the interface and base operation of items that that can be * dragged or can be drop targets. It was designed to be extended, overriding * the event handlers for startDrag, onDrag, onDragOver, onDragOut. * Up to three html elements can be associated with a DragDrop instance: *
      *
    • linked element: the element that is passed into the constructor. * This is the element which defines the boundaries for interaction with * other DragDrop objects.
    • *
    • handle element(s): The drag operation only occurs if the element that * was clicked matches a handle element. By default this is the linked * element, but there are times that you will want only a portion of the * linked element to initiate the drag operation, and the setHandleElId() * method provides a way to define this.
    • *
    • drag element: this represents an the element that would be moved along * with the cursor during a drag operation. By default, this is the linked * element itself as in {@link YAHOO.util.DD}. setDragElId() lets you define * a separate element that would be moved, as in {@link YAHOO.util.DDProxy} *
    • *
    * This class should not be instantiated until the onload event to ensure that * the associated elements are available. * The following would define a DragDrop obj that would interact with any * other DragDrop obj in the "group1" group: *
     *  dd = new YAHOO.util.DragDrop("div1", "group1");
     * 
    * Since none of the event handlers have been implemented, nothing would * actually happen if you were to run the code above. Normally you would * override this class or one of the default implementations, but you can * also override the methods you want on an instance of the class... *
     *  dd.onDragDrop = function(e, id) {
     *    alert("dd was dropped on " + id);
     *  }
     * 
    * @namespace YAHOO.util * @class DragDrop * @constructor * @param {String} id of the element that is linked to this instance * @param {String} sGroup the group of related DragDrop objects * @param {object} config an object containing configurable attributes * Valid properties for DragDrop: * padding, isTarget, maintainOffset, primaryButtonOnly, */ YAHOO.util.DragDrop = function(id, sGroup, config) { if (id) { this.init(id, sGroup, config); } }; YAHOO.util.DragDrop.prototype = { /** * An Object Literal containing the events that we will be using: mouseDown, b4MouseDown, mouseUp, b4StartDrag, startDrag, b4EndDrag, endDrag, mouseUp, drag, b4Drag, invalidDrop, b4DragOut, dragOut, dragEnter, b4DragOver, dragOver, b4DragDrop, dragDrop * By setting any of these to false, then event will not be fired. * @property events * @type object */ events: null, /** * @method on * @description Shortcut for EventProvider.subscribe, see YAHOO.util.EventProvider.subscribe */ on: function() { this.subscribe.apply(this, arguments); }, /** * The id of the element associated with this object. This is what we * refer to as the "linked element" because the size and position of * this element is used to determine when the drag and drop objects have * interacted. * @property id * @type String */ id: null, /** * Configuration attributes passed into the constructor * @property config * @type object */ config: null, /** * The id of the element that will be dragged. By default this is same * as the linked element , but could be changed to another element. Ex: * YAHOO.util.DDProxy * @property dragElId * @type String * @private */ dragElId: null, /** * the id of the element that initiates the drag operation. By default * this is the linked element, but could be changed to be a child of this * element. This lets us do things like only starting the drag when the * header element within the linked html element is clicked. * @property handleElId * @type String * @private */ handleElId: null, /** * An associative array of HTML tags that will be ignored if clicked. * @property invalidHandleTypes * @type {string: string} */ invalidHandleTypes: null, /** * An associative array of ids for elements that will be ignored if clicked * @property invalidHandleIds * @type {string: string} */ invalidHandleIds: null, /** * An indexted array of css class names for elements that will be ignored * if clicked. * @property invalidHandleClasses * @type string[] */ invalidHandleClasses: null, /** * The linked element's absolute X position at the time the drag was * started * @property startPageX * @type int * @private */ startPageX: 0, /** * The linked element's absolute X position at the time the drag was * started * @property startPageY * @type int * @private */ startPageY: 0, /** * The group defines a logical collection of DragDrop objects that are * related. Instances only get events when interacting with other * DragDrop object in the same group. This lets us define multiple * groups using a single DragDrop subclass if we want. * @property groups * @type {string: string} */ groups: null, /** * Individual drag/drop instances can be locked. This will prevent * onmousedown start drag. * @property locked * @type boolean * @private */ locked: false, /** * Lock this instance * @method lock */ lock: function() { this.locked = true; }, /** * Unlock this instace * @method unlock */ unlock: function() { this.locked = false; }, /** * By default, all instances can be a drop target. This can be disabled by * setting isTarget to false. * @property isTarget * @type boolean */ isTarget: true, /** * The padding configured for this drag and drop object for calculating * the drop zone intersection with this object. * @property padding * @type int[] */ padding: null, /** * If this flag is true, do not fire drop events. The element is a drag only element (for movement not dropping) * @property dragOnly * @type Boolean */ dragOnly: false, /** * If this flag is true, a shim will be placed over the screen/viewable area to track mouse events. Should help with dragging elements over iframes and other controls. * @property useShim * @type Boolean */ useShim: false, /** * Cached reference to the linked element * @property _domRef * @private */ _domRef: null, /** * Internal typeof flag * @property __ygDragDrop * @private */ __ygDragDrop: true, /** * Set to true when horizontal contraints are applied * @property constrainX * @type boolean * @private */ constrainX: false, /** * Set to true when vertical contraints are applied * @property constrainY * @type boolean * @private */ constrainY: false, /** * The left constraint * @property minX * @type int * @private */ minX: 0, /** * The right constraint * @property maxX * @type int * @private */ maxX: 0, /** * The up constraint * @property minY * @type int * @type int * @private */ minY: 0, /** * The down constraint * @property maxY * @type int * @private */ maxY: 0, /** * The difference between the click position and the source element's location * @property deltaX * @type int * @private */ deltaX: 0, /** * The difference between the click position and the source element's location * @property deltaY * @type int * @private */ deltaY: 0, /** * Maintain offsets when we resetconstraints. Set to true when you want * the position of the element relative to its parent to stay the same * when the page changes * * @property maintainOffset * @type boolean */ maintainOffset: false, /** * Array of pixel locations the element will snap to if we specified a * horizontal graduation/interval. This array is generated automatically * when you define a tick interval. * @property xTicks * @type int[] */ xTicks: null, /** * Array of pixel locations the element will snap to if we specified a * vertical graduation/interval. This array is generated automatically * when you define a tick interval. * @property yTicks * @type int[] */ yTicks: null, /** * By default the drag and drop instance will only respond to the primary * button click (left button for a right-handed mouse). Set to true to * allow drag and drop to start with any mouse click that is propogated * by the browser * @property primaryButtonOnly * @type boolean */ primaryButtonOnly: true, /** * The availabe property is false until the linked dom element is accessible. * @property available * @type boolean */ available: false, /** * By default, drags can only be initiated if the mousedown occurs in the * region the linked element is. This is done in part to work around a * bug in some browsers that mis-report the mousedown if the previous * mouseup happened outside of the window. This property is set to true * if outer handles are defined. * * @property hasOuterHandles * @type boolean * @default false */ hasOuterHandles: false, /** * Property that is assigned to a drag and drop object when testing to * see if it is being targeted by another dd object. This property * can be used in intersect mode to help determine the focus of * the mouse interaction. DDM.getBestMatch uses this property first to * determine the closest match in INTERSECT mode when multiple targets * are part of the same interaction. * @property cursorIsOver * @type boolean */ cursorIsOver: false, /** * Property that is assigned to a drag and drop object when testing to * see if it is being targeted by another dd object. This is a region * that represents the area the draggable element overlaps this target. * DDM.getBestMatch uses this property to compare the size of the overlap * to that of other targets in order to determine the closest match in * INTERSECT mode when multiple targets are part of the same interaction. * @property overlap * @type YAHOO.util.Region */ overlap: null, /** * Code that executes immediately before the startDrag event * @method b4StartDrag * @private */ b4StartDrag: function(x, y) { }, /** * Abstract method called after a drag/drop object is clicked * and the drag or mousedown time thresholds have beeen met. * @method startDrag * @param {int} X click location * @param {int} Y click location */ startDrag: function(x, y) { /* override this */ }, /** * Code that executes immediately before the onDrag event * @method b4Drag * @private */ b4Drag: function(e) { }, /** * Abstract method called during the onMouseMove event while dragging an * object. * @method onDrag * @param {Event} e the mousemove event */ onDrag: function(e) { /* override this */ }, /** * Abstract method called when this element fist begins hovering over * another DragDrop obj * @method onDragEnter * @param {Event} e the mousemove event * @param {String|DragDrop[]} id In POINT mode, the element * id this is hovering over. In INTERSECT mode, an array of one or more * dragdrop items being hovered over. */ onDragEnter: function(e, id) { /* override this */ }, /** * Code that executes immediately before the onDragOver event * @method b4DragOver * @private */ b4DragOver: function(e) { }, /** * Abstract method called when this element is hovering over another * DragDrop obj * @method onDragOver * @param {Event} e the mousemove event * @param {String|DragDrop[]} id In POINT mode, the element * id this is hovering over. In INTERSECT mode, an array of dd items * being hovered over. */ onDragOver: function(e, id) { /* override this */ }, /** * Code that executes immediately before the onDragOut event * @method b4DragOut * @private */ b4DragOut: function(e) { }, /** * Abstract method called when we are no longer hovering over an element * @method onDragOut * @param {Event} e the mousemove event * @param {String|DragDrop[]} id In POINT mode, the element * id this was hovering over. In INTERSECT mode, an array of dd items * that the mouse is no longer over. */ onDragOut: function(e, id) { /* override this */ }, /** * Code that executes immediately before the onDragDrop event * @method b4DragDrop * @private */ b4DragDrop: function(e) { }, /** * Abstract method called when this item is dropped on another DragDrop * obj * @method onDragDrop * @param {Event} e the mouseup event * @param {String|DragDrop[]} id In POINT mode, the element * id this was dropped on. In INTERSECT mode, an array of dd items this * was dropped on. */ onDragDrop: function(e, id) { /* override this */ }, /** * Abstract method called when this item is dropped on an area with no * drop target * @method onInvalidDrop * @param {Event} e the mouseup event */ onInvalidDrop: function(e) { /* override this */ }, /** * Code that executes immediately before the endDrag event * @method b4EndDrag * @private */ b4EndDrag: function(e) { }, /** * Fired when we are done dragging the object * @method endDrag * @param {Event} e the mouseup event */ endDrag: function(e) { /* override this */ }, /** * Code executed immediately before the onMouseDown event * @method b4MouseDown * @param {Event} e the mousedown event * @private */ b4MouseDown: function(e) { }, /** * Event handler that fires when a drag/drop obj gets a mousedown * @method onMouseDown * @param {Event} e the mousedown event */ onMouseDown: function(e) { /* override this */ }, /** * Event handler that fires when a drag/drop obj gets a mouseup * @method onMouseUp * @param {Event} e the mouseup event */ onMouseUp: function(e) { /* override this */ }, /** * Override the onAvailable method to do what is needed after the initial * position was determined. * @method onAvailable */ onAvailable: function () { }, /** * Returns a reference to the linked element * @method getEl * @return {HTMLElement} the html element */ getEl: function() { if (!this._domRef) { this._domRef = Dom.get(this.id); } return this._domRef; }, /** * Returns a reference to the actual element to drag. By default this is * the same as the html element, but it can be assigned to another * element. An example of this can be found in YAHOO.util.DDProxy * @method getDragEl * @return {HTMLElement} the html element */ getDragEl: function() { return Dom.get(this.dragElId); }, /** * Sets up the DragDrop object. Must be called in the constructor of any * YAHOO.util.DragDrop subclass * @method init * @param id the id of the linked element * @param {String} sGroup the group of related items * @param {object} config configuration attributes */ init: function(id, sGroup, config) { this.initTarget(id, sGroup, config); Event.on(this._domRef || this.id, "mousedown", this.handleMouseDown, this, true); // Event.on(this.id, "selectstart", Event.preventDefault); for (var i in this.events) { this.createEvent(i + 'Event'); } }, /** * Initializes Targeting functionality only... the object does not * get a mousedown handler. * @method initTarget * @param id the id of the linked element * @param {String} sGroup the group of related items * @param {object} config configuration attributes */ initTarget: function(id, sGroup, config) { // configuration attributes this.config = config || {}; this.events = {}; // create a local reference to the drag and drop manager this.DDM = YAHOO.util.DDM; // initialize the groups object this.groups = {}; // assume that we have an element reference instead of an id if the // parameter is not a string if (typeof id !== "string") { this._domRef = id; id = Dom.generateId(id); } // set the id this.id = id; // add to an interaction group this.addToGroup((sGroup) ? sGroup : "default"); // We don't want to register this as the handle with the manager // so we just set the id rather than calling the setter. this.handleElId = id; Event.onAvailable(id, this.handleOnAvailable, this, true); // the linked element is the element that gets dragged by default this.setDragElId(id); // by default, clicked anchors will not start drag operations. // @TODO what else should be here? Probably form fields. this.invalidHandleTypes = { A: "A" }; this.invalidHandleIds = {}; this.invalidHandleClasses = []; this.applyConfig(); }, /** * Applies the configuration parameters that were passed into the constructor. * This is supposed to happen at each level through the inheritance chain. So * a DDProxy implentation will execute apply config on DDProxy, DD, and * DragDrop in order to get all of the parameters that are available in * each object. * @method applyConfig */ applyConfig: function() { this.events = { mouseDown: true, b4MouseDown: true, mouseUp: true, b4StartDrag: true, startDrag: true, b4EndDrag: true, endDrag: true, drag: true, b4Drag: true, invalidDrop: true, b4DragOut: true, dragOut: true, dragEnter: true, b4DragOver: true, dragOver: true, b4DragDrop: true, dragDrop: true }; if (this.config.events) { for (var i in this.config.events) { if (this.config.events[i] === false) { this.events[i] = false; } } } // configurable properties: // padding, isTarget, maintainOffset, primaryButtonOnly this.padding = this.config.padding || [0, 0, 0, 0]; this.isTarget = (this.config.isTarget !== false); this.maintainOffset = (this.config.maintainOffset); this.primaryButtonOnly = (this.config.primaryButtonOnly !== false); this.dragOnly = ((this.config.dragOnly === true) ? true : false); this.useShim = ((this.config.useShim === true) ? true : false); }, /** * Executed when the linked element is available * @method handleOnAvailable * @private */ handleOnAvailable: function() { this.available = true; this.resetConstraints(); this.onAvailable(); }, /** * Configures the padding for the target zone in px. Effectively expands * (or reduces) the virtual object size for targeting calculations. * Supports css-style shorthand; if only one parameter is passed, all sides * will have that padding, and if only two are passed, the top and bottom * will have the first param, the left and right the second. * @method setPadding * @param {int} iTop Top pad * @param {int} iRight Right pad * @param {int} iBot Bot pad * @param {int} iLeft Left pad */ setPadding: function(iTop, iRight, iBot, iLeft) { // this.padding = [iLeft, iRight, iTop, iBot]; if (!iRight && 0 !== iRight) { this.padding = [iTop, iTop, iTop, iTop]; } else if (!iBot && 0 !== iBot) { this.padding = [iTop, iRight, iTop, iRight]; } else { this.padding = [iTop, iRight, iBot, iLeft]; } }, /** * Stores the initial placement of the linked element. * @method setInitialPosition * @param {int} diffX the X offset, default 0 * @param {int} diffY the Y offset, default 0 * @private */ setInitPosition: function(diffX, diffY) { var el = this.getEl(); if (!this.DDM.verifyEl(el)) { if (el && el.style && (el.style.display == 'none')) { } else { } return; } var dx = diffX || 0; var dy = diffY || 0; var p = Dom.getXY( el ); this.initPageX = p[0] - dx; this.initPageY = p[1] - dy; this.lastPageX = p[0]; this.lastPageY = p[1]; this.setStartPosition(p); }, /** * Sets the start position of the element. This is set when the obj * is initialized, the reset when a drag is started. * @method setStartPosition * @param pos current position (from previous lookup) * @private */ setStartPosition: function(pos) { var p = pos || Dom.getXY(this.getEl()); this.deltaSetXY = null; this.startPageX = p[0]; this.startPageY = p[1]; }, /** * Add this instance to a group of related drag/drop objects. All * instances belong to at least one group, and can belong to as many * groups as needed. * @method addToGroup * @param sGroup {string} the name of the group */ addToGroup: function(sGroup) { this.groups[sGroup] = true; this.DDM.regDragDrop(this, sGroup); }, /** * Remove's this instance from the supplied interaction group * @method removeFromGroup * @param {string} sGroup The group to drop */ removeFromGroup: function(sGroup) { if (this.groups[sGroup]) { delete this.groups[sGroup]; } this.DDM.removeDDFromGroup(this, sGroup); }, /** * Allows you to specify that an element other than the linked element * will be moved with the cursor during a drag * @method setDragElId * @param id {string} the id of the element that will be used to initiate the drag */ setDragElId: function(id) { this.dragElId = id; }, /** * Allows you to specify a child of the linked element that should be * used to initiate the drag operation. An example of this would be if * you have a content div with text and links. Clicking anywhere in the * content area would normally start the drag operation. Use this method * to specify that an element inside of the content div is the element * that starts the drag operation. * @method setHandleElId * @param id {string} the id of the element that will be used to * initiate the drag. */ setHandleElId: function(id) { if (typeof id !== "string") { id = Dom.generateId(id); } this.handleElId = id; this.DDM.regHandle(this.id, id); }, /** * Allows you to set an element outside of the linked element as a drag * handle * @method setOuterHandleElId * @param id the id of the element that will be used to initiate the drag */ setOuterHandleElId: function(id) { if (typeof id !== "string") { id = Dom.generateId(id); } Event.on(id, "mousedown", this.handleMouseDown, this, true); this.setHandleElId(id); this.hasOuterHandles = true; }, /** * Remove all drag and drop hooks for this element * @method unreg */ unreg: function() { Event.removeListener(this.id, "mousedown", this.handleMouseDown); this._domRef = null; this.DDM._remove(this); }, /** * Returns true if this instance is locked, or the drag drop mgr is locked * (meaning that all drag/drop is disabled on the page.) * @method isLocked * @return {boolean} true if this obj or all drag/drop is locked, else * false */ isLocked: function() { return (this.DDM.isLocked() || this.locked); }, /** * Fired when this object is clicked * @method handleMouseDown * @param {Event} e * @param {YAHOO.util.DragDrop} oDD the clicked dd object (this dd obj) * @private */ handleMouseDown: function(e, oDD) { var button = e.which || e.button; if (this.primaryButtonOnly && button > 1) { return; } if (this.isLocked()) { return; } // firing the mousedown events prior to calculating positions var b4Return = this.b4MouseDown(e), b4Return2 = true; if (this.events.b4MouseDown) { b4Return2 = this.fireEvent('b4MouseDownEvent', e); } var mDownReturn = this.onMouseDown(e), mDownReturn2 = true; if (this.events.mouseDown) { mDownReturn2 = this.fireEvent('mouseDownEvent', e); } if ((b4Return === false) || (mDownReturn === false) || (b4Return2 === false) || (mDownReturn2 === false)) { return; } this.DDM.refreshCache(this.groups); // var self = this; // setTimeout( function() { self.DDM.refreshCache(self.groups); }, 0); // Only process the event if we really clicked within the linked // element. The reason we make this check is that in the case that // another element was moved between the clicked element and the // cursor in the time between the mousedown and mouseup events. When // this happens, the element gets the next mousedown event // regardless of where on the screen it happened. var pt = new YAHOO.util.Point(Event.getPageX(e), Event.getPageY(e)); if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) { } else { if (this.clickValidator(e)) { // set the initial element position this.setStartPosition(); // start tracking mousemove distance and mousedown time to // determine when to start the actual drag this.DDM.handleMouseDown(e, this); // this mousedown is mine this.DDM.stopEvent(e); } else { } } }, /** * @method clickValidator * @description Method validates that the clicked element * was indeed the handle or a valid child of the handle * @param {Event} e */ clickValidator: function(e) { var target = YAHOO.util.Event.getTarget(e); return ( this.isValidHandleChild(target) && (this.id == this.handleElId || this.DDM.handleWasClicked(target, this.id)) ); }, /** * Finds the location the element should be placed if we want to move * it to where the mouse location less the click offset would place us. * @method getTargetCoord * @param {int} iPageX the X coordinate of the click * @param {int} iPageY the Y coordinate of the click * @return an object that contains the coordinates (Object.x and Object.y) * @private */ getTargetCoord: function(iPageX, iPageY) { var x = iPageX - this.deltaX; var y = iPageY - this.deltaY; if (this.constrainX) { if (x < this.minX) { x = this.minX; } if (x > this.maxX) { x = this.maxX; } } if (this.constrainY) { if (y < this.minY) { y = this.minY; } if (y > this.maxY) { y = this.maxY; } } x = this.getTick(x, this.xTicks); y = this.getTick(y, this.yTicks); return {x:x, y:y}; }, /** * Allows you to specify a tag name that should not start a drag operation * when clicked. This is designed to facilitate embedding links within a * drag handle that do something other than start the drag. * @method addInvalidHandleType * @param {string} tagName the type of element to exclude */ addInvalidHandleType: function(tagName) { var type = tagName.toUpperCase(); this.invalidHandleTypes[type] = type; }, /** * Lets you to specify an element id for a child of a drag handle * that should not initiate a drag * @method addInvalidHandleId * @param {string} id the element id of the element you wish to ignore */ addInvalidHandleId: function(id) { if (typeof id !== "string") { id = Dom.generateId(id); } this.invalidHandleIds[id] = id; }, /** * Lets you specify a css class of elements that will not initiate a drag * @method addInvalidHandleClass * @param {string} cssClass the class of the elements you wish to ignore */ addInvalidHandleClass: function(cssClass) { this.invalidHandleClasses.push(cssClass); }, /** * Unsets an excluded tag name set by addInvalidHandleType * @method removeInvalidHandleType * @param {string} tagName the type of element to unexclude */ removeInvalidHandleType: function(tagName) { var type = tagName.toUpperCase(); // this.invalidHandleTypes[type] = null; delete this.invalidHandleTypes[type]; }, /** * Unsets an invalid handle id * @method removeInvalidHandleId * @param {string} id the id of the element to re-enable */ removeInvalidHandleId: function(id) { if (typeof id !== "string") { id = Dom.generateId(id); } delete this.invalidHandleIds[id]; }, /** * Unsets an invalid css class * @method removeInvalidHandleClass * @param {string} cssClass the class of the element(s) you wish to * re-enable */ removeInvalidHandleClass: function(cssClass) { for (var i=0, len=this.invalidHandleClasses.length; i= this.minX; i = i - iTickSize) { if (!tickMap[i]) { this.xTicks[this.xTicks.length] = i; tickMap[i] = true; } } for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) { if (!tickMap[i]) { this.xTicks[this.xTicks.length] = i; tickMap[i] = true; } } this.xTicks.sort(this.DDM.numericSort) ; }, /** * Create the array of vertical tick marks if an interval was specified in * setYConstraint(). * @method setYTicks * @private */ setYTicks: function(iStartY, iTickSize) { this.yTicks = []; this.yTickSize = iTickSize; var tickMap = {}; for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) { if (!tickMap[i]) { this.yTicks[this.yTicks.length] = i; tickMap[i] = true; } } for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) { if (!tickMap[i]) { this.yTicks[this.yTicks.length] = i; tickMap[i] = true; } } this.yTicks.sort(this.DDM.numericSort) ; }, /** * By default, the element can be dragged any place on the screen. Use * this method to limit the horizontal travel of the element. Pass in * 0,0 for the parameters if you want to lock the drag to the y axis. * @method setXConstraint * @param {int} iLeft the number of pixels the element can move to the left * @param {int} iRight the number of pixels the element can move to the * right * @param {int} iTickSize optional parameter for specifying that the * element * should move iTickSize pixels at a time. */ setXConstraint: function(iLeft, iRight, iTickSize) { this.leftConstraint = parseInt(iLeft, 10); this.rightConstraint = parseInt(iRight, 10); this.minX = this.initPageX - this.leftConstraint; this.maxX = this.initPageX + this.rightConstraint; if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); } this.constrainX = true; }, /** * Clears any constraints applied to this instance. Also clears ticks * since they can't exist independent of a constraint at this time. * @method clearConstraints */ clearConstraints: function() { this.constrainX = false; this.constrainY = false; this.clearTicks(); }, /** * Clears any tick interval defined for this instance * @method clearTicks */ clearTicks: function() { this.xTicks = null; this.yTicks = null; this.xTickSize = 0; this.yTickSize = 0; }, /** * By default, the element can be dragged any place on the screen. Set * this to limit the vertical travel of the element. Pass in 0,0 for the * parameters if you want to lock the drag to the x axis. * @method setYConstraint * @param {int} iUp the number of pixels the element can move up * @param {int} iDown the number of pixels the element can move down * @param {int} iTickSize optional parameter for specifying that the * element should move iTickSize pixels at a time. */ setYConstraint: function(iUp, iDown, iTickSize) { this.topConstraint = parseInt(iUp, 10); this.bottomConstraint = parseInt(iDown, 10); this.minY = this.initPageY - this.topConstraint; this.maxY = this.initPageY + this.bottomConstraint; if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); } this.constrainY = true; }, /** * resetConstraints must be called if you manually reposition a dd element. * @method resetConstraints */ resetConstraints: function() { // Maintain offsets if necessary if (this.initPageX || this.initPageX === 0) { // figure out how much this thing has moved var dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0; var dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0; this.setInitPosition(dx, dy); // This is the first time we have detected the element's position } else { this.setInitPosition(); } if (this.constrainX) { this.setXConstraint( this.leftConstraint, this.rightConstraint, this.xTickSize ); } if (this.constrainY) { this.setYConstraint( this.topConstraint, this.bottomConstraint, this.yTickSize ); } }, /** * Normally the drag element is moved pixel by pixel, but we can specify * that it move a number of pixels at a time. This method resolves the * location when we have it set up like this. * @method getTick * @param {int} val where we want to place the object * @param {int[]} tickArray sorted array of valid points * @return {int} the closest tick * @private */ getTick: function(val, tickArray) { if (!tickArray) { // If tick interval is not defined, it is effectively 1 pixel, // so we return the value passed to us. return val; } else if (tickArray[0] >= val) { // The value is lower than the first tick, so we return the first // tick. return tickArray[0]; } else { for (var i=0, len=tickArray.length; i= val) { var diff1 = val - tickArray[i]; var diff2 = tickArray[next] - val; return (diff2 > diff1) ? tickArray[i] : tickArray[next]; } } // The value is larger than the last tick, so we return the last // tick. return tickArray[tickArray.length - 1]; } }, /** * toString method * @method toString * @return {string} string representation of the dd obj */ toString: function() { return ("DragDrop " + this.id); } }; YAHOO.augment(YAHOO.util.DragDrop, YAHOO.util.EventProvider); /** * @event mouseDownEvent * @description Provides access to the mousedown event. The mousedown does not always result in a drag operation. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4MouseDownEvent * @description Provides access to the mousedown event, before the mouseDownEvent gets fired. Returning false will cancel the drag. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event mouseUpEvent * @description Fired from inside DragDropMgr when the drag operation is finished. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4StartDragEvent * @description Fires before the startDragEvent, returning false will cancel the startDrag Event. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event startDragEvent * @description Occurs after a mouse down and the drag threshold has been met. The drag threshold default is either 3 pixels of mouse movement or 1 full second of holding the mousedown. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4EndDragEvent * @description Fires before the endDragEvent. Returning false will cancel. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event endDragEvent * @description Fires on the mouseup event after a drag has been initiated (startDrag fired). * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragEvent * @description Occurs every mousemove event while dragging. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4DragEvent * @description Fires before the dragEvent. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event invalidDropEvent * @description Fires when the dragged objects is dropped in a location that contains no drop targets. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4DragOutEvent * @description Fires before the dragOutEvent * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragOutEvent * @description Fires when a dragged object is no longer over an object that had the onDragEnter fire. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragEnterEvent * @description Occurs when the dragged object first interacts with another targettable drag and drop object. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4DragOverEvent * @description Fires before the dragOverEvent. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragOverEvent * @description Fires every mousemove event while over a drag and drop object. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4DragDropEvent * @description Fires before the dragDropEvent * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragDropEvent * @description Fires when the dragged objects is dropped on another. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ })(); /** * A DragDrop implementation where the linked element follows the * mouse cursor during a drag. * @class DD * @extends YAHOO.util.DragDrop * @constructor * @param {String} id the id of the linked element * @param {String} sGroup the group of related DragDrop items * @param {object} config an object containing configurable attributes * Valid properties for DD: * scroll */ YAHOO.util.DD = function(id, sGroup, config) { if (id) { this.init(id, sGroup, config); } }; YAHOO.extend(YAHOO.util.DD, YAHOO.util.DragDrop, { /** * When set to true, the utility automatically tries to scroll the browser * window when a drag and drop element is dragged near the viewport boundary. * Defaults to true. * @property scroll * @type boolean */ scroll: true, /** * Sets the pointer offset to the distance between the linked element's top * left corner and the location the element was clicked * @method autoOffset * @param {int} iPageX the X coordinate of the click * @param {int} iPageY the Y coordinate of the click */ autoOffset: function(iPageX, iPageY) { var x = iPageX - this.startPageX; var y = iPageY - this.startPageY; this.setDelta(x, y); }, /** * Sets the pointer offset. You can call this directly to force the * offset to be in a particular location (e.g., pass in 0,0 to set it * to the center of the object, as done in YAHOO.widget.Slider) * @method setDelta * @param {int} iDeltaX the distance from the left * @param {int} iDeltaY the distance from the top */ setDelta: function(iDeltaX, iDeltaY) { this.deltaX = iDeltaX; this.deltaY = iDeltaY; }, /** * Sets the drag element to the location of the mousedown or click event, * maintaining the cursor location relative to the location on the element * that was clicked. Override this if you want to place the element in a * location other than where the cursor is. * @method setDragElPos * @param {int} iPageX the X coordinate of the mousedown or drag event * @param {int} iPageY the Y coordinate of the mousedown or drag event */ setDragElPos: function(iPageX, iPageY) { // the first time we do this, we are going to check to make sure // the element has css positioning var el = this.getDragEl(); this.alignElWithMouse(el, iPageX, iPageY); }, /** * Sets the element to the location of the mousedown or click event, * maintaining the cursor location relative to the location on the element * that was clicked. Override this if you want to place the element in a * location other than where the cursor is. * @method alignElWithMouse * @param {HTMLElement} el the element to move * @param {int} iPageX the X coordinate of the mousedown or drag event * @param {int} iPageY the Y coordinate of the mousedown or drag event */ alignElWithMouse: function(el, iPageX, iPageY) { var oCoord = this.getTargetCoord(iPageX, iPageY); if (!this.deltaSetXY) { var aCoord = [oCoord.x, oCoord.y]; YAHOO.util.Dom.setXY(el, aCoord); var newLeft = parseInt( YAHOO.util.Dom.getStyle(el, "left"), 10 ); var newTop = parseInt( YAHOO.util.Dom.getStyle(el, "top" ), 10 ); this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ]; } else { YAHOO.util.Dom.setStyle(el, "left", (oCoord.x + this.deltaSetXY[0]) + "px"); YAHOO.util.Dom.setStyle(el, "top", (oCoord.y + this.deltaSetXY[1]) + "px"); } this.cachePosition(oCoord.x, oCoord.y); var self = this; setTimeout(function() { self.autoScroll.call(self, oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth); }, 0); }, /** * Saves the most recent position so that we can reset the constraints and * tick marks on-demand. We need to know this so that we can calculate the * number of pixels the element is offset from its original position. * @method cachePosition * @param iPageX the current x position (optional, this just makes it so we * don't have to look it up again) * @param iPageY the current y position (optional, this just makes it so we * don't have to look it up again) */ cachePosition: function(iPageX, iPageY) { if (iPageX) { this.lastPageX = iPageX; this.lastPageY = iPageY; } else { var aCoord = YAHOO.util.Dom.getXY(this.getEl()); this.lastPageX = aCoord[0]; this.lastPageY = aCoord[1]; } }, /** * Auto-scroll the window if the dragged object has been moved beyond the * visible window boundary. * @method autoScroll * @param {int} x the drag element's x position * @param {int} y the drag element's y position * @param {int} h the height of the drag element * @param {int} w the width of the drag element * @private */ autoScroll: function(x, y, h, w) { if (this.scroll) { // The client height var clientH = this.DDM.getClientHeight(); // The client width var clientW = this.DDM.getClientWidth(); // The amt scrolled down var st = this.DDM.getScrollTop(); // The amt scrolled right var sl = this.DDM.getScrollLeft(); // Location of the bottom of the element var bot = h + y; // Location of the right of the element var right = w + x; // The distance from the cursor to the bottom of the visible area, // adjusted so that we don't scroll if the cursor is beyond the // element drag constraints var toBot = (clientH + st - y - this.deltaY); // The distance from the cursor to the right of the visible area var toRight = (clientW + sl - x - this.deltaX); // How close to the edge the cursor must be before we scroll // var thresh = (document.all) ? 100 : 40; var thresh = 40; // How many pixels to scroll per autoscroll op. This helps to reduce // clunky scrolling. IE is more sensitive about this ... it needs this // value to be higher. var scrAmt = (document.all) ? 80 : 30; // Scroll down if we are near the bottom of the visible page and the // obj extends below the crease if ( bot > clientH && toBot < thresh ) { window.scrollTo(sl, st + scrAmt); } // Scroll up if the window is scrolled down and the top of the object // goes above the top border if ( y < st && st > 0 && y - st < thresh ) { window.scrollTo(sl, st - scrAmt); } // Scroll right if the obj is beyond the right border and the cursor is // near the border. if ( right > clientW && toRight < thresh ) { window.scrollTo(sl + scrAmt, st); } // Scroll left if the window has been scrolled to the right and the obj // extends past the left border if ( x < sl && sl > 0 && x - sl < thresh ) { window.scrollTo(sl - scrAmt, st); } } }, /* * Sets up config options specific to this class. Overrides * YAHOO.util.DragDrop, but all versions of this method through the * inheritance chain are called */ applyConfig: function() { YAHOO.util.DD.superclass.applyConfig.call(this); this.scroll = (this.config.scroll !== false); }, /* * Event that fires prior to the onMouseDown event. Overrides * YAHOO.util.DragDrop. */ b4MouseDown: function(e) { this.setStartPosition(); // this.resetConstraints(); this.autoOffset(YAHOO.util.Event.getPageX(e), YAHOO.util.Event.getPageY(e)); }, /* * Event that fires prior to the onDrag event. Overrides * YAHOO.util.DragDrop. */ b4Drag: function(e) { this.setDragElPos(YAHOO.util.Event.getPageX(e), YAHOO.util.Event.getPageY(e)); }, toString: function() { return ("DD " + this.id); } ////////////////////////////////////////////////////////////////////////// // Debugging ygDragDrop events that can be overridden ////////////////////////////////////////////////////////////////////////// /* startDrag: function(x, y) { }, onDrag: function(e) { }, onDragEnter: function(e, id) { }, onDragOver: function(e, id) { }, onDragOut: function(e, id) { }, onDragDrop: function(e, id) { }, endDrag: function(e) { } */ /** * @event mouseDownEvent * @description Provides access to the mousedown event. The mousedown does not always result in a drag operation. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4MouseDownEvent * @description Provides access to the mousedown event, before the mouseDownEvent gets fired. Returning false will cancel the drag. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event mouseUpEvent * @description Fired from inside DragDropMgr when the drag operation is finished. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4StartDragEvent * @description Fires before the startDragEvent, returning false will cancel the startDrag Event. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event startDragEvent * @description Occurs after a mouse down and the drag threshold has been met. The drag threshold default is either 3 pixels of mouse movement or 1 full second of holding the mousedown. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4EndDragEvent * @description Fires before the endDragEvent. Returning false will cancel. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event endDragEvent * @description Fires on the mouseup event after a drag has been initiated (startDrag fired). * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragEvent * @description Occurs every mousemove event while dragging. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4DragEvent * @description Fires before the dragEvent. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event invalidDropEvent * @description Fires when the dragged objects is dropped in a location that contains no drop targets. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4DragOutEvent * @description Fires before the dragOutEvent * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragOutEvent * @description Fires when a dragged object is no longer over an object that had the onDragEnter fire. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragEnterEvent * @description Occurs when the dragged object first interacts with another targettable drag and drop object. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4DragOverEvent * @description Fires before the dragOverEvent. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragOverEvent * @description Fires every mousemove event while over a drag and drop object. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4DragDropEvent * @description Fires before the dragDropEvent * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragDropEvent * @description Fires when the dragged objects is dropped on another. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ }); /** * A DragDrop implementation that inserts an empty, bordered div into * the document that follows the cursor during drag operations. At the time of * the click, the frame div is resized to the dimensions of the linked html * element, and moved to the exact location of the linked element. * * References to the "frame" element refer to the single proxy element that * was created to be dragged in place of all DDProxy elements on the * page. * * @class DDProxy * @extends YAHOO.util.DD * @constructor * @param {String} id the id of the linked html element * @param {String} sGroup the group of related DragDrop objects * @param {object} config an object containing configurable attributes * Valid properties for DDProxy in addition to those in DragDrop: * resizeFrame, centerFrame, dragElId */ YAHOO.util.DDProxy = function(id, sGroup, config) { if (id) { this.init(id, sGroup, config); this.initFrame(); } }; /** * The default drag frame div id * @property YAHOO.util.DDProxy.dragElId * @type String * @static */ YAHOO.util.DDProxy.dragElId = "ygddfdiv"; YAHOO.extend(YAHOO.util.DDProxy, YAHOO.util.DD, { /** * By default we resize the drag frame to be the same size as the element * we want to drag (this is to get the frame effect). We can turn it off * if we want a different behavior. * @property resizeFrame * @type boolean */ resizeFrame: true, /** * By default the frame is positioned exactly where the drag element is, so * we use the cursor offset provided by YAHOO.util.DD. Another option that works only if * you do not have constraints on the obj is to have the drag frame centered * around the cursor. Set centerFrame to true for this effect. * @property centerFrame * @type boolean */ centerFrame: false, /** * Creates the proxy element if it does not yet exist * @method createFrame */ createFrame: function() { var self=this, body=document.body; if (!body || !body.firstChild) { setTimeout( function() { self.createFrame(); }, 50 ); return; } var div=this.getDragEl(), Dom=YAHOO.util.Dom; if (!div) { div = document.createElement("div"); div.id = this.dragElId; var s = div.style; s.position = "absolute"; s.visibility = "hidden"; s.cursor = "move"; s.border = "2px solid #aaa"; s.zIndex = 999; s.height = "25px"; s.width = "25px"; var _data = document.createElement('div'); Dom.setStyle(_data, 'height', '100%'); Dom.setStyle(_data, 'width', '100%'); /** * If the proxy element has no background-color, then it is considered to the "transparent" by Internet Explorer. * Since it is "transparent" then the events pass through it to the iframe below. * So creating a "fake" div inside the proxy element and giving it a background-color, then setting it to an * opacity of 0, it appears to not be there, however IE still thinks that it is so the events never pass through. */ Dom.setStyle(_data, 'background-color', '#ccc'); Dom.setStyle(_data, 'opacity', '0'); div.appendChild(_data); // appendChild can blow up IE if invoked prior to the window load event // while rendering a table. It is possible there are other scenarios // that would cause this to happen as well. body.insertBefore(div, body.firstChild); } }, /** * Initialization for the drag frame element. Must be called in the * constructor of all subclasses * @method initFrame */ initFrame: function() { this.createFrame(); }, applyConfig: function() { YAHOO.util.DDProxy.superclass.applyConfig.call(this); this.resizeFrame = (this.config.resizeFrame !== false); this.centerFrame = (this.config.centerFrame); this.setDragElId(this.config.dragElId || YAHOO.util.DDProxy.dragElId); }, /** * Resizes the drag frame to the dimensions of the clicked object, positions * it over the object, and finally displays it * @method showFrame * @param {int} iPageX X click position * @param {int} iPageY Y click position * @private */ showFrame: function(iPageX, iPageY) { var el = this.getEl(); var dragEl = this.getDragEl(); var s = dragEl.style; this._resizeProxy(); if (this.centerFrame) { this.setDelta( Math.round(parseInt(s.width, 10)/2), Math.round(parseInt(s.height, 10)/2) ); } this.setDragElPos(iPageX, iPageY); YAHOO.util.Dom.setStyle(dragEl, "visibility", "visible"); }, /** * The proxy is automatically resized to the dimensions of the linked * element when a drag is initiated, unless resizeFrame is set to false * @method _resizeProxy * @private */ _resizeProxy: function() { if (this.resizeFrame) { var DOM = YAHOO.util.Dom; var el = this.getEl(); var dragEl = this.getDragEl(); var bt = parseInt( DOM.getStyle(dragEl, "borderTopWidth" ), 10); var br = parseInt( DOM.getStyle(dragEl, "borderRightWidth" ), 10); var bb = parseInt( DOM.getStyle(dragEl, "borderBottomWidth" ), 10); var bl = parseInt( DOM.getStyle(dragEl, "borderLeftWidth" ), 10); if (isNaN(bt)) { bt = 0; } if (isNaN(br)) { br = 0; } if (isNaN(bb)) { bb = 0; } if (isNaN(bl)) { bl = 0; } var newWidth = Math.max(0, el.offsetWidth - br - bl); var newHeight = Math.max(0, el.offsetHeight - bt - bb); DOM.setStyle( dragEl, "width", newWidth + "px" ); DOM.setStyle( dragEl, "height", newHeight + "px" ); } }, // overrides YAHOO.util.DragDrop b4MouseDown: function(e) { this.setStartPosition(); var x = YAHOO.util.Event.getPageX(e); var y = YAHOO.util.Event.getPageY(e); this.autoOffset(x, y); // This causes the autoscroll code to kick off, which means autoscroll can // happen prior to the check for a valid drag handle. // this.setDragElPos(x, y); }, // overrides YAHOO.util.DragDrop b4StartDrag: function(x, y) { // show the drag frame this.showFrame(x, y); }, // overrides YAHOO.util.DragDrop b4EndDrag: function(e) { YAHOO.util.Dom.setStyle(this.getDragEl(), "visibility", "hidden"); }, // overrides YAHOO.util.DragDrop // By default we try to move the element to the last location of the frame. // This is so that the default behavior mirrors that of YAHOO.util.DD. endDrag: function(e) { var DOM = YAHOO.util.Dom; var lel = this.getEl(); var del = this.getDragEl(); // Show the drag frame briefly so we can get its position // del.style.visibility = ""; DOM.setStyle(del, "visibility", ""); // Hide the linked element before the move to get around a Safari // rendering bug. //lel.style.visibility = "hidden"; DOM.setStyle(lel, "visibility", "hidden"); YAHOO.util.DDM.moveToEl(lel, del); //del.style.visibility = "hidden"; DOM.setStyle(del, "visibility", "hidden"); //lel.style.visibility = ""; DOM.setStyle(lel, "visibility", ""); }, toString: function() { return ("DDProxy " + this.id); } /** * @event mouseDownEvent * @description Provides access to the mousedown event. The mousedown does not always result in a drag operation. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4MouseDownEvent * @description Provides access to the mousedown event, before the mouseDownEvent gets fired. Returning false will cancel the drag. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event mouseUpEvent * @description Fired from inside DragDropMgr when the drag operation is finished. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4StartDragEvent * @description Fires before the startDragEvent, returning false will cancel the startDrag Event. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event startDragEvent * @description Occurs after a mouse down and the drag threshold has been met. The drag threshold default is either 3 pixels of mouse movement or 1 full second of holding the mousedown. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4EndDragEvent * @description Fires before the endDragEvent. Returning false will cancel. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event endDragEvent * @description Fires on the mouseup event after a drag has been initiated (startDrag fired). * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragEvent * @description Occurs every mousemove event while dragging. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4DragEvent * @description Fires before the dragEvent. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event invalidDropEvent * @description Fires when the dragged objects is dropped in a location that contains no drop targets. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4DragOutEvent * @description Fires before the dragOutEvent * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragOutEvent * @description Fires when a dragged object is no longer over an object that had the onDragEnter fire. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragEnterEvent * @description Occurs when the dragged object first interacts with another targettable drag and drop object. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4DragOverEvent * @description Fires before the dragOverEvent. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragOverEvent * @description Fires every mousemove event while over a drag and drop object. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event b4DragDropEvent * @description Fires before the dragDropEvent * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ /** * @event dragDropEvent * @description Fires when the dragged objects is dropped on another. * @type YAHOO.util.CustomEvent See Element.addListener for more information on listening for this event. */ }); /** * A DragDrop implementation that does not move, but can be a drop * target. You would get the same result by simply omitting implementation * for the event callbacks, but this way we reduce the processing cost of the * event listener and the callbacks. * @class DDTarget * @extends YAHOO.util.DragDrop * @constructor * @param {String} id the id of the element that is a drop target * @param {String} sGroup the group of related DragDrop objects * @param {object} config an object containing configurable attributes * Valid properties for DDTarget in addition to those in * DragDrop: * none */ YAHOO.util.DDTarget = function(id, sGroup, config) { if (id) { this.initTarget(id, sGroup, config); } }; // YAHOO.util.DDTarget.prototype = new YAHOO.util.DragDrop(); YAHOO.extend(YAHOO.util.DDTarget, YAHOO.util.DragDrop, { toString: function() { return ("DDTarget " + this.id); } }); YAHOO.register("dragdrop", YAHOO.util.DragDropMgr, {version: "2.7.0", build: "1799"}); /* Copyright (c) 2009, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 2.7.0 */ /** * Provides a mechanism to fetch remote resources and * insert them into a document * @module get * @requires yahoo */ /** * Fetches and inserts one or more script or link nodes into the document * @namespace YAHOO.util * @class YAHOO.util.Get */ YAHOO.util.Get = function() { /** * hash of queues to manage multiple requests * @property queues * @private */ var queues={}, /** * queue index used to generate transaction ids * @property qidx * @type int * @private */ qidx=0, /** * node index used to generate unique node ids * @property nidx * @type int * @private */ nidx=0, // ridx=0, // sandboxFrame=null, /** * interal property used to prevent multiple simultaneous purge * processes * @property purging * @type boolean * @private */ purging=false, ua=YAHOO.env.ua, lang=YAHOO.lang; /** * Generates an HTML element, this is not appended to a document * @method _node * @param type {string} the type of element * @param attr {string} the attributes * @param win {Window} optional window to create the element in * @return {HTMLElement} the generated node * @private */ var _node = function(type, attr, win) { var w = win || window, d=w.document, n=d.createElement(type); for (var i in attr) { if (attr[i] && YAHOO.lang.hasOwnProperty(attr, i)) { n.setAttribute(i, attr[i]); } } return n; }; /** * Generates a link node * @method _linkNode * @param url {string} the url for the css file * @param win {Window} optional window to create the node in * @return {HTMLElement} the generated node * @private */ var _linkNode = function(url, win, charset) { var c = charset || "utf-8"; return _node("link", { "id": "yui__dyn_" + (nidx++), "type": "text/css", "charset": c, "rel": "stylesheet", "href": url }, win); }; /** * Generates a script node * @method _scriptNode * @param url {string} the url for the script file * @param win {Window} optional window to create the node in * @return {HTMLElement} the generated node * @private */ var _scriptNode = function(url, win, charset) { var c = charset || "utf-8"; return _node("script", { "id": "yui__dyn_" + (nidx++), "type": "text/javascript", "charset": c, "src": url }, win); }; /** * Returns the data payload for callback functions * @method _returnData * @private */ var _returnData = function(q, msg) { return { tId: q.tId, win: q.win, data: q.data, nodes: q.nodes, msg: msg, purge: function() { _purge(this.tId); } }; }; var _get = function(nId, tId) { var q = queues[tId], n = (lang.isString(nId)) ? q.win.document.getElementById(nId) : nId; if (!n) { _fail(tId, "target node not found: " + nId); } return n; }; /* * The request failed, execute fail handler with whatever * was accomplished. There isn't a failure case at the * moment unless you count aborted transactions * @method _fail * @param id {string} the id of the request * @private */ var _fail = function(id, msg) { var q = queues[id]; // execute failure callback if (q.onFailure) { var sc=q.scope || q.win; q.onFailure.call(sc, _returnData(q, msg)); } }; /** * The request is complete, so executing the requester's callback * @method _finish * @param id {string} the id of the request * @private */ var _finish = function(id) { var q = queues[id]; q.finished = true; if (q.aborted) { var msg = "transaction " + id + " was aborted"; _fail(id, msg); return; } // execute success callback if (q.onSuccess) { var sc=q.scope || q.win; q.onSuccess.call(sc, _returnData(q)); } }; /** * Timeout detected * @method _timeout * @param id {string} the id of the request * @private */ var _timeout = function(id) { var q = queues[id]; if (q.onTimeout) { var sc=q.scope || q; q.onTimeout.call(sc, _returnData(q)); } }; /** * Loads the next item for a given request * @method _next * @param id {string} the id of the request * @param loaded {string} the url that was just loaded, if any * @private */ var _next = function(id, loaded) { var q = queues[id]; if (q.timer) { // Y.log('cancel timer'); q.timer.cancel(); } if (q.aborted) { var msg = "transaction " + id + " was aborted"; _fail(id, msg); return; } if (loaded) { q.url.shift(); if (q.varName) { q.varName.shift(); } } else { // This is the first pass: make sure the url is an array q.url = (lang.isString(q.url)) ? [q.url] : q.url; if (q.varName) { q.varName = (lang.isString(q.varName)) ? [q.varName] : q.varName; } } var w=q.win, d=w.document, h=d.getElementsByTagName("head")[0], n; if (q.url.length === 0) { // Safari 2.x workaround - There is no way to know when // a script is ready in versions of Safari prior to 3.x. // Adding an extra node reduces the problem, but doesn't // eliminate it completely because the browser executes // them asynchronously. if (q.type === "script" && ua.webkit && ua.webkit < 420 && !q.finalpass && !q.varName) { // Add another script node. This does not guarantee that the // scripts will execute in order, but it does appear to fix the // problem on fast connections more effectively than using an // arbitrary timeout. It is possible that the browser does // block subsequent script execution in this case for a limited // time. var extra = _scriptNode(null, q.win, q.charset); extra.innerHTML='YAHOO.util.Get._finalize("' + id + '");'; q.nodes.push(extra); h.appendChild(extra); } else { _finish(id); } return; } var url = q.url[0]; // if the url is undefined, this is probably a trailing comma problem in IE if (!url) { q.url.shift(); return _next(id); } if (q.timeout) { // Y.log('create timer'); q.timer = lang.later(q.timeout, q, _timeout, id); } if (q.type === "script") { n = _scriptNode(url, w, q.charset); } else { n = _linkNode(url, w, q.charset); } // track this node's load progress _track(q.type, n, id, url, w, q.url.length); // add the node to the queue so we can return it to the user supplied callback q.nodes.push(n); // add it to the head or insert it before 'insertBefore' if (q.insertBefore) { var s = _get(q.insertBefore, id); if (s) { s.parentNode.insertBefore(n, s); } } else { h.appendChild(n); } // FireFox does not support the onload event for link nodes, so there is // no way to make the css requests synchronous. This means that the css // rules in multiple files could be applied out of order in this browser // if a later request returns before an earlier one. Safari too. if ((ua.webkit || ua.gecko) && q.type === "css") { _next(id, url); } }; /** * Removes processed queues and corresponding nodes * @method _autoPurge * @private */ var _autoPurge = function() { if (purging) { return; } purging = true; for (var i in queues) { var q = queues[i]; if (q.autopurge && q.finished) { _purge(q.tId); delete queues[i]; } } purging = false; }; /** * Removes the nodes for the specified queue * @method _purge * @private */ var _purge = function(tId) { var q=queues[tId]; if (q) { var n=q.nodes, l=n.length, d=q.win.document, h=d.getElementsByTagName("head")[0]; if (q.insertBefore) { var s = _get(q.insertBefore, tId); if (s) { h = s.parentNode; } } for (var i=0; i= 420) { n.addEventListener("load", function() { f(id, url); }); // Nothing can be done with Safari < 3.x except to pause and hope // for the best, particularly after last script is inserted. The // scripts will always execute in the order they arrive, not // necessarily the order in which they were inserted. To support // script nodes with complete reliability in these browsers, script // nodes either need to invoke a function in the window once they // are loaded or the implementer needs to provide a well-known // property that the utility can poll for. } else { // Poll for the existence of the named variable, if it // was supplied. var q = queues[id]; if (q.varName) { var freq=YAHOO.util.Get.POLL_FREQ; q.maxattempts = YAHOO.util.Get.TIMEOUT/freq; q.attempts = 0; q._cache = q.varName[0].split("."); q.timer = lang.later(freq, q, function(o) { var a=this._cache, l=a.length, w=this.win, i; for (i=0; i this.maxattempts) { var msg = "Over retry limit, giving up"; q.timer.cancel(); _fail(id, msg); } else { } return; } } q.timer.cancel(); f(id, url); }, null, true); } else { lang.later(YAHOO.util.Get.POLL_FREQ, null, f, [id, url]); } } } // FireFox and Opera support onload (but not DOM2 in FF) handlers for // script nodes. Opera, but not FF, supports the onload event for link // nodes. } else { n.onload = function() { f(id, url); }; } }; return { /** * The default poll freqency in ms, when needed * @property POLL_FREQ * @static * @type int * @default 10 */ POLL_FREQ: 10, /** * The number of request required before an automatic purge. * property PURGE_THRESH * @static * @type int * @default 20 */ PURGE_THRESH: 20, /** * The length time to poll for varName when loading a script in * Safari 2.x before the transaction fails. * property TIMEOUT * @static * @type int * @default 2000 */ TIMEOUT: 2000, /** * Called by the the helper for detecting script load in Safari * @method _finalize * @param id {string} the transaction id * @private */ _finalize: function(id) { lang.later(0, null, _finish, id); }, /** * Abort a transaction * @method abort * @param {string|object} either the tId or the object returned from * script() or css() */ abort: function(o) { var id = (lang.isString(o)) ? o : o.tId; var q = queues[id]; if (q) { q.aborted = true; } }, /** * Fetches and inserts one or more script nodes into the head * of the current document or the document in a specified window. * * @method script * @static * @param url {string|string[]} the url or urls to the script(s) * @param opts {object} Options: *
    *
    onSuccess
    *
    * callback to execute when the script(s) are finished loading * The callback receives an object back with the following * data: *
    *
    win
    *
    the window the script(s) were inserted into
    *
    data
    *
    the data object passed in when the request was made
    *
    nodes
    *
    An array containing references to the nodes that were * inserted
    *
    purge
    *
    A function that, when executed, will remove the nodes * that were inserted
    *
    *
    *
    *
    onFailure
    *
    * callback to execute when the script load operation fails * The callback receives an object back with the following * data: *
    *
    win
    *
    the window the script(s) were inserted into
    *
    data
    *
    the data object passed in when the request was made
    *
    nodes
    *
    An array containing references to the nodes that were * inserted successfully
    *
    purge
    *
    A function that, when executed, will remove any nodes * that were inserted
    *
    *
    *
    *
    onTimeout
    *
    * callback to execute when a timeout occurs. * The callback receives an object back with the following * data: *
    *
    win
    *
    the window the script(s) were inserted into
    *
    data
    *
    the data object passed in when the request was made
    *
    nodes
    *
    An array containing references to the nodes that were * inserted
    *
    purge
    *
    A function that, when executed, will remove the nodes * that were inserted
    *
    *
    *
    *
    scope
    *
    the execution context for the callbacks
    *
    win
    *
    a window other than the one the utility occupies
    *
    autopurge
    *
    * setting to true will let the utilities cleanup routine purge * the script once loaded *
    *
    data
    *
    * data that is supplied to the callback when the script(s) are * loaded. *
    *
    varName
    *
    * variable that should be available when a script is finished * loading. Used to help Safari 2.x and below with script load * detection. The type of this property should match what was * passed into the url parameter: if loading a single url, a * string can be supplied. If loading multiple scripts, you * must supply an array that contains the variable name for * each script. *
    *
    insertBefore
    *
    node or node id that will become the new node's nextSibling
    *
    *
    charset
    *
    Node charset, default utf-8
    *
    timeout
    *
    Number of milliseconds to wait before aborting and firing the timeout event
    *
             * // assumes yahoo, dom, and event are already on the page
             *   YAHOO.util.Get.script(
             *   ["http://yui.yahooapis.com/2.3.1/build/dragdrop/dragdrop-min.js",
             *    "http://yui.yahooapis.com/2.3.1/build/animation/animation-min.js"], {
             *     onSuccess: function(o) {
             *       new YAHOO.util.DDProxy("dd1"); // also new o.reference("dd1"); would work
             *       this.log("won't cause error because YAHOO is the scope");
             *       this.log(o.nodes.length === 2) // true
             *       // o.purge(); // optionally remove the script nodes immediately
             *     },
             *     onFailure: function(o) {
             *     },
             *     data: "foo",
             *     timeout: 10000, // 10 second timeout
             *     scope: YAHOO,
             *     // win: otherframe // target another window/frame
             *     autopurge: true // allow the utility to choose when to remove the nodes
             *   });
             * 
    * @return {tId: string} an object containing info about the transaction */ script: function(url, opts) { return _queue("script", url, opts); }, /** * Fetches and inserts one or more css link nodes into the * head of the current document or the document in a specified * window. * @method css * @static * @param url {string} the url or urls to the css file(s) * @param opts Options: *
    *
    onSuccess
    *
    * callback to execute when the css file(s) are finished loading * The callback receives an object back with the following * data: *
    win
    *
    the window the link nodes(s) were inserted into
    *
    data
    *
    the data object passed in when the request was made
    *
    nodes
    *
    An array containing references to the nodes that were * inserted
    *
    purge
    *
    A function that, when executed, will remove the nodes * that were inserted
    *
    *
    * *
    scope
    *
    the execution context for the callbacks
    *
    win
    *
    a window other than the one the utility occupies
    *
    data
    *
    * data that is supplied to the callbacks when the nodes(s) are * loaded. *
    *
    insertBefore
    *
    node or node id that will become the new node's nextSibling
    *
    charset
    *
    Node charset, default utf-8
    * *
             *      YAHOO.util.Get.css("http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css");
             * 
    *
             *      YAHOO.util.Get.css(["http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css",
             * 
    * @return {tId: string} an object containing info about the transaction */ css: function(url, opts) { return _queue("css", url, opts); } }; }(); YAHOO.register("get", YAHOO.util.Get, {version: "2.7.0", build: "1799"}); /* Copyright (c) 2009, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 2.7.0 */ /** * Provides methods to parse JSON strings and convert objects to JSON strings. * @module json * @class JSON * @static */ YAHOO.lang.JSON = (function () { var l = YAHOO.lang, /** * Replace certain Unicode characters that JavaScript may handle incorrectly * during eval--either by deleting them or treating them as line * endings--with escape sequences. * IMPORTANT NOTE: This regex will be used to modify the input if a match is * found. * @property _UNICODE_EXCEPTIONS * @type {RegExp} * @private */ _UNICODE_EXCEPTIONS = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, /** * First step in the validation. Regex used to replace all escape * sequences (i.e. "\\", etc) with '@' characters (a non-JSON character). * @property _ESCAPES * @type {RegExp} * @static * @private */ _ESCAPES = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, /** * Second step in the validation. Regex used to replace all simple * values with ']' characters. * @property _VALUES * @type {RegExp} * @static * @private */ _VALUES = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, /** * Third step in the validation. Regex used to remove all open square * brackets following a colon, comma, or at the beginning of the string. * @property _BRACKETS * @type {RegExp} * @static * @private */ _BRACKETS = /(?:^|:|,)(?:\s*\[)+/g, /** * Final step in the validation. Regex used to test the string left after * all previous replacements for invalid characters. * @property _INVALID * @type {RegExp} * @static * @private */ _INVALID = /^[\],:{}\s]*$/, /** * Regex used to replace special characters in strings for JSON * stringification. * @property _SPECIAL_CHARS * @type {RegExp} * @static * @private */ _SPECIAL_CHARS = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, /** * Character substitution map for common escapes and special characters. * @property _CHARS * @type {Object} * @static * @private */ _CHARS = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\' }; /** * Traverses nested objects, applying a filter or reviver function to * each value. The value returned from the function will replace the * original value in the key:value pair. If the value returned is * undefined, the key will be omitted from the returned object. * @method _revive * @param data {MIXED} Any JavaScript data * @param reviver {Function} filter or mutation function * @return {MIXED} The results of the filtered/mutated data structure * @private */ function _revive(data, reviver) { var walk = function (o,key) { var k,v,value = o[key]; if (value && typeof value === 'object') { for (k in value) { if (l.hasOwnProperty(value,k)) { v = walk(value, k); if (v === undefined) { delete value[k]; } else { value[k] = v; } } } } return reviver.call(o,key,value); }; return typeof reviver === 'function' ? walk({'':data},'') : data; } /** * Escapes a special character to a safe Unicode representation * @method _char * @param c {String} single character to escape * @return {String} safe Unicode escape */ function _char(c) { if (!_CHARS[c]) { _CHARS[c] = '\\u'+('0000'+(+(c.charCodeAt(0))).toString(16)).slice(-4); } return _CHARS[c]; } /** * Replace certain Unicode characters that may be handled incorrectly by * some browser implementations. * @method _prepare * @param s {String} parse input * @return {String} sanitized JSON string ready to be validated/parsed * @private */ function _prepare(s) { return s.replace(_UNICODE_EXCEPTIONS, _char); } /** * Four step determination whether a string is valid JSON. In three steps, * escape sequences, safe values, and properly placed open square brackets * are replaced with placeholders or removed. Then in the final step, the * result of all these replacements is checked for invalid characters. * @method _isValid * @param str {String} JSON string to be tested * @return {boolean} is the string safe for eval? * @static */ function _isValid(str) { return l.isString(str) && _INVALID.test(str. replace(_ESCAPES,'@'). replace(_VALUES,']'). replace(_BRACKETS,'')); } /** * Enclose escaped strings in quotes * @method _string * @param s {String} string to wrap * @return {String} '"'+s+'"' after s has had special characters escaped * @private */ function _string(s) { return '"' + s.replace(_SPECIAL_CHARS, _char) + '"'; } /** * Worker function used by public stringify. * @method _stringify * @param h {Object} object holding the key * @param key {String} String key in object h to serialize * @param depth {Number} depth to serialize * @param w {Array|Function} array of whitelisted keys OR replacer function * @param pstack {Array} used to protect against recursion * @return {String} serialized version of o */ function _stringify(h,key,d,w,pstack) { var o = typeof w === 'function' ? w.call(h,key,h[key]) : h[key], i,len,j, // array iteration k,v, // object iteration isArray, // forking in typeof 'object' a; // composition array for performance over string concat if (o instanceof Date) { o = l.JSON.dateToString(o); } else if (o instanceof String || o instanceof Boolean || o instanceof Number) { o = o.valueOf(); } switch (typeof o) { case 'string' : return _string(o); case 'number' : return isFinite(o) ? String(o) : 'null'; case 'boolean': return String(o); case 'object' : // null if (o === null) { return 'null'; } // Check for cyclical references for (i = pstack.length - 1; i >= 0; --i) { if (pstack[i] === o) { return 'null'; } } // Add the object to the processing stack pstack[pstack.length] = o; a = []; isArray = l.isArray(o); // Only recurse if we're above depth config if (d > 0) { // Array if (isArray) { for (i = o.length - 1; i >= 0; --i) { a[i] = _stringify(o,i,d-1,w,pstack) || 'null'; } // Object } else { j = 0; // Use whitelist keys if provided as an array if (l.isArray(w)) { for (i = 0, len = w.length; i < len; ++i) { k = w[i]; v = _stringify(o,k,d-1,w,pstack); if (v) { a[j++] = _string(k) + ':' + v; } } } else { for (k in o) { if (typeof k === 'string' && l.hasOwnProperty(o,k)) { v = _stringify(o,k,d-1,w,pstack); if (v) { a[j++] = _string(k) + ':' + v; } } } } // sort object keys for easier readability a.sort(); } } // remove the object from the stack pstack.pop(); return isArray ? '['+a.join(',')+']' : '{'+a.join(',')+'}'; } return undefined; // invalid input } // Return the public API return { /** * Four step determination whether a string is valid JSON. In three steps, * escape sequences, safe values, and properly placed open square brackets * are replaced with placeholders or removed. Then in the final step, the * result of all these replacements is checked for invalid characters. * @method isValid * @param str {String} JSON string to be tested * @return {boolean} is the string safe for eval? * @static */ isValid : function (s) { return _isValid(_prepare(s)); }, /** * Parse a JSON string, returning the native JavaScript representation. * Only minor modifications from http://www.json.org/json2.js. * @param s {string} JSON string data * @param reviver {function} (optional) function(k,v) passed each key:value * pair of object literals, allowing pruning or altering values * @return {MIXED} the native JavaScript representation of the JSON string * @throws SyntaxError * @method parse * @static */ parse : function (s,reviver) { // sanitize s = _prepare(s); // Ensure valid JSON if (_isValid(s)) { // Eval the text into a JavaScript data structure, apply the // reviver function if provided, and return return _revive( eval('(' + s + ')'), reviver ); } // The text is not valid JSON throw new SyntaxError('parseJSON'); }, /** * Converts an arbitrary value to a JSON string representation. * Cyclical object or array references are replaced with null. * If a whitelist is provided, only matching object keys will be included. * If a depth limit is provided, objects and arrays at that depth will * be stringified as empty. * @method stringify * @param o {MIXED} any arbitrary object to convert to JSON string * @param w {Array|Function} (optional) whitelist of acceptable object keys to include OR a function(value,key) to alter values before serialization * @param d {number} (optional) depth limit to recurse objects/arrays (practical minimum 1) * @return {string} JSON string representation of the input * @static */ stringify : function (o,w,d) { if (o !== undefined) { // Ensure whitelist keys are unique (bug 2110391) if (l.isArray(w)) { w = (function (a) { var uniq=[],map={},v,i,j,len; for (i=0,j=0,len=a.length; i= 0 ? d : 1/0; // process the input return _stringify({'':o},'',d,w,[]); } return undefined; }, /** * Serializes a Date instance as a UTC date string. Used internally by * stringify. Override this method if you need Dates serialized in a * different format. * @method dateToString * @param d {Date} The Date to serialize * @return {String} stringified Date in UTC format YYYY-MM-DDTHH:mm:SSZ * @static */ dateToString : function (d) { function _zeroPad(v) { return v < 10 ? '0' + v : v; } return d.getUTCFullYear() + '-' + _zeroPad(d.getUTCMonth() + 1) + '-' + _zeroPad(d.getUTCDate()) + 'T' + _zeroPad(d.getUTCHours()) + ':' + _zeroPad(d.getUTCMinutes()) + ':' + _zeroPad(d.getUTCSeconds()) + 'Z'; }, /** * Reconstitute Date instances from the default JSON UTC serialization. * Reference this from a reviver function to rebuild Dates during the * parse operation. * @method stringToDate * @param str {String} String serialization of a Date * @return {Date} */ stringToDate : function (str) { if (/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/.test(str)) { var d = new Date(); d.setUTCFullYear(RegExp.$1, (RegExp.$2|0)-1, RegExp.$3); d.setUTCHours(RegExp.$4, RegExp.$5, RegExp.$6); return d; } return str; } }; })(); YAHOO.register("json", YAHOO.lang.JSON, {version: "2.7.0", build: "1799"}); /* Copyright (c) 2009, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 2.7.0 */ (function () { /** * Config is a utility used within an Object to allow the implementer to * maintain a list of local configuration properties and listen for changes * to those properties dynamically using CustomEvent. The initial values are * also maintained so that the configuration can be reset at any given point * to its initial state. * @namespace YAHOO.util * @class Config * @constructor * @param {Object} owner The owner Object to which this Config Object belongs */ YAHOO.util.Config = function (owner) { if (owner) { this.init(owner); } }; var Lang = YAHOO.lang, CustomEvent = YAHOO.util.CustomEvent, Config = YAHOO.util.Config; /** * Constant representing the CustomEvent type for the config changed event. * @property YAHOO.util.Config.CONFIG_CHANGED_EVENT * @private * @static * @final */ Config.CONFIG_CHANGED_EVENT = "configChanged"; /** * Constant representing the boolean type string * @property YAHOO.util.Config.BOOLEAN_TYPE * @private * @static * @final */ Config.BOOLEAN_TYPE = "boolean"; Config.prototype = { /** * Object reference to the owner of this Config Object * @property owner * @type Object */ owner: null, /** * Boolean flag that specifies whether a queue is currently * being executed * @property queueInProgress * @type Boolean */ queueInProgress: false, /** * Maintains the local collection of configuration property objects and * their specified values * @property config * @private * @type Object */ config: null, /** * Maintains the local collection of configuration property objects as * they were initially applied. * This object is used when resetting a property. * @property initialConfig * @private * @type Object */ initialConfig: null, /** * Maintains the local, normalized CustomEvent queue * @property eventQueue * @private * @type Object */ eventQueue: null, /** * Custom Event, notifying subscribers when Config properties are set * (setProperty is called without the silent flag * @event configChangedEvent */ configChangedEvent: null, /** * Initializes the configuration Object and all of its local members. * @method init * @param {Object} owner The owner Object to which this Config * Object belongs */ init: function (owner) { this.owner = owner; this.configChangedEvent = this.createEvent(Config.CONFIG_CHANGED_EVENT); this.configChangedEvent.signature = CustomEvent.LIST; this.queueInProgress = false; this.config = {}; this.initialConfig = {}; this.eventQueue = []; }, /** * Validates that the value passed in is a Boolean. * @method checkBoolean * @param {Object} val The value to validate * @return {Boolean} true, if the value is valid */ checkBoolean: function (val) { return (typeof val == Config.BOOLEAN_TYPE); }, /** * Validates that the value passed in is a number. * @method checkNumber * @param {Object} val The value to validate * @return {Boolean} true, if the value is valid */ checkNumber: function (val) { return (!isNaN(val)); }, /** * Fires a configuration property event using the specified value. * @method fireEvent * @private * @param {String} key The configuration property's name * @param {value} Object The value of the correct type for the property */ fireEvent: function ( key, value ) { var property = this.config[key]; if (property && property.event) { property.event.fire(value); } }, /** * Adds a property to the Config Object's private config hash. * @method addProperty * @param {String} key The configuration property's name * @param {Object} propertyObject The Object containing all of this * property's arguments */ addProperty: function ( key, propertyObject ) { key = key.toLowerCase(); this.config[key] = propertyObject; propertyObject.event = this.createEvent(key, { scope: this.owner }); propertyObject.event.signature = CustomEvent.LIST; propertyObject.key = key; if (propertyObject.handler) { propertyObject.event.subscribe(propertyObject.handler, this.owner); } this.setProperty(key, propertyObject.value, true); if (! propertyObject.suppressEvent) { this.queueProperty(key, propertyObject.value); } }, /** * Returns a key-value configuration map of the values currently set in * the Config Object. * @method getConfig * @return {Object} The current config, represented in a key-value map */ getConfig: function () { var cfg = {}, currCfg = this.config, prop, property; for (prop in currCfg) { if (Lang.hasOwnProperty(currCfg, prop)) { property = currCfg[prop]; if (property && property.event) { cfg[prop] = property.value; } } } return cfg; }, /** * Returns the value of specified property. * @method getProperty * @param {String} key The name of the property * @return {Object} The value of the specified property */ getProperty: function (key) { var property = this.config[key.toLowerCase()]; if (property && property.event) { return property.value; } else { return undefined; } }, /** * Resets the specified property's value to its initial value. * @method resetProperty * @param {String} key The name of the property * @return {Boolean} True is the property was reset, false if not */ resetProperty: function (key) { key = key.toLowerCase(); var property = this.config[key]; if (property && property.event) { if (this.initialConfig[key] && !Lang.isUndefined(this.initialConfig[key])) { this.setProperty(key, this.initialConfig[key]); return true; } } else { return false; } }, /** * Sets the value of a property. If the silent property is passed as * true, the property's event will not be fired. * @method setProperty * @param {String} key The name of the property * @param {String} value The value to set the property to * @param {Boolean} silent Whether the value should be set silently, * without firing the property event. * @return {Boolean} True, if the set was successful, false if it failed. */ setProperty: function (key, value, silent) { var property; key = key.toLowerCase(); if (this.queueInProgress && ! silent) { // Currently running through a queue... this.queueProperty(key,value); return true; } else { property = this.config[key]; if (property && property.event) { if (property.validator && !property.validator(value)) { return false; } else { property.value = value; if (! silent) { this.fireEvent(key, value); this.configChangedEvent.fire([key, value]); } return true; } } else { return false; } } }, /** * Sets the value of a property and queues its event to execute. If the * event is already scheduled to execute, it is * moved from its current position to the end of the queue. * @method queueProperty * @param {String} key The name of the property * @param {String} value The value to set the property to * @return {Boolean} true, if the set was successful, false if * it failed. */ queueProperty: function (key, value) { key = key.toLowerCase(); var property = this.config[key], foundDuplicate = false, iLen, queueItem, queueItemKey, queueItemValue, sLen, supercedesCheck, qLen, queueItemCheck, queueItemCheckKey, queueItemCheckValue, i, s, q; if (property && property.event) { if (!Lang.isUndefined(value) && property.validator && !property.validator(value)) { // validator return false; } else { if (!Lang.isUndefined(value)) { property.value = value; } else { value = property.value; } foundDuplicate = false; iLen = this.eventQueue.length; for (i = 0; i < iLen; i++) { queueItem = this.eventQueue[i]; if (queueItem) { queueItemKey = queueItem[0]; queueItemValue = queueItem[1]; if (queueItemKey == key) { /* found a dupe... push to end of queue, null current item, and break */ this.eventQueue[i] = null; this.eventQueue.push( [key, (!Lang.isUndefined(value) ? value : queueItemValue)]); foundDuplicate = true; break; } } } // this is a refire, or a new property in the queue if (! foundDuplicate && !Lang.isUndefined(value)) { this.eventQueue.push([key, value]); } } if (property.supercedes) { sLen = property.supercedes.length; for (s = 0; s < sLen; s++) { supercedesCheck = property.supercedes[s]; qLen = this.eventQueue.length; for (q = 0; q < qLen; q++) { queueItemCheck = this.eventQueue[q]; if (queueItemCheck) { queueItemCheckKey = queueItemCheck[0]; queueItemCheckValue = queueItemCheck[1]; if (queueItemCheckKey == supercedesCheck.toLowerCase() ) { this.eventQueue.push([queueItemCheckKey, queueItemCheckValue]); this.eventQueue[q] = null; break; } } } } } return true; } else { return false; } }, /** * Fires the event for a property using the property's current value. * @method refireEvent * @param {String} key The name of the property */ refireEvent: function (key) { key = key.toLowerCase(); var property = this.config[key]; if (property && property.event && !Lang.isUndefined(property.value)) { if (this.queueInProgress) { this.queueProperty(key); } else { this.fireEvent(key, property.value); } } }, /** * Applies a key-value Object literal to the configuration, replacing * any existing values, and queueing the property events. * Although the values will be set, fireQueue() must be called for their * associated events to execute. * @method applyConfig * @param {Object} userConfig The configuration Object literal * @param {Boolean} init When set to true, the initialConfig will * be set to the userConfig passed in, so that calling a reset will * reset the properties to the passed values. */ applyConfig: function (userConfig, init) { var sKey, oConfig; if (init) { oConfig = {}; for (sKey in userConfig) { if (Lang.hasOwnProperty(userConfig, sKey)) { oConfig[sKey.toLowerCase()] = userConfig[sKey]; } } this.initialConfig = oConfig; } for (sKey in userConfig) { if (Lang.hasOwnProperty(userConfig, sKey)) { this.queueProperty(sKey, userConfig[sKey]); } } }, /** * Refires the events for all configuration properties using their * current values. * @method refresh */ refresh: function () { var prop; for (prop in this.config) { if (Lang.hasOwnProperty(this.config, prop)) { this.refireEvent(prop); } } }, /** * Fires the normalized list of queued property change events * @method fireQueue */ fireQueue: function () { var i, queueItem, key, value, property; this.queueInProgress = true; for (i = 0;i < this.eventQueue.length; i++) { queueItem = this.eventQueue[i]; if (queueItem) { key = queueItem[0]; value = queueItem[1]; property = this.config[key]; property.value = value; // Clear out queue entry, to avoid it being // re-added to the queue by any queueProperty/supercedes // calls which are invoked during fireEvent this.eventQueue[i] = null; this.fireEvent(key,value); } } this.queueInProgress = false; this.eventQueue = []; }, /** * Subscribes an external handler to the change event for any * given property. * @method subscribeToConfigEvent * @param {String} key The property name * @param {Function} handler The handler function to use subscribe to * the property's event * @param {Object} obj The Object to use for scoping the event handler * (see CustomEvent documentation) * @param {Boolean} override Optional. If true, will override "this" * within the handler to map to the scope Object passed into the method. * @return {Boolean} True, if the subscription was successful, * otherwise false. */ subscribeToConfigEvent: function (key, handler, obj, override) { var property = this.config[key.toLowerCase()]; if (property && property.event) { if (!Config.alreadySubscribed(property.event, handler, obj)) { property.event.subscribe(handler, obj, override); } return true; } else { return false; } }, /** * Unsubscribes an external handler from the change event for any * given property. * @method unsubscribeFromConfigEvent * @param {String} key The property name * @param {Function} handler The handler function to use subscribe to * the property's event * @param {Object} obj The Object to use for scoping the event * handler (see CustomEvent documentation) * @return {Boolean} True, if the unsubscription was successful, * otherwise false. */ unsubscribeFromConfigEvent: function (key, handler, obj) { var property = this.config[key.toLowerCase()]; if (property && property.event) { return property.event.unsubscribe(handler, obj); } else { return false; } }, /** * Returns a string representation of the Config object * @method toString * @return {String} The Config object in string format. */ toString: function () { var output = "Config"; if (this.owner) { output += " [" + this.owner.toString() + "]"; } return output; }, /** * Returns a string representation of the Config object's current * CustomEvent queue * @method outputEventQueue * @return {String} The string list of CustomEvents currently queued * for execution */ outputEventQueue: function () { var output = "", queueItem, q, nQueue = this.eventQueue.length; for (q = 0; q < nQueue; q++) { queueItem = this.eventQueue[q]; if (queueItem) { output += queueItem[0] + "=" + queueItem[1] + ", "; } } return output; }, /** * Sets all properties to null, unsubscribes all listeners from each * property's change event and all listeners from the configChangedEvent. * @method destroy */ destroy: function () { var oConfig = this.config, sProperty, oProperty; for (sProperty in oConfig) { if (Lang.hasOwnProperty(oConfig, sProperty)) { oProperty = oConfig[sProperty]; oProperty.event.unsubscribeAll(); oProperty.event = null; } } this.configChangedEvent.unsubscribeAll(); this.configChangedEvent = null; this.owner = null; this.config = null; this.initialConfig = null; this.eventQueue = null; } }; /** * Checks to determine if a particular function/Object pair are already * subscribed to the specified CustomEvent * @method YAHOO.util.Config.alreadySubscribed * @static * @param {YAHOO.util.CustomEvent} evt The CustomEvent for which to check * the subscriptions * @param {Function} fn The function to look for in the subscribers list * @param {Object} obj The execution scope Object for the subscription * @return {Boolean} true, if the function/Object pair is already subscribed * to the CustomEvent passed in */ Config.alreadySubscribed = function (evt, fn, obj) { var nSubscribers = evt.subscribers.length, subsc, i; if (nSubscribers > 0) { i = nSubscribers - 1; do { subsc = evt.subscribers[i]; if (subsc && subsc.obj == obj && subsc.fn == fn) { return true; } } while (i--); } return false; }; YAHOO.lang.augmentProto(Config, YAHOO.util.EventProvider); }()); /** * YAHOO.widget.DateMath is used for simple date manipulation. The class is a static utility * used for adding, subtracting, and comparing dates. * @namespace YAHOO.widget * @class DateMath */ YAHOO.widget.DateMath = { /** * Constant field representing Day * @property DAY * @static * @final * @type String */ DAY : "D", /** * Constant field representing Week * @property WEEK * @static * @final * @type String */ WEEK : "W", /** * Constant field representing Year * @property YEAR * @static * @final * @type String */ YEAR : "Y", /** * Constant field representing Month * @property MONTH * @static * @final * @type String */ MONTH : "M", /** * Constant field representing one day, in milliseconds * @property ONE_DAY_MS * @static * @final * @type Number */ ONE_DAY_MS : 1000*60*60*24, /** * Constant field representing the date in first week of January * which identifies the first week of the year. *

    * In the U.S, Jan 1st is normally used based on a Sunday start of week. * ISO 8601, used widely throughout Europe, uses Jan 4th, based on a Monday start of week. *

    * @property WEEK_ONE_JAN_DATE * @static * @type Number */ WEEK_ONE_JAN_DATE : 1, /** * Adds the specified amount of time to the this instance. * @method add * @param {Date} date The JavaScript Date object to perform addition on * @param {String} field The field constant to be used for performing addition. * @param {Number} amount The number of units (measured in the field constant) to add to the date. * @return {Date} The resulting Date object */ add : function(date, field, amount) { var d = new Date(date.getTime()); switch (field) { case this.MONTH: var newMonth = date.getMonth() + amount; var years = 0; if (newMonth < 0) { while (newMonth < 0) { newMonth += 12; years -= 1; } } else if (newMonth > 11) { while (newMonth > 11) { newMonth -= 12; years += 1; } } d.setMonth(newMonth); d.setFullYear(date.getFullYear() + years); break; case this.DAY: this._addDays(d, amount); // d.setDate(date.getDate() + amount); break; case this.YEAR: d.setFullYear(date.getFullYear() + amount); break; case this.WEEK: this._addDays(d, (amount * 7)); // d.setDate(date.getDate() + (amount * 7)); break; } return d; }, /** * Private helper method to account for bug in Safari 2 (webkit < 420) * when Date.setDate(n) is called with n less than -128 or greater than 127. *

    * Fix approach and original findings are available here: * http://brianary.blogspot.com/2006/03/safari-date-bug.html *

    * @method _addDays * @param {Date} d JavaScript date object * @param {Number} nDays The number of days to add to the date object (can be negative) * @private */ _addDays : function(d, nDays) { if (YAHOO.env.ua.webkit && YAHOO.env.ua.webkit < 420) { if (nDays < 0) { // Ensure we don't go below -128 (getDate() is always 1 to 31, so we won't go above 127) for(var min = -128; nDays < min; nDays -= min) { d.setDate(d.getDate() + min); } } else { // Ensure we don't go above 96 + 31 = 127 for(var max = 96; nDays > max; nDays -= max) { d.setDate(d.getDate() + max); } } // nDays should be remainder between -128 and 96 } d.setDate(d.getDate() + nDays); }, /** * Subtracts the specified amount of time from the this instance. * @method subtract * @param {Date} date The JavaScript Date object to perform subtraction on * @param {Number} field The this field constant to be used for performing subtraction. * @param {Number} amount The number of units (measured in the field constant) to subtract from the date. * @return {Date} The resulting Date object */ subtract : function(date, field, amount) { return this.add(date, field, (amount*-1)); }, /** * Determines whether a given date is before another date on the calendar. * @method before * @param {Date} date The Date object to compare with the compare argument * @param {Date} compareTo The Date object to use for the comparison * @return {Boolean} true if the date occurs before the compared date; false if not. */ before : function(date, compareTo) { var ms = compareTo.getTime(); if (date.getTime() < ms) { return true; } else { return false; } }, /** * Determines whether a given date is after another date on the calendar. * @method after * @param {Date} date The Date object to compare with the compare argument * @param {Date} compareTo The Date object to use for the comparison * @return {Boolean} true if the date occurs after the compared date; false if not. */ after : function(date, compareTo) { var ms = compareTo.getTime(); if (date.getTime() > ms) { return true; } else { return false; } }, /** * Determines whether a given date is between two other dates on the calendar. * @method between * @param {Date} date The date to check for * @param {Date} dateBegin The start of the range * @param {Date} dateEnd The end of the range * @return {Boolean} true if the date occurs between the compared dates; false if not. */ between : function(date, dateBegin, dateEnd) { if (this.after(date, dateBegin) && this.before(date, dateEnd)) { return true; } else { return false; } }, /** * Retrieves a JavaScript Date object representing January 1 of any given year. * @method getJan1 * @param {Number} calendarYear The calendar year for which to retrieve January 1 * @return {Date} January 1 of the calendar year specified. */ getJan1 : function(calendarYear) { return this.getDate(calendarYear,0,1); }, /** * Calculates the number of days the specified date is from January 1 of the specified calendar year. * Passing January 1 to this function would return an offset value of zero. * @method getDayOffset * @param {Date} date The JavaScript date for which to find the offset * @param {Number} calendarYear The calendar year to use for determining the offset * @return {Number} The number of days since January 1 of the given year */ getDayOffset : function(date, calendarYear) { var beginYear = this.getJan1(calendarYear); // Find the start of the year. This will be in week 1. // Find the number of days the passed in date is away from the calendar year start var dayOffset = Math.ceil((date.getTime()-beginYear.getTime()) / this.ONE_DAY_MS); return dayOffset; }, /** * Calculates the week number for the given date. Can currently support standard * U.S. week numbers, based on Jan 1st defining the 1st week of the year, and * ISO8601 week numbers, based on Jan 4th defining the 1st week of the year. * * @method getWeekNumber * @param {Date} date The JavaScript date for which to find the week number * @param {Number} firstDayOfWeek The index of the first day of the week (0 = Sun, 1 = Mon ... 6 = Sat). * Defaults to 0 * @param {Number} janDate The date in the first week of January which defines week one for the year * Defaults to the value of YAHOO.widget.DateMath.WEEK_ONE_JAN_DATE, which is 1 (Jan 1st). * For the U.S, this is normally Jan 1st. ISO8601 uses Jan 4th to define the first week of the year. * * @return {Number} The number of the week containing the given date. */ getWeekNumber : function(date, firstDayOfWeek, janDate) { // Setup Defaults firstDayOfWeek = firstDayOfWeek || 0; janDate = janDate || this.WEEK_ONE_JAN_DATE; var targetDate = this.clearTime(date), startOfWeek, endOfWeek; if (targetDate.getDay() === firstDayOfWeek) { startOfWeek = targetDate; } else { startOfWeek = this.getFirstDayOfWeek(targetDate, firstDayOfWeek); } var startYear = startOfWeek.getFullYear(), startTime = startOfWeek.getTime(); // DST shouldn't be a problem here, math is quicker than setDate(); endOfWeek = new Date(startOfWeek.getTime() + 6*this.ONE_DAY_MS); var weekNum; if (startYear !== endOfWeek.getFullYear() && endOfWeek.getDate() >= janDate) { // If years don't match, endOfWeek is in Jan. and if the // week has WEEK_ONE_JAN_DATE in it, it's week one by definition. weekNum = 1; } else { // Get the 1st day of the 1st week, and // find how many days away we are from it. var weekOne = this.clearTime(this.getDate(startYear, 0, janDate)), weekOneDayOne = this.getFirstDayOfWeek(weekOne, firstDayOfWeek); // Round days to smoothen out 1 hr DST diff var daysDiff = Math.round((targetDate.getTime() - weekOneDayOne.getTime())/this.ONE_DAY_MS); // Calc. Full Weeks var rem = daysDiff % 7; var weeksDiff = (daysDiff - rem)/7; weekNum = weeksDiff + 1; } return weekNum; }, /** * Get the first day of the week, for the give date. * @param {Date} dt The date in the week for which the first day is required. * @param {Number} startOfWeek The index for the first day of the week, 0 = Sun, 1 = Mon ... 6 = Sat (defaults to 0) * @return {Date} The first day of the week */ getFirstDayOfWeek : function (dt, startOfWeek) { startOfWeek = startOfWeek || 0; var dayOfWeekIndex = dt.getDay(), dayOfWeek = (dayOfWeekIndex - startOfWeek + 7) % 7; return this.subtract(dt, this.DAY, dayOfWeek); }, /** * Determines if a given week overlaps two different years. * @method isYearOverlapWeek * @param {Date} weekBeginDate The JavaScript Date representing the first day of the week. * @return {Boolean} true if the date overlaps two different years. */ isYearOverlapWeek : function(weekBeginDate) { var overlaps = false; var nextWeek = this.add(weekBeginDate, this.DAY, 6); if (nextWeek.getFullYear() != weekBeginDate.getFullYear()) { overlaps = true; } return overlaps; }, /** * Determines if a given week overlaps two different months. * @method isMonthOverlapWeek * @param {Date} weekBeginDate The JavaScript Date representing the first day of the week. * @return {Boolean} true if the date overlaps two different months. */ isMonthOverlapWeek : function(weekBeginDate) { var overlaps = false; var nextWeek = this.add(weekBeginDate, this.DAY, 6); if (nextWeek.getMonth() != weekBeginDate.getMonth()) { overlaps = true; } return overlaps; }, /** * Gets the first day of a month containing a given date. * @method findMonthStart * @param {Date} date The JavaScript Date used to calculate the month start * @return {Date} The JavaScript Date representing the first day of the month */ findMonthStart : function(date) { var start = this.getDate(date.getFullYear(), date.getMonth(), 1); return start; }, /** * Gets the last day of a month containing a given date. * @method findMonthEnd * @param {Date} date The JavaScript Date used to calculate the month end * @return {Date} The JavaScript Date representing the last day of the month */ findMonthEnd : function(date) { var start = this.findMonthStart(date); var nextMonth = this.add(start, this.MONTH, 1); var end = this.subtract(nextMonth, this.DAY, 1); return end; }, /** * Clears the time fields from a given date, effectively setting the time to 12 noon. * @method clearTime * @param {Date} date The JavaScript Date for which the time fields will be cleared * @return {Date} The JavaScript Date cleared of all time fields */ clearTime : function(date) { date.setHours(12,0,0,0); return date; }, /** * Returns a new JavaScript Date object, representing the given year, month and date. Time fields (hr, min, sec, ms) on the new Date object * are set to 0. The method allows Date instances to be created with the a year less than 100. "new Date(year, month, date)" implementations * set the year to 19xx if a year (xx) which is less than 100 is provided. *

    * NOTE:Validation on argument values is not performed. It is the caller's responsibility to ensure * arguments are valid as per the ECMAScript-262 Date object specification for the new Date(year, month[, date]) constructor. *

    * @method getDate * @param {Number} y Year. * @param {Number} m Month index from 0 (Jan) to 11 (Dec). * @param {Number} d (optional) Date from 1 to 31. If not provided, defaults to 1. * @return {Date} The JavaScript date object with year, month, date set as provided. */ getDate : function(y, m, d) { var dt = null; if (YAHOO.lang.isUndefined(d)) { d = 1; } if (y >= 100) { dt = new Date(y, m, d); } else { dt = new Date(); dt.setFullYear(y); dt.setMonth(m); dt.setDate(d); dt.setHours(0,0,0,0); } return dt; } }; /** * The Calendar component is a UI control that enables users to choose one or more dates from a graphical calendar presented in a one-month or * multi-month interface. Calendars are generated entirely via script and can be navigated without any page refreshes. * @module calendar * @title Calendar * @namespace YAHOO.widget * @requires yahoo,dom,event */ (function(){ var Dom = YAHOO.util.Dom, Event = YAHOO.util.Event, Lang = YAHOO.lang, DateMath = YAHOO.widget.DateMath; /** * Calendar is the base class for the Calendar widget. In its most basic * implementation, it has the ability to render a calendar widget on the page * that can be manipulated to select a single date, move back and forth between * months and years. *

    To construct the placeholder for the calendar widget, the code is as * follows: *

    * <div id="calContainer"></div> * *

    *

    * NOTE: As of 2.4.0, the constructor's ID argument is optional. * The Calendar can be constructed by simply providing a container ID string, * or a reference to a container DIV HTMLElement (the element needs to exist * in the document). * * E.g.: *

    * var c = new YAHOO.widget.Calendar("calContainer", configOptions); * * or: * * var containerDiv = YAHOO.util.Dom.get("calContainer"); * var c = new YAHOO.widget.Calendar(containerDiv, configOptions); * *

    *

    * If not provided, the ID will be generated from the container DIV ID by adding an "_t" suffix. * For example if an ID is not provided, and the container's ID is "calContainer", the Calendar's ID will be set to "calContainer_t". *

    * * @namespace YAHOO.widget * @class Calendar * @constructor * @param {String} id optional The id of the table element that will represent the Calendar widget. As of 2.4.0, this argument is optional. * @param {String | HTMLElement} container The id of the container div element that will wrap the Calendar table, or a reference to a DIV element which exists in the document. * @param {Object} config optional The configuration object containing the initial configuration values for the Calendar. */ function Calendar(id, containerId, config) { this.init.apply(this, arguments); } /** * The path to be used for images loaded for the Calendar * @property YAHOO.widget.Calendar.IMG_ROOT * @static * @deprecated You can now customize images by overriding the calclose, calnavleft and calnavright default CSS classes for the close icon, left arrow and right arrow respectively * @type String */ Calendar.IMG_ROOT = null; /** * Type constant used for renderers to represent an individual date (M/D/Y) * @property YAHOO.widget.Calendar.DATE * @static * @final * @type String */ Calendar.DATE = "D"; /** * Type constant used for renderers to represent an individual date across any year (M/D) * @property YAHOO.widget.Calendar.MONTH_DAY * @static * @final * @type String */ Calendar.MONTH_DAY = "MD"; /** * Type constant used for renderers to represent a weekday * @property YAHOO.widget.Calendar.WEEKDAY * @static * @final * @type String */ Calendar.WEEKDAY = "WD"; /** * Type constant used for renderers to represent a range of individual dates (M/D/Y-M/D/Y) * @property YAHOO.widget.Calendar.RANGE * @static * @final * @type String */ Calendar.RANGE = "R"; /** * Type constant used for renderers to represent a month across any year * @property YAHOO.widget.Calendar.MONTH * @static * @final * @type String */ Calendar.MONTH = "M"; /** * Constant that represents the total number of date cells that are displayed in a given month * @property YAHOO.widget.Calendar.DISPLAY_DAYS * @static * @final * @type Number */ Calendar.DISPLAY_DAYS = 42; /** * Constant used for halting the execution of the remainder of the render stack * @property YAHOO.widget.Calendar.STOP_RENDER * @static * @final * @type String */ Calendar.STOP_RENDER = "S"; /** * Constant used to represent short date field string formats (e.g. Tu or Feb) * @property YAHOO.widget.Calendar.SHORT * @static * @final * @type String */ Calendar.SHORT = "short"; /** * Constant used to represent long date field string formats (e.g. Monday or February) * @property YAHOO.widget.Calendar.LONG * @static * @final * @type String */ Calendar.LONG = "long"; /** * Constant used to represent medium date field string formats (e.g. Mon) * @property YAHOO.widget.Calendar.MEDIUM * @static * @final * @type String */ Calendar.MEDIUM = "medium"; /** * Constant used to represent single character date field string formats (e.g. M, T, W) * @property YAHOO.widget.Calendar.ONE_CHAR * @static * @final * @type String */ Calendar.ONE_CHAR = "1char"; /** * The set of default Config property keys and values for the Calendar * @property YAHOO.widget.Calendar._DEFAULT_CONFIG * @final * @static * @private * @type Object */ Calendar._DEFAULT_CONFIG = { // Default values for pagedate and selected are not class level constants - they are set during instance creation PAGEDATE : {key:"pagedate", value:null}, SELECTED : {key:"selected", value:null}, TITLE : {key:"title", value:""}, CLOSE : {key:"close", value:false}, IFRAME : {key:"iframe", value:(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 6) ? true : false}, MINDATE : {key:"mindate", value:null}, MAXDATE : {key:"maxdate", value:null}, MULTI_SELECT : {key:"multi_select", value:false}, START_WEEKDAY : {key:"start_weekday", value:0}, SHOW_WEEKDAYS : {key:"show_weekdays", value:true}, SHOW_WEEK_HEADER : {key:"show_week_header", value:false}, SHOW_WEEK_FOOTER : {key:"show_week_footer", value:false}, HIDE_BLANK_WEEKS : {key:"hide_blank_weeks", value:false}, NAV_ARROW_LEFT: {key:"nav_arrow_left", value:null} , NAV_ARROW_RIGHT : {key:"nav_arrow_right", value:null} , MONTHS_SHORT : {key:"months_short", value:["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]}, MONTHS_LONG: {key:"months_long", value:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]}, WEEKDAYS_1CHAR: {key:"weekdays_1char", value:["S", "M", "T", "W", "T", "F", "S"]}, WEEKDAYS_SHORT: {key:"weekdays_short", value:["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]}, WEEKDAYS_MEDIUM: {key:"weekdays_medium", value:["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]}, WEEKDAYS_LONG: {key:"weekdays_long", value:["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]}, LOCALE_MONTHS:{key:"locale_months", value:"long"}, LOCALE_WEEKDAYS:{key:"locale_weekdays", value:"short"}, DATE_DELIMITER:{key:"date_delimiter", value:","}, DATE_FIELD_DELIMITER:{key:"date_field_delimiter", value:"/"}, DATE_RANGE_DELIMITER:{key:"date_range_delimiter", value:"-"}, MY_MONTH_POSITION:{key:"my_month_position", value:1}, MY_YEAR_POSITION:{key:"my_year_position", value:2}, MD_MONTH_POSITION:{key:"md_month_position", value:1}, MD_DAY_POSITION:{key:"md_day_position", value:2}, MDY_MONTH_POSITION:{key:"mdy_month_position", value:1}, MDY_DAY_POSITION:{key:"mdy_day_position", value:2}, MDY_YEAR_POSITION:{key:"mdy_year_position", value:3}, MY_LABEL_MONTH_POSITION:{key:"my_label_month_position", value:1}, MY_LABEL_YEAR_POSITION:{key:"my_label_year_position", value:2}, MY_LABEL_MONTH_SUFFIX:{key:"my_label_month_suffix", value:" "}, MY_LABEL_YEAR_SUFFIX:{key:"my_label_year_suffix", value:""}, NAV: {key:"navigator", value: null}, STRINGS : { key:"strings", value: { previousMonth : "Previous Month", nextMonth : "Next Month", close: "Close" }, supercedes : ["close", "title"] } }; var DEF_CFG = Calendar._DEFAULT_CONFIG; /** * The set of Custom Event types supported by the Calendar * @property YAHOO.widget.Calendar._EVENT_TYPES * @final * @static * @private * @type Object */ Calendar._EVENT_TYPES = { BEFORE_SELECT : "beforeSelect", SELECT : "select", BEFORE_DESELECT : "beforeDeselect", DESELECT : "deselect", CHANGE_PAGE : "changePage", BEFORE_RENDER : "beforeRender", RENDER : "render", BEFORE_DESTROY : "beforeDestroy", DESTROY : "destroy", RESET : "reset", CLEAR : "clear", BEFORE_HIDE : "beforeHide", HIDE : "hide", BEFORE_SHOW : "beforeShow", SHOW : "show", BEFORE_HIDE_NAV : "beforeHideNav", HIDE_NAV : "hideNav", BEFORE_SHOW_NAV : "beforeShowNav", SHOW_NAV : "showNav", BEFORE_RENDER_NAV : "beforeRenderNav", RENDER_NAV : "renderNav" }; /** * The set of default style constants for the Calendar * @property YAHOO.widget.Calendar._STYLES * @final * @static * @private * @type Object */ Calendar._STYLES = { CSS_ROW_HEADER: "calrowhead", CSS_ROW_FOOTER: "calrowfoot", CSS_CELL : "calcell", CSS_CELL_SELECTOR : "selector", CSS_CELL_SELECTED : "selected", CSS_CELL_SELECTABLE : "selectable", CSS_CELL_RESTRICTED : "restricted", CSS_CELL_TODAY : "today", CSS_CELL_OOM : "oom", CSS_CELL_OOB : "previous", CSS_HEADER : "calheader", CSS_HEADER_TEXT : "calhead", CSS_BODY : "calbody", CSS_WEEKDAY_CELL : "calweekdaycell", CSS_WEEKDAY_ROW : "calweekdayrow", CSS_FOOTER : "calfoot", CSS_CALENDAR : "yui-calendar", CSS_SINGLE : "single", CSS_CONTAINER : "yui-calcontainer", CSS_NAV_LEFT : "calnavleft", CSS_NAV_RIGHT : "calnavright", CSS_NAV : "calnav", CSS_CLOSE : "calclose", CSS_CELL_TOP : "calcelltop", CSS_CELL_LEFT : "calcellleft", CSS_CELL_RIGHT : "calcellright", CSS_CELL_BOTTOM : "calcellbottom", CSS_CELL_HOVER : "calcellhover", CSS_CELL_HIGHLIGHT1 : "highlight1", CSS_CELL_HIGHLIGHT2 : "highlight2", CSS_CELL_HIGHLIGHT3 : "highlight3", CSS_CELL_HIGHLIGHT4 : "highlight4" }; Calendar.prototype = { /** * The configuration object used to set up the calendars various locale and style options. * @property Config * @private * @deprecated Configuration properties should be set by calling Calendar.cfg.setProperty. * @type Object */ Config : null, /** * The parent CalendarGroup, only to be set explicitly by the parent group * @property parent * @type CalendarGroup */ parent : null, /** * The index of this item in the parent group * @property index * @type Number */ index : -1, /** * The collection of calendar table cells * @property cells * @type HTMLTableCellElement[] */ cells : null, /** * The collection of calendar cell dates that is parallel to the cells collection. The array contains dates field arrays in the format of [YYYY, M, D]. * @property cellDates * @type Array[](Number[]) */ cellDates : null, /** * The id that uniquely identifies this Calendar. * @property id * @type String */ id : null, /** * The unique id associated with the Calendar's container * @property containerId * @type String */ containerId: null, /** * The DOM element reference that points to this calendar's container element. The calendar will be inserted into this element when the shell is rendered. * @property oDomContainer * @type HTMLElement */ oDomContainer : null, /** * A Date object representing today's date. * @property today * @type Date */ today : null, /** * The list of render functions, along with required parameters, used to render cells. * @property renderStack * @type Array[] */ renderStack : null, /** * A copy of the initial render functions created before rendering. * @property _renderStack * @private * @type Array */ _renderStack : null, /** * A reference to the CalendarNavigator instance created for this Calendar. * Will be null if the "navigator" configuration property has not been set * @property oNavigator * @type CalendarNavigator */ oNavigator : null, /** * The private list of initially selected dates. * @property _selectedDates * @private * @type Array */ _selectedDates : null, /** * A map of DOM event handlers to attach to cells associated with specific CSS class names * @property domEventMap * @type Object */ domEventMap : null, /** * Protected helper used to parse Calendar constructor/init arguments. * * As of 2.4.0, Calendar supports a simpler constructor * signature. This method reconciles arguments * received in the pre 2.4.0 and 2.4.0 formats. * * @protected * @method _parseArgs * @param {Array} Function "arguments" array * @return {Object} Object with id, container, config properties containing * the reconciled argument values. **/ _parseArgs : function(args) { /* 2.4.0 Constructors signatures new Calendar(String) new Calendar(HTMLElement) new Calendar(String, ConfigObject) new Calendar(HTMLElement, ConfigObject) Pre 2.4.0 Constructor signatures new Calendar(String, String) new Calendar(String, HTMLElement) new Calendar(String, String, ConfigObject) new Calendar(String, HTMLElement, ConfigObject) */ var nArgs = {id:null, container:null, config:null}; if (args && args.length && args.length > 0) { switch (args.length) { case 1: nArgs.id = null; nArgs.container = args[0]; nArgs.config = null; break; case 2: if (Lang.isObject(args[1]) && !args[1].tagName && !(args[1] instanceof String)) { nArgs.id = null; nArgs.container = args[0]; nArgs.config = args[1]; } else { nArgs.id = args[0]; nArgs.container = args[1]; nArgs.config = null; } break; default: // 3+ nArgs.id = args[0]; nArgs.container = args[1]; nArgs.config = args[2]; break; } } else { } return nArgs; }, /** * Initializes the Calendar widget. * @method init * * @param {String} id optional The id of the table element that will represent the Calendar widget. As of 2.4.0, this argument is optional. * @param {String | HTMLElement} container The id of the container div element that will wrap the Calendar table, or a reference to a DIV element which exists in the document. * @param {Object} config optional The configuration object containing the initial configuration values for the Calendar. */ init : function(id, container, config) { // Normalize 2.4.0, pre 2.4.0 args var nArgs = this._parseArgs(arguments); id = nArgs.id; container = nArgs.container; config = nArgs.config; this.oDomContainer = Dom.get(container); if (!this.oDomContainer.id) { this.oDomContainer.id = Dom.generateId(); } if (!id) { id = this.oDomContainer.id + "_t"; } this.id = id; this.containerId = this.oDomContainer.id; this.initEvents(); this.today = new Date(); DateMath.clearTime(this.today); /** * The Config object used to hold the configuration variables for the Calendar * @property cfg * @type YAHOO.util.Config */ this.cfg = new YAHOO.util.Config(this); /** * The local object which contains the Calendar's options * @property Options * @type Object */ this.Options = {}; /** * The local object which contains the Calendar's locale settings * @property Locale * @type Object */ this.Locale = {}; this.initStyles(); Dom.addClass(this.oDomContainer, this.Style.CSS_CONTAINER); Dom.addClass(this.oDomContainer, this.Style.CSS_SINGLE); this.cellDates = []; this.cells = []; this.renderStack = []; this._renderStack = []; this.setupConfig(); if (config) { this.cfg.applyConfig(config, true); } this.cfg.fireQueue(); }, /** * Default Config listener for the iframe property. If the iframe config property is set to true, * renders the built-in IFRAME shim if the container is relatively or absolutely positioned. * * @method configIframe */ configIframe : function(type, args, obj) { var useIframe = args[0]; if (!this.parent) { if (Dom.inDocument(this.oDomContainer)) { if (useIframe) { var pos = Dom.getStyle(this.oDomContainer, "position"); if (pos == "absolute" || pos == "relative") { if (!Dom.inDocument(this.iframe)) { this.iframe = document.createElement("iframe"); this.iframe.src = "javascript:false;"; Dom.setStyle(this.iframe, "opacity", "0"); if (YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 6) { Dom.addClass(this.iframe, "fixedsize"); } this.oDomContainer.insertBefore(this.iframe, this.oDomContainer.firstChild); } } } else { if (this.iframe) { if (this.iframe.parentNode) { this.iframe.parentNode.removeChild(this.iframe); } this.iframe = null; } } } } }, /** * Default handler for the "title" property * @method configTitle */ configTitle : function(type, args, obj) { var title = args[0]; // "" disables title bar if (title) { this.createTitleBar(title); } else { var close = this.cfg.getProperty(DEF_CFG.CLOSE.key); if (!close) { this.removeTitleBar(); } else { this.createTitleBar(" "); } } }, /** * Default handler for the "close" property * @method configClose */ configClose : function(type, args, obj) { var close = args[0], title = this.cfg.getProperty(DEF_CFG.TITLE.key); if (close) { if (!title) { this.createTitleBar(" "); } this.createCloseButton(); } else { this.removeCloseButton(); if (!title) { this.removeTitleBar(); } } }, /** * Initializes Calendar's built-in CustomEvents * @method initEvents */ initEvents : function() { var defEvents = Calendar._EVENT_TYPES, CE = YAHOO.util.CustomEvent, cal = this; // To help with minification /** * Fired before a date selection is made * @event beforeSelectEvent */ cal.beforeSelectEvent = new CE(defEvents.BEFORE_SELECT); /** * Fired when a date selection is made * @event selectEvent * @param {Array} Array of Date field arrays in the format [YYYY, MM, DD]. */ cal.selectEvent = new CE(defEvents.SELECT); /** * Fired before a date or set of dates is deselected * @event beforeDeselectEvent */ cal.beforeDeselectEvent = new CE(defEvents.BEFORE_DESELECT); /** * Fired when a date or set of dates is deselected * @event deselectEvent * @param {Array} Array of Date field arrays in the format [YYYY, MM, DD]. */ cal.deselectEvent = new CE(defEvents.DESELECT); /** * Fired when the Calendar page is changed * @event changePageEvent */ cal.changePageEvent = new CE(defEvents.CHANGE_PAGE); /** * Fired before the Calendar is rendered * @event beforeRenderEvent */ cal.beforeRenderEvent = new CE(defEvents.BEFORE_RENDER); /** * Fired when the Calendar is rendered * @event renderEvent */ cal.renderEvent = new CE(defEvents.RENDER); /** * Fired just before the Calendar is to be destroyed * @event beforeDestroyEvent */ cal.beforeDestroyEvent = new CE(defEvents.BEFORE_DESTROY); /** * Fired after the Calendar is destroyed. This event should be used * for notification only. When this event is fired, important Calendar instance * properties, dom references and event listeners have already been * removed/dereferenced, and hence the Calendar instance is not in a usable * state. * * @event destroyEvent */ cal.destroyEvent = new CE(defEvents.DESTROY); /** * Fired when the Calendar is reset * @event resetEvent */ cal.resetEvent = new CE(defEvents.RESET); /** * Fired when the Calendar is cleared * @event clearEvent */ cal.clearEvent = new CE(defEvents.CLEAR); /** * Fired just before the Calendar is to be shown * @event beforeShowEvent */ cal.beforeShowEvent = new CE(defEvents.BEFORE_SHOW); /** * Fired after the Calendar is shown * @event showEvent */ cal.showEvent = new CE(defEvents.SHOW); /** * Fired just before the Calendar is to be hidden * @event beforeHideEvent */ cal.beforeHideEvent = new CE(defEvents.BEFORE_HIDE); /** * Fired after the Calendar is hidden * @event hideEvent */ cal.hideEvent = new CE(defEvents.HIDE); /** * Fired just before the CalendarNavigator is to be shown * @event beforeShowNavEvent */ cal.beforeShowNavEvent = new CE(defEvents.BEFORE_SHOW_NAV); /** * Fired after the CalendarNavigator is shown * @event showNavEvent */ cal.showNavEvent = new CE(defEvents.SHOW_NAV); /** * Fired just before the CalendarNavigator is to be hidden * @event beforeHideNavEvent */ cal.beforeHideNavEvent = new CE(defEvents.BEFORE_HIDE_NAV); /** * Fired after the CalendarNavigator is hidden * @event hideNavEvent */ cal.hideNavEvent = new CE(defEvents.HIDE_NAV); /** * Fired just before the CalendarNavigator is to be rendered * @event beforeRenderNavEvent */ cal.beforeRenderNavEvent = new CE(defEvents.BEFORE_RENDER_NAV); /** * Fired after the CalendarNavigator is rendered * @event renderNavEvent */ cal.renderNavEvent = new CE(defEvents.RENDER_NAV); cal.beforeSelectEvent.subscribe(cal.onBeforeSelect, this, true); cal.selectEvent.subscribe(cal.onSelect, this, true); cal.beforeDeselectEvent.subscribe(cal.onBeforeDeselect, this, true); cal.deselectEvent.subscribe(cal.onDeselect, this, true); cal.changePageEvent.subscribe(cal.onChangePage, this, true); cal.renderEvent.subscribe(cal.onRender, this, true); cal.resetEvent.subscribe(cal.onReset, this, true); cal.clearEvent.subscribe(cal.onClear, this, true); }, /** * The default event handler for clicks on the "Previous Month" navigation UI * * @method doPreviousMonthNav * @param {DOMEvent} e The DOM event * @param {Calendar} cal A reference to the calendar */ doPreviousMonthNav : function(e, cal) { Event.preventDefault(e); // previousMonth invoked in a timeout, to allow // event to bubble up, with correct target. Calling // previousMonth, will call render which will remove // HTML which generated the event, resulting in an // invalid event target in certain browsers. setTimeout(function() { cal.previousMonth(); var navs = Dom.getElementsByClassName(cal.Style.CSS_NAV_LEFT, "a", cal.oDomContainer); if (navs && navs[0]) { try { navs[0].focus(); } catch (e) { // ignore } } }, 0); }, /** * The default event handler for clicks on the "Next Month" navigation UI * * @method doNextMonthNav * @param {DOMEvent} e The DOM event * @param {Calendar} cal A reference to the calendar */ doNextMonthNav : function(e, cal) { Event.preventDefault(e); setTimeout(function() { cal.nextMonth(); var navs = Dom.getElementsByClassName(cal.Style.CSS_NAV_RIGHT, "a", cal.oDomContainer); if (navs && navs[0]) { try { navs[0].focus(); } catch (e) { // ignore } } }, 0); }, /** * The default event handler for date cell selection. Currently attached to * the Calendar's bounding box, referenced by it's oDomContainer property. * * @method doSelectCell * @param {DOMEvent} e The DOM event * @param {Calendar} cal A reference to the calendar */ doSelectCell : function(e, cal) { var cell, d, date, index; var target = Event.getTarget(e), tagName = target.tagName.toLowerCase(), defSelector = false; while (tagName != "td" && !Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) { if (!defSelector && tagName == "a" && Dom.hasClass(target, cal.Style.CSS_CELL_SELECTOR)) { defSelector = true; } target = target.parentNode; tagName = target.tagName.toLowerCase(); if (target == this.oDomContainer || tagName == "html") { return; } } if (defSelector) { // Stop link href navigation for default renderer Event.preventDefault(e); } cell = target; if (Dom.hasClass(cell, cal.Style.CSS_CELL_SELECTABLE)) { index = cal.getIndexFromId(cell.id); if (index > -1) { d = cal.cellDates[index]; if (d) { date = DateMath.getDate(d[0],d[1]-1,d[2]); var link; if (cal.Options.MULTI_SELECT) { link = cell.getElementsByTagName("a")[0]; if (link) { link.blur(); } var cellDate = cal.cellDates[index]; var cellDateIndex = cal._indexOfSelectedFieldArray(cellDate); if (cellDateIndex > -1) { cal.deselectCell(index); } else { cal.selectCell(index); } } else { link = cell.getElementsByTagName("a")[0]; if (link) { link.blur(); } cal.selectCell(index); } } } } }, /** * The event that is executed when the user hovers over a cell * @method doCellMouseOver * @param {DOMEvent} e The event * @param {Calendar} cal A reference to the calendar passed by the Event utility */ doCellMouseOver : function(e, cal) { var target; if (e) { target = Event.getTarget(e); } else { target = this; } while (target.tagName && target.tagName.toLowerCase() != "td") { target = target.parentNode; if (!target.tagName || target.tagName.toLowerCase() == "html") { return; } } if (Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) { Dom.addClass(target, cal.Style.CSS_CELL_HOVER); } }, /** * The event that is executed when the user moves the mouse out of a cell * @method doCellMouseOut * @param {DOMEvent} e The event * @param {Calendar} cal A reference to the calendar passed by the Event utility */ doCellMouseOut : function(e, cal) { var target; if (e) { target = Event.getTarget(e); } else { target = this; } while (target.tagName && target.tagName.toLowerCase() != "td") { target = target.parentNode; if (!target.tagName || target.tagName.toLowerCase() == "html") { return; } } if (Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) { Dom.removeClass(target, cal.Style.CSS_CELL_HOVER); } }, setupConfig : function() { var cfg = this.cfg; /** * The month/year representing the current visible Calendar date (mm/yyyy) * @config pagedate * @type String | Date * @default today's date */ cfg.addProperty(DEF_CFG.PAGEDATE.key, { value:new Date(), handler:this.configPageDate } ); /** * The date or range of dates representing the current Calendar selection * @config selected * @type String * @default [] */ cfg.addProperty(DEF_CFG.SELECTED.key, { value:[], handler:this.configSelected } ); /** * The title to display above the Calendar's month header * @config title * @type String * @default "" */ cfg.addProperty(DEF_CFG.TITLE.key, { value:DEF_CFG.TITLE.value, handler:this.configTitle } ); /** * Whether or not a close button should be displayed for this Calendar * @config close * @type Boolean * @default false */ cfg.addProperty(DEF_CFG.CLOSE.key, { value:DEF_CFG.CLOSE.value, handler:this.configClose } ); /** * Whether or not an iframe shim should be placed under the Calendar to prevent select boxes from bleeding through in Internet Explorer 6 and below. * This property is enabled by default for IE6 and below. It is disabled by default for other browsers for performance reasons, but can be * enabled if required. * * @config iframe * @type Boolean * @default true for IE6 and below, false for all other browsers */ cfg.addProperty(DEF_CFG.IFRAME.key, { value:DEF_CFG.IFRAME.value, handler:this.configIframe, validator:cfg.checkBoolean } ); /** * The minimum selectable date in the current Calendar (mm/dd/yyyy) * @config mindate * @type String | Date * @default null */ cfg.addProperty(DEF_CFG.MINDATE.key, { value:DEF_CFG.MINDATE.value, handler:this.configMinDate } ); /** * The maximum selectable date in the current Calendar (mm/dd/yyyy) * @config maxdate * @type String | Date * @default null */ cfg.addProperty(DEF_CFG.MAXDATE.key, { value:DEF_CFG.MAXDATE.value, handler:this.configMaxDate } ); // Options properties /** * True if the Calendar should allow multiple selections. False by default. * @config MULTI_SELECT * @type Boolean * @default false */ cfg.addProperty(DEF_CFG.MULTI_SELECT.key, { value:DEF_CFG.MULTI_SELECT.value, handler:this.configOptions, validator:cfg.checkBoolean } ); /** * The weekday the week begins on. Default is 0 (Sunday = 0, Monday = 1 ... Saturday = 6). * @config START_WEEKDAY * @type number * @default 0 */ cfg.addProperty(DEF_CFG.START_WEEKDAY.key, { value:DEF_CFG.START_WEEKDAY.value, handler:this.configOptions, validator:cfg.checkNumber } ); /** * True if the Calendar should show weekday labels. True by default. * @config SHOW_WEEKDAYS * @type Boolean * @default true */ cfg.addProperty(DEF_CFG.SHOW_WEEKDAYS.key, { value:DEF_CFG.SHOW_WEEKDAYS.value, handler:this.configOptions, validator:cfg.checkBoolean } ); /** * True if the Calendar should show week row headers. False by default. * @config SHOW_WEEK_HEADER * @type Boolean * @default false */ cfg.addProperty(DEF_CFG.SHOW_WEEK_HEADER.key, { value:DEF_CFG.SHOW_WEEK_HEADER.value, handler:this.configOptions, validator:cfg.checkBoolean } ); /** * True if the Calendar should show week row footers. False by default. * @config SHOW_WEEK_FOOTER * @type Boolean * @default false */ cfg.addProperty(DEF_CFG.SHOW_WEEK_FOOTER.key,{ value:DEF_CFG.SHOW_WEEK_FOOTER.value, handler:this.configOptions, validator:cfg.checkBoolean } ); /** * True if the Calendar should suppress weeks that are not a part of the current month. False by default. * @config HIDE_BLANK_WEEKS * @type Boolean * @default false */ cfg.addProperty(DEF_CFG.HIDE_BLANK_WEEKS.key, { value:DEF_CFG.HIDE_BLANK_WEEKS.value, handler:this.configOptions, validator:cfg.checkBoolean } ); /** * The image that should be used for the left navigation arrow. * @config NAV_ARROW_LEFT * @type String * @deprecated You can customize the image by overriding the default CSS class for the left arrow - "calnavleft" * @default null */ cfg.addProperty(DEF_CFG.NAV_ARROW_LEFT.key, { value:DEF_CFG.NAV_ARROW_LEFT.value, handler:this.configOptions } ); /** * The image that should be used for the right navigation arrow. * @config NAV_ARROW_RIGHT * @type String * @deprecated You can customize the image by overriding the default CSS class for the right arrow - "calnavright" * @default null */ cfg.addProperty(DEF_CFG.NAV_ARROW_RIGHT.key, { value:DEF_CFG.NAV_ARROW_RIGHT.value, handler:this.configOptions } ); // Locale properties /** * The short month labels for the current locale. * @config MONTHS_SHORT * @type String[] * @default ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] */ cfg.addProperty(DEF_CFG.MONTHS_SHORT.key, { value:DEF_CFG.MONTHS_SHORT.value, handler:this.configLocale } ); /** * The long month labels for the current locale. * @config MONTHS_LONG * @type String[] * @default ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" */ cfg.addProperty(DEF_CFG.MONTHS_LONG.key, { value:DEF_CFG.MONTHS_LONG.value, handler:this.configLocale } ); /** * The 1-character weekday labels for the current locale. * @config WEEKDAYS_1CHAR * @type String[] * @default ["S", "M", "T", "W", "T", "F", "S"] */ cfg.addProperty(DEF_CFG.WEEKDAYS_1CHAR.key, { value:DEF_CFG.WEEKDAYS_1CHAR.value, handler:this.configLocale } ); /** * The short weekday labels for the current locale. * @config WEEKDAYS_SHORT * @type String[] * @default ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"] */ cfg.addProperty(DEF_CFG.WEEKDAYS_SHORT.key, { value:DEF_CFG.WEEKDAYS_SHORT.value, handler:this.configLocale } ); /** * The medium weekday labels for the current locale. * @config WEEKDAYS_MEDIUM * @type String[] * @default ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] */ cfg.addProperty(DEF_CFG.WEEKDAYS_MEDIUM.key, { value:DEF_CFG.WEEKDAYS_MEDIUM.value, handler:this.configLocale } ); /** * The long weekday labels for the current locale. * @config WEEKDAYS_LONG * @type String[] * @default ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] */ cfg.addProperty(DEF_CFG.WEEKDAYS_LONG.key, { value:DEF_CFG.WEEKDAYS_LONG.value, handler:this.configLocale } ); /** * Refreshes the locale values used to build the Calendar. * @method refreshLocale * @private */ var refreshLocale = function() { cfg.refireEvent(DEF_CFG.LOCALE_MONTHS.key); cfg.refireEvent(DEF_CFG.LOCALE_WEEKDAYS.key); }; cfg.subscribeToConfigEvent(DEF_CFG.START_WEEKDAY.key, refreshLocale, this, true); cfg.subscribeToConfigEvent(DEF_CFG.MONTHS_SHORT.key, refreshLocale, this, true); cfg.subscribeToConfigEvent(DEF_CFG.MONTHS_LONG.key, refreshLocale, this, true); cfg.subscribeToConfigEvent(DEF_CFG.WEEKDAYS_1CHAR.key, refreshLocale, this, true); cfg.subscribeToConfigEvent(DEF_CFG.WEEKDAYS_SHORT.key, refreshLocale, this, true); cfg.subscribeToConfigEvent(DEF_CFG.WEEKDAYS_MEDIUM.key, refreshLocale, this, true); cfg.subscribeToConfigEvent(DEF_CFG.WEEKDAYS_LONG.key, refreshLocale, this, true); /** * The setting that determines which length of month labels should be used. Possible values are "short" and "long". * @config LOCALE_MONTHS * @type String * @default "long" */ cfg.addProperty(DEF_CFG.LOCALE_MONTHS.key, { value:DEF_CFG.LOCALE_MONTHS.value, handler:this.configLocaleValues } ); /** * The setting that determines which length of weekday labels should be used. Possible values are "1char", "short", "medium", and "long". * @config LOCALE_WEEKDAYS * @type String * @default "short" */ cfg.addProperty(DEF_CFG.LOCALE_WEEKDAYS.key, { value:DEF_CFG.LOCALE_WEEKDAYS.value, handler:this.configLocaleValues } ); /** * The value used to delimit individual dates in a date string passed to various Calendar functions. * @config DATE_DELIMITER * @type String * @default "," */ cfg.addProperty(DEF_CFG.DATE_DELIMITER.key, { value:DEF_CFG.DATE_DELIMITER.value, handler:this.configLocale } ); /** * The value used to delimit date fields in a date string passed to various Calendar functions. * @config DATE_FIELD_DELIMITER * @type String * @default "/" */ cfg.addProperty(DEF_CFG.DATE_FIELD_DELIMITER.key, { value:DEF_CFG.DATE_FIELD_DELIMITER.value, handler:this.configLocale } ); /** * The value used to delimit date ranges in a date string passed to various Calendar functions. * @config DATE_RANGE_DELIMITER * @type String * @default "-" */ cfg.addProperty(DEF_CFG.DATE_RANGE_DELIMITER.key, { value:DEF_CFG.DATE_RANGE_DELIMITER.value, handler:this.configLocale } ); /** * The position of the month in a month/year date string * @config MY_MONTH_POSITION * @type Number * @default 1 */ cfg.addProperty(DEF_CFG.MY_MONTH_POSITION.key, { value:DEF_CFG.MY_MONTH_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } ); /** * The position of the year in a month/year date string * @config MY_YEAR_POSITION * @type Number * @default 2 */ cfg.addProperty(DEF_CFG.MY_YEAR_POSITION.key, { value:DEF_CFG.MY_YEAR_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } ); /** * The position of the month in a month/day date string * @config MD_MONTH_POSITION * @type Number * @default 1 */ cfg.addProperty(DEF_CFG.MD_MONTH_POSITION.key, { value:DEF_CFG.MD_MONTH_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } ); /** * The position of the day in a month/year date string * @config MD_DAY_POSITION * @type Number * @default 2 */ cfg.addProperty(DEF_CFG.MD_DAY_POSITION.key, { value:DEF_CFG.MD_DAY_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } ); /** * The position of the month in a month/day/year date string * @config MDY_MONTH_POSITION * @type Number * @default 1 */ cfg.addProperty(DEF_CFG.MDY_MONTH_POSITION.key, { value:DEF_CFG.MDY_MONTH_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } ); /** * The position of the day in a month/day/year date string * @config MDY_DAY_POSITION * @type Number * @default 2 */ cfg.addProperty(DEF_CFG.MDY_DAY_POSITION.key, { value:DEF_CFG.MDY_DAY_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } ); /** * The position of the year in a month/day/year date string * @config MDY_YEAR_POSITION * @type Number * @default 3 */ cfg.addProperty(DEF_CFG.MDY_YEAR_POSITION.key, { value:DEF_CFG.MDY_YEAR_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } ); /** * The position of the month in the month year label string used as the Calendar header * @config MY_LABEL_MONTH_POSITION * @type Number * @default 1 */ cfg.addProperty(DEF_CFG.MY_LABEL_MONTH_POSITION.key, { value:DEF_CFG.MY_LABEL_MONTH_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } ); /** * The position of the year in the month year label string used as the Calendar header * @config MY_LABEL_YEAR_POSITION * @type Number * @default 2 */ cfg.addProperty(DEF_CFG.MY_LABEL_YEAR_POSITION.key, { value:DEF_CFG.MY_LABEL_YEAR_POSITION.value, handler:this.configLocale, validator:cfg.checkNumber } ); /** * The suffix used after the month when rendering the Calendar header * @config MY_LABEL_MONTH_SUFFIX * @type String * @default " " */ cfg.addProperty(DEF_CFG.MY_LABEL_MONTH_SUFFIX.key, { value:DEF_CFG.MY_LABEL_MONTH_SUFFIX.value, handler:this.configLocale } ); /** * The suffix used after the year when rendering the Calendar header * @config MY_LABEL_YEAR_SUFFIX * @type String * @default "" */ cfg.addProperty(DEF_CFG.MY_LABEL_YEAR_SUFFIX.key, { value:DEF_CFG.MY_LABEL_YEAR_SUFFIX.value, handler:this.configLocale } ); /** * Configuration for the Month/Year CalendarNavigator UI which allows the user to jump directly to a * specific Month/Year without having to scroll sequentially through months. *

    * Setting this property to null (default value) or false, will disable the CalendarNavigator UI. *

    *

    * Setting this property to true will enable the CalendarNavigatior UI with the default CalendarNavigator configuration values. *

    *

    * This property can also be set to an object literal containing configuration properties for the CalendarNavigator UI. * The configuration object expects the the following case-sensitive properties, with the "strings" property being a nested object. * Any properties which are not provided will use the default values (defined in the CalendarNavigator class). *

    *
    *
    strings
    *
    Object : An object with the properties shown below, defining the string labels to use in the Navigator's UI *
    *
    month
    String : The string to use for the month label. Defaults to "Month".
    *
    year
    String : The string to use for the year label. Defaults to "Year".
    *
    submit
    String : The string to use for the submit button label. Defaults to "Okay".
    *
    cancel
    String : The string to use for the cancel button label. Defaults to "Cancel".
    *
    invalidYear
    String : The string to use for invalid year values. Defaults to "Year needs to be a number".
    *
    *
    *
    monthFormat
    String : The month format to use. Either YAHOO.widget.Calendar.LONG, or YAHOO.widget.Calendar.SHORT. Defaults to YAHOO.widget.Calendar.LONG
    *
    initialFocus
    String : Either "year" or "month" specifying which input control should get initial focus. Defaults to "year"
    *
    *

    E.g.

    *
    		* var navConfig = {
    		*	  strings: {
    		*		  month:"Calendar Month",
    		*		  year:"Calendar Year",
    		*		  submit: "Submit",
    		*		  cancel: "Cancel",
    		*		  invalidYear: "Please enter a valid year"
    		*	  },
    		*	  monthFormat: YAHOO.widget.Calendar.SHORT,
    		*	  initialFocus: "month"
    		* }
    		* 
    * @config navigator * @type {Object|Boolean} * @default null */ cfg.addProperty(DEF_CFG.NAV.key, { value:DEF_CFG.NAV.value, handler:this.configNavigator } ); /** * The map of UI strings which the Calendar UI uses. * * @config strings * @type {Object} * @default An object with the properties shown below: *
    *
    previousMonth
    String : The string to use for the "Previous Month" navigation UI. Defaults to "Previous Month".
    *
    nextMonth
    String : The string to use for the "Next Month" navigation UI. Defaults to "Next Month".
    *
    close
    String : The string to use for the close button label. Defaults to "Close".
    *
    */ cfg.addProperty(DEF_CFG.STRINGS.key, { value:DEF_CFG.STRINGS.value, handler:this.configStrings, validator: function(val) { return Lang.isObject(val); }, supercedes:DEF_CFG.STRINGS.supercedes }); }, /** * The default handler for the "strings" property * @method configStrings */ configStrings : function(type, args, obj) { var val = Lang.merge(DEF_CFG.STRINGS.value, args[0]); this.cfg.setProperty(DEF_CFG.STRINGS.key, val, true); }, /** * The default handler for the "pagedate" property * @method configPageDate */ configPageDate : function(type, args, obj) { this.cfg.setProperty(DEF_CFG.PAGEDATE.key, this._parsePageDate(args[0]), true); }, /** * The default handler for the "mindate" property * @method configMinDate */ configMinDate : function(type, args, obj) { var val = args[0]; if (Lang.isString(val)) { val = this._parseDate(val); this.cfg.setProperty(DEF_CFG.MINDATE.key, DateMath.getDate(val[0],(val[1]-1),val[2])); } }, /** * The default handler for the "maxdate" property * @method configMaxDate */ configMaxDate : function(type, args, obj) { var val = args[0]; if (Lang.isString(val)) { val = this._parseDate(val); this.cfg.setProperty(DEF_CFG.MAXDATE.key, DateMath.getDate(val[0],(val[1]-1),val[2])); } }, /** * The default handler for the "selected" property * @method configSelected */ configSelected : function(type, args, obj) { var selected = args[0], cfgSelected = DEF_CFG.SELECTED.key; if (selected) { if (Lang.isString(selected)) { this.cfg.setProperty(cfgSelected, this._parseDates(selected), true); } } if (! this._selectedDates) { this._selectedDates = this.cfg.getProperty(cfgSelected); } }, /** * The default handler for all configuration options properties * @method configOptions */ configOptions : function(type, args, obj) { this.Options[type.toUpperCase()] = args[0]; }, /** * The default handler for all configuration locale properties * @method configLocale */ configLocale : function(type, args, obj) { this.Locale[type.toUpperCase()] = args[0]; this.cfg.refireEvent(DEF_CFG.LOCALE_MONTHS.key); this.cfg.refireEvent(DEF_CFG.LOCALE_WEEKDAYS.key); }, /** * The default handler for all configuration locale field length properties * @method configLocaleValues */ configLocaleValues : function(type, args, obj) { type = type.toLowerCase(); var val = args[0], cfg = this.cfg, Locale = this.Locale; switch (type) { case DEF_CFG.LOCALE_MONTHS.key: switch (val) { case Calendar.SHORT: Locale.LOCALE_MONTHS = cfg.getProperty(DEF_CFG.MONTHS_SHORT.key).concat(); break; case Calendar.LONG: Locale.LOCALE_MONTHS = cfg.getProperty(DEF_CFG.MONTHS_LONG.key).concat(); break; } break; case DEF_CFG.LOCALE_WEEKDAYS.key: switch (val) { case Calendar.ONE_CHAR: Locale.LOCALE_WEEKDAYS = cfg.getProperty(DEF_CFG.WEEKDAYS_1CHAR.key).concat(); break; case Calendar.SHORT: Locale.LOCALE_WEEKDAYS = cfg.getProperty(DEF_CFG.WEEKDAYS_SHORT.key).concat(); break; case Calendar.MEDIUM: Locale.LOCALE_WEEKDAYS = cfg.getProperty(DEF_CFG.WEEKDAYS_MEDIUM.key).concat(); break; case Calendar.LONG: Locale.LOCALE_WEEKDAYS = cfg.getProperty(DEF_CFG.WEEKDAYS_LONG.key).concat(); break; } var START_WEEKDAY = cfg.getProperty(DEF_CFG.START_WEEKDAY.key); if (START_WEEKDAY > 0) { for (var w=0; w < START_WEEKDAY; ++w) { Locale.LOCALE_WEEKDAYS.push(Locale.LOCALE_WEEKDAYS.shift()); } } break; } }, /** * The default handler for the "navigator" property * @method configNavigator */ configNavigator : function(type, args, obj) { var val = args[0]; if (YAHOO.widget.CalendarNavigator && (val === true || Lang.isObject(val))) { if (!this.oNavigator) { this.oNavigator = new YAHOO.widget.CalendarNavigator(this); // Cleanup DOM Refs/Events before innerHTML is removed. this.beforeRenderEvent.subscribe(function () { if (!this.pages) { this.oNavigator.erase(); } }, this, true); } } else { if (this.oNavigator) { this.oNavigator.destroy(); this.oNavigator = null; } } }, /** * Defines the style constants for the Calendar * @method initStyles */ initStyles : function() { var defStyle = Calendar._STYLES; this.Style = { /** * @property Style.CSS_ROW_HEADER */ CSS_ROW_HEADER: defStyle.CSS_ROW_HEADER, /** * @property Style.CSS_ROW_FOOTER */ CSS_ROW_FOOTER: defStyle.CSS_ROW_FOOTER, /** * @property Style.CSS_CELL */ CSS_CELL : defStyle.CSS_CELL, /** * @property Style.CSS_CELL_SELECTOR */ CSS_CELL_SELECTOR : defStyle.CSS_CELL_SELECTOR, /** * @property Style.CSS_CELL_SELECTED */ CSS_CELL_SELECTED : defStyle.CSS_CELL_SELECTED, /** * @property Style.CSS_CELL_SELECTABLE */ CSS_CELL_SELECTABLE : defStyle.CSS_CELL_SELECTABLE, /** * @property Style.CSS_CELL_RESTRICTED */ CSS_CELL_RESTRICTED : defStyle.CSS_CELL_RESTRICTED, /** * @property Style.CSS_CELL_TODAY */ CSS_CELL_TODAY : defStyle.CSS_CELL_TODAY, /** * @property Style.CSS_CELL_OOM */ CSS_CELL_OOM : defStyle.CSS_CELL_OOM, /** * @property Style.CSS_CELL_OOB */ CSS_CELL_OOB : defStyle.CSS_CELL_OOB, /** * @property Style.CSS_HEADER */ CSS_HEADER : defStyle.CSS_HEADER, /** * @property Style.CSS_HEADER_TEXT */ CSS_HEADER_TEXT : defStyle.CSS_HEADER_TEXT, /** * @property Style.CSS_BODY */ CSS_BODY : defStyle.CSS_BODY, /** * @property Style.CSS_WEEKDAY_CELL */ CSS_WEEKDAY_CELL : defStyle.CSS_WEEKDAY_CELL, /** * @property Style.CSS_WEEKDAY_ROW */ CSS_WEEKDAY_ROW : defStyle.CSS_WEEKDAY_ROW, /** * @property Style.CSS_FOOTER */ CSS_FOOTER : defStyle.CSS_FOOTER, /** * @property Style.CSS_CALENDAR */ CSS_CALENDAR : defStyle.CSS_CALENDAR, /** * @property Style.CSS_SINGLE */ CSS_SINGLE : defStyle.CSS_SINGLE, /** * @property Style.CSS_CONTAINER */ CSS_CONTAINER : defStyle.CSS_CONTAINER, /** * @property Style.CSS_NAV_LEFT */ CSS_NAV_LEFT : defStyle.CSS_NAV_LEFT, /** * @property Style.CSS_NAV_RIGHT */ CSS_NAV_RIGHT : defStyle.CSS_NAV_RIGHT, /** * @property Style.CSS_NAV */ CSS_NAV : defStyle.CSS_NAV, /** * @property Style.CSS_CLOSE */ CSS_CLOSE : defStyle.CSS_CLOSE, /** * @property Style.CSS_CELL_TOP */ CSS_CELL_TOP : defStyle.CSS_CELL_TOP, /** * @property Style.CSS_CELL_LEFT */ CSS_CELL_LEFT : defStyle.CSS_CELL_LEFT, /** * @property Style.CSS_CELL_RIGHT */ CSS_CELL_RIGHT : defStyle.CSS_CELL_RIGHT, /** * @property Style.CSS_CELL_BOTTOM */ CSS_CELL_BOTTOM : defStyle.CSS_CELL_BOTTOM, /** * @property Style.CSS_CELL_HOVER */ CSS_CELL_HOVER : defStyle.CSS_CELL_HOVER, /** * @property Style.CSS_CELL_HIGHLIGHT1 */ CSS_CELL_HIGHLIGHT1 : defStyle.CSS_CELL_HIGHLIGHT1, /** * @property Style.CSS_CELL_HIGHLIGHT2 */ CSS_CELL_HIGHLIGHT2 : defStyle.CSS_CELL_HIGHLIGHT2, /** * @property Style.CSS_CELL_HIGHLIGHT3 */ CSS_CELL_HIGHLIGHT3 : defStyle.CSS_CELL_HIGHLIGHT3, /** * @property Style.CSS_CELL_HIGHLIGHT4 */ CSS_CELL_HIGHLIGHT4 : defStyle.CSS_CELL_HIGHLIGHT4 }; }, /** * Builds the date label that will be displayed in the calendar header or * footer, depending on configuration. * @method buildMonthLabel * @return {String} The formatted calendar month label */ buildMonthLabel : function() { return this._buildMonthLabel(this.cfg.getProperty(DEF_CFG.PAGEDATE.key)); }, /** * Helper method, to format a Month Year string, given a JavaScript Date, based on the * Calendar localization settings * * @method _buildMonthLabel * @private * @param {Date} date * @return {String} Formated month, year string */ _buildMonthLabel : function(date) { var monthLabel = this.Locale.LOCALE_MONTHS[date.getMonth()] + this.Locale.MY_LABEL_MONTH_SUFFIX, yearLabel = date.getFullYear() + this.Locale.MY_LABEL_YEAR_SUFFIX; if (this.Locale.MY_LABEL_MONTH_POSITION == 2 || this.Locale.MY_LABEL_YEAR_POSITION == 1) { return yearLabel + monthLabel; } else { return monthLabel + yearLabel; } }, /** * Builds the date digit that will be displayed in calendar cells * @method buildDayLabel * @param {Date} workingDate The current working date * @return {String} The formatted day label */ buildDayLabel : function(workingDate) { return workingDate.getDate(); }, /** * Creates the title bar element and adds it to Calendar container DIV * * @method createTitleBar * @param {String} strTitle The title to display in the title bar * @return The title bar element */ createTitleBar : function(strTitle) { var tDiv = Dom.getElementsByClassName(YAHOO.widget.CalendarGroup.CSS_2UPTITLE, "div", this.oDomContainer)[0] || document.createElement("div"); tDiv.className = YAHOO.widget.CalendarGroup.CSS_2UPTITLE; tDiv.innerHTML = strTitle; this.oDomContainer.insertBefore(tDiv, this.oDomContainer.firstChild); Dom.addClass(this.oDomContainer, "withtitle"); return tDiv; }, /** * Removes the title bar element from the DOM * * @method removeTitleBar */ removeTitleBar : function() { var tDiv = Dom.getElementsByClassName(YAHOO.widget.CalendarGroup.CSS_2UPTITLE, "div", this.oDomContainer)[0] || null; if (tDiv) { Event.purgeElement(tDiv); this.oDomContainer.removeChild(tDiv); } Dom.removeClass(this.oDomContainer, "withtitle"); }, /** * Creates the close button HTML element and adds it to Calendar container DIV * * @method createCloseButton * @return The close HTML element created */ createCloseButton : function() { var cssClose = YAHOO.widget.CalendarGroup.CSS_2UPCLOSE, DEPR_CLOSE_PATH = "us/my/bn/x_d.gif", lnk = Dom.getElementsByClassName("link-close", "a", this.oDomContainer)[0], strings = this.cfg.getProperty(DEF_CFG.STRINGS.key), closeStr = (strings && strings.close) ? strings.close : ""; if (!lnk) { lnk = document.createElement("a"); Event.addListener(lnk, "click", function(e, cal) { cal.hide(); Event.preventDefault(e); }, this); } lnk.href = "#"; lnk.className = "link-close"; if (Calendar.IMG_ROOT !== null) { var img = Dom.getElementsByClassName(cssClose, "img", lnk)[0] || document.createElement("img"); img.src = Calendar.IMG_ROOT + DEPR_CLOSE_PATH; img.className = cssClose; lnk.appendChild(img); } else { lnk.innerHTML = '' + closeStr + ''; } this.oDomContainer.appendChild(lnk); return lnk; }, /** * Removes the close button HTML element from the DOM * * @method removeCloseButton */ removeCloseButton : function() { var btn = Dom.getElementsByClassName("link-close", "a", this.oDomContainer)[0] || null; if (btn) { Event.purgeElement(btn); this.oDomContainer.removeChild(btn); } }, /** * Renders the calendar header. * @method renderHeader * @param {Array} html The current working HTML array * @return {Array} The current working HTML array */ renderHeader : function(html) { var colSpan = 7, DEPR_NAV_LEFT = "us/tr/callt.gif", DEPR_NAV_RIGHT = "us/tr/calrt.gif", cfg = this.cfg, pageDate = cfg.getProperty(DEF_CFG.PAGEDATE.key), strings= cfg.getProperty(DEF_CFG.STRINGS.key), prevStr = (strings && strings.previousMonth) ? strings.previousMonth : "", nextStr = (strings && strings.nextMonth) ? strings.nextMonth : "", monthLabel; if (cfg.getProperty(DEF_CFG.SHOW_WEEK_HEADER.key)) { colSpan += 1; } if (cfg.getProperty(DEF_CFG.SHOW_WEEK_FOOTER.key)) { colSpan += 1; } html[html.length] = ""; html[html.length] = ""; html[html.length] = ''; html[html.length] = '
    '; var renderLeft, renderRight = false; if (this.parent) { if (this.index === 0) { renderLeft = true; } if (this.index == (this.parent.cfg.getProperty("pages") -1)) { renderRight = true; } } else { renderLeft = true; renderRight = true; } if (renderLeft) { monthLabel = this._buildMonthLabel(DateMath.subtract(pageDate, DateMath.MONTH, 1)); var leftArrow = cfg.getProperty(DEF_CFG.NAV_ARROW_LEFT.key); // Check for deprecated customization - If someone set IMG_ROOT, but didn't set NAV_ARROW_LEFT, then set NAV_ARROW_LEFT to the old deprecated value if (leftArrow === null && Calendar.IMG_ROOT !== null) { leftArrow = Calendar.IMG_ROOT + DEPR_NAV_LEFT; } var leftStyle = (leftArrow === null) ? "" : ' style="background-image:url(' + leftArrow + ')"'; html[html.length] = '' + prevStr + ' (' + monthLabel + ')' + ''; } var lbl = this.buildMonthLabel(); var cal = this.parent || this; if (cal.cfg.getProperty("navigator")) { lbl = "" + lbl + ""; } html[html.length] = lbl; if (renderRight) { monthLabel = this._buildMonthLabel(DateMath.add(pageDate, DateMath.MONTH, 1)); var rightArrow = cfg.getProperty(DEF_CFG.NAV_ARROW_RIGHT.key); if (rightArrow === null && Calendar.IMG_ROOT !== null) { rightArrow = Calendar.IMG_ROOT + DEPR_NAV_RIGHT; } var rightStyle = (rightArrow === null) ? "" : ' style="background-image:url(' + rightArrow + ')"'; html[html.length] = '' + nextStr + ' (' + monthLabel + ')' + ''; } html[html.length] = '
    \n\n'; if (cfg.getProperty(DEF_CFG.SHOW_WEEKDAYS.key)) { html = this.buildWeekdays(html); } html[html.length] = ''; return html; }, /** * Renders the Calendar's weekday headers. * @method buildWeekdays * @param {Array} html The current working HTML array * @return {Array} The current working HTML array */ buildWeekdays : function(html) { html[html.length] = ''; if (this.cfg.getProperty(DEF_CFG.SHOW_WEEK_HEADER.key)) { html[html.length] = ' '; } for(var i=0;i < this.Locale.LOCALE_WEEKDAYS.length; ++i) { html[html.length] = '' + this.Locale.LOCALE_WEEKDAYS[i] + ''; } if (this.cfg.getProperty(DEF_CFG.SHOW_WEEK_FOOTER.key)) { html[html.length] = ' '; } html[html.length] = ''; return html; }, /** * Renders the calendar body. * @method renderBody * @param {Date} workingDate The current working Date being used for the render process * @param {Array} html The current working HTML array * @return {Array} The current working HTML array */ renderBody : function(workingDate, html) { var startDay = this.cfg.getProperty(DEF_CFG.START_WEEKDAY.key); this.preMonthDays = workingDate.getDay(); if (startDay > 0) { this.preMonthDays -= startDay; } if (this.preMonthDays < 0) { this.preMonthDays += 7; } this.monthDays = DateMath.findMonthEnd(workingDate).getDate(); this.postMonthDays = Calendar.DISPLAY_DAYS-this.preMonthDays-this.monthDays; workingDate = DateMath.subtract(workingDate, DateMath.DAY, this.preMonthDays); var weekNum, weekClass, weekPrefix = "w", cellPrefix = "_cell", workingDayPrefix = "wd", dayPrefix = "d", cellRenderers, renderer, t = this.today, cfg = this.cfg, todayYear = t.getFullYear(), todayMonth = t.getMonth(), todayDate = t.getDate(), useDate = cfg.getProperty(DEF_CFG.PAGEDATE.key), hideBlankWeeks = cfg.getProperty(DEF_CFG.HIDE_BLANK_WEEKS.key), showWeekFooter = cfg.getProperty(DEF_CFG.SHOW_WEEK_FOOTER.key), showWeekHeader = cfg.getProperty(DEF_CFG.SHOW_WEEK_HEADER.key), mindate = cfg.getProperty(DEF_CFG.MINDATE.key), maxdate = cfg.getProperty(DEF_CFG.MAXDATE.key); if (mindate) { mindate = DateMath.clearTime(mindate); } if (maxdate) { maxdate = DateMath.clearTime(maxdate); } html[html.length] = ''; var i = 0, tempDiv = document.createElement("div"), cell = document.createElement("td"); tempDiv.appendChild(cell); var cal = this.parent || this; for (var r=0;r<6;r++) { weekNum = DateMath.getWeekNumber(workingDate, startDay); weekClass = weekPrefix + weekNum; // Local OOM check for performance, since we already have pagedate if (r !== 0 && hideBlankWeeks === true && workingDate.getMonth() != useDate.getMonth()) { break; } else { html[html.length] = ''; if (showWeekHeader) { html = this.renderRowHeader(weekNum, html); } for (var d=0; d < 7; d++){ // Render actual days cellRenderers = []; this.clearElement(cell); cell.className = this.Style.CSS_CELL; cell.id = this.id + cellPrefix + i; if (workingDate.getDate() == todayDate && workingDate.getMonth() == todayMonth && workingDate.getFullYear() == todayYear) { cellRenderers[cellRenderers.length]=cal.renderCellStyleToday; } var workingArray = [workingDate.getFullYear(),workingDate.getMonth()+1,workingDate.getDate()]; this.cellDates[this.cellDates.length] = workingArray; // Add this date to cellDates // Local OOM check for performance, since we already have pagedate if (workingDate.getMonth() != useDate.getMonth()) { cellRenderers[cellRenderers.length]=cal.renderCellNotThisMonth; } else { Dom.addClass(cell, workingDayPrefix + workingDate.getDay()); Dom.addClass(cell, dayPrefix + workingDate.getDate()); for (var s=0;s= d1.getTime() && workingDate.getTime() <= d2.getTime()) { renderer = rArray[2]; if (workingDate.getTime()==d2.getTime()) { this.renderStack.splice(s,1); } } break; case Calendar.WEEKDAY: var weekday = rArray[1][0]; if (workingDate.getDay()+1 == weekday) { renderer = rArray[2]; } break; case Calendar.MONTH: month = rArray[1][0]; if (workingDate.getMonth()+1 == month) { renderer = rArray[2]; } break; } if (renderer) { cellRenderers[cellRenderers.length]=renderer; } } } if (this._indexOfSelectedFieldArray(workingArray) > -1) { cellRenderers[cellRenderers.length]=cal.renderCellStyleSelected; } if ((mindate && (workingDate.getTime() < mindate.getTime())) || (maxdate && (workingDate.getTime() > maxdate.getTime())) ) { cellRenderers[cellRenderers.length]=cal.renderOutOfBoundsDate; } else { cellRenderers[cellRenderers.length]=cal.styleCellDefault; cellRenderers[cellRenderers.length]=cal.renderCellDefault; } for (var x=0; x < cellRenderers.length; ++x) { if (cellRenderers[x].call(cal, workingDate, cell) == Calendar.STOP_RENDER) { break; } } workingDate.setTime(workingDate.getTime() + DateMath.ONE_DAY_MS); // Just in case we crossed DST/Summertime boundaries workingDate = DateMath.clearTime(workingDate); if (i >= 0 && i <= 6) { Dom.addClass(cell, this.Style.CSS_CELL_TOP); } if ((i % 7) === 0) { Dom.addClass(cell, this.Style.CSS_CELL_LEFT); } if (((i+1) % 7) === 0) { Dom.addClass(cell, this.Style.CSS_CELL_RIGHT); } var postDays = this.postMonthDays; if (hideBlankWeeks && postDays >= 7) { var blankWeeks = Math.floor(postDays/7); for (var p=0;p= ((this.preMonthDays+postDays+this.monthDays)-7)) { Dom.addClass(cell, this.Style.CSS_CELL_BOTTOM); } html[html.length] = tempDiv.innerHTML; i++; } if (showWeekFooter) { html = this.renderRowFooter(weekNum, html); } html[html.length] = ''; } } html[html.length] = ''; return html; }, /** * Renders the calendar footer. In the default implementation, there is * no footer. * @method renderFooter * @param {Array} html The current working HTML array * @return {Array} The current working HTML array */ renderFooter : function(html) { return html; }, /** * Renders the calendar after it has been configured. The render() method has a specific call chain that will execute * when the method is called: renderHeader, renderBody, renderFooter. * Refer to the documentation for those methods for information on * individual render tasks. * @method render */ render : function() { this.beforeRenderEvent.fire(); // Find starting day of the current month var workingDate = DateMath.findMonthStart(this.cfg.getProperty(DEF_CFG.PAGEDATE.key)); this.resetRenderers(); this.cellDates.length = 0; Event.purgeElement(this.oDomContainer, true); var html = []; html[html.length] = ''; html = this.renderHeader(html); html = this.renderBody(workingDate, html); html = this.renderFooter(html); html[html.length] = '
    '; this.oDomContainer.innerHTML = html.join("\n"); this.applyListeners(); this.cells = this.oDomContainer.getElementsByTagName("td"); this.cfg.refireEvent(DEF_CFG.TITLE.key); this.cfg.refireEvent(DEF_CFG.CLOSE.key); this.cfg.refireEvent(DEF_CFG.IFRAME.key); this.renderEvent.fire(); }, /** * Applies the Calendar's DOM listeners to applicable elements. * @method applyListeners */ applyListeners : function() { var root = this.oDomContainer, cal = this.parent || this, anchor = "a", click = "click"; var linkLeft = Dom.getElementsByClassName(this.Style.CSS_NAV_LEFT, anchor, root), linkRight = Dom.getElementsByClassName(this.Style.CSS_NAV_RIGHT, anchor, root); if (linkLeft && linkLeft.length > 0) { this.linkLeft = linkLeft[0]; Event.addListener(this.linkLeft, click, this.doPreviousMonthNav, cal, true); } if (linkRight && linkRight.length > 0) { this.linkRight = linkRight[0]; Event.addListener(this.linkRight, click, this.doNextMonthNav, cal, true); } if (cal.cfg.getProperty("navigator") !== null) { this.applyNavListeners(); } if (this.domEventMap) { var el,elements; for (var cls in this.domEventMap) { if (Lang.hasOwnProperty(this.domEventMap, cls)) { var items = this.domEventMap[cls]; if (! (items instanceof Array)) { items = [items]; } for (var i=0;i 0) { Event.addListener(navBtns, "click", function (e, obj) { var target = Event.getTarget(e); // this == navBtn if (this === target || Dom.isAncestor(this, target)) { Event.preventDefault(e); } var navigator = calParent.oNavigator; if (navigator) { var pgdate = cal.cfg.getProperty("pagedate"); navigator.setYear(pgdate.getFullYear()); navigator.setMonth(pgdate.getMonth()); navigator.show(); } }); } }, /** * Retrieves the Date object for the specified Calendar cell * @method getDateByCellId * @param {String} id The id of the cell * @return {Date} The Date object for the specified Calendar cell */ getDateByCellId : function(id) { var date = this.getDateFieldsByCellId(id); return (date) ? DateMath.getDate(date[0],date[1]-1,date[2]) : null; }, /** * Retrieves the Date object for the specified Calendar cell * @method getDateFieldsByCellId * @param {String} id The id of the cell * @return {Array} The array of Date fields for the specified Calendar cell */ getDateFieldsByCellId : function(id) { id = this.getIndexFromId(id); return (id > -1) ? this.cellDates[id] : null; }, /** * Find the Calendar's cell index for a given date. * If the date is not found, the method returns -1. *

    * The returned index can be used to lookup the cell HTMLElement * using the Calendar's cells array or passed to selectCell to select * cells by index. *

    * * See cells, selectCell. * * @method getCellIndex * @param {Date} date JavaScript Date object, for which to find a cell index. * @return {Number} The index of the date in Calendars cellDates/cells arrays, or -1 if the date * is not on the curently rendered Calendar page. */ getCellIndex : function(date) { var idx = -1; if (date) { var m = date.getMonth(), y = date.getFullYear(), d = date.getDate(), dates = this.cellDates; for (var i = 0; i < dates.length; ++i) { var cellDate = dates[i]; if (cellDate[0] === y && cellDate[1] === m+1 && cellDate[2] === d) { idx = i; break; } } } return idx; }, /** * Given the id used to mark each Calendar cell, this method * extracts the index number from the id. * * @param {String} strId The cell id * @return {Number} The index of the cell, or -1 if id does not contain an index number */ getIndexFromId : function(strId) { var idx = -1, li = strId.lastIndexOf("_cell"); if (li > -1) { idx = parseInt(strId.substring(li + 5), 10); } return idx; }, // BEGIN BUILT-IN TABLE CELL RENDERERS /** * Renders a cell that falls before the minimum date or after the maximum date. * widget class. * @method renderOutOfBoundsDate * @param {Date} workingDate The current working Date object being used to generate the calendar * @param {HTMLTableCellElement} cell The current working cell in the calendar * @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering * should not be terminated */ renderOutOfBoundsDate : function(workingDate, cell) { Dom.addClass(cell, this.Style.CSS_CELL_OOB); cell.innerHTML = workingDate.getDate(); return Calendar.STOP_RENDER; }, /** * Renders the row header for a week. * @method renderRowHeader * @param {Number} weekNum The week number of the current row * @param {Array} cell The current working HTML array */ renderRowHeader : function(weekNum, html) { html[html.length] = '' + weekNum + ''; return html; }, /** * Renders the row footer for a week. * @method renderRowFooter * @param {Number} weekNum The week number of the current row * @param {Array} cell The current working HTML array */ renderRowFooter : function(weekNum, html) { html[html.length] = '' + weekNum + ''; return html; }, /** * Renders a single standard calendar cell in the calendar widget table. * All logic for determining how a standard default cell will be rendered is * encapsulated in this method, and must be accounted for when extending the * widget class. * @method renderCellDefault * @param {Date} workingDate The current working Date object being used to generate the calendar * @param {HTMLTableCellElement} cell The current working cell in the calendar */ renderCellDefault : function(workingDate, cell) { cell.innerHTML = '' + this.buildDayLabel(workingDate) + ""; }, /** * Styles a selectable cell. * @method styleCellDefault * @param {Date} workingDate The current working Date object being used to generate the calendar * @param {HTMLTableCellElement} cell The current working cell in the calendar */ styleCellDefault : function(workingDate, cell) { Dom.addClass(cell, this.Style.CSS_CELL_SELECTABLE); }, /** * Renders a single standard calendar cell using the CSS hightlight1 style * @method renderCellStyleHighlight1 * @param {Date} workingDate The current working Date object being used to generate the calendar * @param {HTMLTableCellElement} cell The current working cell in the calendar */ renderCellStyleHighlight1 : function(workingDate, cell) { Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT1); }, /** * Renders a single standard calendar cell using the CSS hightlight2 style * @method renderCellStyleHighlight2 * @param {Date} workingDate The current working Date object being used to generate the calendar * @param {HTMLTableCellElement} cell The current working cell in the calendar */ renderCellStyleHighlight2 : function(workingDate, cell) { Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT2); }, /** * Renders a single standard calendar cell using the CSS hightlight3 style * @method renderCellStyleHighlight3 * @param {Date} workingDate The current working Date object being used to generate the calendar * @param {HTMLTableCellElement} cell The current working cell in the calendar */ renderCellStyleHighlight3 : function(workingDate, cell) { Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT3); }, /** * Renders a single standard calendar cell using the CSS hightlight4 style * @method renderCellStyleHighlight4 * @param {Date} workingDate The current working Date object being used to generate the calendar * @param {HTMLTableCellElement} cell The current working cell in the calendar */ renderCellStyleHighlight4 : function(workingDate, cell) { Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT4); }, /** * Applies the default style used for rendering today's date to the current calendar cell * @method renderCellStyleToday * @param {Date} workingDate The current working Date object being used to generate the calendar * @param {HTMLTableCellElement} cell The current working cell in the calendar */ renderCellStyleToday : function(workingDate, cell) { Dom.addClass(cell, this.Style.CSS_CELL_TODAY); }, /** * Applies the default style used for rendering selected dates to the current calendar cell * @method renderCellStyleSelected * @param {Date} workingDate The current working Date object being used to generate the calendar * @param {HTMLTableCellElement} cell The current working cell in the calendar * @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering * should not be terminated */ renderCellStyleSelected : function(workingDate, cell) { Dom.addClass(cell, this.Style.CSS_CELL_SELECTED); }, /** * Applies the default style used for rendering dates that are not a part of the current * month (preceding or trailing the cells for the current month) * @method renderCellNotThisMonth * @param {Date} workingDate The current working Date object being used to generate the calendar * @param {HTMLTableCellElement} cell The current working cell in the calendar * @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering * should not be terminated */ renderCellNotThisMonth : function(workingDate, cell) { Dom.addClass(cell, this.Style.CSS_CELL_OOM); cell.innerHTML=workingDate.getDate(); return Calendar.STOP_RENDER; }, /** * Renders the current calendar cell as a non-selectable "black-out" date using the default * restricted style. * @method renderBodyCellRestricted * @param {Date} workingDate The current working Date object being used to generate the calendar * @param {HTMLTableCellElement} cell The current working cell in the calendar * @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering * should not be terminated */ renderBodyCellRestricted : function(workingDate, cell) { Dom.addClass(cell, this.Style.CSS_CELL); Dom.addClass(cell, this.Style.CSS_CELL_RESTRICTED); cell.innerHTML=workingDate.getDate(); return Calendar.STOP_RENDER; }, // END BUILT-IN TABLE CELL RENDERERS // BEGIN MONTH NAVIGATION METHODS /** * Adds the designated number of months to the current calendar month, and sets the current * calendar page date to the new month. * @method addMonths * @param {Number} count The number of months to add to the current calendar */ addMonths : function(count) { var cfgPageDate = DEF_CFG.PAGEDATE.key; this.cfg.setProperty(cfgPageDate, DateMath.add(this.cfg.getProperty(cfgPageDate), DateMath.MONTH, count)); this.resetRenderers(); this.changePageEvent.fire(); }, /** * Subtracts the designated number of months from the current calendar month, and sets the current * calendar page date to the new month. * @method subtractMonths * @param {Number} count The number of months to subtract from the current calendar */ subtractMonths : function(count) { var cfgPageDate = DEF_CFG.PAGEDATE.key; this.cfg.setProperty(cfgPageDate, DateMath.subtract(this.cfg.getProperty(cfgPageDate), DateMath.MONTH, count)); this.resetRenderers(); this.changePageEvent.fire(); }, /** * Adds the designated number of years to the current calendar, and sets the current * calendar page date to the new month. * @method addYears * @param {Number} count The number of years to add to the current calendar */ addYears : function(count) { var cfgPageDate = DEF_CFG.PAGEDATE.key; this.cfg.setProperty(cfgPageDate, DateMath.add(this.cfg.getProperty(cfgPageDate), DateMath.YEAR, count)); this.resetRenderers(); this.changePageEvent.fire(); }, /** * Subtcats the designated number of years from the current calendar, and sets the current * calendar page date to the new month. * @method subtractYears * @param {Number} count The number of years to subtract from the current calendar */ subtractYears : function(count) { var cfgPageDate = DEF_CFG.PAGEDATE.key; this.cfg.setProperty(cfgPageDate, DateMath.subtract(this.cfg.getProperty(cfgPageDate), DateMath.YEAR, count)); this.resetRenderers(); this.changePageEvent.fire(); }, /** * Navigates to the next month page in the calendar widget. * @method nextMonth */ nextMonth : function() { this.addMonths(1); }, /** * Navigates to the previous month page in the calendar widget. * @method previousMonth */ previousMonth : function() { this.subtractMonths(1); }, /** * Navigates to the next year in the currently selected month in the calendar widget. * @method nextYear */ nextYear : function() { this.addYears(1); }, /** * Navigates to the previous year in the currently selected month in the calendar widget. * @method previousYear */ previousYear : function() { this.subtractYears(1); }, // END MONTH NAVIGATION METHODS // BEGIN SELECTION METHODS /** * Resets the calendar widget to the originally selected month and year, and * sets the calendar to the initial selection(s). * @method reset */ reset : function() { this.cfg.resetProperty(DEF_CFG.SELECTED.key); this.cfg.resetProperty(DEF_CFG.PAGEDATE.key); this.resetEvent.fire(); }, /** * Clears the selected dates in the current calendar widget and sets the calendar * to the current month and year. * @method clear */ clear : function() { this.cfg.setProperty(DEF_CFG.SELECTED.key, []); this.cfg.setProperty(DEF_CFG.PAGEDATE.key, new Date(this.today.getTime())); this.clearEvent.fire(); }, /** * Selects a date or a collection of dates on the current calendar. This method, by default, * does not call the render method explicitly. Once selection has completed, render must be * called for the changes to be reflected visually. * * Any dates which are OOB (out of bounds, not selectable) will not be selected and the array of * selected dates passed to the selectEvent will not contain OOB dates. * * If all dates are OOB, the no state change will occur; beforeSelect and select events will not be fired. * * @method select * @param {String/Date/Date[]} date The date string of dates to select in the current calendar. Valid formats are * individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006). * Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005). * This method can also take a JavaScript Date object or an array of Date objects. * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected. */ select : function(date) { var aToBeSelected = this._toFieldArray(date), validDates = [], selected = [], cfgSelected = DEF_CFG.SELECTED.key; for (var a=0; a < aToBeSelected.length; ++a) { var toSelect = aToBeSelected[a]; if (!this.isDateOOB(this._toDate(toSelect))) { if (validDates.length === 0) { this.beforeSelectEvent.fire(); selected = this.cfg.getProperty(cfgSelected); } validDates.push(toSelect); if (this._indexOfSelectedFieldArray(toSelect) == -1) { selected[selected.length] = toSelect; } } } if (validDates.length > 0) { if (this.parent) { this.parent.cfg.setProperty(cfgSelected, selected); } else { this.cfg.setProperty(cfgSelected, selected); } this.selectEvent.fire(validDates); } return this.getSelectedDates(); }, /** * Selects a date on the current calendar by referencing the index of the cell that should be selected. * This method is used to easily select a single cell (usually with a mouse click) without having to do * a full render. The selected style is applied to the cell directly. * * If the cell is not marked with the CSS_CELL_SELECTABLE class (as is the case by default for out of month * or out of bounds cells), it will not be selected and in such a case beforeSelect and select events will not be fired. * * @method selectCell * @param {Number} cellIndex The index of the cell to select in the current calendar. * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected. */ selectCell : function(cellIndex) { var cell = this.cells[cellIndex], cellDate = this.cellDates[cellIndex], dCellDate = this._toDate(cellDate), selectable = Dom.hasClass(cell, this.Style.CSS_CELL_SELECTABLE); if (selectable) { this.beforeSelectEvent.fire(); var cfgSelected = DEF_CFG.SELECTED.key; var selected = this.cfg.getProperty(cfgSelected); var selectDate = cellDate.concat(); if (this._indexOfSelectedFieldArray(selectDate) == -1) { selected[selected.length] = selectDate; } if (this.parent) { this.parent.cfg.setProperty(cfgSelected, selected); } else { this.cfg.setProperty(cfgSelected, selected); } this.renderCellStyleSelected(dCellDate,cell); this.selectEvent.fire([selectDate]); this.doCellMouseOut.call(cell, null, this); } return this.getSelectedDates(); }, /** * Deselects a date or a collection of dates on the current calendar. This method, by default, * does not call the render method explicitly. Once deselection has completed, render must be * called for the changes to be reflected visually. * * The method will not attempt to deselect any dates which are OOB (out of bounds, and hence not selectable) * and the array of deselected dates passed to the deselectEvent will not contain any OOB dates. * * If all dates are OOB, beforeDeselect and deselect events will not be fired. * * @method deselect * @param {String/Date/Date[]} date The date string of dates to deselect in the current calendar. Valid formats are * individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006). * Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005). * This method can also take a JavaScript Date object or an array of Date objects. * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected. */ deselect : function(date) { var aToBeDeselected = this._toFieldArray(date), validDates = [], selected = [], cfgSelected = DEF_CFG.SELECTED.key; for (var a=0; a < aToBeDeselected.length; ++a) { var toDeselect = aToBeDeselected[a]; if (!this.isDateOOB(this._toDate(toDeselect))) { if (validDates.length === 0) { this.beforeDeselectEvent.fire(); selected = this.cfg.getProperty(cfgSelected); } validDates.push(toDeselect); var index = this._indexOfSelectedFieldArray(toDeselect); if (index != -1) { selected.splice(index,1); } } } if (validDates.length > 0) { if (this.parent) { this.parent.cfg.setProperty(cfgSelected, selected); } else { this.cfg.setProperty(cfgSelected, selected); } this.deselectEvent.fire(validDates); } return this.getSelectedDates(); }, /** * Deselects a date on the current calendar by referencing the index of the cell that should be deselected. * This method is used to easily deselect a single cell (usually with a mouse click) without having to do * a full render. The selected style is removed from the cell directly. * * If the cell is not marked with the CSS_CELL_SELECTABLE class (as is the case by default for out of month * or out of bounds cells), the method will not attempt to deselect it and in such a case, beforeDeselect and * deselect events will not be fired. * * @method deselectCell * @param {Number} cellIndex The index of the cell to deselect in the current calendar. * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected. */ deselectCell : function(cellIndex) { var cell = this.cells[cellIndex], cellDate = this.cellDates[cellIndex], cellDateIndex = this._indexOfSelectedFieldArray(cellDate); var selectable = Dom.hasClass(cell, this.Style.CSS_CELL_SELECTABLE); if (selectable) { this.beforeDeselectEvent.fire(); var selected = this.cfg.getProperty(DEF_CFG.SELECTED.key), dCellDate = this._toDate(cellDate), selectDate = cellDate.concat(); if (cellDateIndex > -1) { if (this.cfg.getProperty(DEF_CFG.PAGEDATE.key).getMonth() == dCellDate.getMonth() && this.cfg.getProperty(DEF_CFG.PAGEDATE.key).getFullYear() == dCellDate.getFullYear()) { Dom.removeClass(cell, this.Style.CSS_CELL_SELECTED); } selected.splice(cellDateIndex, 1); } if (this.parent) { this.parent.cfg.setProperty(DEF_CFG.SELECTED.key, selected); } else { this.cfg.setProperty(DEF_CFG.SELECTED.key, selected); } this.deselectEvent.fire([selectDate]); } return this.getSelectedDates(); }, /** * Deselects all dates on the current calendar. * @method deselectAll * @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected. * Assuming that this function executes properly, the return value should be an empty array. * However, the empty array is returned for the sake of being able to check the selection status * of the calendar. */ deselectAll : function() { this.beforeDeselectEvent.fire(); var cfgSelected = DEF_CFG.SELECTED.key, selected = this.cfg.getProperty(cfgSelected), count = selected.length, sel = selected.concat(); if (this.parent) { this.parent.cfg.setProperty(cfgSelected, []); } else { this.cfg.setProperty(cfgSelected, []); } if (count > 0) { this.deselectEvent.fire(sel); } return this.getSelectedDates(); }, // END SELECTION METHODS // BEGIN TYPE CONVERSION METHODS /** * Converts a date (either a JavaScript Date object, or a date string) to the internal data structure * used to represent dates: [[yyyy,mm,dd],[yyyy,mm,dd]]. * @method _toFieldArray * @private * @param {String/Date/Date[]} date The date string of dates to deselect in the current calendar. Valid formats are * individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006). * Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005). * This method can also take a JavaScript Date object or an array of Date objects. * @return {Array[](Number[])} Array of date field arrays */ _toFieldArray : function(date) { var returnDate = []; if (date instanceof Date) { returnDate = [[date.getFullYear(), date.getMonth()+1, date.getDate()]]; } else if (Lang.isString(date)) { returnDate = this._parseDates(date); } else if (Lang.isArray(date)) { for (var i=0;i maxDate.getTime())); }, /** * Parses a pagedate configuration property value. The value can either be specified as a string of form "mm/yyyy" or a Date object * and is parsed into a Date object normalized to the first day of the month. If no value is passed in, the month and year from today's date are used to create the Date object * @method _parsePageDate * @private * @param {Date|String} date Pagedate value which needs to be parsed * @return {Date} The Date object representing the pagedate */ _parsePageDate : function(date) { var parsedDate; if (date) { if (date instanceof Date) { parsedDate = DateMath.findMonthStart(date); } else { var month, year, aMonthYear; aMonthYear = date.split(this.cfg.getProperty(DEF_CFG.DATE_FIELD_DELIMITER.key)); month = parseInt(aMonthYear[this.cfg.getProperty(DEF_CFG.MY_MONTH_POSITION.key)-1], 10)-1; year = parseInt(aMonthYear[this.cfg.getProperty(DEF_CFG.MY_YEAR_POSITION.key)-1], 10); parsedDate = DateMath.getDate(year, month, 1); } } else { parsedDate = DateMath.getDate(this.today.getFullYear(), this.today.getMonth(), 1); } return parsedDate; }, // END UTILITY METHODS // BEGIN EVENT HANDLERS /** * Event executed before a date is selected in the calendar widget. * @deprecated Event handlers for this event should be susbcribed to beforeSelectEvent. */ onBeforeSelect : function() { if (this.cfg.getProperty(DEF_CFG.MULTI_SELECT.key) === false) { if (this.parent) { this.parent.callChildFunction("clearAllBodyCellStyles", this.Style.CSS_CELL_SELECTED); this.parent.deselectAll(); } else { this.clearAllBodyCellStyles(this.Style.CSS_CELL_SELECTED); this.deselectAll(); } } }, /** * Event executed when a date is selected in the calendar widget. * @param {Array} selected An array of date field arrays representing which date or dates were selected. Example: [ [2006,8,6],[2006,8,7],[2006,8,8] ] * @deprecated Event handlers for this event should be susbcribed to selectEvent. */ onSelect : function(selected) { }, /** * Event executed before a date is deselected in the calendar widget. * @deprecated Event handlers for this event should be susbcribed to beforeDeselectEvent. */ onBeforeDeselect : function() { }, /** * Event executed when a date is deselected in the calendar widget. * @param {Array} selected An array of date field arrays representing which date or dates were deselected. Example: [ [2006,8,6],[2006,8,7],[2006,8,8] ] * @deprecated Event handlers for this event should be susbcribed to deselectEvent. */ onDeselect : function(deselected) { }, /** * Event executed when the user navigates to a different calendar page. * @deprecated Event handlers for this event should be susbcribed to changePageEvent. */ onChangePage : function() { this.render(); }, /** * Event executed when the calendar widget is rendered. * @deprecated Event handlers for this event should be susbcribed to renderEvent. */ onRender : function() { }, /** * Event executed when the calendar widget is reset to its original state. * @deprecated Event handlers for this event should be susbcribed to resetEvemt. */ onReset : function() { this.render(); }, /** * Event executed when the calendar widget is completely cleared to the current month with no selections. * @deprecated Event handlers for this event should be susbcribed to clearEvent. */ onClear : function() { this.render(); }, /** * Validates the calendar widget. This method has no default implementation * and must be extended by subclassing the widget. * @return Should return true if the widget validates, and false if * it doesn't. * @type Boolean */ validate : function() { return true; }, // END EVENT HANDLERS // BEGIN DATE PARSE METHODS /** * Converts a date string to a date field array * @private * @param {String} sDate Date string. Valid formats are mm/dd and mm/dd/yyyy. * @return A date field array representing the string passed to the method * @type Array[](Number[]) */ _parseDate : function(sDate) { var aDate = sDate.split(this.Locale.DATE_FIELD_DELIMITER), rArray; if (aDate.length == 2) { rArray = [aDate[this.Locale.MD_MONTH_POSITION-1],aDate[this.Locale.MD_DAY_POSITION-1]]; rArray.type = Calendar.MONTH_DAY; } else { rArray = [aDate[this.Locale.MDY_YEAR_POSITION-1],aDate[this.Locale.MDY_MONTH_POSITION-1],aDate[this.Locale.MDY_DAY_POSITION-1]]; rArray.type = Calendar.DATE; } for (var i=0;i *
    *
    * * The tables for the calendars ("cal1_0" and "cal1_1") will be inserted into those containers. * *

    * NOTE: As of 2.4.0, the constructor's ID argument is optional. * The CalendarGroup can be constructed by simply providing a container ID string, * or a reference to a container DIV HTMLElement (the element needs to exist * in the document). * * E.g.: *

    * var c = new YAHOO.widget.CalendarGroup("calContainer", configOptions); * * or: * * var containerDiv = YAHOO.util.Dom.get("calContainer"); * var c = new YAHOO.widget.CalendarGroup(containerDiv, configOptions); * *

    *

    * If not provided, the ID will be generated from the container DIV ID by adding an "_t" suffix. * For example if an ID is not provided, and the container's ID is "calContainer", the CalendarGroup's ID will be set to "calContainer_t". *

    * * @namespace YAHOO.widget * @class CalendarGroup * @constructor * @param {String} id optional The id of the table element that will represent the CalendarGroup widget. As of 2.4.0, this argument is optional. * @param {String | HTMLElement} container The id of the container div element that will wrap the CalendarGroup table, or a reference to a DIV element which exists in the document. * @param {Object} config optional The configuration object containing the initial configuration values for the CalendarGroup. */ function CalendarGroup(id, containerId, config) { if (arguments.length > 0) { this.init.apply(this, arguments); } } /** * The set of default Config property keys and values for the CalendarGroup * @property YAHOO.widget.CalendarGroup._DEFAULT_CONFIG * @final * @static * @private * @type Object */ CalendarGroup._DEFAULT_CONFIG = Calendar._DEFAULT_CONFIG; CalendarGroup._DEFAULT_CONFIG.PAGES = {key:"pages", value:2}; var DEF_CFG = CalendarGroup._DEFAULT_CONFIG; CalendarGroup.prototype = { /** * Initializes the calendar group. All subclasses must call this method in order for the * group to be initialized properly. * @method init * @param {String} id optional The id of the table element that will represent the CalendarGroup widget. As of 2.4.0, this argument is optional. * @param {String | HTMLElement} container The id of the container div element that will wrap the CalendarGroup table, or a reference to a DIV element which exists in the document. * @param {Object} config optional The configuration object containing the initial configuration values for the CalendarGroup. */ init : function(id, container, config) { // Normalize 2.4.0, pre 2.4.0 args var nArgs = this._parseArgs(arguments); id = nArgs.id; container = nArgs.container; config = nArgs.config; this.oDomContainer = Dom.get(container); if (!this.oDomContainer.id) { this.oDomContainer.id = Dom.generateId(); } if (!id) { id = this.oDomContainer.id + "_t"; } /** * The unique id associated with the CalendarGroup * @property id * @type String */ this.id = id; /** * The unique id associated with the CalendarGroup container * @property containerId * @type String */ this.containerId = this.oDomContainer.id; this.initEvents(); this.initStyles(); /** * The collection of Calendar pages contained within the CalendarGroup * @property pages * @type YAHOO.widget.Calendar[] */ this.pages = []; Dom.addClass(this.oDomContainer, CalendarGroup.CSS_CONTAINER); Dom.addClass(this.oDomContainer, CalendarGroup.CSS_MULTI_UP); /** * The Config object used to hold the configuration variables for the CalendarGroup * @property cfg * @type YAHOO.util.Config */ this.cfg = new YAHOO.util.Config(this); /** * The local object which contains the CalendarGroup's options * @property Options * @type Object */ this.Options = {}; /** * The local object which contains the CalendarGroup's locale settings * @property Locale * @type Object */ this.Locale = {}; this.setupConfig(); if (config) { this.cfg.applyConfig(config, true); } this.cfg.fireQueue(); // OPERA HACK FOR MISWRAPPED FLOATS if (YAHOO.env.ua.opera){ this.renderEvent.subscribe(this._fixWidth, this, true); this.showEvent.subscribe(this._fixWidth, this, true); } }, setupConfig : function() { var cfg = this.cfg; /** * The number of pages to include in the CalendarGroup. This value can only be set once, in the CalendarGroup's constructor arguments. * @config pages * @type Number * @default 2 */ cfg.addProperty(DEF_CFG.PAGES.key, { value:DEF_CFG.PAGES.value, validator:cfg.checkNumber, handler:this.configPages } ); /** * The month/year representing the current visible Calendar date (mm/yyyy) * @config pagedate * @type String | Date * @default today's date */ cfg.addProperty(DEF_CFG.PAGEDATE.key, { value:new Date(), handler:this.configPageDate } ); /** * The date or range of dates representing the current Calendar selection * * @config selected * @type String * @default [] */ cfg.addProperty(DEF_CFG.SELECTED.key, { value:[], handler:this.configSelected } ); /** * The title to display above the CalendarGroup's month header * @config title * @type String * @default "" */ cfg.addProperty(DEF_CFG.TITLE.key, { value:DEF_CFG.TITLE.value, handler:this.configTitle } ); /** * Whether or not a close button should be displayed for this CalendarGroup * @config close * @type Boolean * @default false */ cfg.addProperty(DEF_CFG.CLOSE.key, { value:DEF_CFG.CLOSE.value, handler:this.configClose } ); /** * Whether or not an iframe shim should be placed under the Calendar to prevent select boxes from bleeding through in Internet Explorer 6 and below. * This property is enabled by default for IE6 and below. It is disabled by default for other browsers for performance reasons, but can be * enabled if required. * * @config iframe * @type Boolean * @default true for IE6 and below, false for all other browsers */ cfg.addProperty(DEF_CFG.IFRAME.key, { value:DEF_CFG.IFRAME.value, handler:this.configIframe, validator:cfg.checkBoolean } ); /** * The minimum selectable date in the current Calendar (mm/dd/yyyy) * @config mindate * @type String | Date * @default null */ cfg.addProperty(DEF_CFG.MINDATE.key, { value:DEF_CFG.MINDATE.value, handler:this.delegateConfig } ); /** * The maximum selectable date in the current Calendar (mm/dd/yyyy) * @config maxdate * @type String | Date * @default null */ cfg.addProperty(DEF_CFG.MAXDATE.key, { value:DEF_CFG.MAXDATE.value, handler:this.delegateConfig } ); // Options properties /** * True if the Calendar should allow multiple selections. False by default. * @config MULTI_SELECT * @type Boolean * @default false */ cfg.addProperty(DEF_CFG.MULTI_SELECT.key, { value:DEF_CFG.MULTI_SELECT.value, handler:this.delegateConfig, validator:cfg.checkBoolean } ); /** * The weekday the week begins on. Default is 0 (Sunday). * @config START_WEEKDAY * @type number * @default 0 */ cfg.addProperty(DEF_CFG.START_WEEKDAY.key, { value:DEF_CFG.START_WEEKDAY.value, handler:this.delegateConfig, validator:cfg.checkNumber } ); /** * True if the Calendar should show weekday labels. True by default. * @config SHOW_WEEKDAYS * @type Boolean * @default true */ cfg.addProperty(DEF_CFG.SHOW_WEEKDAYS.key, { value:DEF_CFG.SHOW_WEEKDAYS.value, handler:this.delegateConfig, validator:cfg.checkBoolean } ); /** * True if the Calendar should show week row headers. False by default. * @config SHOW_WEEK_HEADER * @type Boolean * @default false */ cfg.addProperty(DEF_CFG.SHOW_WEEK_HEADER.key,{ value:DEF_CFG.SHOW_WEEK_HEADER.value, handler:this.delegateConfig, validator:cfg.checkBoolean } ); /** * True if the Calendar should show week row footers. False by default. * @config SHOW_WEEK_FOOTER * @type Boolean * @default false */ cfg.addProperty(DEF_CFG.SHOW_WEEK_FOOTER.key,{ value:DEF_CFG.SHOW_WEEK_FOOTER.value, handler:this.delegateConfig, validator:cfg.checkBoolean } ); /** * True if the Calendar should suppress weeks that are not a part of the current month. False by default. * @config HIDE_BLANK_WEEKS * @type Boolean * @default false */ cfg.addProperty(DEF_CFG.HIDE_BLANK_WEEKS.key,{ value:DEF_CFG.HIDE_BLANK_WEEKS.value, handler:this.delegateConfig, validator:cfg.checkBoolean } ); /** * The image that should be used for the left navigation arrow. * @config NAV_ARROW_LEFT * @type String * @deprecated You can customize the image by overriding the default CSS class for the left arrow - "calnavleft" * @default null */ cfg.addProperty(DEF_CFG.NAV_ARROW_LEFT.key, { value:DEF_CFG.NAV_ARROW_LEFT.value, handler:this.delegateConfig } ); /** * The image that should be used for the right navigation arrow. * @config NAV_ARROW_RIGHT * @type String * @deprecated You can customize the image by overriding the default CSS class for the right arrow - "calnavright" * @default null */ cfg.addProperty(DEF_CFG.NAV_ARROW_RIGHT.key, { value:DEF_CFG.NAV_ARROW_RIGHT.value, handler:this.delegateConfig } ); // Locale properties /** * The short month labels for the current locale. * @config MONTHS_SHORT * @type String[] * @default ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] */ cfg.addProperty(DEF_CFG.MONTHS_SHORT.key, { value:DEF_CFG.MONTHS_SHORT.value, handler:this.delegateConfig } ); /** * The long month labels for the current locale. * @config MONTHS_LONG * @type String[] * @default ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" */ cfg.addProperty(DEF_CFG.MONTHS_LONG.key, { value:DEF_CFG.MONTHS_LONG.value, handler:this.delegateConfig } ); /** * The 1-character weekday labels for the current locale. * @config WEEKDAYS_1CHAR * @type String[] * @default ["S", "M", "T", "W", "T", "F", "S"] */ cfg.addProperty(DEF_CFG.WEEKDAYS_1CHAR.key, { value:DEF_CFG.WEEKDAYS_1CHAR.value, handler:this.delegateConfig } ); /** * The short weekday labels for the current locale. * @config WEEKDAYS_SHORT * @type String[] * @default ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"] */ cfg.addProperty(DEF_CFG.WEEKDAYS_SHORT.key, { value:DEF_CFG.WEEKDAYS_SHORT.value, handler:this.delegateConfig } ); /** * The medium weekday labels for the current locale. * @config WEEKDAYS_MEDIUM * @type String[] * @default ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] */ cfg.addProperty(DEF_CFG.WEEKDAYS_MEDIUM.key, { value:DEF_CFG.WEEKDAYS_MEDIUM.value, handler:this.delegateConfig } ); /** * The long weekday labels for the current locale. * @config WEEKDAYS_LONG * @type String[] * @default ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] */ cfg.addProperty(DEF_CFG.WEEKDAYS_LONG.key, { value:DEF_CFG.WEEKDAYS_LONG.value, handler:this.delegateConfig } ); /** * The setting that determines which length of month labels should be used. Possible values are "short" and "long". * @config LOCALE_MONTHS * @type String * @default "long" */ cfg.addProperty(DEF_CFG.LOCALE_MONTHS.key, { value:DEF_CFG.LOCALE_MONTHS.value, handler:this.delegateConfig } ); /** * The setting that determines which length of weekday labels should be used. Possible values are "1char", "short", "medium", and "long". * @config LOCALE_WEEKDAYS * @type String * @default "short" */ cfg.addProperty(DEF_CFG.LOCALE_WEEKDAYS.key, { value:DEF_CFG.LOCALE_WEEKDAYS.value, handler:this.delegateConfig } ); /** * The value used to delimit individual dates in a date string passed to various Calendar functions. * @config DATE_DELIMITER * @type String * @default "," */ cfg.addProperty(DEF_CFG.DATE_DELIMITER.key, { value:DEF_CFG.DATE_DELIMITER.value, handler:this.delegateConfig } ); /** * The value used to delimit date fields in a date string passed to various Calendar functions. * @config DATE_FIELD_DELIMITER * @type String * @default "/" */ cfg.addProperty(DEF_CFG.DATE_FIELD_DELIMITER.key,{ value:DEF_CFG.DATE_FIELD_DELIMITER.value, handler:this.delegateConfig } ); /** * The value used to delimit date ranges in a date string passed to various Calendar functions. * @config DATE_RANGE_DELIMITER * @type String * @default "-" */ cfg.addProperty(DEF_CFG.DATE_RANGE_DELIMITER.key,{ value:DEF_CFG.DATE_RANGE_DELIMITER.value, handler:this.delegateConfig } ); /** * The position of the month in a month/year date string * @config MY_MONTH_POSITION * @type Number * @default 1 */ cfg.addProperty(DEF_CFG.MY_MONTH_POSITION.key, { value:DEF_CFG.MY_MONTH_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } ); /** * The position of the year in a month/year date string * @config MY_YEAR_POSITION * @type Number * @default 2 */ cfg.addProperty(DEF_CFG.MY_YEAR_POSITION.key, { value:DEF_CFG.MY_YEAR_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } ); /** * The position of the month in a month/day date string * @config MD_MONTH_POSITION * @type Number * @default 1 */ cfg.addProperty(DEF_CFG.MD_MONTH_POSITION.key, { value:DEF_CFG.MD_MONTH_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } ); /** * The position of the day in a month/year date string * @config MD_DAY_POSITION * @type Number * @default 2 */ cfg.addProperty(DEF_CFG.MD_DAY_POSITION.key, { value:DEF_CFG.MD_DAY_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } ); /** * The position of the month in a month/day/year date string * @config MDY_MONTH_POSITION * @type Number * @default 1 */ cfg.addProperty(DEF_CFG.MDY_MONTH_POSITION.key, { value:DEF_CFG.MDY_MONTH_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } ); /** * The position of the day in a month/day/year date string * @config MDY_DAY_POSITION * @type Number * @default 2 */ cfg.addProperty(DEF_CFG.MDY_DAY_POSITION.key, { value:DEF_CFG.MDY_DAY_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } ); /** * The position of the year in a month/day/year date string * @config MDY_YEAR_POSITION * @type Number * @default 3 */ cfg.addProperty(DEF_CFG.MDY_YEAR_POSITION.key, { value:DEF_CFG.MDY_YEAR_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } ); /** * The position of the month in the month year label string used as the Calendar header * @config MY_LABEL_MONTH_POSITION * @type Number * @default 1 */ cfg.addProperty(DEF_CFG.MY_LABEL_MONTH_POSITION.key, { value:DEF_CFG.MY_LABEL_MONTH_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } ); /** * The position of the year in the month year label string used as the Calendar header * @config MY_LABEL_YEAR_POSITION * @type Number * @default 2 */ cfg.addProperty(DEF_CFG.MY_LABEL_YEAR_POSITION.key, { value:DEF_CFG.MY_LABEL_YEAR_POSITION.value, handler:this.delegateConfig, validator:cfg.checkNumber } ); /** * The suffix used after the month when rendering the Calendar header * @config MY_LABEL_MONTH_SUFFIX * @type String * @default " " */ cfg.addProperty(DEF_CFG.MY_LABEL_MONTH_SUFFIX.key, { value:DEF_CFG.MY_LABEL_MONTH_SUFFIX.value, handler:this.delegateConfig } ); /** * The suffix used after the year when rendering the Calendar header * @config MY_LABEL_YEAR_SUFFIX * @type String * @default "" */ cfg.addProperty(DEF_CFG.MY_LABEL_YEAR_SUFFIX.key, { value:DEF_CFG.MY_LABEL_YEAR_SUFFIX.value, handler:this.delegateConfig } ); /** * Configuration for the Month Year Navigation UI. By default it is disabled * @config NAV * @type Object * @default null */ cfg.addProperty(DEF_CFG.NAV.key, { value:DEF_CFG.NAV.value, handler:this.configNavigator } ); /** * The map of UI strings which the CalendarGroup UI uses. * * @config strings * @type {Object} * @default An object with the properties shown below: *
    *
    previousMonth
    String : The string to use for the "Previous Month" navigation UI. Defaults to "Previous Month".
    *
    nextMonth
    String : The string to use for the "Next Month" navigation UI. Defaults to "Next Month".
    *
    close
    String : The string to use for the close button label. Defaults to "Close".
    *
    */ cfg.addProperty(DEF_CFG.STRINGS.key, { value:DEF_CFG.STRINGS.value, handler:this.configStrings, validator: function(val) { return Lang.isObject(val); }, supercedes: DEF_CFG.STRINGS.supercedes }); }, /** * Initializes CalendarGroup's built-in CustomEvents * @method initEvents */ initEvents : function() { var me = this, strEvent = "Event", CE = YAHOO.util.CustomEvent; /** * Proxy subscriber to subscribe to the CalendarGroup's child Calendars' CustomEvents * @method sub * @private * @param {Function} fn The function to subscribe to this CustomEvent * @param {Object} obj The CustomEvent's scope object * @param {Boolean} bOverride Whether or not to apply scope correction */ var sub = function(fn, obj, bOverride) { for (var p=0;p