Syntactic sugar for JavaScript's setTimeout() and setInterval()
JavaScript Other
Switch branches/tags
Nothing to show
Pull request Compare This branch is 7 commits ahead, 26 commits behind avk:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
doc
jsdoc-toolkit
lib
test
BSD_LICENSE.txt
README.md

README.md

jQuery Chrono plugin

jQuery Chrono provides syntactic sugar around JavaScript's native setTimeout and setInterval functions.

To execute some code in 5 minutes, instead of writing:

    setTimeout(function() { ... }, 300000); // how many zeros is that?

or the slightly more readable:

    setTimeout(function() { ... }, 5 * 60 * 1000); // 5... (multiplies in head) min

now you can just write:

    $.after(5, "minutes", function() { ... }); // :)

setTimeout becomes $.after and setInterval becomes $.every.

Usage

These are all valid calls:

    $.after(100, function() { ... });           // 100 milliseconds
    $.after("9.7", function() { ... });         // 9.7 milliseconds
    $.after("50sec", function() { ... });       // 50 seconds
    $.after("1 minute", function() { ... });       // 1 minute
    $.after(7, "mins", function() { ... });     // 7 minutes
    $.after("33", "hours", function() { ... }); // 33 hours
    $.after("1 hour, 2 minutes, 15 seconds", function() { ... }); // 1:02:15 hours
    $.after("1min, 15 s", function() { ... }); // 1:15 minutes

$.every, for creating intervals, has the same exact syntax as $.after.

Valid time units include:

  • millisecond (default)

  • second

  • minute

  • hour

  • day

along with all their common abbreviations and pluralizations.

Meta

Licensed under the 3-clause BSD license (BSD_LICENSE.txt)

Copyright (c) 2011, Arthur Klepchukov (at gmail)