this.currentView = 'default';
- if ( this.getHighlightedItems().length > 0 ) {
- this.toggleHighlight( true );
- }
+ this.updateHighlightedState();
// Finish initialization
this.emit( 'initialize' );
filterItem.clearHighlightColor();
}
} );
- this.toggleHighlight( !!Number( params.highlight ) );
+ this.updateHighlightedState();
// Check all filter interactions
this.reassessFilterInteractions();
true,
{},
this.getParametersFromFilters( {} ),
- this.getEmptyHighlightParameters(),
- { highlight: '0' }
+ this.getEmptyHighlightParameters()
);
}
return this.emptyParameterState;
// Highlights
Object.keys( this.getEmptyHighlightParameters() ).forEach( function ( param ) {
- if ( param !== 'highlight' && parameters[ param ] ) {
+ if ( parameters[ param ] ) {
// If a highlight parameter is not undefined and not null
// add it to the result
- // Ignore "highlight" parameter because that, we checked already with
- // the empty parameter state (and this soon changes to an implicit value)
result[ param ] = parameters[ param ];
}
} );
true,
{},
this.getParametersFromFilters( this.getSelectedState() ),
- this.getHighlightParameters(),
- {
- // HACK: Add highlight. This is only needed while it's
- // stored as an outside state
- highlight: String( Number( this.isHighlightEnabled() ) )
- }
+ this.getHighlightParameters()
) );
if ( removeExcludedParams ) {
return this.getItems().map( function ( item ) { return item.getName(); } );
};
+ /**
+ * Turn the highlight feature on or off
+ */
+ mw.rcfilters.dm.FiltersViewModel.prototype.updateHighlightedState = function () {
+ this.toggleHighlight( this.getHighlightedItems().length > 0 );
+ };
+
/**
* Get the object that defines groups by their name.
*
* are the selected highlight colors.
*/
mw.rcfilters.dm.FiltersViewModel.prototype.getHighlightParameters = function () {
- var result = {};
+ var highlightEnabled = this.isHighlightEnabled(),
+ result = {};
this.getItems().forEach( function ( filterItem ) {
if ( filterItem.isHighlightSupported() ) {
- result[ filterItem.getName() + '_color' ] = filterItem.getHighlightColor() || null;
+ result[ filterItem.getName() + '_color' ] = highlightEnabled && filterItem.isHighlighted() ?
+ filterItem.getHighlightColor() :
+ null;
}
} );
- result.highlight = String( Number( this.isHighlightEnabled() ) );
return result;
};
result[ filterItem.getName() + '_color' ] = null;
}
} );
- result.highlight = '0';
-
- return result;
- };
-
- /**
- * Extract the highlight values from given object. Since highlights are
- * the same for filter and parameters, it doesn't matter which one is
- * given; values will be returned with a full list of the highlights
- * with colors or null values.
- *
- * @param {Object} representation Object containing representation of
- * some or all highlight values
- * @return {Object} Object where keys are `<filter name>_color` and values
- * are the selected highlight colors. The returned object
- * contains all available filters either with a color value
- * or with null.
- */
- mw.rcfilters.dm.FiltersViewModel.prototype.extractHighlightValues = function ( representation ) {
- var result = {};
-
- this.getItems().forEach( function ( filterItem ) {
- var highlightName = filterItem.getName() + '_color';
- result[ highlightName ] = representation[ highlightName ] || null;
- } );
return result;
};
mw.rcfilters.dm.FiltersViewModel.prototype.getCurrentlyUsedHighlightColors = function () {
var result = [];
- this.getHighlightedItems().forEach( function ( filterItem ) {
- var color = filterItem.getHighlightColor();
+ if ( this.isHighlightEnabled() ) {
+ this.getHighlightedItems().forEach( function ( filterItem ) {
+ var color = filterItem.getHighlightColor();
- if ( result.indexOf( color ) === -1 ) {
- result.push( color );
- }
- } );
+ if ( result.indexOf( color ) === -1 ) {
+ result.push( color );
+ }
+ } );
+ }
return result;
};
enable = enable === undefined ? !this.highlightEnabled : enable;
if ( this.highlightEnabled !== enable ) {
- // HACK make sure highlights are disabled globally while we toggle on the items,
- // otherwise we'll call clearHighlight() and applyHighlight() many many times
- this.highlightEnabled = false;
- this.getItems().forEach( function ( filterItem ) {
- filterItem.toggleHighlight( enable );
- } );
-
this.highlightEnabled = enable;
this.emit( 'highlightChange', this.highlightEnabled );
}