Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(jqLite): attr() should not special-case 'class' attribute
Browse files Browse the repository at this point in the history
since jQuery 1.6 'class' is not treated specially, so we have to revert this fix and use className in tests instead
  • Loading branch information
IgorMinar committed Sep 16, 2011
1 parent a2a830e commit 0d7fe97
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
8 changes: 1 addition & 7 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,7 @@ forEach({
},

attr: function(element, name, value){
if (name === 'class') {
if(isDefined(value)) {
element.className = value;
} else {
return element.className;
}
} else if (SPECIAL_ATTR[name]) {
if (SPECIAL_ATTR[name]) {
if (isDefined(value)) {
element[name] = !!value;
} else {
Expand Down
10 changes: 5 additions & 5 deletions test/directivesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ describe("directive", function() {
scope.$digest();
scope.dynCls = 'foo';
scope.$digest();
expect(element.attr('class')).toBe('ui-panel ui-selected ng-directive foo');
expect(element[0].className).toBe('ui-panel ui-selected ng-directive foo');
});


it('should not add duplicate classes', function() {
var scope = compile('<div class="panel bar" ng:class="dynCls"></div>');
scope.dynCls = 'panel';
scope.$digest();
expect(element.attr('class')).toBe('panel bar ng-directive');
expect(element[0].className).toBe('panel bar ng-directive');
});


Expand All @@ -272,7 +272,7 @@ describe("directive", function() {
scope.$digest();
scope.dynCls = 'window';
scope.$digest();
expect(element.attr('class')).toBe('bar ng-directive window');
expect(element[0].className).toBe('bar ng-directive window');
});


Expand All @@ -283,15 +283,15 @@ describe("directive", function() {
element.addClass('foo');
scope.dynCls = '';
scope.$digest();
expect(element.attr('class')).toBe('ng-directive');
expect(element[0].className).toBe('ng-directive');
});


it('should convert undefined and null values to an empty string', function() {
var scope = compile('<div ng:class="dynCls"></div>');
scope.dynCls = [undefined, null];
scope.$digest();
expect(element.attr('class')).toBe('ng-directive');
expect(element[0].className).toBe('ng-directive');
});
});

Expand Down
9 changes: 0 additions & 9 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,6 @@ describe('jqLite', function(){
var elm = jqLite('<div class="any">a</div>');
expect(elm.attr('non-existing')).toBeUndefined();
});

it('should special-case "class" attribute', function() {
// stupid IE9 returns null for element.getAttribute('class') when element has ng:class attr
var elm = jqLite('<div class=" any " ng:class="dynCls">a</div>');
expect(elm.attr('class')).toBe(' any ');

elm.attr('class', 'foo bar');
expect(elm.attr('class')).toBe('foo bar');
});
});


Expand Down

0 comments on commit 0d7fe97

Please sign in to comment.