PageRenderTime 51ms CodeModel.GetById 16ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/resources/org/apache/struts2/static/element/element-debug.js

http://struts2yuiplugin.googlecode.com/
JavaScript | 1072 lines | 488 code | 149 blank | 435 comment | 97 complexity | 3acfcab5df53a14e44ed9d02904ea682 MD5 | raw file
   1/*
   2Copyright (c) 2009, Yahoo! Inc. All rights reserved.
   3Code licensed under the BSD License:
   4http://developer.yahoo.net/yui/license.txt
   5version: 2.7.0
   6*/
   7/**
   8 * Provides Attribute configurations.
   9 * @namespace YAHOO.util
  10 * @class Attribute
  11 * @constructor
  12 * @param hash {Object} The intial Attribute.
  13 * @param {YAHOO.util.AttributeProvider} The owner of the Attribute instance.
  14 */
  15
  16YAHOO.util.Attribute = function(hash, owner) {
  17    if (owner) { 
  18        this.owner = owner;
  19        this.configure(hash, true);
  20    }
  21};
  22
  23YAHOO.util.Attribute.prototype = {
  24    /**
  25     * The name of the attribute.
  26     * @property name
  27     * @type String
  28     */
  29    name: undefined,
  30    
  31    /**
  32     * The value of the attribute.
  33     * @property value
  34     * @type String
  35     */
  36    value: null,
  37    
  38    /**
  39     * The owner of the attribute.
  40     * @property owner
  41     * @type YAHOO.util.AttributeProvider
  42     */
  43    owner: null,
  44    
  45    /**
  46     * Whether or not the attribute is read only.
  47     * @property readOnly
  48     * @type Boolean
  49     */
  50    readOnly: false,
  51    
  52    /**
  53     * Whether or not the attribute can only be written once.
  54     * @property writeOnce
  55     * @type Boolean
  56     */
  57    writeOnce: false,
  58
  59    /**
  60     * The attribute's initial configuration.
  61     * @private
  62     * @property _initialConfig
  63     * @type Object
  64     */
  65    _initialConfig: null,
  66    
  67    /**
  68     * Whether or not the attribute's value has been set.
  69     * @private
  70     * @property _written
  71     * @type Boolean
  72     */
  73    _written: false,
  74    
  75    /**
  76     * A function to call when setting the attribute's value.
  77     * The method receives the new value as the first arg and the attribute name as the 2nd
  78     * @property method
  79     * @type Function
  80     */
  81    method: null,
  82    
  83    /**
  84     * The function to use when setting the attribute's value.
  85     * The setter receives the new value as the first arg and the attribute name as the 2nd
  86     * The return value of the setter replaces the value passed to set(). 
  87     * @property setter
  88     * @type Function
  89     */
  90    setter: null,
  91    
  92    /**
  93     * The function to use when getting the attribute's value.
  94     * The getter receives the new value as the first arg and the attribute name as the 2nd
  95     * The return value of the getter will be used as the return from get().
  96     * @property getter
  97     * @type Function
  98     */
  99    getter: null,
 100
 101    /**
 102     * The validator to use when setting the attribute's value.
 103     * @property validator
 104     * @type Function
 105     * @return Boolean
 106     */
 107    validator: null,
 108    
 109    /**
 110     * Retrieves the current value of the attribute.
 111     * @method getValue
 112     * @return {any} The current value of the attribute.
 113     */
 114    getValue: function() {
 115        var val = this.value;
 116
 117        if (this.getter) {
 118            val = this.getter.call(this.owner, this.name);
 119        }
 120
 121        return val;
 122    },
 123    
 124    /**
 125     * Sets the value of the attribute and fires beforeChange and change events.
 126     * @method setValue
 127     * @param {Any} value The value to apply to the attribute.
 128     * @param {Boolean} silent If true the change events will not be fired.
 129     * @return {Boolean} Whether or not the value was set.
 130     */
 131    setValue: function(value, silent) {
 132        var beforeRetVal,
 133            owner = this.owner,
 134            name = this.name;
 135        
 136        var event = {
 137            type: name, 
 138            prevValue: this.getValue(),
 139            newValue: value
 140        };
 141        
 142        if (this.readOnly || ( this.writeOnce && this._written) ) {
 143            YAHOO.log( 'setValue ' + name + ', ' +  value +
 144                    ' failed: read only', 'error', 'Attribute');
 145            return false; // write not allowed
 146        }
 147        
 148        if (this.validator && !this.validator.call(owner, value) ) {
 149            YAHOO.log( 'setValue ' + name + ', ' + value +
 150                    ' validation failed', 'error', 'Attribute');
 151            return false; // invalid value
 152        }
 153
 154        if (!silent) {
 155            beforeRetVal = owner.fireBeforeChangeEvent(event);
 156            if (beforeRetVal === false) {
 157                YAHOO.log('setValue ' + name + 
 158                        ' cancelled by beforeChange event', 'info', 'Attribute');
 159                return false;
 160            }
 161        }
 162
 163        if (this.setter) {
 164            value = this.setter.call(owner, value, this.name);
 165            if (value === undefined) {
 166                YAHOO.log('setter for ' + this.name + ' returned undefined', 'warn', 'Attribute');
 167            }
 168        }
 169        
 170        if (this.method) {
 171            this.method.call(owner, value, this.name);
 172        }
 173        
 174        this.value = value; // TODO: set before calling setter/method?
 175        this._written = true;
 176        
 177        event.type = name;
 178        
 179        if (!silent) {
 180            this.owner.fireChangeEvent(event);
 181        }
 182        
 183        return true;
 184    },
 185    
 186    /**
 187     * Allows for configuring the Attribute's properties.
 188     * @method configure
 189     * @param {Object} map A key-value map of Attribute properties.
 190     * @param {Boolean} init Whether or not this should become the initial config.
 191     */
 192    configure: function(map, init) {
 193        map = map || {};
 194
 195        if (init) {
 196            this._written = false; // reset writeOnce
 197        }
 198
 199        this._initialConfig = this._initialConfig || {};
 200        
 201        for (var key in map) {
 202            if ( map.hasOwnProperty(key) ) {
 203                this[key] = map[key];
 204                if (init) {
 205                    this._initialConfig[key] = map[key];
 206                }
 207            }
 208        }
 209    },
 210    
 211    /**
 212     * Resets the value to the initial config value.
 213     * @method resetValue
 214     * @return {Boolean} Whether or not the value was set.
 215     */
 216    resetValue: function() {
 217        return this.setValue(this._initialConfig.value);
 218    },
 219    
 220    /**
 221     * Resets the attribute config to the initial config state.
 222     * @method resetConfig
 223     */
 224    resetConfig: function() {
 225        this.configure(this._initialConfig, true);
 226    },
 227    
 228    /**
 229     * Resets the value to the current value.
 230     * Useful when values may have gotten out of sync with actual properties.
 231     * @method refresh
 232     * @return {Boolean} Whether or not the value was set.
 233     */
 234    refresh: function(silent) {
 235        this.setValue(this.value, silent);
 236    }
 237};
 238
 239(function() {
 240    var Lang = YAHOO.util.Lang;
 241
 242    /*
 243    Copyright (c) 2006, Yahoo! Inc. All rights reserved.
 244    Code licensed under the BSD License:
 245    http://developer.yahoo.net/yui/license.txt
 246    */
 247    
 248    /**
 249     * Provides and manages YAHOO.util.Attribute instances
 250     * @namespace YAHOO.util
 251     * @class AttributeProvider
 252     * @uses YAHOO.util.EventProvider
 253     */
 254    YAHOO.util.AttributeProvider = function() {};
 255
 256    YAHOO.util.AttributeProvider.prototype = {
 257        
 258        /**
 259         * A key-value map of Attribute configurations
 260         * @property _configs
 261         * @protected (may be used by subclasses and augmentors)
 262         * @private
 263         * @type {Object}
 264         */
 265        _configs: null,
 266        /**
 267         * Returns the current value of the attribute.
 268         * @method get
 269         * @param {String} key The attribute whose value will be returned.
 270         * @return {Any} The current value of the attribute.
 271         */
 272        get: function(key){
 273            this._configs = this._configs || {};
 274            var config = this._configs[key];
 275            
 276            if (!config || !this._configs.hasOwnProperty(key)) {
 277                YAHOO.log(key + ' not found', 'error', 'AttributeProvider');
 278                return null;
 279            }
 280            
 281            return config.getValue();
 282        },
 283        
 284        /**
 285         * Sets the value of a config.
 286         * @method set
 287         * @param {String} key The name of the attribute
 288         * @param {Any} value The value to apply to the attribute
 289         * @param {Boolean} silent Whether or not to suppress change events
 290         * @return {Boolean} Whether or not the value was set.
 291         */
 292        set: function(key, value, silent){
 293            this._configs = this._configs || {};
 294            var config = this._configs[key];
 295            
 296            if (!config) {
 297                YAHOO.log('set failed: ' + key + ' not found',
 298                        'error', 'AttributeProvider');
 299                return false;
 300            }
 301            
 302            return config.setValue(value, silent);
 303        },
 304    
 305        /**
 306         * Returns an array of attribute names.
 307         * @method getAttributeKeys
 308         * @return {Array} An array of attribute names.
 309         */
 310        getAttributeKeys: function(){
 311            this._configs = this._configs;
 312            var keys = [], key;
 313
 314            for (key in this._configs) {
 315                if ( Lang.hasOwnProperty(this._configs, key) && 
 316                        !Lang.isUndefined(this._configs[key]) ) {
 317                    keys[keys.length] = key;
 318                }
 319            }
 320            
 321            return keys;
 322        },
 323        
 324        /**
 325         * Sets multiple attribute values.
 326         * @method setAttributes
 327         * @param {Object} map  A key-value map of attributes
 328         * @param {Boolean} silent Whether or not to suppress change events
 329         */
 330        setAttributes: function(map, silent){
 331            for (var key in map) {
 332                if ( Lang.hasOwnProperty(map, key) ) {
 333                    this.set(key, map[key], silent);
 334                }
 335            }
 336        },
 337    
 338        /**
 339         * Resets the specified attribute's value to its initial value.
 340         * @method resetValue
 341         * @param {String} key The name of the attribute
 342         * @param {Boolean} silent Whether or not to suppress change events
 343         * @return {Boolean} Whether or not the value was set
 344         */
 345        resetValue: function(key, silent){
 346            this._configs = this._configs || {};
 347            if (this._configs[key]) {
 348                this.set(key, this._configs[key]._initialConfig.value, silent);
 349                return true;
 350            }
 351            return false;
 352        },
 353    
 354        /**
 355         * Sets the attribute's value to its current value.
 356         * @method refresh
 357         * @param {String | Array} key The attribute(s) to refresh
 358         * @param {Boolean} silent Whether or not to suppress change events
 359         */
 360        refresh: function(key, silent) {
 361            this._configs = this._configs || {};
 362            var configs = this._configs;
 363            
 364            key = ( ( Lang.isString(key) ) ? [key] : key ) || 
 365                    this.getAttributeKeys();
 366            
 367            for (var i = 0, len = key.length; i < len; ++i) { 
 368                if (configs.hasOwnProperty(key[i])) {
 369                    this._configs[key[i]].refresh(silent);
 370                }
 371            }
 372        },
 373    
 374        /**
 375         * Adds an Attribute to the AttributeProvider instance. 
 376         * @method register
 377         * @param {String} key The attribute's name
 378         * @param {Object} map A key-value map containing the
 379         * attribute's properties.
 380         * @deprecated Use setAttributeConfig
 381         */
 382        register: function(key, map) {
 383            this.setAttributeConfig(key, map);
 384        },
 385        
 386        
 387        /**
 388         * Returns the attribute's properties.
 389         * @method getAttributeConfig
 390         * @param {String} key The attribute's name
 391         * @private
 392         * @return {object} A key-value map containing all of the
 393         * attribute's properties.
 394         */
 395        getAttributeConfig: function(key) {
 396            this._configs = this._configs || {};
 397            var config = this._configs[key] || {};
 398            var map = {}; // returning a copy to prevent overrides
 399            
 400            for (key in config) {
 401                if ( Lang.hasOwnProperty(config, key) ) {
 402                    map[key] = config[key];
 403                }
 404            }
 405    
 406            return map;
 407        },
 408        
 409        /**
 410         * Sets or updates an Attribute instance's properties. 
 411         * @method setAttributeConfig
 412         * @param {String} key The attribute's name.
 413         * @param {Object} map A key-value map of attribute properties
 414         * @param {Boolean} init Whether or not this should become the intial config.
 415         */
 416        setAttributeConfig: function(key, map, init) {
 417            this._configs = this._configs || {};
 418            map = map || {};
 419            if (!this._configs[key]) {
 420                map.name = key;
 421                this._configs[key] = this.createAttribute(map);
 422            } else {
 423                this._configs[key].configure(map, init);
 424            }
 425        },
 426        
 427        /**
 428         * Sets or updates an Attribute instance's properties. 
 429         * @method configureAttribute
 430         * @param {String} key The attribute's name.
 431         * @param {Object} map A key-value map of attribute properties
 432         * @param {Boolean} init Whether or not this should become the intial config.
 433         * @deprecated Use setAttributeConfig
 434         */
 435        configureAttribute: function(key, map, init) {
 436            this.setAttributeConfig(key, map, init);
 437        },
 438        
 439        /**
 440         * Resets an attribute to its intial configuration. 
 441         * @method resetAttributeConfig
 442         * @param {String} key The attribute's name.
 443         * @private
 444         */
 445        resetAttributeConfig: function(key){
 446            this._configs = this._configs || {};
 447            this._configs[key].resetConfig();
 448        },
 449        
 450        // wrapper for EventProvider.subscribe
 451        // to create events on the fly
 452        subscribe: function(type, callback) {
 453            this._events = this._events || {};
 454
 455            if ( !(type in this._events) ) {
 456                this._events[type] = this.createEvent(type);
 457            }
 458
 459            YAHOO.util.EventProvider.prototype.subscribe.apply(this, arguments);
 460        },
 461
 462        on: function() {
 463            this.subscribe.apply(this, arguments);
 464        },
 465
 466        addListener: function() {
 467            this.subscribe.apply(this, arguments);
 468        },
 469
 470        /**
 471         * Fires the attribute's beforeChange event. 
 472         * @method fireBeforeChangeEvent
 473         * @param {String} key The attribute's name.
 474         * @param {Obj} e The event object to pass to handlers.
 475         */
 476        fireBeforeChangeEvent: function(e) {
 477            var type = 'before';
 478            type += e.type.charAt(0).toUpperCase() + e.type.substr(1) + 'Change';
 479            e.type = type;
 480            return this.fireEvent(e.type, e);
 481        },
 482        
 483        /**
 484         * Fires the attribute's change event. 
 485         * @method fireChangeEvent
 486         * @param {String} key The attribute's name.
 487         * @param {Obj} e The event object to pass to the handlers.
 488         */
 489        fireChangeEvent: function(e) {
 490            e.type += 'Change';
 491            return this.fireEvent(e.type, e);
 492        },
 493
 494        createAttribute: function(map) {
 495            return new YAHOO.util.Attribute(map, this);
 496        }
 497    };
 498    
 499    YAHOO.augment(YAHOO.util.AttributeProvider, YAHOO.util.EventProvider);
 500})();
 501
 502(function() {
 503// internal shorthand
 504var Dom = YAHOO.util.Dom,
 505    AttributeProvider = YAHOO.util.AttributeProvider;
 506
 507/**
 508 * Element provides an wrapper object to simplify adding
 509 * event listeners, using dom methods, and managing attributes. 
 510 * @module element
 511 * @namespace YAHOO.util
 512 * @requires yahoo, dom, event
 513 */
 514
 515/**
 516 * Element provides an wrapper object to simplify adding
 517 * event listeners, using dom methods, and managing attributes. 
 518 * @class Element
 519 * @uses YAHOO.util.AttributeProvider
 520 * @constructor
 521 * @param el {HTMLElement | String} The html element that 
 522 * represents the Element.
 523 * @param {Object} map A key-value map of initial config names and values
 524 */
 525var Element = function(el, map) {
 526    this.init.apply(this, arguments);
 527};
 528
 529Element.DOM_EVENTS = {
 530    'click': true,
 531    'dblclick': true,
 532    'keydown': true,
 533    'keypress': true,
 534    'keyup': true,
 535    'mousedown': true,
 536    'mousemove': true,
 537    'mouseout': true, 
 538    'mouseover': true, 
 539    'mouseup': true,
 540    'focus': true,
 541    'blur': true,
 542    'submit': true,
 543    'change': true
 544};
 545
 546Element.prototype = {
 547    /**
 548     * Dom events supported by the Element instance.
 549     * @property DOM_EVENTS
 550     * @type Object
 551     */
 552    DOM_EVENTS: null,
 553
 554    DEFAULT_HTML_SETTER: function(value, key) {
 555        var el = this.get('element');
 556        
 557        if (el) {
 558            el[key] = value;
 559        }
 560    },
 561
 562    DEFAULT_HTML_GETTER: function(key) {
 563        var el = this.get('element'),
 564            val;
 565
 566        if (el) {
 567            val = el[key];
 568        }
 569
 570        return val;
 571    },
 572
 573    /**
 574     * Wrapper for HTMLElement method.
 575     * @method appendChild
 576     * @param {YAHOO.util.Element || HTMLElement} child The element to append. 
 577     * @return {HTMLElement} The appended DOM element. 
 578     */
 579    appendChild: function(child) {
 580        child = child.get ? child.get('element') : child;
 581        return this.get('element').appendChild(child);
 582    },
 583    
 584    /**
 585     * Wrapper for HTMLElement method.
 586     * @method getElementsByTagName
 587     * @param {String} tag The tagName to collect
 588     * @return {HTMLCollection} A collection of DOM elements. 
 589     */
 590    getElementsByTagName: function(tag) {
 591        return this.get('element').getElementsByTagName(tag);
 592    },
 593    
 594    /**
 595     * Wrapper for HTMLElement method.
 596     * @method hasChildNodes
 597     * @return {Boolean} Whether or not the element has childNodes
 598     */
 599    hasChildNodes: function() {
 600        return this.get('element').hasChildNodes();
 601    },
 602    
 603    /**
 604     * Wrapper for HTMLElement method.
 605     * @method insertBefore
 606     * @param {HTMLElement} element The HTMLElement to insert
 607     * @param {HTMLElement} before The HTMLElement to insert
 608     * the element before.
 609     * @return {HTMLElement} The inserted DOM element. 
 610     */
 611    insertBefore: function(element, before) {
 612        element = element.get ? element.get('element') : element;
 613        before = (before && before.get) ? before.get('element') : before;
 614        
 615        return this.get('element').insertBefore(element, before);
 616    },
 617    
 618    /**
 619     * Wrapper for HTMLElement method.
 620     * @method removeChild
 621     * @param {HTMLElement} child The HTMLElement to remove
 622     * @return {HTMLElement} The removed DOM element. 
 623     */
 624    removeChild: function(child) {
 625        child = child.get ? child.get('element') : child;
 626        return this.get('element').removeChild(child);
 627    },
 628    
 629    /**
 630     * Wrapper for HTMLElement method.
 631     * @method replaceChild
 632     * @param {HTMLElement} newNode The HTMLElement to insert
 633     * @param {HTMLElement} oldNode The HTMLElement to replace
 634     * @return {HTMLElement} The replaced DOM element. 
 635     */
 636    replaceChild: function(newNode, oldNode) {
 637        newNode = newNode.get ? newNode.get('element') : newNode;
 638        oldNode = oldNode.get ? oldNode.get('element') : oldNode;
 639        return this.get('element').replaceChild(newNode, oldNode);
 640    },
 641
 642    
 643    /**
 644     * Registers Element specific attributes.
 645     * @method initAttributes
 646     * @param {Object} map A key-value map of initial attribute configs
 647     */
 648    initAttributes: function(map) {
 649    },
 650
 651    /**
 652     * Adds a listener for the given event.  These may be DOM or 
 653     * customEvent listeners.  Any event that is fired via fireEvent
 654     * can be listened for.  All handlers receive an event object. 
 655     * @method addListener
 656     * @param {String} type The name of the event to listen for
 657     * @param {Function} fn The handler to call when the event fires
 658     * @param {Any} obj A variable to pass to the handler
 659     * @param {Object} scope The object to use for the scope of the handler 
 660     */
 661    addListener: function(type, fn, obj, scope) {
 662        var el = this.get('element') || this.get('id');
 663        scope = scope || this;
 664        
 665        var self = this; 
 666        if (!this._events[type]) { // create on the fly
 667            if (el && this.DOM_EVENTS[type]) {
 668                YAHOO.util.Event.addListener(el, type, function(e) {
 669                    if (e.srcElement && !e.target) { // supplement IE with target
 670                        e.target = e.srcElement;
 671                    }
 672                    self.fireEvent(type, e);
 673                }, obj, scope);
 674            }
 675            this.createEvent(type, this);
 676        }
 677        
 678        return YAHOO.util.EventProvider.prototype.subscribe.apply(this, arguments); // notify via customEvent
 679    },
 680    
 681    
 682    /**
 683     * Alias for addListener
 684     * @method on
 685     * @param {String} type The name of the event to listen for
 686     * @param {Function} fn The function call when the event fires
 687     * @param {Any} obj A variable to pass to the handler
 688     * @param {Object} scope The object to use for the scope of the handler 
 689     */
 690    on: function() {
 691        return this.addListener.apply(this, arguments);
 692    },
 693    
 694    /**
 695     * Alias for addListener
 696     * @method subscribe
 697     * @param {String} type The name of the event to listen for
 698     * @param {Function} fn The function call when the event fires
 699     * @param {Any} obj A variable to pass to the handler
 700     * @param {Object} scope The object to use for the scope of the handler 
 701     */
 702    subscribe: function() {
 703        return this.addListener.apply(this, arguments);
 704    },
 705    
 706    /**
 707     * Remove an event listener
 708     * @method removeListener
 709     * @param {String} type The name of the event to listen for
 710     * @param {Function} fn The function call when the event fires
 711     */
 712    removeListener: function(type, fn) {
 713        return this.unsubscribe.apply(this, arguments);
 714    },
 715    
 716    /**
 717     * Wrapper for Dom method.
 718     * @method addClass
 719     * @param {String} className The className to add
 720     */
 721    addClass: function(className) {
 722        Dom.addClass(this.get('element'), className);
 723    },
 724    
 725    /**
 726     * Wrapper for Dom method.
 727     * @method getElementsByClassName
 728     * @param {String} className The className to collect
 729     * @param {String} tag (optional) The tag to use in
 730     * conjunction with class name
 731     * @return {Array} Array of HTMLElements
 732     */
 733    getElementsByClassName: function(className, tag) {
 734        return Dom.getElementsByClassName(className, tag,
 735                this.get('element') );
 736    },
 737    
 738    /**
 739     * Wrapper for Dom method.
 740     * @method hasClass
 741     * @param {String} className The className to add
 742     * @return {Boolean} Whether or not the element has the class name
 743     */
 744    hasClass: function(className) {
 745        return Dom.hasClass(this.get('element'), className); 
 746    },
 747    
 748    /**
 749     * Wrapper for Dom method.
 750     * @method removeClass
 751     * @param {String} className The className to remove
 752     */
 753    removeClass: function(className) {
 754        return Dom.removeClass(this.get('element'), className);
 755    },
 756    
 757    /**
 758     * Wrapper for Dom method.
 759     * @method replaceClass
 760     * @param {String} oldClassName The className to replace
 761     * @param {String} newClassName The className to add
 762     */
 763    replaceClass: function(oldClassName, newClassName) {
 764        return Dom.replaceClass(this.get('element'), 
 765                oldClassName, newClassName);
 766    },
 767    
 768    /**
 769     * Wrapper for Dom method.
 770     * @method setStyle
 771     * @param {String} property The style property to set
 772     * @param {String} value The value to apply to the style property
 773     */
 774    setStyle: function(property, value) {
 775        return Dom.setStyle(this.get('element'),  property, value); // TODO: always queuing?
 776    },
 777    
 778    /**
 779     * Wrapper for Dom method.
 780     * @method getStyle
 781     * @param {String} property The style property to retrieve
 782     * @return {String} The current value of the property
 783     */
 784    getStyle: function(property) {
 785        return Dom.getStyle(this.get('element'),  property);
 786    },
 787    
 788    /**
 789     * Apply any queued set calls.
 790     * @method fireQueue
 791     */
 792    fireQueue: function() {
 793        var queue = this._queue;
 794        for (var i = 0, len = queue.length; i < len; ++i) {
 795            this[queue[i][0]].apply(this, queue[i][1]);
 796        }
 797    },
 798    
 799    /**
 800     * Appends the HTMLElement into either the supplied parentNode.
 801     * @method appendTo
 802     * @param {HTMLElement | Element} parentNode The node to append to
 803     * @param {HTMLElement | Element} before An optional node to insert before
 804     * @return {HTMLElement} The appended DOM element. 
 805     */
 806    appendTo: function(parent, before) {
 807        parent = (parent.get) ?  parent.get('element') : Dom.get(parent);
 808        
 809        this.fireEvent('beforeAppendTo', {
 810            type: 'beforeAppendTo',
 811            target: parent
 812        });
 813        
 814        
 815        before = (before && before.get) ? 
 816                before.get('element') : Dom.get(before);
 817        var element = this.get('element');
 818        
 819        if (!element) {
 820            YAHOO.log('appendTo failed: element not available',
 821                    'error', 'Element');
 822            return false;
 823        }
 824        
 825        if (!parent) {
 826            YAHOO.log('appendTo failed: parent not available',
 827                    'error', 'Element');
 828            return false;
 829        }
 830        
 831        if (element.parent != parent) {
 832            if (before) {
 833                parent.insertBefore(element, before);
 834            } else {
 835                parent.appendChild(element);
 836            }
 837        }
 838        
 839        YAHOO.log(element + 'appended to ' + parent);
 840        
 841        this.fireEvent('appendTo', {
 842            type: 'appendTo',
 843            target: parent
 844        });
 845
 846        return element;
 847    },
 848    
 849    get: function(key) {
 850        var configs = this._configs || {},
 851            el = configs.element; // avoid loop due to 'element'
 852
 853        if (el && !configs[key] && !YAHOO.lang.isUndefined(el.value[key]) ) {
 854            this._setHTMLAttrConfig(key);
 855        }
 856
 857        return AttributeProvider.prototype.get.call(this, key);
 858    },
 859
 860    setAttributes: function(map, silent) {
 861        // set based on configOrder
 862        var done = {},
 863            configOrder = this._configOrder;
 864
 865        // set based on configOrder
 866        for (var i = 0, len = configOrder.length; i < len; ++i) {
 867            if (map[configOrder[i]] !== undefined) {
 868                done[configOrder[i]] = true;
 869                this.set(configOrder[i], map[configOrder[i]], silent);
 870            }
 871        }
 872
 873        // unconfigured (e.g. Dom attributes)
 874        for (var att in map) {
 875            if (map.hasOwnProperty(att) && !done[att]) {
 876                this.set(att, map[att], silent);
 877            }
 878        }
 879    },
 880
 881    set: function(key, value, silent) {
 882        var el = this.get('element');
 883        if (!el) {
 884            this._queue[this._queue.length] = ['set', arguments];
 885            if (this._configs[key]) {
 886                this._configs[key].value = value; // so "get" works while queueing
 887            
 888            }
 889            return;
 890        }
 891        
 892        // set it on the element if not configured and is an HTML attribute
 893        if ( !this._configs[key] && !YAHOO.lang.isUndefined(el[key]) ) {
 894            this._setHTMLAttrConfig(key);
 895        }
 896
 897        return AttributeProvider.prototype.set.apply(this, arguments);
 898    },
 899    
 900    setAttributeConfig: function(key, map, init) {
 901        this._configOrder.push(key);
 902        AttributeProvider.prototype.setAttributeConfig.apply(this, arguments);
 903    },
 904
 905    createEvent: function(type, scope) {
 906        this._events[type] = true;
 907        return AttributeProvider.prototype.createEvent.apply(this, arguments);
 908    },
 909    
 910    init: function(el, attr) {
 911        this._initElement(el, attr); 
 912    },
 913
 914    destroy: function() {
 915        var el = this.get('element');
 916        YAHOO.util.Event.purgeElement(el, true); // purge DOM listeners recursively
 917        this.unsubscribeAll(); // unsubscribe all custom events
 918
 919        if (el && el.parentNode) {
 920            el.parentNode.removeChild(el); // pull from the DOM
 921        }
 922
 923        // revert initial configs
 924        this._queue = [];
 925        this._events = {};
 926        this._configs = {};
 927        this._configOrder = []; 
 928    },
 929
 930    _initElement: function(el, attr) {
 931        this._queue = this._queue || [];
 932        this._events = this._events || {};
 933        this._configs = this._configs || {};
 934        this._configOrder = []; 
 935        attr = attr || {};
 936        attr.element = attr.element || el || null;
 937
 938        var isReady = false;  // to determine when to init HTMLElement and content
 939
 940        var DOM_EVENTS = Element.DOM_EVENTS;
 941        this.DOM_EVENTS = this.DOM_EVENTS || {};
 942
 943        for (var event in DOM_EVENTS) {
 944            if (DOM_EVENTS.hasOwnProperty(event)) {
 945                this.DOM_EVENTS[event] = DOM_EVENTS[event];
 946            }
 947        }
 948
 949        if (typeof attr.element === 'string') { // register ID for get() access
 950            this._setHTMLAttrConfig('id', { value: attr.element });
 951        }
 952
 953        if (Dom.get(attr.element)) {
 954            isReady = true;
 955            this._initHTMLElement(attr);
 956            this._initContent(attr);
 957        }
 958
 959        YAHOO.util.Event.onAvailable(attr.element, function() {
 960            if (!isReady) { // otherwise already done
 961                this._initHTMLElement(attr);
 962            }
 963
 964            this.fireEvent('available', { type: 'available', target: Dom.get(attr.element) });  
 965        }, this, true);
 966        
 967        YAHOO.util.Event.onContentReady(attr.element, function() {
 968            if (!isReady) { // otherwise already done
 969                this._initContent(attr);
 970            }
 971            this.fireEvent('contentReady', { type: 'contentReady', target: Dom.get(attr.element) });  
 972        }, this, true);
 973    },
 974
 975    _initHTMLElement: function(attr) {
 976        /**
 977         * The HTMLElement the Element instance refers to.
 978         * @attribute element
 979         * @type HTMLElement
 980         */
 981        this.setAttributeConfig('element', {
 982            value: Dom.get(attr.element),
 983            readOnly: true
 984         });
 985    },
 986
 987    _initContent: function(attr) {
 988        this.initAttributes(attr);
 989        this.setAttributes(attr, true);
 990        this.fireQueue();
 991
 992    },
 993
 994    /**
 995     * Sets the value of the property and fires beforeChange and change events.
 996     * @private
 997     * @method _setHTMLAttrConfig
 998     * @param {YAHOO.util.Element} element The Element instance to
 999     * register the config to.
1000     * @param {String} key The name of the config to register
1001     * @param {Object} map A key-value map of the config's params
1002     */
1003    _setHTMLAttrConfig: function(key, map) {
1004        var el = this.get('element');
1005        map = map || {};
1006        map.name = key;
1007
1008        map.setter = map.setter || this.DEFAULT_HTML_SETTER;
1009        map.getter = map.getter || this.DEFAULT_HTML_GETTER;
1010
1011        map.value = map.value || el[key];
1012        this._configs[key] = new YAHOO.util.Attribute(map, this);
1013    }
1014};
1015
1016/**
1017 * Fires when the Element's HTMLElement can be retrieved by Id.
1018 * <p>See: <a href="#addListener">Element.addListener</a></p>
1019 * <p><strong>Event fields:</strong><br>
1020 * <code>&lt;String&gt; type</code> available<br>
1021 * <code>&lt;HTMLElement&gt;
1022 * target</code> the HTMLElement bound to this Element instance<br>
1023 * <p><strong>Usage:</strong><br>
1024 * <code>var handler = function(e) {var target = e.target};<br>
1025 * myTabs.addListener('available', handler);</code></p>
1026 * @event available
1027 */
1028 
1029/**
1030 * Fires when the Element's HTMLElement subtree is rendered.
1031 * <p>See: <a href="#addListener">Element.addListener</a></p>
1032 * <p><strong>Event fields:</strong><br>
1033 * <code>&lt;String&gt; type</code> contentReady<br>
1034 * <code>&lt;HTMLElement&gt;
1035 * target</code> the HTMLElement bound to this Element instance<br>
1036 * <p><strong>Usage:</strong><br>
1037 * <code>var handler = function(e) {var target = e.target};<br>
1038 * myTabs.addListener('contentReady', handler);</code></p>
1039 * @event contentReady
1040 */
1041
1042/**
1043 * Fires before the Element is appended to another Element.
1044 * <p>See: <a href="#addListener">Element.addListener</a></p>
1045 * <p><strong>Event fields:</strong><br>
1046 * <code>&lt;String&gt; type</code> beforeAppendTo<br>
1047 * <code>&lt;HTMLElement/Element&gt;
1048 * target</code> the HTMLElement/Element being appended to 
1049 * <p><strong>Usage:</strong><br>
1050 * <code>var handler = function(e) {var target = e.target};<br>
1051 * myTabs.addListener('beforeAppendTo', handler);</code></p>
1052 * @event beforeAppendTo
1053 */
1054
1055/**
1056 * Fires after the Element is appended to another Element.
1057 * <p>See: <a href="#addListener">Element.addListener</a></p>
1058 * <p><strong>Event fields:</strong><br>
1059 * <code>&lt;String&gt; type</code> appendTo<br>
1060 * <code>&lt;HTMLElement/Element&gt;
1061 * target</code> the HTMLElement/Element being appended to 
1062 * <p><strong>Usage:</strong><br>
1063 * <code>var handler = function(e) {var target = e.target};<br>
1064 * myTabs.addListener('appendTo', handler);</code></p>
1065 * @event appendTo
1066 */
1067
1068YAHOO.augment(Element, AttributeProvider);
1069YAHOO.util.Element = Element;
1070})();
1071
1072YAHOO.register("element", YAHOO.util.Element, {version: "2.7.0", build: "1799"});