Merge "RCFilters: refactor highlight state"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / dm / mw.rcfilters.dm.ItemModel.js
index 9c56f09..d940321 100644 (file)
@@ -14,8 +14,6 @@
         *  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
@@ -38,7 +36,6 @@
                this.description = config.description || '';
                this.selected = !!config.selected;
 
-               this.inverted = !!config.inverted;
                this.identifiers = config.identifiers || [];
 
                // Highlight
@@ -69,8 +66,7 @@
         */
        mw.rcfilters.dm.ItemModel.prototype.getState = function () {
                return {
-                       selected: this.isSelected(),
-                       inverted: this.isInverted()
+                       selected: this.isSelected()
                };
        };
 
        /**
         * Get a prefixed label
         *
+        * @param {boolean} inverted This item should be considered inverted
         * @return {string} Prefixed label
         */
-       mw.rcfilters.dm.ItemModel.prototype.getPrefixedLabel = function () {
+       mw.rcfilters.dm.ItemModel.prototype.getPrefixedLabel = function ( inverted ) {
                if ( this.labelPrefixKey ) {
                        if ( typeof this.labelPrefixKey === 'string' ) {
                                return mw.message( this.labelPrefixKey, this.getLabel() ).parse();
@@ -97,7 +94,7 @@
                                        this.labelPrefixKey[
                                                // Only use inverted-prefix if the item is selected
                                                // Highlight-only an inverted item makes no sense
-                                               this.isInverted() && this.isSelected() ?
+                                               inverted && this.isSelected() ?
                                                        'inverted' : 'default'
                                        ],
                                        this.getLabel()
                }
        };
 
-       /**
-        * 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 ) );