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

Commit bdc11b2

Browse files
committed
improve formatting
1 parent c039659 commit bdc11b2

File tree

1 file changed

+53
-54
lines changed

1 file changed

+53
-54
lines changed

README.md

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

3-
**jQuery 1.5** introduced the [Deferred
4-
Object](http://api.jquery.com/category/deferred-object/) to ease
5-
handling callbacks for asynchronous events. Although the jQuery
6-
documentation contains examples on how to use Deferred objects with
7-
the native `window.setTimeout()` and `window.clearTimeout()`
8-
functions, jQuery does not provide a simple interface for timer-based
9-
Deferreds yet.
3+
**jQuery 1.5** introduced the [Deferred Object][1] to register
4+
callbacks for asynchronous events. Although the jQuery documentation
5+
contains examples on how to use Deferred objects with the native
6+
[`window.setTimeout()`][2] and [`window.clearTimeout()`][3] functions,
7+
jQuery does not provide a simple interface for timer-based Deferreds
8+
yet.
109

11-
This plugin provides the two functions `jQuery.timeout()` and
12-
`jQuery.timeoutWith()` that, given a delay in milliseconds, create a
13-
`jQuery.Deferred` instance that will be resolved after the given
14-
delay. The returned Promise object also provides `clear()` and
15-
`clearWith()` methods, which will reject the Deferred object and clear
16-
the native timeout ID, if called before the timeout has elapsed.
10+
This plugin provides the two functions [`jQuery.timeout()`](#timeout)
11+
and [`jQuery.timeoutWith()`](#timeoutWith) that create a Deferred
12+
object which is resolved after a given delay. The Deferred's Promise
13+
object provides additional methods [`clear()`](#clear) and
14+
[`clearWith()`](#clearWith), which will reject the Deferred and clear
15+
the native timeout ID if called before the delay has elapsed.
1716

1817

1918
## API Documentation
2019

21-
### jQuery.timeout( delay [, args... ] )
20+
### <a name="timeout"></a> jQuery.timeout( delay [, args... ] )
2221

2322
Create a Deferred object that will be resolved after the specified
2423
`delay` in milliseconds. When the Deferred is resolved, any
2524
doneCallbacks are called with optional arguments `args`. The returned
2625
`Timeout` object extends the Deferred's Promise object with the
27-
addional methods `clear()` and `clearWith()`, for rejecting the
28-
Deferred before the delay has elapsed.
26+
addional methods [`clear()`](#clear) and [`clearWith()`](#clearWith),
27+
for rejecting the Deferred before the delay has elapsed.
2928

30-
### jQuery.timeoutWith( delay, context [, args ] )
29+
### <a name="timeoutWith"></a> jQuery.timeoutWith( delay, context [, args ] )
3130

3231
Create a Deferred object that will be resolved after the specified
3332
`delay` in milliseconds. When the Deferred is resolved, any
3433
doneCallbacks are called with the given `context` as the `this`
3534
object, and the optional array `args` as arguments. The returned
3635
`Timeout` object extends the Deferred's Promise object with the
37-
addional methods `clear()` and `clearWith()`, for rejecting the
38-
Deferred before the delay has elapsed.
36+
addional methods [`clear()`](#clear) and [`clearWith()`](#clearWith),
37+
for rejecting the Deferred before the delay has elapsed.
3938

40-
### timeout.clear( [ args... ] )
39+
### <a name="clear"></a> timeout.clear( [ args... ] )
4140

42-
Clear a pending Promise object returned by `jQuery.timeout()` or
43-
`jQuery.timeoutWith()` by immediately rejecting the corresponding
44-
Deferred object. When the Deferred is rejected, any failCallbacks are
45-
called with optional arguments `args`.
41+
Clear a pending Promise object returned by
42+
[`jQuery.timeout()`](#timeout) or
43+
[`jQuery.timeoutWith()`](#timeoutWith) by immediately rejecting the
44+
corresponding Deferred object. When the Deferred is rejected, any
45+
failCallbacks are called with optional arguments `args`.
4646

47-
### timeout.clearWith( context [, args ] )
47+
### <a name="clearWith"></a> timeout.clearWith( context [, args ] )
4848

49-
Clear a pending Promise object returned by `jQuery.timeout()` or
50-
`jQuery.timeoutWith()` by immediately rejecting the corresponding
51-
Deferred object. When the Deferred is rejected, any failCallbacks are
52-
called with the given `context` as the `this` object, and the optional
53-
array `args` as arguments.
49+
Clear a pending Promise object returned by
50+
[`jQuery.timeout()`](#timeout) or
51+
[`jQuery.timeoutWith()`](#timeoutWith) by immediately rejecting the
52+
corresponding Deferred object. When the Deferred is rejected, any
53+
failCallbacks are called with the given `context` as the `this`
54+
object, and the optional array `args` as arguments.
5455

5556

5657
## Examples
5758

5859
Invoke a callback function after a five-second delay:
5960

60-
```
61-
$.timeout( 5000, $("#status"), "5 seconds" ).done(function( $e, msg ) {
62-
$e.text( msg + " later..." );
63-
});
64-
```
61+
$.timeout( 5000, $("#status"), "5 seconds" ).done(function( $e, msg ) {
62+
$e.text( msg + " later..." );
63+
});
6564

66-
Same as above, but pass the element as the context argument to
67-
`deferredWith`:
65+
Same as above, but pass the element as context argument to
66+
[`jQuery.timeoutWith()`](#timeoutWith):
6867

69-
```
70-
$.timeoutWith( 5000, $("#status"), [ "5 seconds" ] ).done(function( msg ) {
71-
this.text(msg + " later...");
72-
});
73-
```
68+
$.timeoutWith( 5000, $("#status"), [ "5 seconds" ] ).done(function( msg ) {
69+
this.text(msg + " later...");
70+
});
7471

7572
Provide handlers to be called when the timeout is resolved (elapsed)
7673
or rejected (cleared), and an event handler to manually clear the
7774
timeout.
78-
79-
```
80-
var timeout = $.timeout( 10000 );
81-
timeout.then(
82-
function() { alert( "timeout elapsed" ) },
83-
function() { alert( "timeout cleared" ) }
84-
);
85-
$( "#clear" ).click(function() {
86-
timeout.clear();
87-
});
88-
```
75+
76+
var timeout = $.timeout( 10000 );
77+
timeout.then(
78+
function() { alert( "timeout elapsed" ) },
79+
function() { alert( "timeout cleared" ) }
80+
);
81+
$( "#clear" ).click(function() {
82+
timeout.clear();
83+
});
84+
85+
[1]: http://api.jquery.com/category/deferred-object/
86+
[2]: http://developer.mozilla.org/en/docs/Web/API/window.setTimeout
87+
[3]: http://developer.mozilla.org/en/docs/Web/API/window.clearTimeout

0 commit comments

Comments
 (0)