Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7222

Show
Ignore:
Timestamp:
07/24/07 17:31:23 (1 year ago)
Author:
sam
Message:

prototype: Make Element#readAttribute work for cloned elements in IE. Closes #8481.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/prototype/trunk/CHANGELOG

    r7221 r7222  
    11*SVN* 
     2 
     3* Make Element#readAttribute work for cloned elements in IE. Closes #8481. [chem, Tobie Langel] 
    24 
    35* Template enhancements.  Closes #8166.  [Christophe Porteneuve] 
  • spinoffs/prototype/trunk/src/dom.js

    r7184 r7222  
    237237    element = $(element); 
    238238    if (Prototype.Browser.IE) { 
    239       if (!element.attributes) return null; 
    240239      var t = Element._attributeTranslations.read; 
    241240      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]; 
    245242    }     
    246243    return element.getAttribute(name); 
     
    751748    read: { 
    752749      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' 
    763752      }, 
    764753      values: { 
    765754        _getAttr: function(element, attribute) { 
    766755          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; 
    767760        }, 
    768761        _flag: function(element, attribute) { 
     
    773766        }, 
    774767        title: function(element) { 
    775           var node = element.getAttributeNode('title'); 
    776           return node.specified ? node.nodeValue : null; 
     768          return element.title; 
    777769        } 
    778770      } 
     
    782774  Element._attributeTranslations.write = { 
    783775    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     
    787788    values: { 
    788789      checked: function(element, value) { 
     
    796797  }; 
    797798   
    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 
    807826    }); 
    808   }).call(Element._attributeTranslations.read.values); 
     827  })(Element._attributeTranslations.read.values); 
    809828} 
    810829 
  • spinoffs/prototype/trunk/test/unit/dom.html

    r7184 r7222  
    229229</div> 
    230230 
    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> 
    232233<a id="attributes_with_issues_2" href="" accesskey="" tabindex="" title=""></a> 
    233234<a id="attributes_with_issues_3"></a> 
     
    10491050    testElementReadAttribute: function() {with(this) { 
    10501051      assertEqual('test.html' , $('attributes_with_issues_1').readAttribute('href')); 
    1051        
    10521052      assertEqual('L' , $('attributes_with_issues_1').readAttribute('accesskey')); 
    10531053      assertEqual('50' , $('attributes_with_issues_1').readAttribute('tabindex')); 
    10541054      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       
    10561062      ['href', 'accesskey', 'accesskey', 'title'].each(function(attr){ 
    10571063        assertEqual('' , $('attributes_with_issues_2').readAttribute(attr)); 
     
    10621068      }); 
    10631069       
     1070      assertEqual("alert('hello world');", $('attributes_with_issues_1').readAttribute('onclick')); 
     1071      assertNull($('attributes_with_issues_1').readAttribute('onmouseover')); 
     1072      
    10641073      assertEqual('date', $('attributes_with_issues_type').readAttribute('type')); 
    10651074      assertEqual('text', $('attributes_with_issues_readonly').readAttribute('type'));