Index: trunk/phase3/includes/Preferences.php |
— | — | @@ -1154,6 +1154,7 @@ |
1155 | 1155 | $formDescriptor = Preferences::getPreferences( $user ); |
1156 | 1156 | $htmlForm = new $formClass( $formDescriptor, 'prefs' ); |
1157 | 1157 | |
| 1158 | + $htmlForm->setId( 'mw-prefs-form' ); |
1158 | 1159 | $htmlForm->setSubmitText( wfMsg( 'saveprefs' ) ); |
1159 | 1160 | # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save' |
1160 | 1161 | $htmlForm->setSubmitTooltip( 'preferences-save' ); |
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.preferences.js |
— | — | @@ -39,26 +39,52 @@ |
40 | 40 | ); |
41 | 41 | } ); |
42 | 42 | |
| 43 | +// User preference form validation |
| 44 | +$( '#mw-prefs-form' ) |
| 45 | + .submit( function () { |
| 46 | + var isValid = wfValidateEmail( $('#mw-input-wpemailaddress').val() ); |
| 47 | + wfUpdateMailValidityLabel( isValid ); |
| 48 | + if(isValid == false ) { |
| 49 | + $('#mw-input-wpemailaddress').focus(); |
| 50 | + return false; |
| 51 | + } |
| 52 | + } |
| 53 | +); |
| 54 | + |
43 | 55 | // Lame tip to let user know if its email is valid. See bug 22449 |
44 | 56 | $( '#mw-input-wpemailaddress' ) |
45 | | - .keyup( function () { |
| 57 | + .blur( function () { |
46 | 58 | if( $( "#mw-emailaddress-validity" ).length == 0 ) { |
47 | 59 | $(this).after( '<label for="mw-input-wpemailaddress" id="mw-emailaddress-validity"></label>' ); |
48 | 60 | } |
49 | 61 | var isValid = wfValidateEmail( $(this).val() ); |
50 | | - var class_to_add = isValid ? 'valid' : 'invalid'; |
51 | | - var class_to_remove = isValid ? 'invalid' : 'valid'; |
52 | | - $( '#mw-emailaddress-validity' ) |
53 | | - .text( |
54 | | - isValid ? |
55 | | - mediaWiki.msg( 'email-address-validity-valid' ) |
56 | | - : mediaWiki.msg( 'email-address-validity-invalid' ) |
57 | | - ) |
58 | | - .addClass( class_to_add ) |
59 | | - .removeClass( class_to_remove ); |
| 62 | + wfUpdateMailValidityLabel( isValid ); |
60 | 63 | } ); |
61 | 64 | |
62 | 65 | /** |
| 66 | + * Given an email validity status (true, false, null) update the label CSS class |
| 67 | + */ |
| 68 | +wfUpdateMailValidityLabel = function( isValid ) { |
| 69 | + var class_to_add = isValid ? 'valid' : 'invalid'; |
| 70 | + var class_to_remove = isValid ? 'invalid' : 'valid'; |
| 71 | + |
| 72 | + // We allow null address |
| 73 | + if( isValid == null ) { |
| 74 | + $( '#mw-emailaddress-validity' ).text( '' ) |
| 75 | + .removeClass( 'valid invalid'); |
| 76 | + } else { |
| 77 | + $( '#mw-emailaddress-validity' ) |
| 78 | + .text( |
| 79 | + isValid ? |
| 80 | + mediaWiki.msg( 'email-address-validity-valid' ) |
| 81 | + : mediaWiki.msg( 'email-address-validity-invalid' ) |
| 82 | + ) |
| 83 | + .addClass( class_to_add ) |
| 84 | + .removeClass( class_to_remove ); |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +/** |
63 | 89 | * Validate a string as representing a valid e-mail address |
64 | 90 | * according to HTML5 specification. Please note the specification |
65 | 91 | * does not validate a domain with one character. |
— | — | @@ -120,12 +146,12 @@ |
121 | 147 | '[' + rfc1034_ldh_str + ']+' |
122 | 148 | + |
123 | 149 | // Second part and following are separated by a dot |
124 | | - '(\\.[' + rfc1034_ldh_str + ']+)+' |
| 150 | + '(?:\\.[' + rfc1034_ldh_str + ']+)+' |
125 | 151 | + |
126 | 152 | // End of string |
127 | 153 | '$', |
128 | 154 | // RegExp is case insensitive |
129 | 155 | 'i' |
130 | 156 | ); |
131 | | - return mailtxt.match( HTML5_email_regexp ); |
| 157 | + return (null != mailtxt.match( HTML5_email_regexp ) ); |
132 | 158 | }; |