1 const HighlightColors = require( '../HighlightColors.js' );
4 * A button to configure highlight for a filter item.
6 * @class mw.rcfilters.ui.FilterItemHighlightButton
8 * @extends OO.ui.PopupButtonWidget
10 * @param {mw.rcfilters.Controller} controller RCFilters controller
11 * @param {mw.rcfilters.dm.FilterItem} model Filter item model
12 * @param {mw.rcfilters.ui.HighlightPopupWidget} highlightPopup Shared highlight color picker
13 * @param {Object} [config] Configuration object
15 const FilterItemHighlightButton = function MwRcfiltersUiFilterItemHighlightButton( controller, model, highlightPopup, config ) {
16 config = config || {};
19 FilterItemHighlightButton.super.call( this, $.extend( true, {}, config, {
24 this.controller = controller;
26 this.popup = highlightPopup;
29 this.model.connect( this, { update: 'updateUiBasedOnModel' } );
30 // This lives inside a MenuOptionWidget, which intercepts mousedown
31 // to select the item. We want to prevent that when we click the highlight
33 this.$element.on( 'mousedown', ( e ) => {
37 this.updateUiBasedOnModel();
40 .addClass( 'mw-rcfilters-ui-filterItemHighlightButton' );
45 OO.inheritClass( FilterItemHighlightButton, OO.ui.PopupButtonWidget );
47 /* Static Properties */
52 FilterItemHighlightButton.static.cancelButtonMouseDownEvents = true;
56 FilterItemHighlightButton.prototype.onAction = function () {
57 this.popup.setAssociatedButton( this );
58 this.popup.setFilterItem( this.model );
61 FilterItemHighlightButton.super.prototype.onAction.call( this );
65 * Respond to item model update event
67 FilterItemHighlightButton.prototype.updateUiBasedOnModel = function () {
68 const currentColor = this.model.getHighlightColor();
70 this.$icon.toggleClass(
71 'mw-rcfilters-ui-filterItemHighlightButton-circle',
75 HighlightColors.forEach( ( c ) => {
76 // The following classes are used here:
77 // * mw-rcfilters-ui-filterItemHighlightButton-circle-color-c1
78 // * mw-rcfilters-ui-filterItemHighlightButton-circle-color-c2
79 // * mw-rcfilters-ui-filterItemHighlightButton-circle-color-c3
80 // * mw-rcfilters-ui-filterItemHighlightButton-circle-color-c4
81 // * mw-rcfilters-ui-filterItemHighlightButton-circle-color-c5
84 'mw-rcfilters-ui-filterItemHighlightButton-circle-color-' + c,
90 module.exports = FilterItemHighlightButton;