/hudson-war/src/main/webapp/scripts/yui/element/element-beta-debug.js

http://github.com/hudson/hudson · JavaScript · 1006 lines · 460 code · 132 blank · 414 comment · 92 complexity · e9c208e2514c75b0b2bd62dbe48f30e1 MD5 · raw file

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