-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow context to be passed as a third argument to can.each.
- Loading branch information
Ralph Holzmann
committed
Jun 2, 2012
1 parent
19c9ca0
commit bbd2ad5
Showing
1 changed file
with
18 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
steal(function(){ | ||
can.each = function(elements, callback) { | ||
can.each = function( elements, callback, context ) { | ||
var i = 0, key; | ||
if ( elements ) { | ||
if (typeof elements.length == 'number' && elements.pop) { | ||
elements.attr && elements.attr('length'); | ||
for(var len = elements.length; i < len; i++) { | ||
if(callback(elements[i], i, elements) === false) return elements; | ||
} | ||
} else { | ||
for(key in elements) { | ||
if(callback(elements[key], key) === false) return elements; | ||
} | ||
} | ||
} | ||
if ( elements ) { | ||
if ( typeof elements.length == 'number' && elements.pop ) { | ||
elements.attr && elements.attr('length'); | ||
for ( var len = elements.length; i < len; i++ ) { | ||
if ( callback.call( context, elements[i], i, elements ) === false ) { | ||
break; | ||
} | ||
} | ||
} else { | ||
for ( key in elements ) { | ||
if ( callback.call( context, elements[key], key ) === false ) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
return elements; | ||
} | ||
}) | ||
}); |