Ticket #8481: readAttribute.diff
| File readAttribute.diff, 6.7 kB (added by Tobie, 1 year ago) |
|---|
-
test/unit/dom.html
old new 228 228 <div foo="2"></div> 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> 234 235 <form id="attributes_with_issues_form" method="post" action="blah"> … … 1038 1039 1039 1040 testElementReadAttribute: function() {with(this) { 1040 1041 assertEqual('test.html' , $('attributes_with_issues_1').readAttribute('href')); 1041 1042 1042 assertEqual('L' , $('attributes_with_issues_1').readAttribute('accesskey')); 1043 1043 assertEqual('50' , $('attributes_with_issues_1').readAttribute('tabindex')); 1044 1044 assertEqual('a link' , $('attributes_with_issues_1').readAttribute('title')); 1045 1045 1046 $('cloned_element_attributes_issue').readAttribute('foo') 1047 var clone = $('cloned_element_attributes_issue').cloneNode(true); 1048 clone.writeAttribute('foo', 'cloned'); 1049 assertEqual('cloned', clone.readAttribute('foo')); 1050 assertEqual('original', $('cloned_element_attributes_issue').readAttribute('foo')); 1051 1046 1052 ['href', 'accesskey', 'accesskey', 'title'].each(function(attr){ 1047 1053 assertEqual('' , $('attributes_with_issues_2').readAttribute(attr)); 1048 1054 }); … … 1051 1057 assertEqual(attr, $('attributes_with_issues_'+attr).readAttribute(attr)); 1052 1058 }); 1053 1059 1060 assertEqual("alert('hello world');", $('attributes_with_issues_1').readAttribute('onclick')); 1061 assertNull($('attributes_with_issues_1').readAttribute('onmouseover')); 1062 1054 1063 assertEqual('date', $('attributes_with_issues_type').readAttribute('type')); 1055 1064 assertEqual('text', $('attributes_with_issues_readonly').readAttribute('type')); 1056 1065 -
src/dom.js
old new 231 231 readAttribute: function(element, name) { 232 232 element = $(element); 233 233 if (Prototype.Browser.IE) { 234 if (!element.attributes) return null;235 234 var t = Element._attributeTranslations.read; 236 235 if (t.values[name]) return t.values[name](element, name); 237 if (t.names[name]) name = t.names[name]; 238 var attribute = element.attributes[name]; 239 return attribute ? attribute.nodeValue : null; 236 if (t.names[name]) name = t.names[name]; 240 237 } 241 238 return element.getAttribute(name); 242 239 }, … … 743 740 Element._attributeTranslations = { 744 741 read: { 745 742 names: { 746 colspan: "colSpan", 747 rowspan: "rowSpan", 748 valign: "vAlign", 749 datetime: "dateTime", 750 accesskey: "accessKey", 751 tabindex: "tabIndex", 752 enctype: "encType", 753 maxlength: "maxLength", 754 readonly: "readOnly", 755 longdesc: "longDesc" 743 'class': 'className', 744 'for': 'htmlFor' 756 745 }, 757 746 values: { 758 747 _getAttr: function(element, attribute) { 759 748 return element.getAttribute(attribute, 2); 760 749 }, 750 _getEv: function(element, attribute) { 751 var attribute = element.getAttribute(attribute); 752 return attribute ? attribute.toString().slice(23, -2) : null; 753 }, 761 754 _flag: function(element, attribute) { 762 755 return $(element).hasAttribute(attribute) ? attribute : null; 763 756 }, … … 765 758 return element.style.cssText.toLowerCase(); 766 759 }, 767 760 title: function(element) { 768 var node = element.getAttributeNode('title'); 769 return node.specified ? node.nodeValue : null; 761 return element.title; 770 762 } 771 763 } 772 764 } … … 774 766 775 767 Element._attributeTranslations.write = { 776 768 names: Object.extend({ 777 'class': 'className', 778 'for': 'htmlFor' 779 }, Element._attributeTranslations.read.names), 769 colspan: 'colSpan', 770 rowspan: 'rowSpan', 771 valign: 'vAlign', 772 datetime: 'dateTime', 773 accesskey: 'accessKey', 774 tabindex: 'tabIndex', 775 enctype: 'encType', 776 maxlength: 'maxLength', 777 readonly: 'readOnly', 778 longdesc: 'longDesc' 779 }, Element._attributeTranslations.read.names), 780 780 781 values: { 781 782 checked: function(element, value) { 782 783 element.checked = !!value; … … 788 789 } 789 790 }; 790 791 791 (function() { 792 Object.extend(this, { 793 href: this._getAttr, 794 src: this._getAttr, 795 type: this._getAttr, 796 disabled: this._flag, 797 checked: this._flag, 798 readonly: this._flag, 799 multiple: this._flag 792 (function(v) { 793 Object.extend(v, { 794 href: v._getAttr, 795 src: v._getAttr, 796 type: v._getAttr, 797 disabled: v._flag, 798 checked: v._flag, 799 readonly: v._flag, 800 multiple: v._flag, 801 onload: v._getEv, 802 onunload: v._getEv, 803 onclick: v._getEv, 804 ondblclick: v._getEv, 805 onmousedown: v._getEv, 806 onmouseup: v._getEv, 807 onmouseover: v._getEv, 808 onmousemove: v._getEv, 809 onmouseout: v._getEv, 810 onfocus: v._getEv, 811 onblur: v._getEv, 812 onkeypress: v._getEv, 813 onkeydown: v._getEv, 814 onkeyup: v._getEv, 815 onsubmit: v._getEv, 816 onreset: v._getEv, 817 onselect: v._getEv, 818 onchange: v._getEv 800 819 }); 801 }) .call(Element._attributeTranslations.read.values);820 })(Element._attributeTranslations.read.values); 802 821 } 803 822 804 823 else if (Prototype.Browser.Gecko) { -
CHANGELOG
old new 1 1 *SVN* 2 2 3 * Make Element#readAttribute work for cloned elements in IE. Closes #8481. [chem, Tobie Langel] 4 3 5 * The action for Form#request defaults to the current URL if the "action" attribute is empty. (This is what most of the major browsers do.) Fixes #8483. [Tomas, Mislav MarohniÄ] 4 6 5 7 * In form serialization, change the way submit buttons are handled. Previously all submit buttons were serialized; now Prototype serializes only the first one. Change Form#serialize and Form.serializeElements to accept a params hash. With the "hash: false" option, a serialized string is returned instead of the hash data object. With the "submit: 'foo'" option, only the submit button with the name "foo" is serialized. References #5031. [Mislav MarohniÄ]