this.controller = controller;
this.model = model;
+ this.selected = false;
mw.rcfilters.ui.FilterTagItemWidget.parent.call( this, $.extend( {
data: this.model.getName(),
}
};
+ /**
+ * Get the selected state of this widget
+ *
+ * @return {boolean} Tag is selected
+ */
+ mw.rcfilters.ui.FilterTagItemWidget.prototype.isSelected = function () {
+ return this.selected;
+ };
+
/**
* Get item name
*
} else {
// Clear selection
this.getMenu().selectItem( null );
+ this.selectTag( null );
}
};
mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onMenuChoose = function ( item ) {
this.controller.toggleFilterSelect( item.model.getName() );
+ // Select the tag if it exists, or reset selection otherwise
+ this.selectTag( this.getItemFromData( item.model.getName() ) );
+
this.focus();
};
mw.rcfilters.ui.FilterTagMultiselectWidget.parent.prototype.onTagSelect.call( this, tagItem );
this.menu.selectItem( menuOption );
+ this.selectTag( tagItem );
// Scroll to the item
if ( oldInputValue ) {
}
};
+ /**
+ * Select a tag by reference. This is what OO.ui.SelectWidget is doing.
+ * If no items are given, reset selection from all.
+ *
+ * @param {mw.rcfilters.ui.FilterTagItemWidget} [item] Tag to select,
+ * omit to deselect all
+ */
+ mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.selectTag = function ( item ) {
+ var i, len, selected;
+
+ for ( i = 0, len = this.items.length; i < len; i++ ) {
+ selected = this.items[ i ] === item;
+ if ( this.items[ i ].isSelected() !== selected ) {
+ this.items[ i ].toggleSelected( selected );
+ }
+ }
+ };
/**
* @inheritdoc
*/