rcfilters: Remove implemented filters from list of links
authorRoan Kattouw <roan.kattouw@gmail.com>
Tue, 24 Jan 2017 04:12:04 +0000 (15:12 +1100)
committerRoan Kattouw <roan.kattouw@gmail.com>
Tue, 24 Jan 2017 04:35:10 +0000 (15:35 +1100)
This is a bit hacky because the filter name needs to be inferred
from the class on each span, and because the separators aren't
wrapped.

Change-Id: Ib39ad435d3b48fa38533926e4ab49942c3bd5d6f

resources/Resources.php
resources/src/mediawiki.rcfilters/mw.rcfilters.init.js
resources/src/mediawiki.rcfilters/styles/mw.rcfilters.less [deleted file]

index bd7f68e..cd5e3b9 100644 (file)
@@ -1747,7 +1747,6 @@ return [
                        'resources/src/mediawiki.rcfilters/mw.rcfilters.init.js',
                ],
                'styles' => [
-                       'resources/src/mediawiki.rcfilters/styles/mw.rcfilters.less',
                        'resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.FilterItemWidget.less',
                        'resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.FilterGroupWidget.less',
                        'resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.FiltersListWidget.less',
index ce0fc8a..9f4ad48 100644 (file)
                        // Initialize values
                        controller.initialize();
 
+                       // 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
+                       $( '.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 ( model.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 );
+                               }
+                       } );
+
                        $( '.rcoptions form' ).submit( function () {
                                var $form = $( this );
 
diff --git a/resources/src/mediawiki.rcfilters/styles/mw.rcfilters.less b/resources/src/mediawiki.rcfilters/styles/mw.rcfilters.less
deleted file mode 100644 (file)
index 7f71c0c..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-.rcshowhidemine {
-       // HACK: Hide this filter since it already appears in
-       // the new filter drop-down.
-       display: none;
-}