/**
* Animate watch/unwatch links to use asynchronous API requests to
* watch pages, rather than clicking on links. Requires jQuery.
- * Uses jsMsg() from wikibits.js.
*/
if ( typeof wgAjaxWatch === 'undefined' || !wgAjaxWatch ) {
wgAjaxWatch.$links.trigger( 'mw-ajaxwatch', [response.title, 'unwatch', $link] );
} else {
// Either we got an error code or it just plain broke.
- window.location.href = $link.attr( 'href' );
+ window.location.href = $link[0].href;
return;
}
- jsMsg( response.message, 'watch' );
+ mw.util.jsMessage( response.message, 'watch' );
// Bug 12395 - update the watch checkbox on edit pages when the
// page is watched or unwatched via the tab.
if( response.watched !== undefined ) {
- $( '#wpWatchthis' ).attr( 'checked', '1' );
+ $( '#wpWatchthis' ).attr( 'checked', 'checked' );
} else {
$( '#wpWatchthis' ).removeAttr( 'checked' );
}
$links.click( function( event ) {
var $link = $( this );
- if( wgAjaxWatch.supported === false || !wgEnableWriteAPI || !wfSupportsAjax() ) {
+ if( wgAjaxWatch.supported === false || !mw.config.get( 'wgEnableWriteAPI' ) || !wfSupportsAjax() ) {
// Lazy initialization so we don't toss up
// ActiveX warnings on initial page load
// for IE 6 users with security settings.
}
wgAjaxWatch.setLinkText( $link, $link.data( 'action' ) + 'ing' );
- $.getJSON( wgScriptPath
- + '/api' + wgScriptExtension + '?action=watch&format=json&title='
+ $.getJSON( mw.config.get( 'wgScriptPath' )
+ + '/api' + mw.config.get( 'wgScriptExtension' ) + '?action=watch&format=json&title='
+ encodeURIComponent( $link.data( 'target' ) )
+ ( $link.data( 'action' ) == 'unwatch' ? '&unwatch' : '' ),
function( data, textStatus, xhr ) {
$link.data( 'action', otheraction );
wgAjaxWatch.setLinkText( $link, otheraction );
$link.attr( 'href', $link.attr( 'href' ).replace( '&action=' + action , '&action=' + otheraction ) );
- if( $link.parents( 'li' ).attr( 'id' ) == 'ca-' + action ) {
- $link.parents( 'li' ).attr( 'id', 'ca-' + otheraction );
+ if( $link.closest( 'li' ).attr( 'id' ) == 'ca-' + action ) {
+ $link.closest( 'li' ).attr( 'id', 'ca-' + otheraction );
// update the link text with the new message
$link.text( mediaWiki.msg( otheraction ) );
}
return $item.get( 0 );
}
+ },
+
+ /**
+ * Add a little box at the top of the screen to inform the user of
+ * something, replacing any previous message.
+ *
+ * @param message mixed DOM-element or HTML to be put inside the message box
+ * @param className string Used in adding a class; should be different for each
+ * call to allow CSS/JS to hide different boxes. null = no class used.
+ * @return Boolean True on success, false on failure
+ */
+ 'jsMessage' : function( message, className ) {
+ // We special-case skin structures provided by the software. Skins that
+ // choose to abandon or significantly modify our formatting can just define
+ // an mw-js-message div to start with.
+ var $messageDiv = $( '#mw-js-message' );
+ if ( !$messageDiv.length ) {
+ $messageDiv = $( '<div id="mw-js-message">' );
+ if ( mw.util.$content.parent().length ) {
+ mw.util.$content.parent().prepend( $messageDiv );
+ } else {
+ return false;
+ }
+ }
+
+ $messageDiv.show();
+ if ( className ) {
+ $messageDiv.attr( 'class', 'mw-js-message-' + className );
+ }
+
+ if ( typeof message === 'object' ) {
+ $messageDiv.empty();
+ $messageDiv.append( message ); // Append new content
+ } else {
+ $messageDiv.html( message );
+ }
+ return true;
}
};