Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of https://github.com/errorhandler/zepto into e…

…rrorhandler-master
  • Loading branch information...
commit 4b0efd9faf4d3ab8ac7e5ccf9d0f744506e26069 2 parents c3171e5 + c4f6c74
@madrobby authored
Showing with 15 additions and 0 deletions.
  1. +1 −0  src/zepto.js
  2. +14 −0 test/zepto.html
View
1  src/zepto.js
@@ -84,6 +84,7 @@ var Zepto = (function() {
},
attr: function(name, value){
return (typeof name == 'string' && value === undefined) ?
+ (this.dom.length > 0 && this.dom[0].nodeName === 'INPUT' && this.dom[0].type === 'text' && name === 'value') ? (this.dom[0].value) :
(this.dom.length > 0 ? this.dom[0].getAttribute(name) || undefined : null) :
this.each(function(element){
if (typeof name == 'object') for (key in name) element.setAttribute(key, name[key])
View
14 test/zepto.html
@@ -22,6 +22,8 @@
<div id="attr_1" data-id="someId1" data-name="someName1"></div>
<div id="attr_2" data-id="someId2" data-name="someName2"></div>
+ <input type="text" id="attr_with_text_input" name="attr_input" value="Hello World" />
+
<div class="htmltest" id="htmltest1"></div>
<div class="htmltest" id="htmltest2"></div>
<div id="htmltest3"></div>
@@ -611,6 +613,18 @@
t.assertEqual('name', els.attr("data-name"));
t.assertEqual('id', $('#attr_2').attr('data-id'));
},
+
+ testAttrOnInputFieldWithTypeOfText: function(t) {
+ var els = $('#attr_with_text_input');
+
+ t.assertEqual(els.get(0).value, els.attr('value'));
+ t.assertEqual('Hello World', els.attr('value'));
+
+ els.attr('value', '');
+ t.assertEqual(els.get(0).value, els.attr('value'));
+ t.assertEqual('', els.attr('value'));
+
+ },
testChaining: function(t){
t.assert(document.getElementById('nay').innerHTML == "nay");
Please sign in to comment.
Something went wrong with that request. Please try again.