X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.rcfilters%2Fdm%2Fmw.rcfilters.dm.FilterGroup.js;h=4dc86f6f657dd872891b1f18d83da920db46377c;hp=6acc44dc5b41ca1934e3698f6580a0e8c7fcc09c;hb=2480aae0c97d822e10b50619e7b48b25c45af073;hpb=6c9a2923fe1ee3a65cb027be5e781772f2b12fbd diff --git a/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterGroup.js b/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterGroup.js index 6acc44dc5b..4dc86f6f65 100644 --- a/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterGroup.js +++ b/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterGroup.js @@ -222,34 +222,39 @@ mw.rcfilters.dm.FilterGroup.prototype.onFilterItemUpdate = function ( item ) { // Update state var changed = false, - active = this.areAnySelected(); - - if ( - item.isSelected() && - this.getType() === 'single_option' && - this.currSelected && - this.currSelected !== item - ) { - this.currSelected.toggleSelected( false ); - } - - // For 'single_option' groups, check if we just unselected all - // items. This should never be the result. If we did unselect - // all (like resetting all filters to false) then this group - // must choose its default item or the first item in the group - if ( - this.getType() === 'single_option' && - !this.getItems().some( function ( filterItem ) { - return filterItem.isSelected(); - } ) - ) { - // Single option means there must be a single option - // selected, so we have to either select the default - // or select the first option - this.currSelected = this.getItemByParamName( this.defaultParams[ this.getName() ] ) || - this.getItems()[ 0 ]; - this.currSelected.toggleSelected( true ); - changed = true; + active = this.areAnySelected(), + model = this; + + if ( this.getType() === 'single_option' ) { + // This group must have one item selected always + // and must never have more than one item selected at a time + if ( this.getSelectedItems().length === 0 ) { + // Nothing is selected anymore + // Select the default or the first item + this.currSelected = this.getItemByParamName( this.defaultParams[ this.getName() ] ) || + this.getItems()[ 0 ]; + this.currSelected.toggleSelected( true ); + changed = true; + } else if ( this.getSelectedItems().length > 1 ) { + // There is more than one item selected + // This should only happen if the item given + // is the one that is selected, so unselect + // all items that is not it + this.getSelectedItems().forEach( function ( itemModel ) { + // Note that in case the given item is actually + // not selected, this loop will end up unselecting + // all items, which would trigger the case above + // when the last item is unselected anyways + var selected = itemModel.getName() === item.getName() && + item.isSelected(); + + itemModel.toggleSelected( selected ); + if ( selected ) { + model.currSelected = itemModel; + } + } ); + changed = true; + } } if (