* with 'default' and 'inverted' as keys.
* @cfg {boolean} [active=true] The filter is active and affecting the result
* @cfg {boolean} [selected] The item is selected
- * @cfg {boolean} [inverted] The item is inverted, meaning the search is excluding
- * this parameter.
* @cfg {string} [namePrefix='item_'] A prefix to add to the param name to act as a unique
* identifier
* @cfg {string} [cssClass] The class identifying the results that match this filter
* @cfg {string[]} [identifiers] An array of identifiers for this item. They will be
* added and considered in the view.
+ * @cfg {string} [defaultHighlightColor] If set, highlight this filter by default with this color
*/
mw.rcfilters.dm.ItemModel = function MwRcfiltersDmItemModel( param, config ) {
config = config || {};
this.description = config.description || '';
this.selected = !!config.selected;
- this.inverted = !!config.inverted;
this.identifiers = config.identifiers || [];
// Highlight
this.cssClass = config.cssClass;
- this.highlightColor = null;
- this.highlightEnabled = false;
+ this.highlightColor = config.defaultHighlightColor;
};
/* Initialization */
*/
mw.rcfilters.dm.ItemModel.prototype.getState = function () {
return {
- selected: this.isSelected(),
- inverted: this.isInverted()
+ selected: this.isSelected()
};
};
};
/**
- * Get a prefixed label
+ * Get the message key to use to wrap the label. This message takes the label as a parameter.
*
- * @return {string} Prefixed label
+ * @param {boolean} inverted Whether this item should be considered inverted
+ * @return {string|null} Message key, or null if no message
*/
- mw.rcfilters.dm.ItemModel.prototype.getPrefixedLabel = function () {
+ mw.rcfilters.dm.ItemModel.prototype.getLabelMessageKey = function ( inverted ) {
if ( this.labelPrefixKey ) {
if ( typeof this.labelPrefixKey === 'string' ) {
- return mw.message( this.labelPrefixKey, this.getLabel() ).parse();
- } else {
- return mw.message(
- this.labelPrefixKey[
- // Only use inverted-prefix if the item is selected
- // Highlight-only an inverted item makes no sense
- this.isInverted() && this.isSelected() ?
- 'inverted' : 'default'
- ],
- this.getLabel()
- ).parse();
+ return this.labelPrefixKey;
}
- } else {
- return this.getLabel();
+ return this.labelPrefixKey[
+ // Only use inverted-prefix if the item is selected
+ // Highlight-only an inverted item makes no sense
+ inverted && this.isSelected() ?
+ 'inverted' : 'default'
+ ];
}
+ return null;
};
/**
}
};
- /**
- * Get the inverted state of this item
- *
- * @return {boolean} Item is inverted
- */
- mw.rcfilters.dm.ItemModel.prototype.isInverted = function () {
- return this.inverted;
- };
-
- /**
- * Toggle the inverted state of the item
- *
- * @param {boolean} [isInverted] Item is inverted
- * @fires update
- */
- mw.rcfilters.dm.ItemModel.prototype.toggleInverted = function ( isInverted ) {
- isInverted = isInverted === undefined ? !this.inverted : isInverted;
-
- if ( this.inverted !== isInverted ) {
- this.inverted = isInverted;
- this.emit( 'update' );
- }
- };
-
/**
* Set the highlight color
*
* @param {string|null} highlightColor
*/
mw.rcfilters.dm.ItemModel.prototype.setHighlightColor = function ( highlightColor ) {
+ if ( !this.isHighlightSupported() ) {
+ return;
+ }
+
if ( this.highlightColor !== highlightColor ) {
this.highlightColor = highlightColor;
this.emit( 'update' );
return this.identifiers;
};
- /**
- * Toggle the highlight feature on and off for this filter.
- * It only works if highlight is supported for this filter.
- *
- * @param {boolean} enable Highlight should be enabled
- */
- mw.rcfilters.dm.ItemModel.prototype.toggleHighlight = function ( enable ) {
- enable = enable === undefined ? !this.highlightEnabled : enable;
-
- if ( !this.isHighlightSupported() ) {
- return;
- }
-
- if ( enable === this.highlightEnabled ) {
- return;
- }
-
- this.highlightEnabled = enable;
- this.emit( 'update' );
- };
-
- /**
- * Check if the highlight feature is currently enabled for this filter
- *
- * @return {boolean}
- */
- mw.rcfilters.dm.ItemModel.prototype.isHighlightEnabled = function () {
- return !!this.highlightEnabled;
- };
-
/**
* Check if the highlight feature is supported for this filter
*
* @return {boolean}
*/
mw.rcfilters.dm.ItemModel.prototype.isHighlighted = function () {
- return this.isHighlightEnabled() && !!this.getHighlightColor();
+ return !!this.getHighlightColor();
};
}( mediaWiki ) );