Permalink
Browse files

Merge pull request #61 from redolent/master

$.fn.each now breaks on `return false`
  • Loading branch information...
2 parents c0bd2f4 + 4023394 commit fc70e4d2726e6c3d400873c91db8f427eb60dc53 @statianzo statianzo committed Jun 23, 2015
Showing with 29 additions and 1 deletion.
  1. +2 −1 src/jquip.js
  2. +1 −0 test/runner.html
  3. +26 −0 test/spec/base.js
View
3 src/jquip.js
@@ -166,7 +166,8 @@ window['$'] = window['jquip'] = (function(){
p['each'] = function(fn){
if (!isF(fn)) return this;
for(var i = 0, l = this.length; i < l; i++)
- fn.call(this[i], i, this[i]);
+ if ( fn.call(this[i], i, this[i]) === false )
+ break;
return this;
};
p['attr'] = function(name, val){
View
1 test/runner.html
@@ -12,6 +12,7 @@
<script type="text/javascript" src="../src/jquip.events.js"></script>
+ <script type="text/javascript" src="spec/base.js"></script>
<script type="text/javascript" src="spec/data.js"></script>
<script type="text/javascript" src="spec/display.js"></script>
<script type="text/javascript" src="spec/wrap.js"></script>
View
26 test/spec/base.js
@@ -0,0 +1,26 @@
+(function($){
+ describe('jquip.base', function() {
+
+ describe('jquip.each', function() {
+ it('iterates over dom', function() {
+ var $el = $('<div name="life"></div><div name="is"></div><div name="absurd"></div>')
+ , concat = "";
+ $el.each(function(){
+ concat += this.getAttribute('name');
+ });
+ expect(concat).toEqual("lifeisabsurd");
+ });
+
+ it('iterates over dom and stops halfway', function() {
+ var $el = $('<div name="life"></div><div name="is"></div><div name="absurd"></div>')
+ , concat = "";
+ $el.each(function(){
+ concat += this.getAttribute('name');
+ return false;
+ });
+ expect(concat).toEqual("life");
+ });
+ });
+ });
+
+}(jquip));

0 comments on commit fc70e4d

Please sign in to comment.