MediaWiki:Timeless.js: Difference between revisions
From Exuvia Wiki
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
=============================================================================== | =============================================================================== | ||
The sidebar contains | The sidebar contains: | ||
Locations | Locations | ||
| Line 11: | Line 11: | ||
World Building | World Building | ||
JavaScript turns selected entries into expandable menus. | |||
The top-level entries DO NOT need to be real wiki pages. | |||
=============================================================================== | =============================================================================== | ||
| Line 24: | Line 22: | ||
/* | /* | ||
=========================================================================== | =========================================================================== | ||
DROPDOWN | DROPDOWN MENUS | ||
=========================================================================== | =========================================================================== | ||
The name on the left must exactly match the text in MediaWiki:Sidebar. | |||
The names inside [ ] are the wiki pages that appear when the menu opens. | |||
=========================================================================== | =========================================================================== | ||
| Line 52: | Line 34: | ||
var menus = { | var menus = { | ||
Locations: [ | 'Locations': [ | ||
'Continents', | 'Continents', | ||
'Kingdoms', | 'Kingdoms', | ||
'Towns' | 'Towns' | ||
] | ], | ||
'Religions': [ | |||
'The Valor', | 'The Valor', | ||
'The Brumal' | 'The Brumal' | ||
], | ], | ||
People: [ | 'People': [ | ||
'High Lord Kip', | 'High Lord Kip', | ||
'Queen Melena' | 'Queen Melena' | ||
| Line 78: | Line 55: | ||
'War' | 'War' | ||
] | ] | ||
}; | }; | ||
| Line 85: | Line 61: | ||
/* | /* | ||
=========================================================================== | =========================================================================== | ||
FIND THE | FIND THE TIMeless SIDEBAR | ||
=========================================================================== | =========================================================================== | ||
*/ | */ | ||
| Line 98: | Line 74: | ||
/* | /* | ||
=========================================================================== | =========================================================================== | ||
FIND EVERY SIDEBAR LINK | |||
=========================================================================== | =========================================================================== | ||
*/ | */ | ||
sidebar.find( 'a' ).each( function () { | |||
var link = $( this ); | |||
/* | /* | ||
Get only the visible text. | |||
trim() removes extra spaces. | |||
*/ | */ | ||
var | var name = $.trim( link.clone().children().remove().end().text() ); | ||
/* | /* | ||
Check whether this sidebar item is one of our dropdowns. | |||
*/ | */ | ||
if ( ! | if ( !Object.prototype.hasOwnProperty.call( menus, name ) ) { | ||
return; | return; | ||
} | } | ||
| Line 123: | Line 101: | ||
/* | /* | ||
======================================================================= | |||
FIND THE CONTAINER | |||
======================================================================= | |||
*/ | */ | ||
var parent = | var parent = link.closest( 'li' ); | ||
/* | /* | ||
======================================================================= | |||
CREATE THE DROPDOWN | |||
======================================================================= | |||
*/ | */ | ||
| Line 138: | Line 120: | ||
/* | /* | ||
======================================================================= | |||
CREATE EACH LINK | |||
======================================================================= | |||
*/ | */ | ||
menus[ | menus[ name ].forEach( function ( page ) { | ||
var | var childLink = $( '<a>' ) | ||
.attr( 'href', mw.util.getUrl( | .attr( 'href', mw.util.getUrl( page ) ) | ||
.text( | .text( page ); | ||
var | var childItem = $( '<li>' ) | ||
.append( | .append( childLink ); | ||
dropdown.append( | dropdown.append( childItem ); | ||
} ); | } ); | ||
| Line 156: | Line 140: | ||
/* | /* | ||
======================================================================= | |||
ADD DROPDOWN TO SIDEBAR | |||
======================================================================= | |||
*/ | */ | ||
| Line 163: | Line 149: | ||
/* | /* | ||
Start closed. | |||
*/ | */ | ||
| Line 170: | Line 156: | ||
/* | /* | ||
======================================================================= | |||
MAKE THE TITLE A DROPDOWN BUTTON | |||
======================================================================= | |||
*/ | */ | ||
link.on( 'click', function ( event ) { | |||
event.preventDefault(); | event.preventDefault(); | ||
| Line 181: | Line 167: | ||
dropdown.stop( true, true ).slideToggle( 150 ); | dropdown.stop( true, true ).slideToggle( 150 ); | ||
} ); | }); | ||
/* | /* | ||
======================================================================= | |||
ADD ARROW | |||
======================================================================= | |||
*/ | */ | ||
link.append( | |||
$( '<span>' ) | $( '<span>' ) | ||
.addClass( 'exuvia-dropdown-arrow' ) | .addClass( 'exuvia-dropdown-arrow' ) | ||
| Line 194: | Line 182: | ||
); | ); | ||
} ); | }); | ||
} ); | }); | ||
Revision as of 01:52, 26 August 2026
/*
===============================================================================
EXUVIA WIKI SIDEBAR DROPDOWNS
===============================================================================
The sidebar contains:
Locations
Religions
People
World Building
JavaScript turns selected entries into expandable menus.
The top-level entries DO NOT need to be real wiki pages.
===============================================================================
*/
$( function () {
/*
===========================================================================
DROPDOWN MENUS
===========================================================================
The name on the left must exactly match the text in MediaWiki:Sidebar.
The names inside [ ] are the wiki pages that appear when the menu opens.
===========================================================================
*/
var menus = {
'Locations': [
'Continents',
'Kingdoms',
'Towns'
],
'Religions': [
'The Valor',
'The Brumal'
],
'People': [
'High Lord Kip',
'Queen Melena'
],
'World Building': [
'History',
'Magic',
'War'
]
};
/*
===========================================================================
FIND THE TIMeless SIDEBAR
===========================================================================
*/
var sidebar = $( '#mw-site-navigation' );
if ( !sidebar.length ) {
return;
}
/*
===========================================================================
FIND EVERY SIDEBAR LINK
===========================================================================
*/
sidebar.find( 'a' ).each( function () {
var link = $( this );
/*
Get only the visible text.
trim() removes extra spaces.
*/
var name = $.trim( link.clone().children().remove().end().text() );
/*
Check whether this sidebar item is one of our dropdowns.
*/
if ( !Object.prototype.hasOwnProperty.call( menus, name ) ) {
return;
}
/*
=======================================================================
FIND THE CONTAINER
=======================================================================
*/
var parent = link.closest( 'li' );
/*
=======================================================================
CREATE THE DROPDOWN
=======================================================================
*/
var dropdown = $( '<ul>' )
.addClass( 'exuvia-dropdown-menu' );
/*
=======================================================================
CREATE EACH LINK
=======================================================================
*/
menus[ name ].forEach( function ( page ) {
var childLink = $( '<a>' )
.attr( 'href', mw.util.getUrl( page ) )
.text( page );
var childItem = $( '<li>' )
.append( childLink );
dropdown.append( childItem );
} );
/*
=======================================================================
ADD DROPDOWN TO SIDEBAR
=======================================================================
*/
parent.append( dropdown );
/*
Start closed.
*/
dropdown.hide();
/*
=======================================================================
MAKE THE TITLE A DROPDOWN BUTTON
=======================================================================
*/
link.on( 'click', function ( event ) {
event.preventDefault();
dropdown.stop( true, true ).slideToggle( 150 );
});
/*
=======================================================================
ADD ARROW
=======================================================================
*/
link.append(
$( '<span>' )
.addClass( 'exuvia-dropdown-arrow' )
.text( ' ▼' )
);
});
});