PageRenderTime 70ms CodeModel.GetById 2ms app.highlight 61ms RepoModel.GetById 1ms app.codeStats 0ms

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

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