From 2eac57b977cb3b005fb0e0fdef9ab628182aeeb4 Mon Sep 17 00:00:00 2001 From: Matthew Flaschen Date: Thu, 25 Apr 2013 20:12:49 -0400 Subject: [PATCH] Make it show email as required if you choose to email a random password. * Use prop( 'checked' ) as recommended by jQuery. Bug: 47686 Change-Id: Iaf789db6e49396a19decdc2e5ee5cccf155fe78d --- resources/Resources.php | 1 + .../mediawiki.special.createAccount.js | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/resources/Resources.php b/resources/Resources.php index fcb3d6a36a..1fcc3ad4f7 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -982,6 +982,7 @@ return array( 'scripts' => 'resources/mediawiki.special/mediawiki.special.createAccount.js', 'messages' => array( 'createacct-captcha', + 'createacct-emailrequired', 'createacct-imgcaptcha-ph' ), 'dependencies' => 'mediawiki.jqueryMsg', diff --git a/resources/mediawiki.special/mediawiki.special.createAccount.js b/resources/mediawiki.special/mediawiki.special.createAccount.js index aa61a1eca2..2cd562584e 100644 --- a/resources/mediawiki.special/mediawiki.special.createAccount.js +++ b/resources/mediawiki.special/mediawiki.special.createAccount.js @@ -6,11 +6,25 @@ // When sending password by email, hide the password input fields. // This function doesn't need to be loaded early by ResourceLoader, but is tiny. function hidePasswordOnEmail( $ ) { - $( '#wpCreateaccountMail' ) - .on( 'change', function() { - $( '.mw-row-password' ).toggle( !$( this ).attr( 'checked' ) ); - } ) - .trigger( 'change' ); + // Always required if checked, otherwise it depends, so we use the original + var $emailLabel = $( 'label[for="wpEmail"]' ), + originalText = $emailLabel.text(), + requiredText = mw.message( 'createacct-emailrequired' ).text(), + $createByMailCheckbox = $( '#wpCreateaccountMail' ); + + function updateForCheckbox() { + var checked = $createByMailCheckbox.prop( 'checked' ); + if ( checked ) { + $( '.mw-row-password' ).hide(); + $emailLabel.text( requiredText ); + } else { + $( '.mw-row-password' ).show(); + $emailLabel.text( originalText ); + } + } + + $createByMailCheckbox.on( 'change', updateForCheckbox ); + updateForCheckbox(); } // Move the FancyCaptcha image into a more attractive container. -- 2.20.1