Permalink
Browse files

Merge branch 'master' of https://github.com/playup/zepto into playup-…

…master
  • Loading branch information...
2 parents 10770c1 + d576f13 commit 1e45fa5626870eebcb57f7a37e55f9dd5882a8a2 @madrobby committed Jan 18, 2011
Showing with 37 additions and 1 deletion.
  1. +11 −1 src/zepto.js
  2. +26 −0 test/zepto.html
View
@@ -115,13 +115,23 @@ var Zepto = (function() {
},
attr: function(name, value){
return (typeof name == 'string' && value === undefined) ?
- (this.length > 0 && this.dom[0].nodeName === 'INPUT' && this.dom[0].type === 'text' && name === 'value') ? (this.dom[0].value) :
+ (this.length > 0 && this.dom[0].nodeName === 'INPUT' && this.dom[0].type === 'text' && name === 'value') ? (this.val()) :
(this.length > 0 ? this.dom[0].getAttribute(name) || undefined : null) :
this.each(function(){
if (typeof name == 'object') for (key in name) this.setAttribute(key, name[key])
else this.setAttribute(name, value);
});
},
+ removeAttr: function(name) {
+ return this.each(function() { this.removeAttribute(name); });
+ },
+ val: function(value){
+ return (value === undefined) ?
+ (this.length > 0 ? this.dom[0].value : null) :
+ this.each(function(){
+ this.value = value;
+ });
+ },
offset: function(){
var obj = this.dom[0].getBoundingClientRect();
return {
View
@@ -689,6 +689,32 @@
els.attr('value', '');
t.assertEqual(els.get(0).value, els.attr('value'));
t.assertEqual('', els.attr('value'));
+ },
+
+ testRemoveAttr: function(t) {
+ var els = $('#attr_with_text_input');
+
+ els.get(0).removeAttribute('disabled');
+ t.assertEqual(els.attr('disabled'), undefined);
+
+ els.attr('disabled', 'definitely');
+ t.assertEqual(els.attr('disabled'), 'definitely');
+
+ els.removeAttr('disabled');
+ t.assertEqual(els.attr('disabled'), undefined);
+ },
+
+ testVal: function(t) {
+ var els = $('#attr_with_text_input');
+
+ els.get(0).value = "Hello World";
+
+ t.assertEqual(els.get(0).value, els.val());
+ t.assertEqual('Hello World', els.val());
+
+ els.val('');
+ t.assertEqual(els.get(0).value, els.val());
+ t.assertEqual('', els.val());
},

0 comments on commit 1e45fa5

Please sign in to comment.