Merge "Fix Flow thank of post with descendents"

This commit is contained in:
jenkins-bot 2016-02-02 09:18:12 +00:00 committed by Gerrit Code Review
commit b2c796653b

View file

@ -7,10 +7,16 @@
var $thankedLabel = $( '<span></span>' ) var $thankedLabel = $( '<span></span>' )
.addClass( 'mw-thanks-flow-thanked mw-ui-quiet' ); .addClass( 'mw-thanks-flow-thanked mw-ui-quiet' );
function findPostAuthorFromThankLink( $thankLink ) {
// We can't use 'closest' directly because .flow-author is a cousin
// of $thankLink rather than its ancestor
return $( $thankLink.findWithParent( '< .flow-post .flow-author a.mw-userlink' )[0] ).text().trim();
}
function reloadThankedState() { function reloadThankedState() {
$( 'a.mw-thanks-flow-thank-link' ).each( function ( idx, el ) { $( 'a.mw-thanks-flow-thank-link' ).each( function ( idx, el ) {
var $thankLink = $( el ), var $thankLink = $( el ),
author = $thankLink.findWithParent( '< .flow-post .flow-author a.mw-userlink' ).text().trim(); author = findPostAuthorFromThankLink( $thankLink );
if ( mw.thanks.thanked.contains( $thankLink.closest( '.flow-post' ) ) ) { if ( mw.thanks.thanked.contains( $thankLink.closest( '.flow-post' ) ) ) {
mw.thanks.getUserGender( author ) mw.thanks.getUserGender( author )
.done( function ( recipientGender ) { .done( function ( recipientGender ) {
@ -35,9 +41,7 @@
.then( .then(
// Success // Success
function ( data ) { function ( data ) {
// We can't use 'closest' directly because .flow-author is a cousin var author = findPostAuthorFromThankLink( $thankLink );
// of $thankLink rather than its ancestor
var author = $thankLink.findWithParent( '< .flow-post .flow-author a.mw-userlink' ).text().trim();
// Get the user who was thanked (for gender purposes) // Get the user who was thanked (for gender purposes)
return mw.thanks.getUserGender( author ); return mw.thanks.getUserGender( author );
}, },