r99270 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99269‎ | r99270 | r99271 >
Date:21:53, 7 October 2011
Author:neilk
Status:ok (Comments)
Tags:
Comment:
fix issue with UploadWizard caused by jquery 1.6.4 upgrade
Modified paths:
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizardLicenseInput.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardLicenseInput.js
@@ -152,11 +152,51 @@
153153 */
154154 setValues: function( values ) {
155155 var _this = this;
156 - $j.each( _this.inputs, function( i, $input ) {
157 - var licenseName = $input.data( 'licenseName' );
158 - // !! to ensure boolean.
159 - $input.attr( 'checked', !!values[licenseName] );
160 - } );
 156+ // ugly division between radio and checkbox, because in jquery 1.6.4 if you set any element of a radio input to false, every element
 157+ // is set to false! Unfortunately the incoming data structure is a key-val object so we have to make extra sure it makes sense for
 158+ // a radio button input.
 159+
 160+ // this works fine for blanking all of a radio input, or for checking/unchecking individual checkboxes
 161+ function setInputsIndividually() {
 162+ $j.each( _this.inputs, function( i, $input ) {
 163+ var licenseName = $input.data( 'licenseName' );
 164+ // !! to ensure boolean.
 165+ $input.attr( 'checked', !!values[licenseName] );
 166+ } );
 167+ }
 168+
 169+ if ( _this.type === 'radio' ) {
 170+
 171+ // check if how many license names are set to true in the values requested. Should be 0 or 1
 172+ var trueCount = 0;
 173+ var trueLicenseName = undefined;
 174+ $j.each( values, function( licenseName, val ) {
 175+ if ( val === true ) {
 176+ trueCount++;
 177+ trueLicenseName = licenseName;
 178+ }
 179+ } );
 180+
 181+ if ( trueCount === 0 ) {
 182+ setInputsIndividually();
 183+ } else if ( trueCount === 1 ) {
 184+ // set just one of the radio inputs and don't touch anything else
 185+ $j.each( _this.inputs, function( i, $input ) {
 186+ var licenseName = $input.data( 'licenseName' );
 187+ // !! to ensure boolean.
 188+ if ( licenseName === trueLicenseName ) {
 189+ $input.attr( 'checked', true );
 190+ }
 191+ } );
 192+ } else {
 193+ mw.log( "too many true values for a radio button!");
 194+ }
 195+
 196+ } else if ( _this.type === 'checkbox' ) {
 197+ setInputsIndividually();
 198+ } else {
 199+ mw.log( "impossible? UploadWizardLicenseInput type neither radio nor checkbox" );
 200+ }
161201 // we use the selector because events can't be unbound unless they're in the DOM.
162202 _this.$selector.trigger( 'changeLicenses' );
163203 },

Follow-up revisions

RevisionCommit summaryAuthorDate
r99275MFT r99270neilk22:01, 7 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99231upgrading to jquery 1.6.4 to fix bug #31424neilk18:53, 7 October 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   22:00, 7 October 2011

Seems to work!

Status & tagging log