From: Moriel Schottlender Date: Thu, 1 Jun 2017 15:36:53 +0000 (+0300) Subject: Make sure URI comparisons include highlight states X-Git-Tag: 1.31.0-rc.0~3065^2 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=4bd3e749ffbf0059d66cd83f118d301296ff16b4;p=lhc%2Fweb%2Fwiklou.git Make sure URI comparisons include highlight states When we compare URI states to see whether it is different, we have to also take into account highlight states and the highlight toggle. Change-Id: Ic6bdd8b7d27280b028f6a40879de0dbeb2850dbd --- diff --git a/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FiltersViewModel.js b/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FiltersViewModel.js index 402dbf928c..3c2f8d7f67 100644 --- a/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FiltersViewModel.js +++ b/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FiltersViewModel.js @@ -505,7 +505,7 @@ /** * Get the highlight parameters based on current filter configuration * - * @return {object} Object where keys are "_color" and values + * @return {Object} Object where keys are "_color" and values * are the selected highlight colors. */ mw.rcfilters.dm.FiltersViewModel.prototype.getHighlightParameters = function () { @@ -519,6 +519,30 @@ 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 "_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; + }; + /** * Sanitize value group of a string_option groups type * Remove duplicates and make sure to only use valid diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js index e1694f69f7..b7b46f6748 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js @@ -619,6 +619,7 @@ */ mw.rcfilters.Controller.prototype._updateURL = function ( params ) { var currentFilterState, updatedFilterState, updatedUri, + uri = new mw.Uri(), notEquivalent = function ( obj1, obj2 ) { var keys = Object.keys( obj1 ).concat( Object.keys( obj2 ) ); return keys.some( function ( key ) { @@ -635,9 +636,21 @@ // This will allow us to always have a proper check of whether // the requested new url is one to change or not, regardless of // actual parameter visibility/representation in the URL - currentFilterState = this.filtersModel.getFiltersFromParameters( new mw.Uri().query ); + currentFilterState = this.filtersModel.getFiltersFromParameters( uri.query ); updatedFilterState = this.filtersModel.getFiltersFromParameters( updatedUri.query ); + // Include highlight states + $.extend( true, + currentFilterState, + this.filtersModel.extractHighlightValues( uri.query ), + { highlight: !!Number( uri.query.highlight ) } + ); + $.extend( true, + updatedFilterState, + this.filtersModel.extractHighlightValues( updatedUri.query ), + { highlight: !!Number( updatedUri.query.highlight ) } + ); + if ( notEquivalent( currentFilterState, updatedFilterState ) ) { if ( this.initializing ) { // Initially, when we just build the first page load