Changeset 7223
- Timestamp:
- 07/24/07 17:41:27 (1 year ago)
- Files:
-
- spinoffs/prototype/trunk/CHANGELOG (modified) (1 diff)
- spinoffs/prototype/trunk/src/dom.js (modified) (3 diffs)
- spinoffs/prototype/trunk/test/unit/dom.html (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spinoffs/prototype/trunk/CHANGELOG
r7222 r7223 1 1 *SVN* 2 3 * Add Element#identify, which returns the element's ID if it exists, or sets and returns a unique, auto-generated ID (of the form "anonymous_element_" + auto-incremented digit) otherwise. Use this when you need to ensure an element has an ID. Closes #9012. [Jeff Watkins, sam, Tobie Langel] 2 4 3 5 * Make Element#readAttribute work for cloned elements in IE. Closes #8481. [chem, Tobie Langel] spinoffs/prototype/trunk/src/dom.js
r7222 r7223 232 232 var args = $A(arguments), element = $(args.shift()); 233 233 return Selector.findChildElements(element.parentNode, args).without(element); 234 }, 235 236 identify: function(element) { 237 element = $(element); 238 var id = element.readAttribute('id'), self = arguments.callee; 239 if (id) return id; 240 do { id = 'anonymous_element_' + self.counter++ } while ($(id)); 241 element.writeAttribute('id', id); 242 return id; 234 243 }, 235 244 … … 598 607 }; 599 608 600 Element.Methods. getElementsBySelector = Element.Methods.select;609 Element.Methods.identify.counter = 1; 601 610 602 611 if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){ … … 637 646 638 647 Object.extend(Element.Methods, { 648 getElementsBySelector: Element.Methods.select, 639 649 childElements: Element.Methods.immediateDescendants 640 650 }); spinoffs/prototype/trunk/test/unit/dom.html
r7222 r7223 343 343 344 344 <div id="unextended"></div> 345 <div id="identification"> 346 <div id="predefined_id"></div> 347 <div></div> 348 <div></div> 349 <div></div> 350 <div id="anonymous_element_3"></div> 351 </div> 345 352 346 353 <!-- Tests follow --> … … 677 684 }); 678 685 }}, 686 687 testElementIdentify: function() {with(this) { 688 var parent = $('identification'); 689 assertEqual(parent.down().identify(), 'predefined_id'); 690 assertEqual(parent.down(1).identify(), 'anonymous_element_1'); 691 assertEqual(parent.down(2).identify(), 'anonymous_element_2'); 692 assertEqual(parent.down(3).identify(), 'anonymous_element_4'); 693 }}, 679 694 680 695 testElementClassNameMethod: function() {with(this) {