Permalink
Browse files

Merge branch 'master' into local

  • Loading branch information...
joaodubas committed Feb 24, 2011
2 parents 45194b6 + 3611f6c commit 5213585be9cea83cd5c093a359722a02d0d979a0
Showing with 30 additions and 7 deletions.
  1. +3 −4 src/ajax.js
  2. +4 −1 src/zepto.js
  3. +23 −2 test/zepto.html
View
@@ -4,14 +4,13 @@
function empty() {}
$.ajaxJSONP = function(options){
- var jsonpString;
- jsonpString = 'jsonp' + ++jsonpID;
+ var jsonpString = 'jsonp' + ++jsonpID,
+ script = document.createElement('script');
window[jsonpString] = function(data){
options.success(data);
delete window.jsonpString;
};
- var script = document.createElement('script');
- $(script).attr({ src: options.url.replace(/=\?/, '=' + jsonpString) });
+ script.src = options.url.replace(/=\?/, '=' + jsonpString);
$('head').append(script);
};
View
@@ -119,7 +119,7 @@ var Zepto = (function() {
attr: function(name, value){
return (typeof name == 'string' && value === undefined) ?
(this.length > 0 && this[0].nodeName === 'INPUT' && this[0].type === 'text' && name === 'value') ? (this.val()) :
- (this.length > 0 ? this[0].getAttribute(name) || undefined : null) :
+ (this.length > 0 ? this[0].getAttribute(name) || (name in this[0] ? this[0][name] : undefined) : null) :
this.each(function(idx){
if (typeof name == 'object') for (key in name) this.setAttribute(key, name[key])
else this.setAttribute(name, typeof value == 'function' ? value(idx, this.getAttribute(name)) : value);
@@ -128,6 +128,9 @@ var Zepto = (function() {
removeAttr: function(name) {
return this.each(function() { this.removeAttribute(name); });
},
+ data: function(name, value){
+ return this.attr('data-' + name, value);
+ },
val: function(value){
return (value === undefined) ?
(this.length > 0 ? this[0].value : null) :
View
@@ -36,6 +36,8 @@ <h1>Zepto DOM unit tests</h1>
<div id="attr_1" data-id="someId1" data-name="someName1"></div>
<div id="attr_2" data-id="someId2" data-name="someName2"></div>
+ <div id="data_attr" data-blah="whatever"></div>
+
<input type="text" id="attr_with_text_input" name="attr_input" value="Hello World" />
<div class="htmltest" id="htmltest1"></div>
@@ -98,7 +100,10 @@ <h1>Zepto DOM unit tests</h1>
<div id="namespace_test"></div>
+ <input type="text" id="BooleanInput" required />
+
<script>
+
function click(el){
var event = document.createEvent('MouseEvents');
event.initMouseEvent('click', true, true, document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
@@ -739,13 +744,24 @@ <h1>Zepto DOM unit tests</h1>
var els = $('#attr_with_text_input');
els.get(0).removeAttribute('disabled');
- t.assertEqual(els.attr('disabled'), undefined);
+ console.log(els[0].disabled);
+ console.log(els.attr('disabled'))
+ t.assertFalse(els.attr('disabled'));
els.attr('disabled', 'definitely');
t.assertEqual(els.attr('disabled'), 'definitely');
els.removeAttr('disabled');
- t.assertEqual(els.attr('disabled'), undefined);
+ t.assertFalse(els.attr('disabled'));
+ },
+
+ testData: function(t) {
+ var els = $('#data_attr');
+ els.data('fun', 'hello');
+ t.assertEqual(els.attr('data-fun'), 'hello');
+
+ t.assertEqual(els.data('fun'), 'hello');
+ t.assertEqual(els.data('blah'), 'whatever');
},
testVal: function(t) {
@@ -916,6 +932,11 @@ <h1>Zepto DOM unit tests</h1>
t.assertEqual($("p > span").index(".yay"), 0);
t.assertEqual($("span").index("span"), 0);
t.assertEqual($("span").index("boo"), -1);
+ },
+
+ testBoolAttr: function (t) {
+ t.assertEqual($('#BooleanInput').attr('required'), true);
+ t.assertEqual($('#BooleanInput').attr('non_existant_attr'), undefined);
}
});

0 comments on commit 5213585

Please sign in to comment.