| 1 |
const HighlightColors = require( '../HighlightColors.js' ); |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
const FilterItemHighlightButton = function MwRcfiltersUiFilterItemHighlightButton( controller, model, highlightPopup, config ) { |
| 16 |
config = config || {}; |
| 17 |
|
| 18 |
|
| 19 |
FilterItemHighlightButton.super.call( this, $.extend( true, {}, config, { |
| 20 |
icon: 'highlight', |
| 21 |
indicator: 'down' |
| 22 |
} ) ); |
| 23 |
|
| 24 |
this.controller = controller; |
| 25 |
this.model = model; |
| 26 |
this.popup = highlightPopup; |
| 27 |
|
| 28 |
|
| 29 |
this.model.connect( this, { update: 'updateUiBasedOnModel' } ); |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
this.$element.on( 'mousedown', ( e ) => { |
| 34 |
e.stopPropagation(); |
| 35 |
} ); |
| 36 |
|
| 37 |
this.updateUiBasedOnModel(); |
| 38 |
|
| 39 |
this.$element |
| 40 |
.addClass( 'mw-rcfilters-ui-filterItemHighlightButton' ); |
| 41 |
}; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
OO.inheritClass( FilterItemHighlightButton, OO.ui.PopupButtonWidget ); |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
FilterItemHighlightButton.static.cancelButtonMouseDownEvents = true; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
FilterItemHighlightButton.prototype.onAction = function () { |
| 57 |
this.popup.setAssociatedButton( this ); |
| 58 |
this.popup.setFilterItem( this.model ); |
| 59 |
|
| 60 |
|
| 61 |
FilterItemHighlightButton.super.prototype.onAction.call( this ); |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
FilterItemHighlightButton.prototype.updateUiBasedOnModel = function () { |
| 68 |
const currentColor = this.model.getHighlightColor(), |
| 69 |
widget = this; |
| 70 |
|
| 71 |
this.$icon.toggleClass( |
| 72 |
'mw-rcfilters-ui-filterItemHighlightButton-circle', |
| 73 |
currentColor !== null |
| 74 |
); |
| 75 |
|
| 76 |
HighlightColors.forEach( ( c ) => { |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
widget.$icon |
| 84 |
.toggleClass( |
| 85 |
'mw-rcfilters-ui-filterItemHighlightButton-circle-color-' + c, |
| 86 |
c === currentColor |
| 87 |
); |
| 88 |
} ); |
| 89 |
}; |
| 90 |
|
| 91 |
module.exports = FilterItemHighlightButton; |