Skip to content
This repository was archived by the owner on Jun 3, 2018. It is now read-only.

Commit 60efa16

Browse files
committed
improve documentation
1 parent 39e6378 commit 60efa16

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

README.md

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,81 @@
1-
# [jQuery Timeout](https://github.com/tkem/jquery-timeout/)
1+
# [jQuery Timeout Plugin](https://github.com/tkem/jquery-timeout/)
22

33
**jQuery 1.5** introduced the _Deferred_ callback management system,
44
to ease handling callbacks for asynchronous events. Although the
5-
jQuery documentation contains examples on how to use deferred objects
5+
jQuery documentation contains examples on how to use Deferred objects
66
with the native `window.setTimeout` and `window.clearTimeout`
77
functions, jQuery does not provide a simple interface for timer-based
8-
deferreds by its own.
8+
Deferreds yet.
99

1010
This plugin provides the two functions `jQuery.timeout` and
1111
`jQuery.timeoutWith` that, given a delay in milliseconds, create a
1212
`jQuery.Deferred` instance that will be resolved after the given
13-
delay. The returned _promise_ object also provides `clear` and
14-
`clearWith` methods, which will reject the deferred object and clear
13+
delay. The returned Promise object also provides `clear` and
14+
`clearWith` methods, which will reject the Deferred object and clear
1515
the native timeout ID, if called before the timeout has elapsed.
1616

1717

1818
## API Documentation
1919

20-
### jQuery.timeout( delay [, args ] )
20+
### jQuery.timeout( delay [, args... ] )
2121

22-
Return a Promise object that will be resolved after the given `delay`.
22+
Create a Deferred object that will be resolved after the specified
23+
`delay` in milliseconds. When the Deferred is resolved, any
24+
doneCallbacks are called with optional arguments `args`.
2325

2426
### jQuery.timeoutWith( delay, context [, args ] )
2527

26-
Return a Promise object that will be resolved after the given `delay`.
28+
Create a Deferred object that will be resolved after the specified
29+
`delay` in milliseconds. When the Deferred is resolved, any
30+
doneCallbacks are called with the given `context` as the `this`
31+
object, and the optional array `args` as arguments.
2732

28-
### timeout.clear( [ args ] )
33+
### timeout.clear( [ args... ] )
2934

30-
Reject a Deferred timeout object.
35+
Clear a pending timeout by immediately rejecting the corresponding
36+
Deferred object. When the Deferred is rejected, any failCallbacks are
37+
called with optional arguments `args`.
3138

3239
### timeout.clearWith( context [, args ] )
3340

34-
Reject a Deferred timeout object.
41+
Clear a pending timeout by immediately rejecting the corresponding
42+
Deferred object. When the Deferred is rejected, any failCallbacks are
43+
called with the given `context` as the `this` object, and the optional
44+
array `args` as arguments.
3545

3646

3747
## Examples
3848

3949
Invoke a callback function after a five-second delay:
4050

4151
```
42-
$.timeout(5000, $("#status"), "5 seconds").done(function($e, msg) {
43-
$e.text(msg + " later...");
44-
});
52+
$.timeout( 5000, $("#status"), "5 seconds" ).done(function( $e, msg ) {
53+
$e.text( msg + " later..." );
54+
});
55+
```
56+
57+
Same as above, but pass the element as the context argument to
58+
`deferredWith`:
59+
60+
```
61+
$.timeoutWith( 5000, $("#status"), [ "5 seconds" ] ).done(function( msg ) {
62+
this.text(msg + " later...");
63+
});
4564
```
4665

4766
Provide handlers to be called when the timeout is resolved (elapsed)
4867
or rejected (cleared), and an event handler to manually clear the
4968
timeout.
5069

5170
```
52-
var timeout = $.timeout(10000);
71+
var timeout = $.timeout( 10000 );
5372
54-
timeout.then(
55-
function() { alert("timeout elapsed") },
56-
function() { alert("timeout cleared") }
57-
);
73+
timeout.then(
74+
function() { alert( "timeout elapsed" ) },
75+
function() { alert( "timeout cleared" ) }
76+
);
5877
59-
$("#clear").click(function() {
60-
timeout.clear();
61-
});
78+
$( "#clear" ).click(function() {
79+
timeout.clear();
80+
});
6281
```

timeout.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "timeout",
33
"version": "1.2.0",
4-
"title": "jQuery Timeout",
4+
"title": "jQuery Timeout Plugin",
55
"author": {
66
"name": "Thomas Kemmer",
77
"email": "tkemmer@computer.org"

0 commit comments

Comments
 (0)