Forked from jswhisperer/CoffeeScript Jquery better each loop
Created
July 22, 2014 07:19
-
-
Save boostbob/f80f56c41acca8c6e263 to your computer and use it in GitHub Desktop.
Revisions
-
Greg created this gist
Jul 19, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ # Better each() for use with coffeescript # 1. Wraps child in jquery object # 2. Sets child first argument, so that fat-binding can be used. # 3. Sets @ as well, for normal binds jQuery.fn.loop = (block) -> for i in @ element = jQuery(i) res = block.call element, element break if res == false ### USE $('.photo').loop -> @hide() $('.thing').loop (thing) => thing.css width: @width()