Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

return null for offset(), width(), and height() for empty sets. fixes #…

  • Loading branch information...
commit 2ad719efbf6020c729259ee85f06ae3d6a14407c 1 parent 79dd84c
@madrobby madrobby authored
Showing with 5 additions and 1 deletion.
  1. +2 −1  src/zepto.js
  2. +3 −0  test/zepto.html
View
3  src/zepto.js
@@ -201,6 +201,7 @@ var Zepto = (function() {
});
},
offset: function(){
+ if(this.length==0) return null;
var obj = this[0].getBoundingClientRect();
return {
left: obj.left + document.body.scrollLeft,
@@ -252,7 +253,7 @@ var Zepto = (function() {
};
['width', 'height'].forEach(function(property){
- $.fn[property] = function(){ return this.offset()[property] }
+ $.fn[property] = function(){ var offset = this.offset(); return offset ? offset[property] : null }
});
View
3  test/zepto.html
@@ -399,14 +399,17 @@
testOffset: function(t){
// TODO
+ t.assertNull($('#doesnotexist').offset());
},
testWidth: function(t){
t.assertEqual(100, $('#offset').width());
+ t.assertNull($('#doesnotexist').width());
},
testHeight: function(t){
t.assertEqual(50, $('#offset').height());
+ t.assertNull($('#doesnotexist').height());
},
testClosest: function(t){
Please sign in to comment.
Something went wrong with that request. Please try again.