Permalink
Browse files

Fixes #2247.

This fixes a nasty regression that custom attributes set by HTML text
(e.g. innerHTML) would previously be considered `expando` and therefore
thought to have been considered a fake attribute. Therefore, we didn't
return the value.

This fix relies now on outerHTML to check for the existence of the
attribute. Keep in mind this also fixes the previous bug of returning
custom functions since any new `el.attribute =` are not shown in
outerHTML.

PASSED: IE6-9.
  • Loading branch information...
1 parent fc3595d commit d0208f98e9eb94a27c7a7fec3e32ef32d3a83b28 @ibolmo committed Jan 24, 2012
Showing with 20 additions and 2 deletions.
  1. +6 −2 Source/Element/Element.js
  2. +14 −0 Specs/1.4client/Element/Element.js
@@ -607,6 +607,9 @@ Element.implement({
} else {
if (value == null){
this.removeAttribute(name);
+ /* <ltIE9> */
+ if (pollutesGetAttribute) delete attributeWhiteList[name];
+ /* </ltIE9> */
} else {
this.setAttribute(name, value);
/* <ltIE9> */
@@ -627,8 +630,9 @@ Element.implement({
if (getter) return getter(this);
/* <ltIE9> */
if (pollutesGetAttribute && !attributeWhiteList[name]){
- var attr = this.getAttributeNode(name);
- if (!attr || attr.expando) return null;
+ var outer = this.outerHTML, i = outer.indexOf(name);
+ if ((i < 0) || (i > outer.indexOf('><'))) return null;
+ attributeWhiteList[name] = true;
}
/* </ltIE9> */
var result = Slick.getAttribute(this, name);
@@ -26,6 +26,20 @@ describe('Element', function(){
expect(div.getProperty('random')).toEqual('attribute');
});
+ it('should get custom attributes in html', function(){
+ var div = new Element('div', {html: '<div data-load="test"></div>'}).getFirst();
+ expect(div.get('data-load')).toEqual('test');
+
+ div = new Element('div', {html: '<div data-custom></div>'}).getFirst();
+ expect(div.get('data-custom')).toEqual('');
+
+ div = new Element('div', {html: '<div data-custom="test"><a data-custom="other"></a></div>'}).getFirst();
+ expect(div.get('data-custom')).toEqual('test');
+
+ div = new Element('div', {html: '<div><a data-custom="other"></a></div>'}).getFirst();
+ expect(div.get('data-custom')).toEqual(null);
+ });
+
});
describe('Element.set', function(){

0 comments on commit d0208f9

Please sign in to comment.