items.push( filterItem );
}
- if ( data.type === 'string_options' && data.default ) {
+ if ( data.type === 'string_options' ) {
// Store the default parameter group state
// For this group, the parameter is group name and value is the names
// of selected items
model.defaultParams[ group ] = model.sanitizeStringOptionGroup(
group,
- data.default.split( model.groups[ group ].getSeparator() )
+ data.default ?
+ data.default.split( model.groups[ group ].getSeparator() ) :
+ []
).join( model.groups[ group ].getSeparator() );
}
} );
return this.defaultParams;
};
- /**
- * Set all filter states to default values
- */
- mw.rcfilters.dm.FiltersViewModel.prototype.setFiltersToDefaults = function () {
- var defaultFilterStates = this.getFiltersFromParameters( this.getDefaultParams() );
-
- this.toggleFiltersSelected( defaultFilterStates );
- };
-
/**
* Analyze the groups and their filters and output an object representing
* the state of the parameters they represent.
*
- * @param {Object} [filterGroups] An object defining the filter groups to
- * translate to parameters. Its structure must follow that of this.groups
- * see #getFilterGroups
+ * @param {Object} [filterDefinition] An object defining the filter values,
+ * keyed by filter names.
* @return {Object} Parameter state object
*/
- mw.rcfilters.dm.FiltersViewModel.prototype.getParametersFromFilters = function ( filterGroups ) {
- var result = {},
- groupItems = filterGroups || this.getFilterGroups();
+ mw.rcfilters.dm.FiltersViewModel.prototype.getParametersFromFilters = function ( filterDefinition ) {
+ var groupItemDefinition,
+ result = {},
+ groupItems = this.getFilterGroups();
+
+ if ( filterDefinition ) {
+ groupItemDefinition = {};
+ // Filter definition is "flat", but in effect
+ // each group needs to tell us its result based
+ // on the values in it. We need to split this list
+ // back into groupings so we can "feed" it to the
+ // loop below, and we need to expand it so it includes
+ // all filters (set to false)
+ this.getItems().forEach( function ( filterItem ) {
+ groupItemDefinition[ filterItem.getGroupName() ] = groupItemDefinition[ filterItem.getGroupName() ] || {};
+ groupItemDefinition[ filterItem.getGroupName() ][ filterItem.getName() ] = !!filterDefinition[ filterItem.getName() ];
+ } );
+ }
$.each( groupItems, function ( group, model ) {
- $.extend( result, model.getParamRepresentation() );
+ $.extend(
+ result,
+ model.getParamRepresentation(
+ groupItemDefinition ?
+ groupItemDefinition[ group ] : null
+ )
+ );
} );
return result;
} );
};
+ /**
+ * Get items that allow highlights even if they're not currently highlighted
+ *
+ * @return {mw.rcfilters.dm.FilterItem[]} Items supporting highlights
+ */
+ mw.rcfilters.dm.FiltersViewModel.prototype.getItemsSupportingHighlights = function () {
+ return this.getItems().filter( function ( filterItem ) {
+ return filterItem.isHighlightSupported();
+ } );
+ };
+
/**
* Toggle the highlight feature on and off.
* Propagate the change to filter items.