Skip to content
Browse files

move end() and andSelf() are now in the stack.js plugin

  • Loading branch information...
1 parent 41fe2cd commit 9e03f259a61f642d8717bca7253f85a0e46d1469 @madrobby committed
Showing with 89 additions and 35 deletions.
  1. +3 −1 Rakefile
  2. +22 −0 src/stack.js
  3. +0 −15 src/zepto.js
  4. +64 −0 test/stack.html
  5. +0 −19 test/zepto.html
View
4 Rakefile
@@ -19,7 +19,8 @@ ZEPTO_COMPONENTS = [
# 'assets',
# 'data',
'touch',
- # 'gesture'
+ # 'gesture',
+ # 'stack',
]
task :default => [:clean, :concat, :dist]
@@ -32,6 +33,7 @@ ZEPTO_TESTS = %w[
test/form.html
test/fx.html
test/polyfill.html
+ test/stack.html
]
desc "Clean the distribution directory."
View
22 src/stack.js
@@ -0,0 +1,22 @@
+// Zepto.js
+// (c) 2010-2012 Thomas Fuchs
+// Zepto.js may be freely distributed under the MIT license.
+
+;(function($){
+ $.fn.end = function(){
+ return this.prevObject || $()
+ }
+
+ $.fn.andSelf = function(){
+ return this.add(this.prevObject || $())
+ }
+
+ '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
+ }
+ })
+})(Zepto)
View
15 src/zepto.js
@@ -199,12 +199,6 @@ var Zepto = (function() {
return element.parentNode && $$(element.parentNode, selector).indexOf(element) >= 0
}))
},
- end: function(){
- return this.prevObject || $()
- },
- andSelf: function(){
- return this.add(this.prevObject || $())
- },
add: function(selector,context){
return $(uniq(this.concat($(selector,context))))
},
@@ -414,15 +408,6 @@ 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(dimension){
$.fn[dimension] = function(value){
var offset, Dimension = dimension.replace(/./, function(m){ return m[0].toUpperCase() })
View
64 test/stack.html
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
+ <link rel="stylesheet" href="test.css">
+ <title>Zepto Stack unit tests</title>
+ <script src="../vendor/evidence.js"></script>
+ <script src="evidence_runner.js"></script>
+ <script src="../src/polyfill.js"></script>
+ <script src="../src/zepto.js"></script>
+ <script src="../src/stack.js"></script>
+</head>
+<body>
+ <h1>Zepto DOM unit tests</h1>
+ <p id="results">
+ Running… see browser console for results
+ </p>
+ <div id="fixtures">
+
+ <div id="end_test">
+ <div class="end_one"><b><span></span></b></div>
+ <div class="end_two"><b><span>1</span><span>2</span></b></div>
+ </div>
+
+ <div id="andself_test">
+ <div class="one"></div>
+ <div class="two"></div>
+ <div class="three"></div>
+ <div class="four"></div>
+ </div>
+
+ </div><!-- fixtures -->
+
+ <script>
+ (function(){
+
+ Evidence('ZeptoTest', {
+
+ testEnd: function (t) {
+ t.assert($().end().length == 0)
+
+ var $endTest = $('#end_test')
+ var $endTest2 = $('#end_test').find('div').find('span').end().end()
+ t.assertEqual($endTest.length, $endTest2.length)
+ t.assertEqual($endTest.get(0), $endTest2.get(0))
+ },
+
+ testAndSelf: function (t) {
+ var testDiv = $('#andself_test'),
+ secondEl = $('.two', testDiv),
+ thirdEl = $('.three', testDiv),
+ nextAndSelf = secondEl.next().andSelf()
+
+ t.assert(secondEl.get(0), nextAndSelf.get(0))
+ t.assert(thirdEl.get(0), nextAndSelf.get(1))
+ }
+
+ })
+
+ })()
+ </script>
+</body>
+</html>
View
19 test/zepto.html
@@ -1601,25 +1601,6 @@
t.assertEqual($els.slice().length, 3)
t.assertEqual(typeof $els.slice().ready, 'function')
t.assertEqual($els.slice(-1)[0].className, 'slice3')
- },
-
- testEnd: function (t) {
- t.assert($().end().length, 0)
-
- var $endTest = $('#end_test')
- var $endTest2 = $('#end_test').find('div').find('span').end().end()
- t.assertEqual($endTest.length, $endTest2.length)
- t.assertEqual($endTest.get(0), $endTest2.get(0))
- },
-
- testAndSelf: function (t) {
- var testDiv = $('#andself_test'),
- secondEl = $('.two', testDiv),
- thirdEl = $('.three', testDiv),
- nextAndSelf = secondEl.next().andSelf()
-
- t.assert( secondEl.get(0), nextAndSelf.get(0) )
- t.assert( thirdEl.get(0), nextAndSelf.get(1) )
}
})

0 comments on commit 9e03f25

Please sign in to comment.
Something went wrong with that request. Please try again.