From e08847765a5010638df1d140e6c4fb437622c9b3 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Fri, 10 Mar 2017 17:37:02 -0800 Subject: [PATCH] RCFilters UI: Use data-feature-in-structured-ui in the frontend This allows us to remove a bunch of hacky code. Change-Id: I282cad16df10da801a991967f44f3c4a0c88a225 --- .../ui/mw.rcfilters.ui.FormWrapperWidget.js | 48 ++++--------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FormWrapperWidget.js b/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FormWrapperWidget.js index e914bbe7d9..d786025b8f 100644 --- a/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FormWrapperWidget.js +++ b/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FormWrapperWidget.js @@ -111,45 +111,17 @@ * Clean up the old-style show/hide that we have implemented in the filter list */ mw.rcfilters.ui.FormWrapperWidget.prototype.cleanUpFieldset = function () { - var widget = this; - - // HACK: Remove old-style filter links for filters handled by the widget - // Ideally the widget would handle all filters and we'd just remove .rcshowhide entirely - this.$element.find( '.rcshowhide' ).children().each( function () { - // HACK: Interpret the class name to get the filter name - // This should really be set as a data attribute - var i, - name = null, - // Some of the older browsers we support don't have .classList, - // so we have to interpret the class attribute manually. - classes = this.getAttribute( 'class' ).split( ' ' ); - for ( i = 0; i < classes.length; i++ ) { - if ( classes[ i ].substr( 0, 'rcshow'.length ) === 'rcshow' ) { - name = classes[ i ].substr( 'rcshow'.length ); - break; - } - } - if ( name === null ) { - return; - } - if ( name === 'hidemine' ) { - // HACK: the span for hidemyself is called hidemine - name = 'hidemyself'; - } - - // This span corresponds to a filter that's in our model, so remove it - if ( widget.filtersModel.getItemByName( name ) ) { - // HACK: Remove the text node after the span. - // If there isn't one, we're at the end, so remove the text node before the span. - // This would be unnecessary if we added separators with CSS. - if ( this.nextSibling && this.nextSibling.nodeType === Node.TEXT_NODE ) { - this.parentNode.removeChild( this.nextSibling ); - } else if ( this.previousSibling && this.previousSibling.nodeType === Node.TEXT_NODE ) { - this.parentNode.removeChild( this.previousSibling ); - } - // Remove the span itself - this.parentNode.removeChild( this ); + this.$element.find( '.rcshowhideoption[data-feature-in-structured-ui=1]' ).each( function () { + // HACK: Remove the text node after the span. + // If there isn't one, we're at the end, so remove the text node before the span. + // This would be unnecessary if we added separators with CSS. + if ( this.nextSibling && this.nextSibling.nodeType === Node.TEXT_NODE ) { + this.parentNode.removeChild( this.nextSibling ); + } else if ( this.previousSibling && this.previousSibling.nodeType === Node.TEXT_NODE ) { + this.parentNode.removeChild( this.previousSibling ); } + // Remove the span itself + this.parentNode.removeChild( this ); } ); }; }( mediaWiki ) ); -- 2.20.1