From bc229aa6538758a10cafd76791269b5e440535dd Mon Sep 17 00:00:00 2001 From: Krinkle Date: Mon, 10 Jan 2011 04:40:57 +0000 Subject: [PATCH] * Consistent single quotes * The problem with onKeyUp was that is shows errors even when initially typing a (possibly valid) address. onBlur has the downside of not giving feedback while correcting the mistake + since e-mail is the last input element at the moment, it doesn't blur on submit and required a seperate event handler. ** Solution: Bind onBlur once, and then listen for onKeyUp. * Adding missing semicolon(s) * Compare with strict (===) to empty string / null * Moved non-global wfFunction to mw.util ** The "FIXME:" note was kept * Comment "apostrophe" fixed to "at". Comments don't run :) * Caching selector in wfUpdateMailValidityLabel * Renaming "wfUpdateMailValidityLabel" to "updateMailValidityLabel" ( Ping r79910, r75670, r75627 ) --- resources/Resources.php | 2 +- .../mediawiki.special.preferences.css | 8 +- .../mediawiki.special.preferences.js | 135 ++++-------------- resources/mediawiki.util/mediawiki.util.js | 108 +++++++++++--- 4 files changed, 122 insertions(+), 131 deletions(-) diff --git a/resources/Resources.php b/resources/Resources.php index 4496105fdd..576056238e 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -358,9 +358,9 @@ return array( 'dependencies' => 'mediawiki.util', ), 'mediawiki.special.preferences' => array( - 'messages' => array( 'email-address-validity-valid', 'email-address-validity-invalid' ), 'scripts' => 'resources/mediawiki.special/mediawiki.special.preferences.js', 'styles' => 'resources/mediawiki.special/mediawiki.special.preferences.css', + 'messages' => array( 'email-address-validity-valid', 'email-address-validity-invalid' ), ), 'mediawiki.special.changeslist' => array( 'styles' => 'resources/mediawiki.special/mediawiki.special.changeslist.css', diff --git a/resources/mediawiki.special/mediawiki.special.preferences.css b/resources/mediawiki.special/mediawiki.special.preferences.css index b6298a5749..8f628a95b9 100644 --- a/resources/mediawiki.special/mediawiki.special.preferences.css +++ b/resources/mediawiki.special/mediawiki.special.preferences.css @@ -2,12 +2,12 @@ padding: 2px 1em; } body.ltr #mw-emailaddress-validity { - border-bottom-right-radius:0.8em; - border-top-right-radius:0.8em; + border-bottom-right-radius: 0.8em; + border-top-right-radius: 0.8em; } body.rtl #mw-emailaddress-validity { - border-bottom-left-radius:0.8em; - border-top-left-radius:0.8em; + border-bottom-left-radius: 0.8em; + border-top-left-radius: 0.8em; } #mw-emailaddress-validity.valid { border: 1px solid #80FF80; diff --git a/resources/mediawiki.special/mediawiki.special.preferences.js b/resources/mediawiki.special/mediawiki.special.preferences.js index 084ed9012d..ad4e0a5d8c 100644 --- a/resources/mediawiki.special/mediawiki.special.preferences.js +++ b/resources/mediawiki.special/mediawiki.special.preferences.js @@ -39,119 +39,36 @@ $( '#preferences' ) ); } ); -// User preference form validation -$( '#mw-prefs-form' ) - .submit( function () { - var isValid = wfValidateEmail( $('#mw-input-wpemailaddress').val() ); - wfUpdateMailValidityLabel( isValid ); - if(isValid == false ) { - $('#mw-input-wpemailaddress').focus(); - return false; - } - } -); - -// Lame tip to let user know if its email is valid. See bug 22449 -$( '#mw-input-wpemailaddress' ) - .blur( function () { - if( $( "#mw-emailaddress-validity" ).length == 0 ) { - $(this).after( '' ); - } - var isValid = wfValidateEmail( $(this).val() ); - wfUpdateMailValidityLabel( isValid ); - } ); - /** * Given an email validity status (true, false, null) update the label CSS class */ -wfUpdateMailValidityLabel = function( isValid ) { - var class_to_add = isValid ? 'valid' : 'invalid'; - var class_to_remove = isValid ? 'invalid' : 'valid'; +var updateMailValidityLabel = function( mail ) { + var isValid = mw.util.validateEmail( mail ), + $label = $( '#mw-emailaddress-validity' ); - // We allow null address - if( isValid == null ) { - $( '#mw-emailaddress-validity' ).text( '' ) - .removeClass( 'valid invalid'); - } else { - $( '#mw-emailaddress-validity' ) - .text( - isValid ? - mediaWiki.msg( 'email-address-validity-valid' ) - : mediaWiki.msg( 'email-address-validity-invalid' ) - ) - .addClass( class_to_add ) - .removeClass( class_to_remove ); - } -} + // We allow empty address + if( isValid === null ) { + $label.text( '' ).removeClass( 'valid invalid' ); -/** - * Validate a string as representing a valid e-mail address - * according to HTML5 specification. Please note the specification - * does not validate a domain with one character. - * - * FIXME: should be moved to a JavaScript validation module. - */ -wfValidateEmail = function( mailtxt ) { - if( mailtxt == '' ) { return null; } + // Valid + } else if ( isValid ) { + $label.text( mw.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' ); - /** - * HTML 5 define a string as valid e-mail address if it matches - * the ABNF : - * 1 * ( atext / "." ) "@" ldh-str 1*( "." ldh-str ) - * With: - * - atext : defined in RFC 5322 section 3.2.3 - * - ldh-str : defined in RFC 1034 section 3.5 - * - * (see STD 68 / RFC 5234 http://tools.ietf.org/html/std68): - */ - - /** - * First, define the RFC 5322 'atext' which is pretty easy : - * atext = ALPHA / DIGIT / ; Printable US-ASCII - "!" / "#" / ; characters not including - "$" / "%" / ; specials. Used for atoms. - "&" / "'" / - "*" / "+" / - "-" / "/" / - "=" / "?" / - "^" / "_" / - "`" / "{" / - "|" / "}" / - "~" - */ - var rfc5322_atext = "a-z0-9!#$%&'*+-/=?^_`{|}—~" ; - - /** - * Next define the RFC 1034 'ldh-str' - * ::= | " " - * ::=