jenkins-bot has submitted this change and it was merged.
Change subject: made the footer cleanup script suck less
......................................................................
made the footer cleanup script suck less
Rewrote it to make it a little more readable and discovered a couple
of bugs in the process.
Fixes:
* The list slid up on initial collapsing and just toggled on click.
This was clearly backwards; now it acts the other way.
* The function silently failed when invalid arguments were passed.
Now it throws instead.
* The footerCollapsibleList function accepted a <ul> as its argument
and then thrashed about, adding and removing elements within its
container. Now it accepts the container itself.
Change-Id: I4ceea2242a977379ca724b8a4fee6f3d2bc0fd24
---
M modules/ext.vector.footerCleanup.js
M modules/jquery.footerCollapsibleList.js
2 files changed, 36 insertions(+), 38 deletions(-)
Approvals:
Ori.livneh: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ext.vector.footerCleanup.js
b/modules/ext.vector.footerCleanup.js
index 7c4b689..6db5eeb 100644
--- a/modules/ext.vector.footerCleanup.js
+++ b/modules/ext.vector.footerCleanup.js
@@ -17,13 +17,13 @@
// Waiting until dom ready as the module is loaded in the head.
$( document ).ready( function () {
// Make "Templates used" a collapsible list.
- $( '.templatesUsed ul' ).footerCollapsibleList( {
+ $( '.templatesUsed' ).footerCollapsibleList( {
name: 'templates-used-list',
title: mw.msg( 'vector-footercleanup-templates' )
} );
// Make "Hidden categories" a collapsible list.
- $( '.hiddencats ul' ).footerCollapsibleList( {
+ $( '.hiddencats' ).footerCollapsibleList( {
name: 'hidden-categories-list',
title: mw.msg( 'vector-footercleanup-categories' )
} );
diff --git a/modules/jquery.footerCollapsibleList.js
b/modules/jquery.footerCollapsibleList.js
index 2915ce2..7b9b5bc 100644
--- a/modules/jquery.footerCollapsibleList.js
+++ b/modules/jquery.footerCollapsibleList.js
@@ -2,45 +2,43 @@
// Small jQuery plugin to handle the toggle function & cookie for state
// For collapsible items in the footer
$.fn.footerCollapsibleList = function( config ) {
- if (
- ! ( 'title' in config ) ||
- ! ( 'name' in config )
- ) {
+ if ( !( 'title' in config ) || !( 'name' in config ) ) {
return;
}
+
return this.each( function () {
- // Setup
- $( this )
- .parent()
- .prepend(
- $( '<a>' )
- .addClass(
'collapsible-list' )
- .text( config.title )
- .on( 'click', function(
e ) {
-
e.preventDefault();
- // Modify state
cookie.
- var state = (
$.cookie( config.name ) !== 'expanded' ) ?
-
'expanded' : 'collapsed';
- $.cookie(
config.name, state );
- // Modify DOM.
- $( this
).next().toggle();
- $( this ).find(
'span' ).toggleClass( 'collapsed' );
- } )
- .append( $( '<span>' ) )
- )
- .end()
- .prev()
- .remove();
- // Check cookie and collapse.
- if(
- $.cookie( config.name ) === null ||
- $.cookie( config.name ) === 'collapsed'
- ) {
- $( this )
- .slideUp()
- .prev()
- .find( 'span'
).addClass( 'collapsed' );
- }
+ var $container, $ul, $explanation, $icon;
+
+ $container = $( this );
+ $ul = $container.find( 'ul' );
+ $explanation = $container.find(
'.mw-templatesUsedExplanation, .mw-hiddenCategoriesExplanation' );
+
+ $icon = $( '<span>' );
+ $ul.before(
+ $( '<a>' )
+ .addClass( 'collapsible-list' )
+ .text( config.title )
+ .append( $icon )
+ .on( 'click', function( e ) {
+ // Modify state cookie.
+ var state = ( $.cookie(
config.name ) !== 'expanded' ) ? 'expanded' : 'collapsed';
+ $.cookie( config.name, state );
+
+ // Modify DOM.
+ $ul.slideToggle();
+ $icon.toggleClass( 'collapsed'
);
+
+ e.preventDefault();
+ } )
+ );
+
+ $explanation.remove();
+
+ // Check cookie and collapse.
+ if( $.cookie( config.name ) === null || $.cookie(
config.name ) === 'collapsed' ) {
+ $ul.hide();
+ $icon.addClass( 'collapsed' );
+ }
} );
};
}( jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/48033
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4ceea2242a977379ca724b8a4fee6f3d2bc0fd24
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Vector
Gerrit-Branch: master
Gerrit-Owner: Matmarex <[email protected]>
Gerrit-Reviewer: Matmarex <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits