From: MatmaRex Date: Sun, 16 Dec 2012 14:15:49 +0000 (+0100) Subject: applying code conventions and cleanup in mediawiki.special.* X-Git-Tag: 1.31.0-rc.0~21280^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/rappel_supprimer.php?a=commitdiff_plain;h=c1cc8b932779eca7591e3876511ab7a1bc1833fa;p=lhc%2Fweb%2Fwiklou.git applying code conventions and cleanup in mediawiki.special.* Using standard closures per [[CC/JS]], typos in comments, indentation inconsistencies, some other minor changes. Change-Id: I53eef75006d87c8b55d6780d36165317066d1368 --- diff --git a/resources/mediawiki.special/mediawiki.special.block.js b/resources/mediawiki.special/mediawiki.special.block.js index 077adcdbb6..2a158dfbd0 100644 --- a/resources/mediawiki.special/mediawiki.special.block.js +++ b/resources/mediawiki.special/mediawiki.special.block.js @@ -2,8 +2,7 @@ * JavaScript for Special:Block */ ( function ( mw, $ ) { - $( function ( $ ) { - + $( document ).ready( function () { var $blockTarget = $( '#mw-bi-target' ), $anonOnlyRow = $( '#mw-input-wpHardBlock' ).closest( 'tr' ), $enableAutoblockRow = $( '#mw-input-wpAutoBlock' ).closest( 'tr' ), @@ -11,10 +10,6 @@ $watchUser = $( '#mw-input-wpWatch' ).closest( 'tr' ); function updateBlockOptions( instant ) { - if ( !$blockTarget.length ) { - return; - } - var blocktarget = $.trim( $blockTarget.val() ), isEmpty = blocktarget === '', isIp = mw.util.isIPv4Address( blocktarget, true ) || mw.util.isIPv6Address( blocktarget, true ), @@ -39,11 +34,13 @@ } } - // Bind functions so they're checked whenever stuff changes - $blockTarget.keyup( updateBlockOptions ); + if ( $blockTarget.length ) { + // Bind functions so they're checked whenever stuff changes + $blockTarget.keyup( updateBlockOptions ); - // Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours) - updateBlockOptions( /* instant= */ true ); + // Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours) + updateBlockOptions( /* instant= */ true ); + } } ); }( mediaWiki, jQuery ) ); diff --git a/resources/mediawiki.special/mediawiki.special.changeemail.js b/resources/mediawiki.special/mediawiki.special.changeemail.js index cab0bbd3ee..14c2f03677 100644 --- a/resources/mediawiki.special/mediawiki.special.changeemail.js +++ b/resources/mediawiki.special/mediawiki.special.changeemail.js @@ -1,42 +1,42 @@ -/* +/** * JavaScript for Special:ChangeEmail */ ( function ( mw, $ ) { + /** + * Given an email validity status (true, false, null) update the label CSS class + */ + function updateMailValidityLabel( mail ) { + var isValid = mw.util.validateEmail( mail ), + $label = $( '#mw-emailaddress-validity' ); -/** - * Given an email validity status (true, false, null) update the label CSS class - */ -function updateMailValidityLabel( mail ) { - var isValid = mw.util.validateEmail( mail ), - $label = $( '#mw-emailaddress-validity' ); - - // We allow empty address - if( isValid === null ) { - $label.text( '' ).removeClass( 'valid invalid' ); + // We allow empty address + if ( isValid === null ) { + $label.text( '' ).removeClass( 'valid invalid' ); - // Valid - } else if ( isValid ) { - $label.text( mw.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' ); + // Valid + } else if ( isValid ) { + $label.text( mw.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' ); - // Not valid - } else { - $label.text( mw.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' ); + // Not valid + } else { + $label.text( mw.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' ); + } } -} -$( document ).ready( function () { - // Lame tip to let user know if its email is valid. See bug 22449 - // Only bind once for 'blur' so that the user can fill it in without errors - // After that look at every keypress for direct feedback if it was invalid onblur - $( '#wpNewEmail' ).one( 'blur', function () { - if ( $( '#mw-emailaddress-validity' ).length === 0 ) { - $(this).after( '' ); - } - updateMailValidityLabel( $(this).val() ); - $(this).keyup( function () { - updateMailValidityLabel( $(this).val() ); + $( document ).ready( function () { + // Lame tip to let user know if its email is valid. See bug 22449. + // Only bind once for 'blur' so that the user can fill it in without errors; + // after that, look at every keypress for immediate feedback. + $( '#wpNewEmail' ).one( 'blur', function () { + var $this = $( this ); + if ( $( '#mw-emailaddress-validity' ).length === 0 ) { + $this.after( '' ); + } + + updateMailValidityLabel( $this.val() ); + $this.keyup( function () { + updateMailValidityLabel( $this.val() ); + } ); } ); } ); -} ); - }( mediaWiki, jQuery ) ); diff --git a/resources/mediawiki.special/mediawiki.special.movePage.js b/resources/mediawiki.special/mediawiki.special.movePage.js index 7a55806607..f719d07c6f 100644 --- a/resources/mediawiki.special/mediawiki.special.movePage.js +++ b/resources/mediawiki.special/mediawiki.special.movePage.js @@ -1,7 +1,6 @@ /** * JavaScript for Special:MovePage */ - -jQuery( function( $ ) { +jQuery( document ).ready( function ( $ ) { $( '#wpReason, #wpNewTitleMain' ).byteLimit(); } ); diff --git a/resources/mediawiki.special/mediawiki.special.preferences.js b/resources/mediawiki.special/mediawiki.special.preferences.js index d8d092b6b6..46384a8009 100644 --- a/resources/mediawiki.special/mediawiki.special.preferences.js +++ b/resources/mediawiki.special/mediawiki.special.preferences.js @@ -1,4 +1,4 @@ -/* +/** * JavaScript for Special:Preferences */ jQuery( document ).ready( function ( $ ) { @@ -8,20 +8,19 @@ jQuery( document ).ready( function ( $ ) { $( '#prefsubmit' ).attr( 'id', 'prefcontrol' ); - $preftoc = $(''), - $preferences = $( '#preferences' ) - .addClass( 'jsprefs' ) - .before( $preftoc ), - $fieldsets = $preferences.children( 'fieldset' ) - .hide() - .addClass( 'prefsection' ), - $legends = $fieldsets - .children( 'legend' ) - .addClass( 'mainLegend' ); + $preftoc = $(''); + $preferences = $( '#preferences' ) + .addClass( 'jsprefs' ) + .before( $preftoc ); + $fieldsets = $preferences.children( 'fieldset' ) + .hide() + .addClass( 'prefsection' ); + $legends = $fieldsets + .children( 'legend' ) + .addClass( 'mainLegend' ); /** - * It uses document.getElementById for security reasons (html injections in - * jQuery()). + * It uses document.getElementById for security reasons (HTML injections in $()). * * @param String name: the name of a tab without the prefix ("mw-prefsection-") * @param String mode: [optional] A hash will be set according to the current diff --git a/resources/mediawiki.special/mediawiki.special.recentchanges.js b/resources/mediawiki.special/mediawiki.special.recentchanges.js index 3cba9d3972..d1c1354f0e 100644 --- a/resources/mediawiki.special/mediawiki.special.recentchanges.js +++ b/resources/mediawiki.special/mediawiki.special.recentchanges.js @@ -2,19 +2,16 @@ * JavaScript for Special:RecentChanges */ ( function ( mw, $ ) { - var rc, - $checkboxes, - $select; + var rc, $checkboxes, $select; rc = { - /** * Handler to disable/enable the namespace selector checkboxes when the * special 'all' namespace is selected/unselected respectively. */ updateCheckboxes: function () { // The option element for the 'all' namespace has an empty value - var isAllNS = $select.find( 'option:selected' ).val() === ''; + var isAllNS = $select.val() === ''; // Iterates over checkboxes and propagate the selected option $checkboxes.prop( 'disabled', isAllNS ); @@ -30,7 +27,7 @@ } }; - $( rc.init ); + $( document ).ready( rc.init ); mw.special.recentchanges = rc; diff --git a/resources/mediawiki.special/mediawiki.special.search.js b/resources/mediawiki.special/mediawiki.special.search.js index 0cca26dba4..2dab3026c4 100644 --- a/resources/mediawiki.special/mediawiki.special.search.js +++ b/resources/mediawiki.special/mediawiki.special.search.js @@ -1,8 +1,8 @@ -/* +/** * JavaScript for Special:Search */ -( function ( $, mw ) { - $( function () { +( function ( mw, $ ) { + $( document ).ready( function () { var $checkboxes, $headerLinks; // Emulate HTML5 autofocus behavior in non HTML5 compliant browsers @@ -50,4 +50,4 @@ } ); -}( jQuery, mediaWiki ) ); +}( mediaWiki, jQuery ) ); diff --git a/resources/mediawiki.special/mediawiki.special.undelete.js b/resources/mediawiki.special/mediawiki.special.undelete.js index c6e5d614ec..d20aab5198 100644 --- a/resources/mediawiki.special/mediawiki.special.undelete.js +++ b/resources/mediawiki.special/mediawiki.special.undelete.js @@ -1,11 +1,11 @@ -/* - * JavaScript for Specical:Undelete +/** + * JavaScript for Special:Undelete */ jQuery( document ).ready( function ( $ ) { $( '#mw-undelete-invert' ).click( function ( e ) { - e.preventDefault(); $( '#undelete input[type="checkbox"]' ).prop( 'checked', function ( i, val ) { return !val; } ); + e.preventDefault(); } ); } ); diff --git a/resources/mediawiki.special/mediawiki.special.upload.js b/resources/mediawiki.special/mediawiki.special.upload.js index b05fd71a47..75532f1810 100644 --- a/resources/mediawiki.special/mediawiki.special.upload.js +++ b/resources/mediawiki.special/mediawiki.special.upload.js @@ -6,7 +6,7 @@ /** * Add a preview to the upload form */ - $( function ( $ ) { + $( document ).ready( function () { /** * Is the FileAPI available with sufficient functionality? */ @@ -25,7 +25,7 @@ * @return boolean */ function fileIsPreviewable( file ) { - var known = ['image/png', 'image/gif', 'image/jpeg', 'image/svg+xml'], + var known = ['image/png', 'image/gif', 'image/jpeg', 'image/svg+xml'], tooHuge = 10 * 1024 * 1024; return ( $.inArray( file.type, known ) !== -1 ) && file.size > 0 && file.size < tooHuge; } @@ -62,7 +62,7 @@ $( '#mw-htmlform-source' ).parent().prepend( thumb ); fetchPreview( file, function ( dataURL ) { - var img = new Image(), + var img = new Image(), rotation = 0; if ( meta && meta.tiff && meta.tiff.Orientation ) { @@ -290,7 +290,7 @@ /** * Disable all upload source fields except the selected one */ - $( function ( $ ) { + $( document ).ready( function () { var i, $row, $rows = $( '.mw-htmlform-field-UploadSourceField' );