Skip to content

Commit

Permalink
Merge pull request #2167 from ibolmo/fix-2109-ie-getProperty-expando-…
Browse files Browse the repository at this point in the history
…methods

Fixes #2109.
  • Loading branch information
ibolmo committed Jan 8, 2012
2 parents 2cafdd8 + 8fe6021 commit 70b402e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
25 changes: 23 additions & 2 deletions Source/Element/Element.js
Expand Up @@ -590,15 +590,30 @@ if (el.type != 'button') propertySetters.type = function(node, value){

/* getProperty, setProperty */

/* <ltIE9> */
var pollutesGetAttribute = (function(div){
div.random = 'attribute';
return (div.getAttribute('random') == 'attribute');
})(document.createElement('div'));

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

Element.implement({

setProperty: function(name, value){
var setter = propertySetters[name.toLowerCase()];
if (setter){
setter(this, value);
} else {
if (value == null) this.removeAttribute(name);
else this.setAttribute(name, value);
if (value == null){
this.removeAttribute(name);
} else {
this.setAttribute(name, value);
/* <ltIE9> */
if (pollutesGetAttribute) attributeWhiteList[name] = true;
/* </ltIE9> */
}
}
return this;
},
Expand All @@ -611,6 +626,12 @@ Element.implement({
getProperty: function(name){
var getter = propertyGetters[name.toLowerCase()];
if (getter) return getter(this);
/* <ltIE9> */
if (pollutesGetAttribute && !attributeWhiteList[name]){
var attr = this.getAttributeNode(name);
if (!attr || attr.expando) return null;
}
/* </ltIE9> */
var result = Slick.getAttribute(this, name);
return (!result && !Slick.hasAttribute(this, name)) ? null : result;
},
Expand Down
2 changes: 1 addition & 1 deletion Specs/1.3client/Element/Element.js
Expand Up @@ -43,7 +43,7 @@ describe('Element.getElementById', function(){
describe('Element.removeProperty', function(){

it('should removeProperty from an Element', function (){
var readonly = new Element('input', { type: 'text', readonly: 'readonly', maxlenght: 10 });
var readonly = new Element('input', { type: 'text', readonly: 'readonly', maxlength: 10 });
readonly.removeProperty('readonly');
readonly.removeProperty('maxlength');
var props = readonly.getProperties('type', 'readonly');
Expand Down
10 changes: 10 additions & 0 deletions Specs/1.4client/Element/Element.js
Expand Up @@ -16,6 +16,16 @@ describe('Element', function(){
expect($(div.firstChild).getProperty('action')).toEqual('s');
});

it('should ignore expandos', function(){
var div = new Element('div');
expect(div.getProperty('inject')).toBeNull();
});

it('should work in collaboration with setProperty', function(){
var div = new Element('div', {random: 'attribute'});
expect(div.getProperty('random')).toEqual('attribute');
});

});

describe('Element.set', function(){
Expand Down

0 comments on commit 70b402e

Please sign in to comment.