Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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