18a909477093e43a14310408f58cad8b3df383dc
3 * View model for the filters selection and display
5 * @mixins OO.EventEmitter
6 * @mixins OO.EmitterList
10 mw
.rcfilters
.dm
.FiltersViewModel
= function MwRcfiltersDmFiltersViewModel() {
12 OO
.EventEmitter
.call( this );
13 OO
.EmitterList
.call( this );
16 this.defaultParams
= {};
17 this.defaultFiltersEmpty
= null;
18 this.highlightEnabled
= false;
19 this.parameterMap
= {};
22 this.aggregate( { update
: 'filterItemUpdate' } );
23 this.connect( this, { filterItemUpdate
: [ 'emit', 'itemUpdate' ] } );
27 OO
.initClass( mw
.rcfilters
.dm
.FiltersViewModel
);
28 OO
.mixinClass( mw
.rcfilters
.dm
.FiltersViewModel
, OO
.EventEmitter
);
29 OO
.mixinClass( mw
.rcfilters
.dm
.FiltersViewModel
, OO
.EmitterList
);
36 * Filter list is initialized
41 * @param {mw.rcfilters.dm.FilterItem} item Filter item updated
43 * Filter item has changed
47 * @event highlightChange
48 * @param {boolean} Highlight feature is enabled
50 * Highlight feature has been toggled enabled or disabled
56 * Re-assess the states of filter items based on the interactions between them
58 * @param {mw.rcfilters.dm.FilterItem} [item] Changed item. If not given, the
59 * method will go over the state of all items
61 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.reassessFilterInteractions = function ( item
) {
64 iterationItems
= item
!== undefined ? [ item
] : this.getItems();
66 iterationItems
.forEach( function ( checkedItem
) {
67 var allCheckedItems
= checkedItem
.getSubset().concat( [ checkedItem
.getName() ] ),
68 groupModel
= checkedItem
.getGroupModel();
70 // Check for subsets (included filters) plus the item itself:
71 allCheckedItems
.forEach( function ( filterItemName
) {
72 var itemInSubset
= model
.getItemByName( filterItemName
);
74 itemInSubset
.toggleIncluded(
75 // If any of itemInSubset's supersets are selected, this item
77 itemInSubset
.getSuperset().some( function ( supersetName
) {
78 return ( model
.getItemByName( supersetName
).isSelected() );
83 // Update coverage for the changed group
84 if ( groupModel
.isFullCoverage() ) {
85 allSelected
= groupModel
.areAllSelected();
86 groupModel
.getItems().forEach( function ( filterItem
) {
87 filterItem
.toggleFullyCovered( allSelected
);
92 // Check for conflicts
93 // In this case, we must go over all items, since
94 // conflicts are bidirectional and depend not only on
95 // individual items, but also on the selected states of
96 // the groups they're in.
97 this.getItems().forEach( function ( filterItem
) {
98 var inConflict
= false,
99 filterItemGroup
= filterItem
.getGroupModel();
101 // For each item, see if that item is still conflicting
102 $.each( model
.groups
, function ( groupName
, groupModel
) {
103 if ( filterItem
.getGroupName() === groupName
) {
104 // Check inside the group
105 inConflict
= groupModel
.areAnySelectedInConflictWith( filterItem
);
107 // According to the spec, if two items conflict from two different
108 // groups, the conflict only lasts if the groups **only have selected
109 // items that are conflicting**. If a group has selected items that
110 // are conflicting and non-conflicting, the scope of the result has
111 // expanded enough to completely remove the conflict.
113 // For example, see two groups with conflicts:
116 // name: 'experienced',
117 // conflicts: [ 'unregistered' ]
122 // name: 'registered',
125 // name: 'unregistered',
128 // If we select 'experienced', then 'unregistered' is in conflict (and vice versa),
129 // because, inherently, 'experienced' filter only includes registered users, and so
130 // both filters are in conflict with one another.
131 // However, the minute we select 'registered', the scope of our results
132 // has expanded to no longer have a conflict with 'experienced' filter, and
133 // so the conflict is removed.
135 // In our case, we need to check if the entire group conflicts with
136 // the entire item's group, so we follow the above spec
138 // The foreign group is in conflict with this item
139 groupModel
.areAllSelectedInConflictWith( filterItem
) &&
140 // Every selected member of the item's own group is also
141 // in conflict with the other group
142 filterItemGroup
.getSelectedItems().every( function ( otherGroupItem
) {
143 return groupModel
.areAllSelectedInConflictWith( otherGroupItem
);
148 // If we're in conflict, this will return 'false' which
149 // will break the loop. Otherwise, we're not in conflict
150 // and the loop continues
154 // Toggle the item state
155 filterItem
.toggleConflicted( inConflict
);
160 * Get whether the model has any conflict in its items
162 * @return {boolean} There is a conflict
164 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.hasConflict = function () {
165 return this.getItems().some( function ( filterItem
) {
166 return filterItem
.isSelected() && filterItem
.isConflicted();
171 * Get the first item with a current conflict
173 * @return {mw.rcfilters.dm.FilterItem} Conflicted item
175 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getFirstConflictedItem = function () {
178 $.each( this.getItems(), function ( index
, filterItem
) {
179 if ( filterItem
.isSelected() && filterItem
.isConflicted() ) {
180 conflictedItem
= filterItem
;
185 return conflictedItem
;
189 * Set filters and preserve a group relationship based on
190 * the definition given by an object
192 * @param {Array} filters Filter group definition
194 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.initializeFilters = function ( filters
) {
195 var i
, filterItem
, filterConflictResult
, groupConflictResult
, subsetNames
,
199 groupConflictMap
= {},
200 filterConflictMap
= {},
201 addArrayElementsUnique = function ( arr
, elements
) {
202 elements
= Array
.isArray( elements
) ? elements
: [ elements
];
204 elements
.forEach( function ( element
) {
205 if ( arr
.indexOf( element
) === -1 ) {
212 expandConflictDefinitions = function ( obj
) {
215 $.each( obj
, function ( key
, conflicts
) {
217 adjustedConflicts
= {};
219 conflicts
.forEach( function ( conflict
) {
222 if ( conflict
.filter
) {
223 filterName
= model
.groups
[ conflict
.group
].getNamePrefix() + conflict
.filter
;
224 filter
= model
.getItemByName( filterName
);
227 adjustedConflicts
[ filterName
] = $.extend(
236 // This conflict is for an entire group. Split it up to
237 // represent each filter
239 // Get the relevant group items
240 model
.groups
[ conflict
.group
].getItems().forEach( function ( groupItem
) {
241 // Rebuild the conflict
242 adjustedConflicts
[ groupItem
.getName() ] = $.extend(
246 filter
: groupItem
.getName(),
254 result
[ key
] = adjustedConflicts
;
264 filters
.forEach( function ( data
) {
265 var group
= data
.name
;
267 if ( !model
.groups
[ group
] ) {
268 model
.groups
[ group
] = new mw
.rcfilters
.dm
.FilterGroup( group
, {
270 title
: mw
.msg( data
.title
),
271 separator
: data
.separator
,
272 fullCoverage
: !!data
.fullCoverage
,
274 body
: data
.whatsThisBody
,
275 header
: data
.whatsThisHeader
,
276 linkText
: data
.whatsThisLinkText
,
277 url
: data
.whatsThisUrl
282 if ( data
.conflicts
) {
283 groupConflictMap
[ group
] = data
.conflicts
;
286 for ( i
= 0; i
< data
.filters
.length
; i
++ ) {
287 data
.filters
[ i
].subset
= data
.filters
[ i
].subset
|| [];
288 data
.filters
[ i
].subset
= data
.filters
[ i
].subset
.map( function ( el
) {
292 filterItem
= new mw
.rcfilters
.dm
.FilterItem( data
.filters
[ i
].name
, model
.groups
[ group
], {
294 label
: mw
.msg( data
.filters
[ i
].label
),
295 description
: mw
.msg( data
.filters
[ i
].description
),
296 cssClass
: data
.filters
[ i
].cssClass
299 if ( data
.filters
[ i
].subset
) {
301 data
.filters
[ i
].subset
.forEach( function ( subsetFilterName
) { // eslint-disable-line no-loop-func
302 var subsetName
= model
.groups
[ group
].getNamePrefix() + subsetFilterName
;
303 // For convenience, we should store each filter's "supersets" -- these are
304 // the filters that have that item in their subset list. This will just
305 // make it easier to go through whether the item has any other items
306 // that affect it (and are selected) at any given time
307 supersetMap
[ subsetName
] = supersetMap
[ subsetName
] || [];
308 addArrayElementsUnique(
309 supersetMap
[ subsetName
],
313 // Translate subset param name to add the group name, so we
314 // get consistent naming. We know that subsets are only within
316 subsetNames
.push( subsetName
);
319 // Set translated subset
320 filterItem
.setSubset( subsetNames
);
324 if ( data
.filters
[ i
].conflicts
) {
325 filterConflictMap
[ filterItem
.getName() ] = data
.filters
[ i
].conflicts
;
328 if ( data
.type
=== 'send_unselected_if_any' ) {
329 // Store the default parameter state
330 // For this group type, parameter values are direct
331 model
.defaultParams
[ data
.filters
[ i
].name
] = Number( !!data
.filters
[ i
].default );
334 model
.groups
[ group
].addItems( filterItem
);
335 items
.push( filterItem
);
338 if ( data
.type
=== 'string_options' && data
.default ) {
339 // Store the default parameter group state
340 // For this group, the parameter is group name and value is the names
342 model
.defaultParams
[ group
] = model
.sanitizeStringOptionGroup(
344 data
.default.split( model
.groups
[ group
].getSeparator() )
345 ).join( model
.groups
[ group
].getSeparator() );
349 // Add items to the model
350 this.addItems( items
);
353 groupConflictResult
= expandConflictDefinitions( groupConflictMap
);
354 filterConflictResult
= expandConflictDefinitions( filterConflictMap
);
356 // Set conflicts for groups
357 $.each( groupConflictResult
, function ( group
, conflicts
) {
358 model
.groups
[ group
].setConflicts( conflicts
);
361 items
.forEach( function ( filterItem
) {
362 // Apply the superset map
363 filterItem
.setSuperset( supersetMap
[ filterItem
.getName() ] );
365 // set conflicts for item
366 if ( filterConflictResult
[ filterItem
.getName() ] ) {
367 filterItem
.setConflicts( filterConflictResult
[ filterItem
.getName() ] );
371 // Create a map between known parameters and their models
372 $.each( this.groups
, function ( group
, groupModel
) {
373 if ( groupModel
.getType() === 'send_unselected_if_any' ) {
374 // Individual filters
375 groupModel
.getItems().forEach( function ( filterItem
) {
376 model
.parameterMap
[ filterItem
.getParamName() ] = filterItem
;
378 } else if ( groupModel
.getType() === 'string_options' ) {
380 model
.parameterMap
[ groupModel
.getName() ] = groupModel
;
384 this.emit( 'initialize' );
388 * Get the names of all available filters
390 * @return {string[]} An array of filter names
392 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getFilterNames = function () {
393 return this.getItems().map( function ( item
) { return item
.getName(); } );
397 * Get the object that defines groups by their name.
399 * @return {Object} Filter groups
401 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getFilterGroups = function () {
406 * Get the value of a specific parameter
408 * @param {string} name Parameter name
409 * @return {number|string} Parameter value
411 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getParamValue = function ( name
) {
412 return this.parameters
[ name
];
416 * Get the current selected state of the filters
418 * @return {Object} Filters selected state
420 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getSelectedState = function () {
422 items
= this.getItems(),
425 for ( i
= 0; i
< items
.length
; i
++ ) {
426 result
[ items
[ i
].getName() ] = items
[ i
].isSelected();
433 * Get the current full state of the filters
435 * @return {Object} Filters full state
437 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getFullState = function () {
439 items
= this.getItems(),
442 for ( i
= 0; i
< items
.length
; i
++ ) {
443 result
[ items
[ i
].getName() ] = {
444 selected
: items
[ i
].isSelected(),
445 conflicted
: items
[ i
].isConflicted(),
446 included
: items
[ i
].isIncluded()
454 * Get the default parameters object
456 * @return {Object} Default parameter values
458 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getDefaultParams = function () {
459 return this.defaultParams
;
463 * Set all filter states to default values
465 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.setFiltersToDefaults = function () {
466 var defaultFilterStates
= this.getFiltersFromParameters( this.getDefaultParams() );
468 this.toggleFiltersSelected( defaultFilterStates
);
472 * Analyze the groups and their filters and output an object representing
473 * the state of the parameters they represent.
475 * @param {Object} [filterDefinition] An object defining the filter values,
476 * keyed by filter names.
477 * @return {Object} Parameter state object
479 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getParametersFromFilters = function ( filterDefinition
) {
480 var groupItemDefinition
,
482 groupItems
= this.getFilterGroups();
484 if ( filterDefinition
) {
485 groupItemDefinition
= {};
486 // Filter definition is "flat", but in effect
487 // each group needs to tell us its result based
488 // on the values in it. We need to split this list
489 // back into groupings so we can "feed" it to the
490 // loop below, and we need to expand it so it includes
491 // all filters (set to false)
492 this.getItems().forEach( function ( filterItem
) {
493 groupItemDefinition
[ filterItem
.getGroupName() ] = groupItemDefinition
[ filterItem
.getGroupName() ] || {};
494 groupItemDefinition
[ filterItem
.getGroupName() ][ filterItem
.getName() ] = !!filterDefinition
[ filterItem
.getName() ];
498 $.each( groupItems
, function ( group
, model
) {
501 model
.getParamRepresentation(
502 groupItemDefinition
?
503 groupItemDefinition
[ group
] : null
512 * Get the highlight parameters based on current filter configuration
514 * @return {object} Object where keys are "<filter name>_color" and values
515 * are the selected highlight colors.
517 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getHighlightParameters = function () {
518 var result
= { highlight
: Number( this.isHighlightEnabled() ) };
520 this.getItems().forEach( function ( filterItem
) {
521 result
[ filterItem
.getName() + '_color' ] = filterItem
.getHighlightColor();
527 * Sanitize value group of a string_option groups type
528 * Remove duplicates and make sure to only use valid
532 * @param {string} groupName Group name
533 * @param {string[]} valueArray Array of values
534 * @return {string[]} Array of valid values
536 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.sanitizeStringOptionGroup = function( groupName
, valueArray
) {
538 validNames
= this.getGroupFilters( groupName
).map( function ( filterItem
) {
539 return filterItem
.getParamName();
542 if ( valueArray
.indexOf( 'all' ) > -1 ) {
543 // If anywhere in the values there's 'all', we
544 // treat it as if only 'all' was selected.
545 // Example: param=valid1,valid2,all
550 // Get rid of any dupe and invalid parameter, only output
552 // Example: param=valid1,valid2,invalid1,valid1
553 // Result: param=valid1,valid2
554 valueArray
.forEach( function ( value
) {
556 validNames
.indexOf( value
) > -1 &&
557 result
.indexOf( value
) === -1
559 result
.push( value
);
567 * Check whether the current filter state is set to all false.
569 * @return {boolean} Current filters are all empty
571 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.areCurrentFiltersEmpty = function () {
572 // Check if there are either any selected items or any items
573 // that have highlight enabled
574 return !this.getItems().some( function ( filterItem
) {
575 return filterItem
.isSelected() || filterItem
.isHighlighted();
580 * Check whether the default values of the filters are all false.
582 * @return {boolean} Default filters are all false
584 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.areDefaultFiltersEmpty = function () {
587 if ( this.defaultFiltersEmpty
!== null ) {
588 // We only need to do this test once,
589 // because defaults are set once per session
590 defaultFilters
= this.getFiltersFromParameters();
591 this.defaultFiltersEmpty
= Object
.keys( defaultFilters
).every( function ( filterName
) {
592 return !defaultFilters
[ filterName
];
596 return this.defaultFiltersEmpty
;
600 * This is the opposite of the #getParametersFromFilters method; this goes over
601 * the given parameters and translates into a selected/unselected value in the filters.
603 * @param {Object} params Parameters query object
604 * @return {Object} Filter state object
606 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getFiltersFromParameters = function ( params
) {
610 base
= this.getDefaultParams(),
613 params
= $.extend( {}, base
, params
);
615 // Go over the given parameters
616 $.each( params
, function ( paramName
, paramValue
) {
617 var itemOrGroup
= model
.parameterMap
[ paramName
];
619 if ( itemOrGroup
instanceof mw
.rcfilters
.dm
.FilterItem
) {
620 // Mark the group if it has any items that are selected
621 groupMap
[ itemOrGroup
.getGroupName() ] = groupMap
[ itemOrGroup
.getGroupName() ] || {};
622 groupMap
[ itemOrGroup
.getGroupName() ].hasSelected
= (
623 groupMap
[ itemOrGroup
.getGroupName() ].hasSelected
||
624 !!Number( paramValue
)
628 groupMap
[ itemOrGroup
.getGroupName() ].filters
= groupMap
[ itemOrGroup
.getGroupName() ].filters
|| [];
629 groupMap
[ itemOrGroup
.getGroupName() ].filters
.push( itemOrGroup
);
630 } else if ( itemOrGroup
instanceof mw
.rcfilters
.dm
.FilterGroup
) {
631 groupMap
[ itemOrGroup
.getName() ] = groupMap
[ itemOrGroup
.getName() ] || {};
632 // This parameter represents a group (values are the filters)
633 // this is equivalent to checking if the group is 'string_options'
634 groupMap
[ itemOrGroup
.getName() ].filters
= itemOrGroup
.getItems();
638 // Now that we know the groups' selection states, we need to go over
639 // the filters in the groups and mark their selected states appropriately
640 $.each( groupMap
, function ( group
, data
) {
641 var paramValues
, filterItem
,
642 allItemsInGroup
= data
.filters
;
644 if ( model
.groups
[ group
].getType() === 'send_unselected_if_any' ) {
645 for ( i
= 0; i
< allItemsInGroup
.length
; i
++ ) {
646 filterItem
= allItemsInGroup
[ i
];
648 result
[ filterItem
.getName() ] = groupMap
[ filterItem
.getGroupName() ].hasSelected
?
649 // Flip the definition between the parameter
650 // state and the filter state
651 // This is what the 'toggleSelected' value of the filter is
652 !Number( params
[ filterItem
.getParamName() ] ) :
653 // Otherwise, there are no selected items in the
654 // group, which means the state is false
657 } else if ( model
.groups
[ group
].getType() === 'string_options' ) {
658 paramValues
= model
.sanitizeStringOptionGroup(
660 params
[ group
].split(
661 model
.groups
[ group
].getSeparator()
665 for ( i
= 0; i
< allItemsInGroup
.length
; i
++ ) {
666 filterItem
= allItemsInGroup
[ i
];
668 result
[ filterItem
.getName() ] = (
669 // If it is the word 'all'
670 paramValues
.length
=== 1 && paramValues
[ 0 ] === 'all' ||
671 // All values are written
672 paramValues
.length
=== model
.groups
[ group
].getItemCount()
674 // All true (either because all values are written or the term 'all' is written)
675 // is the same as all filters set to true
677 // Otherwise, the filter is selected only if it appears in the parameter values
678 paramValues
.indexOf( filterItem
.getParamName() ) > -1;
687 * Get the item that matches the given name
689 * @param {string} name Filter name
690 * @return {mw.rcfilters.dm.FilterItem} Filter item
692 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getItemByName = function ( name
) {
693 return this.getItems().filter( function ( item
) {
694 return name
=== item
.getName();
699 * Set all filters to false or empty/all
700 * This is equivalent to display all.
702 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.emptyAllFilters = function () {
703 this.getItems().forEach( function ( filterItem
) {
704 this.toggleFilterSelected( filterItem
.getName(), false );
709 * Toggle selected state of one item
711 * @param {string} name Name of the filter item
712 * @param {boolean} [isSelected] Filter selected state
714 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.toggleFilterSelected = function ( name
, isSelected
) {
715 var item
= this.getItemByName( name
);
718 item
.toggleSelected( isSelected
);
723 * Toggle selected state of items by their names
725 * @param {Object} filterDef Filter definitions
727 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.toggleFiltersSelected = function ( filterDef
) {
728 Object
.keys( filterDef
).forEach( function ( name
) {
729 this.toggleFilterSelected( name
, filterDef
[ name
] );
734 * Get a group model from its name
736 * @param {string} groupName Group name
737 * @return {mw.rcfilters.dm.FilterGroup} Group model
739 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getGroup = function ( groupName
) {
740 return this.groups
[ groupName
];
744 * Get all filters within a specified group by its name
746 * @param {string} groupName Group name
747 * @return {mw.rcfilters.dm.FilterItem[]} Filters belonging to this group
749 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getGroupFilters = function ( groupName
) {
750 return ( this.getGroup( groupName
) && this.getGroup( groupName
).getItems() ) || [];
754 * Find items whose labels match the given string
756 * @param {string} query Search string
757 * @param {boolean} [returnFlat] Return a flat array. If false, the result
758 * is an object whose keys are the group names and values are an array of
759 * filters per group. If set to true, returns an array of filters regardless
761 * @return {Object} An object of items to show
762 * arranged by their group names
764 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.findMatches = function ( query
, returnFlat
) {
769 items
= this.getItems();
771 // Normalize so we can search strings regardless of case
772 query
= query
.toLowerCase();
774 // item label starting with the query string
775 for ( i
= 0; i
< items
.length
; i
++ ) {
776 if ( items
[ i
].getLabel().toLowerCase().indexOf( query
) === 0 ) {
777 result
[ items
[ i
].getGroupName() ] = result
[ items
[ i
].getGroupName() ] || [];
778 result
[ items
[ i
].getGroupName() ].push( items
[ i
] );
779 flatResult
.push( items
[ i
] );
783 if ( $.isEmptyObject( result
) ) {
784 // item containing the query string in their label, description, or group title
785 for ( i
= 0; i
< items
.length
; i
++ ) {
786 groupTitle
= items
[ i
].getGroupModel().getTitle();
788 items
[ i
].getLabel().toLowerCase().indexOf( query
) > -1 ||
789 items
[ i
].getDescription().toLowerCase().indexOf( query
) > -1 ||
790 groupTitle
.toLowerCase().indexOf( query
) > -1
792 result
[ items
[ i
].getGroupName() ] = result
[ items
[ i
].getGroupName() ] || [];
793 result
[ items
[ i
].getGroupName() ].push( items
[ i
] );
794 flatResult
.push( items
[ i
] );
799 return returnFlat
? flatResult
: result
;
803 * Get items that are highlighted
805 * @return {mw.rcfilters.dm.FilterItem[]} Highlighted items
807 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.getHighlightedItems = function () {
808 return this.getItems().filter( function ( filterItem
) {
809 return filterItem
.isHighlightSupported() &&
810 filterItem
.getHighlightColor();
815 * Toggle the highlight feature on and off.
816 * Propagate the change to filter items.
818 * @param {boolean} enable Highlight should be enabled
819 * @fires highlightChange
821 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.toggleHighlight = function ( enable
) {
822 enable
= enable
=== undefined ? !this.highlightEnabled
: enable
;
824 if ( this.highlightEnabled
!== enable
) {
825 this.highlightEnabled
= enable
;
827 this.getItems().forEach( function ( filterItem
) {
828 filterItem
.toggleHighlight( this.highlightEnabled
);
831 this.emit( 'highlightChange', this.highlightEnabled
);
836 * Check if the highlight feature is enabled
839 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.isHighlightEnabled = function () {
840 return !!this.highlightEnabled
;
844 * Set highlight color for a specific filter item
846 * @param {string} filterName Name of the filter item
847 * @param {string} color Selected color
849 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.setHighlightColor = function ( filterName
, color
) {
850 this.getItemByName( filterName
).setHighlightColor( color
);
854 * Clear highlight for a specific filter item
856 * @param {string} filterName Name of the filter item
858 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.clearHighlightColor = function ( filterName
) {
859 this.getItemByName( filterName
).clearHighlightColor();
863 * Clear highlight for all filter items
865 mw
.rcfilters
.dm
.FiltersViewModel
.prototype.clearAllHighlightColors = function () {
866 this.getItems().forEach( function ( filterItem
) {
867 filterItem
.clearHighlightColor();
870 }( mediaWiki
, jQuery
) );