Permalink
Browse files

Merge pull request #2167 from ibolmo/fix-2109-ie-getProperty-expando-…

…methods

Fixes #2109.
  • Loading branch information...
2 parents 2cafdd8 + 8fe6021 commit 70b402e63e5ea8ec7a5c6b5bc862101158b62ca3 @ibolmo ibolmo committed Jan 8, 2012
Showing with 34 additions and 3 deletions.
  1. +23 −2 Source/Element/Element.js
  2. +1 −1 Specs/1.3client/Element/Element.js
  3. +10 −0 Specs/1.4client/Element/Element.js
View
@@ -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;
},
@@ -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;
},
@@ -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');
@@ -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(){

0 comments on commit 70b402e

Please sign in to comment.