From Brotato Wiki
(well im a div, I was using an ES6 template literal string (ie. backticks ``) đ¤Śââď¸) |
(StatsCardsToggles (WIP)) |
||
Line 12: | Line 12: | ||
// ============================================================================ | // ============================================================================ | ||
initCardTabs(); | initCardTabs(); // Template:StatsCardWeaponTabs | ||
initStatsCardsToggles(); // Allows hiding StatsCard (.ibox) elements, via toggle buttons (WIP) | |||
Line 75: | Line 76: | ||
}); | }); | ||
}//end:initCardTabs | }//end:initCardTabs | ||
/** | |||
* Toggle a StatsCard box (.ibox). Template for the toggle buttons is WIP | |||
* | |||
* @return {void} | |||
*/ | |||
function initStatsCardsToggles() | |||
{ | |||
$( '[data-hide-type]' ).on( 'click', function( ev ) | |||
{ | |||
var $btn   = $( ev.currentTarget ); | |||
var filterStr = $btn.attr( 'data-hide-target' ); // eg "rarity3" | |||
var $targets = $( '[data-ibox-type="item"].' + filterStr ); | |||
$targets.each( ( i, el ) => | |||
{ | |||
var $target = $( el ); | |||
var isHidden = $target.hasClass( 'ibox--hidden' ); | |||
// @todo: Use just the class for this, instead of JS-injected CSS | |||
// (then just use .toggleClass) | |||
if ( isHidden ) | |||
{ | |||
$target.removeClass( 'ibox--hidden' ); | |||
$targets.css( { opacity: 1 } ); | |||
} | |||
else | |||
{ | |||
$target.addClass( 'ibox--hidden' ); | |||
$targets.css( { opacity: 0.2 } ); | |||
} | |||
}); | |||
}); | |||
}//end:initStatsCardsToggles | |||
}); // end:$(document).ready | }); // end:$(document).ready |
Revision as of 02:17, 14 December 2022
/* Any JavaScript here will be loaded for all users on every page load. */
/*
WARNING: ES5 ONLY!
*/
$(document).ready( function()
{
// Inits
// ============================================================================
initCardTabs(); // Template:StatsCardWeaponTabs
initStatsCardsToggles(); // Allows hiding StatsCard (.ibox) elements, via toggle buttons (WIP)
// Funcs
// ============================================================================
/**
* Sets up tabs. Used by the StatsCardWeaponTabs template
*
* @link https://brotato.wiki.spellsandguns.com/Template:StatsCardWeaponTabs
* @link https://brotato.wiki.spellsandguns.com/MediaWiki:Common.css
*
* @return {void}
*/
function initCardTabs()
{
var $containers = $( '[data-cardtabs]' );
if ( !$containers.length )
{
return;
}
// Loop over every container
$containers.each( function( i1, containerEl )
{
var $tabs = $( containerEl );
// We use the extra step of targetting containers here, instead of
// just using `.find`, because this lets us support nesteds tabs!
var $panelsContainer = $tabs.children( '[data-cardtabs-panels]' );
var $btnsContainer = $tabs.children( '[data-cardtabs-btns]' );
var $panels = $panelsContainer.children( '[data-cardtabs-panel]' );
var $btns = $btnsContainer.children( '[data-cardtabs-btn]' );
// Loop over buttons and set up their onclicks
$btns.each( function( i2, btnEl )
{
var $btn = $( btnEl );
var btnNum = $btn.attr( 'data-cardtabs-btn' );
var $panel = $panels.filter( '[data-cardtabs-panel="' + btnNum + '"]' );
var btnActiveCls = 'cardtabs__button--active';
var panelHideCls = 'cardtabs__panel--js-hidden';
// Disabled buttons use "-1" for their numbers
if ( btnNum === '-1' )
{
return;
}
$btn.on( 'click', function()
{
// Hide all other panels, then show the button's own panel
$panels.addClass( panelHideCls );
$panel.removeClass( panelHideCls );
$btns.removeClass( btnActiveCls );
$btn.addClass( btnActiveCls );
});
});
});
}//end:initCardTabs
/**
* Toggle a StatsCard box (.ibox). Template for the toggle buttons is WIP
*
* @return {void}
*/
function initStatsCardsToggles()
{
$( '[data-hide-type]' ).on( 'click', function( ev )
{
var $btn = $( ev.currentTarget );
var filterStr = $btn.attr( 'data-hide-target' ); // eg "rarity3"
var $targets = $( '[data-ibox-type="item"].' + filterStr );
$targets.each( ( i, el ) =>
{
var $target = $( el );
var isHidden = $target.hasClass( 'ibox--hidden' );
// @todo: Use just the class for this, instead of JS-injected CSS
// (then just use .toggleClass)
if ( isHidden )
{
$target.removeClass( 'ibox--hidden' );
$targets.css( { opacity: 1 } );
}
else
{
$target.addClass( 'ibox--hidden' );
$targets.css( { opacity: 0.2 } );
}
});
});
}//end:initStatsCardsToggles
}); // end:$(document).ready