Changeset 7222
- Timestamp:
- 07/24/07 17:31:23 (1 year ago)
- Files:
-
- spinoffs/prototype/trunk/CHANGELOG (modified) (1 diff)
- spinoffs/prototype/trunk/src/dom.js (modified) (5 diffs)
- spinoffs/prototype/trunk/test/unit/dom.html (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spinoffs/prototype/trunk/CHANGELOG
r7221 r7222 1 1 *SVN* 2 3 * Make Element#readAttribute work for cloned elements in IE. Closes #8481. [chem, Tobie Langel] 2 4 3 5 * Template enhancements. Closes #8166. [Christophe Porteneuve] spinoffs/prototype/trunk/src/dom.js
r7184 r7222 237 237 element = $(element); 238 238 if (Prototype.Browser.IE) { 239 if (!element.attributes) return null;240 239 var t = Element._attributeTranslations.read; 241 240 if (t.values[name]) return t.values[name](element, name); 242 if (t.names[name]) name = t.names[name]; 243 var attribute = element.attributes[name]; 244 return attribute ? attribute.nodeValue : null; 241 if (t.names[name]) name = t.names[name]; 245 242 } 246 243 return element.getAttribute(name); … … 751 748 read: { 752 749 names: { 753 colspan: "colSpan", 754 rowspan: "rowSpan", 755 valign: "vAlign", 756 datetime: "dateTime", 757 accesskey: "accessKey", 758 tabindex: "tabIndex", 759 enctype: "encType", 760 maxlength: "maxLength", 761 readonly: "readOnly", 762 longdesc: "longDesc" 750 'class': 'className', 751 'for': 'htmlFor' 763 752 }, 764 753 values: { 765 754 _getAttr: function(element, attribute) { 766 755 return element.getAttribute(attribute, 2); 756 }, 757 _getEv: function(element, attribute) { 758 var attribute = element.getAttribute(attribute); 759 return attribute ? attribute.toString().slice(23, -2) : null; 767 760 }, 768 761 _flag: function(element, attribute) { … … 773 766 }, 774 767 title: function(element) { 775 var node = element.getAttributeNode('title'); 776 return node.specified ? node.nodeValue : null; 768 return element.title; 777 769 } 778 770 } … … 782 774 Element._attributeTranslations.write = { 783 775 names: Object.extend({ 784 'class': 'className', 785 'for': 'htmlFor' 786 }, Element._attributeTranslations.read.names), 776 colspan: 'colSpan', 777 rowspan: 'rowSpan', 778 valign: 'vAlign', 779 datetime: 'dateTime', 780 accesskey: 'accessKey', 781 tabindex: 'tabIndex', 782 enctype: 'encType', 783 maxlength: 'maxLength', 784 readonly: 'readOnly', 785 longdesc: 'longDesc' 786 }, Element._attributeTranslations.read.names), 787 787 788 values: { 788 789 checked: function(element, value) { … … 796 797 }; 797 798 798 (function() { 799 Object.extend(this, { 800 href: this._getAttr, 801 src: this._getAttr, 802 type: this._getAttr, 803 disabled: this._flag, 804 checked: this._flag, 805 readonly: this._flag, 806 multiple: this._flag 799 (function(v) { 800 Object.extend(v, { 801 href: v._getAttr, 802 src: v._getAttr, 803 type: v._getAttr, 804 disabled: v._flag, 805 checked: v._flag, 806 readonly: v._flag, 807 multiple: v._flag, 808 onload: v._getEv, 809 onunload: v._getEv, 810 onclick: v._getEv, 811 ondblclick: v._getEv, 812 onmousedown: v._getEv, 813 onmouseup: v._getEv, 814 onmouseover: v._getEv, 815 onmousemove: v._getEv, 816 onmouseout: v._getEv, 817 onfocus: v._getEv, 818 onblur: v._getEv, 819 onkeypress: v._getEv, 820 onkeydown: v._getEv, 821 onkeyup: v._getEv, 822 onsubmit: v._getEv, 823 onreset: v._getEv, 824 onselect: v._getEv, 825 onchange: v._getEv 807 826 }); 808 }) .call(Element._attributeTranslations.read.values);827 })(Element._attributeTranslations.read.values); 809 828 } 810 829 spinoffs/prototype/trunk/test/unit/dom.html
r7184 r7222 229 229 </div> 230 230 231 <a id="attributes_with_issues_1" href="test.html" accesskey="L" tabindex="50" title="a link"></a> 231 <div id="cloned_element_attributes_issue" foo="original"></div> 232 <a id="attributes_with_issues_1" href="test.html" accesskey="L" tabindex="50" title="a link" onclick="alert('hello world');"></a> 232 233 <a id="attributes_with_issues_2" href="" accesskey="" tabindex="" title=""></a> 233 234 <a id="attributes_with_issues_3"></a> … … 1049 1050 testElementReadAttribute: function() {with(this) { 1050 1051 assertEqual('test.html' , $('attributes_with_issues_1').readAttribute('href')); 1051 1052 1052 assertEqual('L' , $('attributes_with_issues_1').readAttribute('accesskey')); 1053 1053 assertEqual('50' , $('attributes_with_issues_1').readAttribute('tabindex')); 1054 1054 assertEqual('a link' , $('attributes_with_issues_1').readAttribute('title')); 1055 1055 1056 $('cloned_element_attributes_issue').readAttribute('foo') 1057 var clone = $('cloned_element_attributes_issue').cloneNode(true); 1058 clone.writeAttribute('foo', 'cloned'); 1059 assertEqual('cloned', clone.readAttribute('foo')); 1060 assertEqual('original', $('cloned_element_attributes_issue').readAttribute('foo')); 1061 1056 1062 ['href', 'accesskey', 'accesskey', 'title'].each(function(attr){ 1057 1063 assertEqual('' , $('attributes_with_issues_2').readAttribute(attr)); … … 1062 1068 }); 1063 1069 1070 assertEqual("alert('hello world');", $('attributes_with_issues_1').readAttribute('onclick')); 1071 assertNull($('attributes_with_issues_1').readAttribute('onmouseover')); 1072 1064 1073 assertEqual('date', $('attributes_with_issues_type').readAttribute('type')); 1065 1074 assertEqual('text', $('attributes_with_issues_readonly').readAttribute('type'));