mediawiki-extensions-Thanks/modules/ext.thanks.mobilediff.js
kaldari 22adcc3625 Add mw-ui-button styles since old button styles have been scrapped
Also adding a helpful comment.

Leaving existing mw-mf-action-button class for now since this
provides the float left. Eventually we should migrate the styles
in MobileFrontend to use mw-ui-button as well and reduce the
redundant styles that are set. See also:
Change I59e8441f4c4e1d33bff33afcab6c6670d7b99634

Bug: 61490
Change-Id: I7e14b8eb522d8d7443fa917d97cb91773c6410f0
2014-03-03 17:31:14 -08:00

88 lines
2.8 KiB
JavaScript

( function( M, $ ) {
var api = M.require( 'api' ),
popup = M.require( 'toast' ),
schema = M.require( 'loggingSchemas/MobileWebClickTracking' );
function thankUser( name, revision, gender ) {
var d = $.Deferred();
api.getToken( 'edit' ).done( function( token ) {
api.get( {
'action' : 'thank',
'rev' : revision,
'source' : 'mobilediff',
'token' : token
} )
.done( function() {
popup.show( mw.msg( 'thanks-thanked-notice', name, gender ) );
d.resolve();
} )
.fail( function( errorCode ) {
switch( errorCode ) {
case 'invalidrevision':
popup.show( mw.msg( 'thanks-error-invalidrevision' ) );
break;
case 'ratelimited':
popup.show( mw.msg( 'thanks-error-ratelimited', gender ) );
break;
default:
popup.show( mw.msg( 'thanks-error-undefined' ) );
}
d.reject();
} );
} );
return d;
}
/**
* Create a thank button for a given edit
*
* @param name String The username of the user who made the edit
* @param rev String The revision the user created
* @param gender String The gender of the user who made the edit
*/
function createThankLink( name, rev, gender ) {
var thankImg = mw.config.get( 'wgExtensionAssetsPath' ) + '/Thanks/WhiteSmiley.png',
thankImgTag = '<img width="25" height="20" src="' + thankImg + '" class="mw-mf-action-button-icon"/>',
$thankBtn;
// Don't make thank button for self
if ( name !== mw.config.get( 'wgUserName' ) ) {
// See if user has already been thanked for this edit
if ( mw.config.get( 'wgThanksAlreadySent' ) ) {
$thankBtn = $( '<button class="mw-mf-action-button mw-ui-button mw-ui-constructive thanked">' )
.attr( 'disabled', true )
.html( thankImgTag + mw.message( 'thanks-button-thanked', mw.user ).escaped() );
} else {
$thankBtn = $( '<button class="mw-mf-action-button mw-ui-button mw-ui-constructive">' )
.html( thankImgTag + mw.message( 'thanks-button-thank', mw.user ).escaped()
)
.on( 'click', function() {
var $this = $( this );
schema.log( 'diff-thank', name );
if ( !$this.hasClass( 'thanked' ) ) {
thankUser( name, rev, gender ).done( function() {
$this.addClass( 'thanked' ).attr( 'disabled', true )
.html( thankImgTag + mw.message( 'thanks-button-thanked', mw.user ).escaped() );
} );
}
} );
}
return $thankBtn;
}
}
$( function() {
var $user = $( '.mw-mf-user' ),
username = $user.data( 'user-name' ),
rev = $user.data( 'revision-id' ),
gender = $user.data( 'user-gender' ),
$thankBtn;
if ( !$user.hasClass( 'mw-mf-anon' ) ) {
$thankBtn = createThankLink( username, rev, gender );
if ( $thankBtn ) {
$thankBtn.prependTo( '#mw-mf-userinfo' );
}
}
} );
} )( mw.mobileFrontend, jQuery );