/* Copyright (c) 2006, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 0.12.0 */ (function() { YAHOO.util.Lang = { isArray: function(val) { // frames lose type, so test constructor string if (val.constructor && val.constructor.toString().indexOf('Array') > -1) { return true; } else { return YAHOO.util.Lang.isObject(val) && val.constructor == Array; } }, isBoolean: function(val) { return typeof val == 'boolean'; }, isFunction: function(val) { return typeof val == 'function'; }, isNull: function(val) { return val === null; }, isNumber: function(val) { return !isNaN(val); }, isObject: function(val) { return typeof val == 'object' || YAHOO.util.Lang.isFunction(val); }, isString: function(val) { return typeof val == 'string'; }, isUndefined: function(val) { return typeof val == 'undefined'; } }; })();/** * Provides Attribute configurations. * @namespace YAHOO.util * @class Attribute * @constructor * @param hash {Object} The intial Attribute. * @param {YAHOO.util.AttributeProvider} The owner of the Attribute instance. */ YAHOO.util.Attribute = function(hash, owner) { if (owner) { this.owner = owner; this.configure(hash, true); } }; YAHOO.util.Attribute.prototype = { /** * The name of the attribute. * @property name * @type String */ name: undefined, /** * The value of the attribute. * @property value * @type String */ value: null, /** * The owner of the attribute. * @property owner * @type YAHOO.util.AttributeProvider */ owner: null, /** * Whether or not the attribute is read only. * @property readOnly * @type Boolean */ readOnly: false, /** * Whether or not the attribute can only be written once. * @property writeOnce * @type Boolean */ writeOnce: false, /** * The attribute's initial configuration. * @private * @property _initialConfig * @type Object */ _initialConfig: null, /** * Whether or not the attribute's value has been set. * @private * @property _written * @type Boolean */ _written: false, /** * The method to use when setting the attribute's value. * The method recieves the new value as the only argument. * @property method * @type Function */ method: null, /** * The validator to use when setting the attribute's value. * @property validator * @type Function * @return Boolean */ validator: null, /** * Retrieves the current value of the attribute. * @method getValue * @return {any} The current value of the attribute. */ getValue: function() { return this.value; }, /** * Sets the value of the attribute and fires beforeChange and change events. * @method setValue * @param {Any} value The value to apply to the attribute. * @param {Boolean} silent If true the change events will not be fired. * @return {Boolean} Whether or not the value was set. */ setValue: function(value, silent) { var beforeRetVal; var owner = this.owner; var name = this.name; var event = { type: name, prevValue: this.getValue(), newValue: value }; if (this.readOnly || ( this.writeOnce && this._written) ) { return false; // write not allowed } if (this.validator && !this.validator.call(owner, value) ) { return false; // invalid value } if (!silent) { beforeRetVal = owner.fireBeforeChangeEvent(event); if (beforeRetVal === false) { YAHOO.log('setValue ' + name + 'cancelled by beforeChange event', 'info', 'Attribute'); return false; } } if (this.method) { this.method.call(owner, value); } this.value = value; this._written = true; event.type = name; if (!silent) { this.owner.fireChangeEvent(event); } return true; }, /** * Allows for configuring the Attribute's properties. * @method configure * @param {Object} map A key-value map of Attribute properties. * @param {Boolean} init Whether or not this should become the initial config. */ configure: function(map, init) { map = map || {}; this._written = false; // reset writeOnce this._initialConfig = this._initialConfig || {}; for (var key in map) { if ( key && map.hasOwnProperty(key) ) { this[key] = map[key]; if (init) { this._initialConfig[key] = map[key]; } } } }, /** * Resets the value to the initial config value. * @method resetValue * @return {Boolean} Whether or not the value was set. */ resetValue: function() { return this.setValue(this._initialConfig.value); }, /** * Resets the attribute config to the initial config state. * @method resetConfig */ resetConfig: function() { this.configure(this._initialConfig); }, /** * Resets the value to the current value. * Useful when values may have gotten out of sync with actual properties. * @method refresh * @return {Boolean} Whether or not the value was set. */ refresh: function(silent) { this.setValue(this.value, silent); } };(function() { var Lang = YAHOO.util.Lang; /* Copyright (c) 2006, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt */ /** * Provides and manages YAHOO.util.Attribute instances * @namespace YAHOO.util * @class AttributeProvider * @uses YAHOO.util.EventProvider */ YAHOO.util.AttributeProvider = function() {}; YAHOO.util.AttributeProvider.prototype = { /** * A key-value map of Attribute configurations * @property _configs * @protected (may be used by subclasses and augmentors) * @private * @type {Object} */ _configs: null, /** * Returns the current value of the attribute. * @method get * @param {String} key The attribute whose value will be returned. */ get: function(key){ var configs = this._configs || {}; var config = configs[key]; if (!config) { YAHOO.log(key + ' not found', 'error', 'AttributeProvider'); return undefined; } return config.value; }, /** * Sets the value of a config. * @method set * @param {String} key The name of the attribute * @param {Any} value The value to apply to the attribute * @param {Boolean} silent Whether or not to suppress change events * @return {Boolean} Whether or not the value was set. */ set: function(key, value, silent){ var configs = this._configs || {}; var config = configs[key]; if (!config) { YAHOO.log('set failed: ' + key + ' not found', 'error', 'AttributeProvider'); return false; } return config.setValue(value, silent); }, /** * Returns an array of attribute names. * @method getAttributeKeys * @return {Array} An array of attribute names. */ getAttributeKeys: function(){ var configs = this._configs; var keys = []; var config; for (var key in configs) { config = configs[key]; if ( configs.hasOwnProperty(key) && !Lang.isUndefined(config) ) { keys[keys.length] = key; } } return keys; }, /** * Sets multiple attribute values. * @method setAttributes * @param {Object} map A key-value map of attributes * @param {Boolean} silent Whether or not to suppress change events */ setAttributes: function(map, silent){ for (var key in map) { if ( map.hasOwnProperty(key) ) { this.set(key, map[key], silent); } } }, /** * Resets the specified attribute's value to its initial value. * @method resetValue * @param {String} key The name of the attribute * @param {Boolean} silent Whether or not to suppress change events * @return {Boolean} Whether or not the value was set */ resetValue: function(key, silent){ var configs = this._configs || {}; if (configs[key]) { this.set(key, configs[key]._initialConfig.value, silent); return true; } return false; }, /** * Sets the attribute's value to its current value. * @method refresh * @param {String | Array} key The attribute(s) to refresh * @param {Boolean} silent Whether or not to suppress change events */ refresh: function(key, silent){ var configs = this._configs; key = ( ( Lang.isString(key) ) ? [key] : key ) || this.getAttributeKeys(); for (var i = 0, len = key.length; i < len; ++i) { if ( // only set if there is a value and not null configs[key[i]] && ! Lang.isUndefined(configs[key[i]].value) && ! Lang.isNull(configs[key[i]].value) ) { configs[key[i]].refresh(silent); } } }, /** * Adds an Attribute to the AttributeProvider instance. * @method register * @param {String} key The attribute's name * @param {Object} map A key-value map containing the * attribute's properties. */ register: function(key, map) { this._configs = this._configs || {}; if (this._configs[key]) { // dont override return false; } map.name = key; this._configs[key] = new YAHOO.util.Attribute(map, this); return true; }, /** * Returns the attribute's properties. * @method getAttributeConfig * @param {String} key The attribute's name * @private * @return {object} A key-value map containing all of the * attribute's properties. */ getAttributeConfig: function(key) { var configs = this._configs || {}; var config = configs[key] || {}; var map = {}; // returning a copy to prevent overrides for (key in config) { if ( config.hasOwnProperty(key) ) { map[key] = config[key]; } } return map; }, /** * Sets or updates an Attribute instance's properties. * @method configureAttribute * @param {String} key The attribute's name. * @param {Object} map A key-value map of attribute properties * @param {Boolean} init Whether or not this should become the intial config. */ configureAttribute: function(key, map, init) { var configs = this._configs || {}; if (!configs[key]) { YAHOO.log('unable to configure, ' + key + ' not found', 'error', 'AttributeProvider'); return false; } configs[key].configure(map, init); }, /** * Resets an attribute to its intial configuration. * @method resetAttributeConfig * @param {String} key The attribute's name. * @private */ resetAttributeConfig: function(key){ var configs = this._configs || {}; configs[key].resetConfig(); }, /** * Fires the attribute's beforeChange event. * @method fireBeforeChangeEvent * @param {String} key The attribute's name. * @param {Obj} e The event object to pass to handlers. */ fireBeforeChangeEvent: function(e) { var type = 'before'; type += e.type.charAt(0).toUpperCase() + e.type.substr(1) + 'Change'; e.type = type; return this.fireEvent(e.type, e); }, /** * Fires the attribute's change event. * @method fireChangeEvent * @param {String} key The attribute's name. * @param {Obj} e The event object to pass to the handlers. */ fireChangeEvent: function(e) { e.type += 'Change'; return this.fireEvent(e.type, e); } }; YAHOO.augment(YAHOO.util.AttributeProvider, YAHOO.util.EventProvider); })();(function() { // internal shorthand var Dom = YAHOO.util.Dom, Lang = YAHOO.util.Lang, EventPublisher = YAHOO.util.EventPublisher, AttributeProvider = YAHOO.util.AttributeProvider; /** * Element provides an interface to an HTMLElement's attributes and common * methods. Other commonly used attributes are added as well. * @namespace YAHOO.util * @class Element * @uses YAHOO.util.AttributeProvider * @constructor * @param el {HTMLElement | String} The html element that * represents the Element. * @param {Object} map A key-value map of initial config names and values */ YAHOO.util.Element = function(el, map) { if (arguments.length) { this.init(el, map); } }; YAHOO.util.Element.prototype = { /** * Dom events supported by the Element instance. * @property DOM_EVENTS * @type Object */ DOM_EVENTS: null, /** * Wrapper for HTMLElement method. * @method appendChild * @param {Boolean} deep Whether or not to do a deep clone */ appendChild: function(child) { child = child.get ? child.get('element') : child; this.get('element').appendChild(child); }, /** * Wrapper for HTMLElement method. * @method getElementsByTagName * @param {String} tag The tagName to collect */ getElementsByTagName: function(tag) { return this.get('element').getElementsByTagName(tag); }, /** * Wrapper for HTMLElement method. * @method hasChildNodes * @return {Boolean} Whether or not the element has childNodes */ hasChildNodes: function() { return this.get('element').hasChildNodes(); }, /** * Wrapper for HTMLElement method. * @method insertBefore * @param {HTMLElement} element The HTMLElement to insert * @param {HTMLElement} before The HTMLElement to insert * the element before. */ insertBefore: function(element, before) { element = element.get ? element.get('element') : element; before = (before && before.get) ? before.get('element') : before; this.get('element').insertBefore(element, before); }, /** * Wrapper for HTMLElement method. * @method removeChild * @param {HTMLElement} child The HTMLElement to remove */ removeChild: function(child) { child = child.get ? child.get('element') : child; this.get('element').removeChild(child); return true; }, /** * Wrapper for HTMLElement method. * @method replaceChild * @param {HTMLElement} newNode The HTMLElement to insert * @param {HTMLElement} oldNode The HTMLElement to replace */ replaceChild: function(newNode, oldNode) { newNode = newNode.get ? newNode.get('element') : newNode; oldNode = oldNode.get ? oldNode.get('element') : oldNode; return this.get('element').replaceChild(newNode, oldNode); }, /** * Registers Element specific attributes. * @method initAttributes * @param {Object} map A key-value map of initial attribute configs */ initAttributes: function(map) { map = map || {}; var element = Dom.get(map.element) || null; /** * The HTMLElement the Element instance refers to. * @config element * @type HTMLElement */ this.register('element', { value: element, readOnly: true }); }, /** * Adds a listener for the given event. These may be DOM or * customEvent listeners. Any event that is fired via fireEvent * can be listened for. All handlers receive an event object. * @method addListener * @param {String} type The name of the event to listen for * @param {Function} fn The handler to call when the event fires * @param {Any} obj A variable to pass to the handler * @param {Object} scope The object to use for the scope of the handler */ addListener: function(type, fn, obj, scope) { var el = this.get('element'); var scope = scope || this; el = this.get('id') || el; if (!this._events[type]) { // create on the fly if ( this.DOM_EVENTS[type] ) { YAHOO.util.Event.addListener(el, type, function(e) { if (e.srcElement && !e.target) { // supplement IE with target e.target = e.srcElement; } this.fireEvent(type, e); }, obj, scope); } this.createEvent(type, this); this._events[type] = true; } this.subscribe.apply(this, arguments); // notify via customEvent }, /** * Alias for addListener * @method on * @param {String} type The name of the event to listen for * @param {Function} fn The function call when the event fires * @param {Any} obj A variable to pass to the handler * @param {Object} scope The object to use for the scope of the handler */ on: function() { this.addListener.apply(this, arguments); }, /** * Remove an event listener * @method removeListener * @param {String} type The name of the event to listen for * @param {Function} fn The function call when the event fires */ removeListener: function(type, fn) { this.unsubscribe.apply(this, arguments); }, /** * Wrapper for Dom method. * @method addClass * @param {String} className The className to add */ addClass: function(className) { Dom.addClass(this.get('element'), className); }, /** * Wrapper for Dom method. * @method getElementsByClassName * @param {String} className The className to collect * @param {String} tag (optional) The tag to use in * conjunction with class name * @return {Array} Array of HTMLElements */ getElementsByClassName: function(className, tag) { return Dom.getElementsByClassName(className, tag, this.get('element') ); }, /** * Wrapper for Dom method. * @method hasClass * @param {String} className The className to add * @return {Boolean} Whether or not the element has the class name */ hasClass: function(className) { return Dom.hasClass(this.get('element'), className); }, /** * Wrapper for Dom method. * @method removeClass * @param {String} className The className to remove */ removeClass: function(className) { return Dom.removeClass(this.get('element'), className); }, /** * Wrapper for Dom method. * @method replaceClass * @param {String} oldClassName The className to replace * @param {String} newClassName The className to add */ replaceClass: function(oldClassName, newClassName) { return Dom.replaceClass(this.get('element'), oldClassName, newClassName); }, /** * Wrapper for Dom method. * @method setStyle * @param {String} property The style property to set * @param {String} value The value to apply to the style property */ setStyle: function(property, value) { return Dom.setStyle(this.get('element'), property, value); }, /** * Wrapper for Dom method. * @method getStyle * @param {String} property The style property to retrieve * @return {String} The current value of the property */ getStyle: function(property) { return Dom.getStyle(this.get('element'), property); }, /** * Apply any queued set calls. * @method fireQueue */ fireQueue: function() { var queue = this._queue; for (var i = 0, len = queue.length; i < len; ++i) { this[queue[i][0]].apply(this, queue[i][1]); } }, /** * Appends the HTMLElement into either the supplied parentNode. * @method appendTo * @param {HTMLElement | Element} parentNode The node to append to * @param {HTMLElement | Element} before An optional node to insert before */ appendTo: function(parent, before) { parent = (parent.get) ? parent.get('element') : Dom.get(parent); before = (before && before.get) ? before.get('element') : Dom.get(before); var element = this.get('element'); var newAddition = !Dom.inDocument(element); if (!element) { YAHOO.log('appendTo failed: element not available', 'error', 'Element'); return false; } if (!parent) { YAHOO.log('appendTo failed: parent not available', 'error', 'Element'); return false; } if (element.parent != parent) { if (before) { parent.insertBefore(element, before); } else { parent.appendChild(element); } } YAHOO.log(element + 'appended to ' + parent); if (!newAddition) { return false; // note return; no refresh if in document } // if a new addition, refresh HTMLElement any applied attributes var keys = this.getAttributeKeys(); for (var key in keys) { // only refresh HTMLElement attributes if ( !Lang.isUndefined(element[key]) ) { this.refresh(key); } } }, get: function(key) { var configs = this._configs || {}; var el = configs.element; // avoid loop due to 'element' if (el && !configs[key] && !Lang.isUndefined(el.value[key]) ) { return el.value[key]; } return AttributeProvider.prototype.get.call(this, key); }, set: function(key, value, silent) { var el = this.get('element'); if (!el) { this._queue[key] = ['set', arguments]; return false; } // set it on the element if not a property if ( !this._configs[key] && !Lang.isUndefined(el[key]) ) { _registerHTMLAttr(this, key); } return AttributeProvider.prototype.set.apply(this, arguments); }, register: function(key) { // protect html attributes var configs = this._configs || {}; var element = this.get('element') || null; if ( element && !Lang.isUndefined(element[key]) ) { YAHOO.log(key + ' is reserved for ' + element, 'error', 'Element'); return false; } return AttributeProvider.prototype.register.apply(this, arguments); }, configureAttribute: function(property, map, init) { // protect html attributes if (!this._configs[property] && this._configs.element && !Lang.isUndefined(this._configs.element[property]) ) { _registerHTMLAttr(this, property, map); return false; } return AttributeProvider.prototype.configure.apply(this, arguments); }, getAttributeKeys: function() { var el = this.get('element'); var keys = AttributeProvider.prototype.getAttributeKeys.call(this); //add any unconfigured element keys for (var key in el) { if (!this._configs[key]) { keys[key] = keys[key] || el[key]; } } return keys; }, init: function(el, attr) { this._queue = this._queue || []; this._events = this._events || {}; this._configs = this._configs || {}; attr = attr || {}; attr.element = attr.element || el || null; this.DOM_EVENTS = { 'click': true, 'keydown': true, 'keypress': true, 'keyup': true, 'mousedown': true, 'mousemove': true, 'mouseout': true, 'mouseover': true, 'mouseup': true }; var readyHandler = function() { this.initAttributes(attr); this.setAttributes(attr, true); this.fireQueue(); this.fireEvent('contentReady', { type: 'contentReady', target: attr.element }); }; if ( Lang.isString(el) ) { _registerHTMLAttr(this, 'id', { value: el }); YAHOO.util.Event.onAvailable(el, function() { attr.element = Dom.get(el); this.fireEvent('available', { type: 'available', target: attr.element }); }, this, true); YAHOO.util.Event.onContentReady(el, function() { readyHandler.call(this); }, this, true); } else { readyHandler.call(this); } } }; /** * Sets the value of the property and fires beforeChange and change events. * @private * @method _registerHTMLAttr * @param {YAHOO.util.Element} element The Element instance to * register the config to. * @param {String} key The name of the config to register * @param {Object} map A key-value map of the config's params */ var _registerHTMLAttr = function(self, key, map) { var el = self.get('element'); map = map || {}; map.name = key; map.method = map.method || function(value) { el[key] = value; }; map.value = map.value || el[key]; self._configs[key] = new YAHOO.util.Attribute(map, self); }; /** * Fires when the Element's HTMLElement can be retrieved by Id. *
See: Element.addListener
*Event fields:
* <String> type
available
* <HTMLElement>
* target
the HTMLElement bound to this Element instance
*
Usage:
* var handler = function(e) {var target = e.target};
* myTabs.addListener('available', handler);
See: Element.addListener
*Event fields:
* <String> type
contentReady
* <HTMLElement>
* target
the HTMLElement bound to this Element instance
*
Usage:
* var handler = function(e) {var target = e.target};
* myTabs.addListener('contentReady', handler);
See: Element.addListener
*If handler returns false, the change will be cancelled, and the value will not * be set.
*Event fields:
* <String> type
beforeActiveChange
* <Boolean>
* prevValue
the current value
* <Boolean>
* newValue
the new value
Usage:
* var handler = function(e) {var previous = e.prevValue};
* myTabs.addListener('beforeActiveChange', handler);
See: Element.addListener
*Event fields:
* <String> type
activeChange
* <Boolean>
* prevValue
the previous value
* <Boolean>
* newValue
the updated value
Usage:
* var handler = function(e) {var previous = e.prevValue};
* myTabs.addListener('activeChange', handler);
See: Element.addListener
*If handler returns false, the change will be cancelled, and the value will not * be set.
*Event fields:
* <String> type
beforeLabelChange
* <String>
* prevValue
the current value
* <String>
* newValue
the new value
Usage:
* var handler = function(e) {var previous = e.prevValue};
* myTabs.addListener('beforeLabelChange', handler);
See: Element.addListener
*Event fields:
* <String> type
labelChange
* <String>
* prevValue
the previous value
* <String>
* newValue
the updated value
Usage:
* var handler = function(e) {var previous = e.prevValue};
* myTabs.addListener('labelChange', handler);
See: Element.addListener
*If handler returns false, the change will be cancelled, and the value will not * be set.
*Event fields:
* <String> type
beforeContentChange
* <String>
* prevValue
the current value
* <String>
* newValue
the new value
Usage:
* var handler = function(e) {var previous = e.prevValue};
* myTabs.addListener('beforeContentChange', handler);
See: Element.addListener
*Event fields:
* <String> type
contentChange
* <String>
* prevValue
the previous value
* <Boolean>
* newValue
the updated value
Usage:
* var handler = function(e) {var previous = e.prevValue};
* myTabs.addListener('contentChange', handler);
See: Element.addListener
*If handler returns false, the change will be cancelled, and the value will not * be set.
*Event fields:
* <String> type
beforeActiveTabChange
* <YAHOO.widget.Tab>
* prevValue
the currently active tab
* <YAHOO.widget.Tab>
* newValue
the tab to be made active
Usage:
* var handler = function(e) {var previous = e.prevValue};
* myTabs.addListener('beforeActiveTabChange', handler);
See: Element.addListener
*Event fields:
* <String> type
activeTabChange
* <YAHOO.widget.Tab>
* prevValue
the formerly active tab
* <YAHOO.widget.Tab>
* newValue
the new active tab
Usage:
* var handler = function(e) {var previous = e.prevValue};
* myTabs.addListener('activeTabChange', handler);
See: Element.addListener
*If handler returns false, the change will be cancelled, and the value will not * be set.
*Event fields:
* <String> type
beforeOrientationChange
* <String>
* prevValue
the current orientation
* <String>
* newValue
the new orientation to be applied
Usage:
* var handler = function(e) {var previous = e.prevValue};
* myTabs.addListener('beforeOrientationChange', handler);
See: Element.addListener
*Event fields:
* <String> type
orientationChange
* <String>
* prevValue
the former orientation
* <String>
* newValue
the new orientation
Usage:
* var handler = function(e) {var previous = e.prevValue};
* myTabs.addListener('orientationChange', handler);