mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-25 10:50:22 +00:00
feat(jqLite): add prop() support
since jQuery 1.6.4 prop() became very important because attr() does't have access to certain properties any more (e.g. className), so I'm adding it to jqLite as well so that jqLite preserves the feature-set it had before the jQuery upgrade.
This commit is contained in:
parent
009059dd1b
commit
3800d17703
2 changed files with 41 additions and 0 deletions
|
|
@ -40,6 +40,7 @@
|
|||
* - [eq()](http://api.jquery.com/eq/)
|
||||
* - [hasClass()](http://api.jquery.com/hasClass/)
|
||||
* - [parent()](http://api.jquery.com/parent/)
|
||||
* - [prop()](http://api.jquery.com/prop/)
|
||||
* - [remove()](http://api.jquery.com/remove/)
|
||||
* - [removeAttr()](http://api.jquery.com/removeAttr/)
|
||||
* - [removeClass()](http://api.jquery.com/removeClass/)
|
||||
|
|
@ -287,6 +288,14 @@ forEach({
|
|||
}
|
||||
},
|
||||
|
||||
prop: function(element, name, value) {
|
||||
if (isDefined(value)) {
|
||||
element[name] = value;
|
||||
} else {
|
||||
return element[name];
|
||||
}
|
||||
},
|
||||
|
||||
text: extend((msie < 9)
|
||||
? function(element, value) {
|
||||
// NodeType == 3 is text node
|
||||
|
|
|
|||
|
|
@ -171,6 +171,38 @@ describe('jqLite', function(){
|
|||
});
|
||||
|
||||
|
||||
describe('prop', function() {
|
||||
it('should read element property', function() {
|
||||
var elm = jqLite('<div class="foo">a</div>');
|
||||
expect(elm.prop('className')).toBe('foo');
|
||||
});
|
||||
|
||||
it('should set element property to a value', function() {
|
||||
var elm = jqLite('<div class="foo">a</div>');
|
||||
elm.prop('className', 'bar');
|
||||
expect(elm[0].className).toBe('bar');
|
||||
expect(elm.prop('className')).toBe('bar');
|
||||
});
|
||||
|
||||
it('should set boolean element property', function() {
|
||||
var elm = jqLite('<input type="checkbox">');
|
||||
expect(elm.prop('checked')).toBe(false);
|
||||
|
||||
elm.prop('checked', true);
|
||||
expect(elm.prop('checked')).toBe(true);
|
||||
|
||||
elm.prop('checked', '');
|
||||
expect(elm.prop('checked')).toBe(false);
|
||||
|
||||
elm.prop('checked', 'lala');
|
||||
expect(elm.prop('checked')).toBe(true);
|
||||
|
||||
elm.prop('checked', null);
|
||||
expect(elm.prop('checked')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('class', function(){
|
||||
|
||||
describe('hasClass', function(){
|
||||
|
|
|
|||
Loading…
Reference in a new issue