Animate watch/unwatch links to use asynchronous API requests to watch pages, rather than navigating to a different URI.
Example
var watch = require( 'mediawiki.page.watch.ajax' );
watch.updateWatchLink(
$node,
'watch',
'loading'
);
// When the watch status of the page has been updated:
watch.updatePageWatchStatus( true );
Methods
updatePageWatchStatus(isWatched, [expiry], [expirySelected])static
#
Update the page watch status.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
isWatched |
boolean | The page is watched |
||
expiry |
string |
optional |
'infinity' | The expiry date if a page is being watched temporarily. |
expirySelected |
string |
optional |
'infinite' | The expiry length that was just selected from a dropdown, e.g. '1 week' |
Fires:
updateWatchLink(titleOrLink, action, [state], [expiry], [expirySelected])static
#
Update the link text, link href
attribute and (if applicable) "loading" class.
For an individual link being set to 'loading', the first
argument can be a jQuery collection. When updating to an
"idle" state, an mw.Title
object should be passed to that
all watchstars associated with that title are updated.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
titleOrLink |
mw.Title | jQuery | Title of watchlinks to update (when state is idle), or an individual watchlink |
||
action |
string | One of 'watch', 'unwatch' |
||
state |
string |
optional |
"idle" | 'idle' or 'loading'. Default is 'idle' |
expiry |
string |
optional |
'infinity' | The expiry date if a page is being watched temporarily. |
expirySelected |
string |
optional |
'infinite' | The expiry length that was just selected from a dropdown, e.g. '1 week' |
Fires:
href
attribute and (if applicable) "loading" class.
watchstar($links, title, [callback])static
#
Bind a given watchstar element to make it interactive.
This is meant to allow binding of watchstars for arbitrary page titles, especially if different from the currently viewed page. As such, this function will not synchronise its state with any "Watch this page" checkbox such as found on the "Edit page" and "Publish changes" forms. The caller should either make "current page" watchstars picked up by init (and not use this function) or sync it manually from the callback this function provides.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
$links |
jQuery | One or more anchor elements that must have an href
with a URL containing a |
|
title |
string | Title of page that this watchstar will affect |
|
callback |
module:mediawiki.page.watch.ajax~callback |
optional |
Callback to run after the action has been processed and API request completed. |
Type Definitions
callback($link, isWatched, expiry)
#
Parameters:
Name | Type | Description |
---|---|---|
$link |
jQuery | The element being manipulated. |
isWatched |
boolean | Whether the page is now watched. |
expiry |
string | The expiry date if the page is being watched temporarily,
or an 'infinity'-like value (see |