[jQuery] Re: Wait plugin
Hi all, thanks for checking my code out, nice to see some response. I think that something like this is a good candidate for the core. There's so many requests and things for how can I pause my code, etc. I can't see this being all that large in size. Matter of fact, it is not all that short, for reason's I'll come to in a second. I think this makes a good first impression but the .then starts to annoy me after a while (looking at the code I can see why it's there, but it still feels superfluous --- I don't get to use that word very often!): .then and .and are entirely superfluous - they just return a reference to the ChainCollector instance. They are they so you can stick them anywhere in your chain for readability, and are completely optional. And of course, it's code is pretty heavy compared to the Pause plugin. The crux of this thing is that I didn't write it to be a specific plugin, I just used jQuery to demonstrate the syntactic possibilities it opens. I wrote it to be a totally abstract, general-purpose function queue collector as a component of another library I'm working on. It will be used to collect event handlers, Ajax callbacks and post- animation callbacks so you don't end up with lots of nested braces. The reason it's quite long is that is has to be able to implement the methods of any object given to it - most of that code is inspecting the objects passed and figuring out what to do. More tightly-focussed plugins will likely be smaller and more suited to their task.
[jQuery] Re: Wait plugin
(Google seems to have lost my first post, sorry if this comes up twice...) I think that something like this is a good candidate for the core. There's so many requests and things for how can I pause my code, etc. I can't see this being all that large in size. It's not that small, for reasons I'll come to in a second. I think this makes a good first impression but the .then starts to annoy me after a while (looking at the code I can see why it's there, but it still feels superfluous --- I don't get to use that word very often!) .then and .and are totally optional and are just references to the ChainCollector instance - you can put them anywhere you like in the chain for legibility, or not use them at all if you prefer. The crux of all this is that I wrote ChainCollector as a general purpose function queueing object for use with event handlers, Ajax callbacks and post-animation callbacks in the library I'm working on. I just used the idea of a jquery plugin to demonstrate the syntactic possibilities it opens up. Most of its code is inspecting the objects you're using so it knows which method names it needs to implement. A more tightly focussed plugin would likely be smaller and better suited to its task. As an example, here's something you can use it to implement (this is not jQuery, it's based on my new lib): $('li').on('click').setStyle({color: '#ccc'}).and.wait(1).then._('h1').setContent('Hello!') The on() and wait() functions both use a ChainCollector to queue the chain up for asynchronous execution.
[jQuery] Re: Wait plugin
(this is not jQuery, it's based on my new lib): $('li').on('click').setStyle({color: '#ccc'}).and.wait(1).then._('h1').setContent('Hello!') That's cool. Could u tell us more about Your New lib?! GC
[jQuery] Re: Wait plugin
Okay, so Google just didn't update my copy of the thread for a few hours - that'll teach me to bother rewriting posts... That's cool. Could u tell us more about Your New lib?! Unfortunately not at this point. I've been writing it for about a week so it's early days. Basically it's a wrapper for YUI's codebase that provides better syntax. I released the ChainCollector as I came up with it on my own time and added it to my work project later, but in general I can't release any code from this new library. We may open- source it in the future, and if we do I'm sure we'll publicising it somewhere or other. Your best bet is to watch my blog: blog.jcoglan.com.
[jQuery] Re: Wait plugin
I guess it's not well known that there's a plugin in the wild, Pause, which does the same thing. The original is at http://blog.mythin.net/projects/jquery.php -- you can find that link at the docs.jquery.com/Plugins wiki. However, the queue method changed around the 1.2 (I think) release, so for current versions y'all are welcome to leech my updated pause script at http://www.doublerebel.com/scripts/jquery.pause.js . There is also another suggested method at http://www.learningjquery.com/2007/01/effect-delay-trick which (ab)uses the animate method as a timer. It is a very useful tool but I don't think it's ready for the jQuery core yet, as you can see there are very complicated and very simple ways to wait/pause the jQuery execution chain -- we'd have to standardize a method first. Charles doublerebel.com On Oct 30, 11:32 am, Tane Piper [EMAIL PROTECTED] wrote: I dunno, I'm one of these people starting to really see the benefits of keeping as much out the core as possible, as jQuery's plugin architecture doesn't add any overhead, although I'm starting to link along the lines of jQuery.core.js and jQuery.utilities.js, where functions like this come as part of a core package, but are not required by the core. On 30/10/2007, Andy Matthews [EMAIL PROTECTED] wrote: I think that something like this is a good candidate for the core. There's so many requests and things for how can I pause my code, etc. I can't see this being all that large in size. -Original Message- From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Tane Piper Sent: Tuesday, October 30, 2007 12:32 PM To: jquery-en@googlegroups.com Subject: [jQuery] [INTERESTING PLUGIN] Wait plugin I came across an interesting plugin today on my travels around the web: http://blog.jcoglan.com/2007/10/30/asynchronous-function-chaining-in-... ipt It's interesting, because it's a setTimeout plugin but is coded so it can be chained along my event queue. For example, in my code before I had: $(self).animate({top: -90, opacity: 0.9}, 2000); setTimeout(function() { $(self).animate({ top: -150, opacity: 0 }, 1000); }, 5000); But using this plugin, I can now do: $(self).animate({top: -90, opacity: 0.9}, 2000).wait(5).then.animate({ top: -150, opacity: 0 }, 1000); To me, this makes a lot of sense, and also looks more jQuery-like. Kudos for the developer for making this one. -- Tane Piper Blog -http://digitalspaghetti.me.uk AJAX Pastebin -http://pastemonkey.org This email is: [ ] blogable [ x ] ask first [ ] private -- Tane Piper Blog -http://digitalspaghetti.me.uk AJAX Pastebin -http://pastemonkey.org This email is: [ ] blogable [ x ] ask first [ ] private
[jQuery] Re: Wait plugin
On Oct 30, 2007, at 5:57 PM, polyrhythmic wrote: There is also another suggested method at http://www.learningjquery.com/2007/01/ effect-delay-trick which (ab)uses the animate method as a timer. Ha! (ab)uses just about sums it up. Thanks for giving me a little chuckle. :-) --Karl _ Karl Swedberg www.englishrules.com www.learningjquery.com
[jQuery] Re: Wait plugin
polyrhythmic wrote: It is a very useful tool but I don't think it's ready for the jQuery core yet, as you can see there are very complicated and very simple ways to wait/pause the jQuery execution chain -- we'd have to standardize a method first. I think this makes a good first impression but the .then starts to annoy me after a while (looking at the code I can see why it's there, but it still feels superfluous --- I don't get to use that word very often!): |$('#myNode').wait(2).then.hide();| And of course, it's code is pretty heavy compared to the Pause plugin. I do prefer .wait() to .pause() though. Although maybe .pause() would be more palatable if .unpause() was renamed to .continue(), .resume() or .play()? Meh, 5am and I need sleep. nn