forked from madrobby/zepto
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move end() and andSelf() are now in the stack.js plugin
- Loading branch information
Showing
5 changed files
with
89 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters