Merge "Cleanup page creation in RevisionIntegrationTest"
[lhc/web/wiklou.git] / resources / src / mediawiki / page / watch.js
index 6f52cbf..5b55bb2 100644 (file)
@@ -2,11 +2,22 @@
  * Animate watch/unwatch links to use asynchronous API requests to
  * watch pages, rather than navigating to a different URI.
  *
- * @class mw.page.watch.ajax
+ * Usage:
+ *
+ *     var watch = require( 'mediawiki.page.watch.ajax' );
+ *     watch.updateWatchLink(
+ *         $node,
+ *         'watch',
+ *         'loading'
+ *     );
+ *
+ * @class mw.plugin.page.watch.ajax
+ * @singleton
  */
 ( function ( mw, $ ) {
-       // The name of the page to watch or unwatch
-       var title = mw.config.get( 'wgRelevantPageName' );
+       var watch,
+               // The name of the page to watch or unwatch
+               title = mw.config.get( 'wgRelevantPageName' );
 
        /**
         * Update the link text, link href attribute and (if applicable)
        }
 
        // Expose public methods
-       mw.page = {
-               watch: {
-                       updateWatchLink: updateWatchLink
-               }
+       watch = {
+               updateWatchLink: updateWatchLink
        };
+       module.exports = watch;
 
        $( function () {
-               var $links = $( '.mw-watchlink a, a.mw-watchlink' );
-               // Restrict to core interfaces, ignore user-generated content
-               $links = $links.filter( ':not( #bodyContent *, #content * )' );
+               var $links = $( '.mw-watchlink a[data-mw="interface"], a.mw-watchlink[data-mw="interface"]' );
+               if ( !$links.length ) {
+                       // Fallback to the class-based exclusion method for backwards-compatibility
+                       $links = $( '.mw-watchlink a, a.mw-watchlink' );
+                       // Restrict to core interfaces, ignore user-generated content
+                       $links = $links.filter( ':not( #bodyContent *, #content * )' );
+               }
 
                $links.click( function ( e ) {
                        var mwTitle, action, api, $link;