Created
November 19, 2011 00:37
-
-
Save ded/1378205 to your computer and use it in GitHub Desktop.
ender delay()
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
!function ($) { | |
$.ender({ | |
delay: function (n) { | |
var mock = {} | |
, chain = [] | |
, key | |
, $el = $(this) | |
for (key in $el) { | |
if (isFinite(key)) continue | |
!function (key) { | |
mock[key] = function () { | |
chain.push({key:key,arguments:arguments}) | |
return mock | |
} | |
}(key) | |
} | |
setTimeout(function () { | |
for (var i = 0; i < chain.length; i++) { | |
$el = $el[chain[i].key].apply($el, chain[i].arguments) | |
} | |
}, n) | |
return mock | |
} | |
}, true) | |
}(ender); | |
$('p').css('color', 'red').delay(100).addClass('a').hide().delay(200).fadeIn() |
you have way too much time on your hand. this was meant to send to a coworker as a simple proof of concept
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
_chain
is onmockObj
rather than being a separate variable for a special reason?$el
should probably bevar $el
I'm guessing.&, lastly, the additional function inside the first loop seems a bit heavy handed to me, if it's just to get a copy of
key
perhaps something likekey:''+key
would do that without the overhead of a new function each time?Interesting idea though. Tests for it would look pretty funky.
I dunno if you wanted public comment on this or not but there you go! Couldn't help myself.