From ca6f41db171b74c33e8598ec61f1bb70a3debb64 Mon Sep 17 00:00:00 2001 From: John Boxall Date: Fri, 3 Jun 2011 08:53:39 -0700 Subject: [PATCH] Add end() support to Zepto by wrapping methods that change the working elements. --- src/zepto.js | 12 ++++++++++++ test/zepto.html | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/zepto.js b/src/zepto.js index cd1dfb278..8db7978c4 100644 --- a/src/zepto.js +++ b/src/zepto.js @@ -102,6 +102,9 @@ var Zepto = (function() { return $$(element.parentNode, selector).indexOf(element) >= 0; })); }, + end: function(){ + return this.prevObject || $(); + }, add:function(selector,context){ return $(uniq(this.concat($(selector,context)))); }, @@ -300,6 +303,15 @@ var Zepto = (function() { } }; + 'filter,add,not,eq,first,last,find,closest,parents,parent,children,siblings'.split(',').forEach(function(property){ + var fn = $.fn[property]; + $.fn[property] = function() { + var ret = fn.apply(this, arguments); + ret.prevObject = this; + return ret; + } + }); + ['width', 'height'].forEach(function(property){ $.fn[property] = function(){ var offset = this.offset(); return offset ? offset[property] : null } }); diff --git a/test/zepto.html b/test/zepto.html index f32260599..7f2e9a57e 100644 --- a/test/zepto.html +++ b/test/zepto.html @@ -162,6 +162,11 @@

Zepto DOM unit tests

12
+
+
+
12
+
+