Content deleted Content added
Technical 13 (talk | contribs) Note that this is an unstable beta and how to find stable version... |
Technical 13 (talk | contribs) copied from my talk page. Code in thanks to User:Kaldari |
||
Line 22:
});
}
var thankedHistory = {
maxHistory: 100,
load: function() {
var cookie = $.cookie( 'thanks-thanked' );
if ( cookie === null ) {
return [];
}
return unescape( cookie ).split( ',' );
},
push: function( $thankLink ) {
var saved = this.load();
saved.push( $thankLink.attr( 'data-revision-id' ) );
if ( saved.length > this.maxHistory ) { // prevent forever growing
saved = saved.slice( saved.length - this.maxHistory );
}
$.cookie( 'thanks-thanked', escape( saved.join( ',' ) ) );
}
};
$( 'a.mw-thanks-thank-link' ).click( function( e ) {
var $thankLink = $( this ), source;
e.preventDefault();
if ( mw.config.get( 'wgAction' ) === 'history' ) {
source = 'history';
} else {
source = 'diff';
}
( new mw.Api ).get( {
'action' : 'thank',
'rev' : $thankLink.attr( 'data-revision-id' ),
'source' : source,
'token' : mw.user.tokens.values.editToken
} )
.done( function( data ) {
$thankLink.before( mw.message( 'thanks-thanked', mw.user ).escaped() );
$thankLink.remove();
thankedHistory.push( $thankLink );
} )
.fail( function( errorCode, details ) {
// TODO: use something besides alert for the error messages
switch( errorCode ) {
case 'invalidrevision':
alert( mw.msg( 'thanks-error-invalidrevision' ) );
break;
case 'ratelimited':
alert( mw.msg( 'thanks-error-ratelimited' ) );
break;
default:
alert( mw.msg( 'thanks-error-undefined' ) );
}
} );
} );
|