r99275 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99274‎ | r99275 | r99276 >
Date:22:01, 7 October 2011
Author:neilk
Status:ok (Comments)
Tags:
Comment:
MFT r99270
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/UploadWizard/resources/mw.UploadWizardLicenseInput.js (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/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 },

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99270fix issue with UploadWizard caused by jquery 1.6.4 upgradeneilk21:53, 7 October 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   23:34, 7 October 2011

This doesn't apply cleanly on REL1_18; are intermediate revs missing there?

#Comment by NeilK (talk | contribs)   01:58, 8 October 2011

yup -- r95727. I could just rebranch from trunk, is that still okay to do?

Status & tagging log