Skip to content

Commit

Permalink
attributeWhiteList now per Element, fixed for unnested html, a little
Browse files Browse the repository at this point in the history
optimization for valid attributes.

PASSED: IE6-9
  • Loading branch information
ibolmo committed Jan 26, 2012
1 parent d0208f9 commit 26e8c54
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
17 changes: 12 additions & 5 deletions Source/Element/Element.js
Expand Up @@ -595,7 +595,6 @@ var pollutesGetAttribute = (function(div){
return (div.getAttribute('random') == 'attribute');
})(document.createElement('div'));

if (pollutesGetAttribute) var attributeWhiteList = {};
/* <ltIE9> */

Element.implement({
Expand All @@ -605,6 +604,10 @@ Element.implement({
if (setter){
setter(this, value);
} else {
/* <ltIE9> */
if (pollutesGetAttribute) var attributeWhiteList = this.retrieve('$attributeWhiteList', {});
/* </ltIE9> */

if (value == null){
this.removeAttribute(name);
/* <ltIE9> */
Expand All @@ -629,10 +632,14 @@ Element.implement({
var getter = propertyGetters[name.toLowerCase()];
if (getter) return getter(this);
/* <ltIE9> */
if (pollutesGetAttribute && !attributeWhiteList[name]){
var outer = this.outerHTML, i = outer.indexOf(name);
if ((i < 0) || (i > outer.indexOf('><'))) return null;
attributeWhiteList[name] = true;
if (pollutesGetAttribute){
var attr = this.getAttributeNode(name), attributeWhiteList = this.retrieve('$attributeWhiteList', {});
if (!attr) return null;
if (attr.expando && !attributeWhiteList[name]){
var outer = this.outerHTML, i = outer.indexOf(name), l = outer.indexOf('><');
if ((i < 0) || (i > l && l > 0)) return null;
attributeWhiteList[name] = true;
}
}
/* </ltIE9> */
var result = Slick.getAttribute(this, name);
Expand Down
11 changes: 7 additions & 4 deletions Specs/1.4client/Element/Element.js
Expand Up @@ -27,17 +27,20 @@ describe('Element', function(){
});

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');
var div = new Element('div', {html: '<div data-load="typical"></div>'}).getFirst();
expect(div.get('data-load')).toEqual('typical');

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 data-custom="nested"><a data-custom="other"></a></div>'}).getFirst();
expect(div.get('data-custom')).toEqual('nested');

div = new Element('div', {html: '<div><a data-custom="other"></a></div>'}).getFirst();
expect(div.get('data-custom')).toEqual(null);

div = new Element('div', {html: '<a data-custom="singular" href="#">href</a>'}).getFirst();
expect(div.get('data-custom')).toEqual('singular');
});

});
Expand Down

0 comments on commit 26e8c54

Please sign in to comment.