From Dark and Darker Wiki

(Added Graph Data)
 
(testing)
 
(34 intermediate revisions by 3 users not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */


var ItemEquipSpeedGraph = {
    x: [0.0, 15.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, 64.0, 65.0, 67.0, 68.0, 70.0, 71.0, 73.0, 74.0, 76.0, 77.0, 79.0, 80.0, 82.0, 83.0, 85.0, 86.0, 88.0, 89.0, 91.0, 92.0, 94.0, 95.0, 97.0, 98.0, 100.0, 0.0, 8.0, 10.0, 13.0, 18.0, 20.0, 21.0, 25.0, 26.0, 34.0, 38.0, 41.0, 42.0, 46.0, 47.0, 49.0, 50.0, 54.0, 55.0, 60.0, 70.0, 71.0, 82.0, 95.0, 96.0, 100.0, 0.0, 1.0, 2.0, 3.0, 8.0, 9.0, 11.0, 12.0, 14.0, 15.0, 17.0, 19.0, 22.0, 23.0, 27.0, 32.0, 35.0, 38.0, 39.0, 44.0, 50.0, 51.0, 56.0, 63.0, 64.0, 69.0, 70.0, 81.0, 82.0, 93.0, 100.0],
    y: [-30.0, 0.0, 30.0, 30.0, 31.0, 31.0, 32.0, 32.0, 33.0, 33.0, 34.0, 34.0, 35.0, 35.0, 36.0, 36.0, 37.0, 37.0, 38.0, 38.0, 39.0, 39.0, 40.0, 40.0, 41.0, 41.0, 42.0, 42.0, 43.0, 43.0, 44.0, 44.0, 45.0, 45.0, 46.0, 46.0, 47.0, 47.0, 48.0, 48.0, 49.0, 49.0, 50.0, 50.0, 51.0, 51.0, -0.38, -0.14, -0.08, -0.02, 0.03, 0.05, 0.06, 0.1, 0.115, 0.235, 0.295, 0.34, 0.35, 0.39, 0.4, 0.42, 0.43, 0.45, 0.455, 0.48, 0.53, 0.535, 0.59, 0.655, 0.66, 0.68, -0.95, -0.95, -0.91, -0.84, -0.49, -0.42, -0.28, -0.21, -0.07, 0.0, 0.1, 0.2, 0.35, 0.4, 0.6, 0.85, 1.0, 1.06, 1.08, 1.18, 1.3, 1.32, 1.42, 1.56, 1.58, 1.68, 1.7, 1.81, 1.82, 1.93, 2.0],
    type: 'scatter'
};


var data = [ItemEquipSpeedGraph];
/*
WARNING: ES5 ONLY!
*/


Plotly.newPlot('ItemEquipSpeedGraph', data);


$(document).ready( function()
{
// Inits
// ============================================================================


var PhysicalReductionGraph = {
initCardTabs(); // Template:StatsCardWeaponTabs
    x: [-300.0, -278.0, -253.0, -228.0, -197.0, -184.0, -183.0, -172.0, -159.0, -158.0, -147.0, -134.0, -133.0, -122.0, -109.0, -108.0, -100.0, -99.0, -94.0, -87.0, -86.0, -81.0, -75.0, -74.0, -69.0, -62.0, -61.0, -56.0, -49.0, -48.0, -42.0, -36.0, -30.0, -25.0, -20.0, -19.0, -17.0, -16.0, -15.0, -14.0, -13.0, -11.0, -10.0, -1.0, 1.0, 4.0, 5.0, 8.0, 10.0, 14.0, 15.0, 16.0, 19.0, 20.0, 23.0, 30.0, 33.0, 34.0, 39.0, 40.0, 41.0, 42.0, 48.0, 50.0, 54.0, 61.0, 69.0, 70.0, 76.0, 77.0, 83.0, 84.0, 91.0, 98.0, 100.0, 102.0, 106.0, 107.0, 110.0, 117.0, 121.0, 122.0, 124.0, 128.0, 129.0, 130.0, 137.0, 145.0, 146.0, 150.0, 152.0, 153.0, 155.0, 156.0, 158.0, 159.0, 162.0, 169.0, 170.0, 172.0, 173.0, 175.0, 176.0, 179.0, 185.0, 189.0, 190.0, 192.0, 193.0, 196.0, 202.0, 206.0, 207.0, 209.0, 210.0, 213.0, 219.0, 220.0, 226.0, 232.0, 237.0, 243.0, 249.0, 250.0, 251.0, 252.0, 257.0, 260.0, 262.0, 265.0, 266.0, 271.0, 274.0, 276.0, 279.0, 280.0, 285.0, 288.0, 289.0, 294.0, 297.0, 299.0, 302.0, 303.0, 308.0, 311.0, 313.0, 316.0, 317.0, 322.0, 325.0, 327.0, 330.0, 331.0, 334.0, 336.0, 339.0, 340.0, 345.0, 348.0, 350.0, 351.0, 354.0, 359.0, 364.0, 368.0, 369.0, 373.0, 374.0, 378.0, 379.0, 382.0, 387.0, 392.0, 396.0, 397.0, 401.0, 402.0, 405.0, 410.0, 415.0, 419.0, 420.0, 424.0, 425.0, 429.0, 430.0, 433.0, 438.0, 442.0, 443.0, 447.0, 448.0, 452.0, 453.0, 456.0, 461.0, 466.0, 470.0, 471.0, 475.0, 476.0, 479.0, 484.0, 489.0, 493.0, 494.0, 498.0, 499.0, 500.0],
initStatsCardsToggles(); // Allows hiding StatsCard (.ibox) elements, via toggle buttons (WIP)
    y: [-5.95, -5.51, -5.01, -4.51, -3.89, -3.63, -3.61, -3.39, -3.13, -3.11, -2.89, -2.63, -2.61, -2.39, -2.13, -2.11, -1.95, -1.93, -1.83, -1.69, -1.67, -1.57, -1.45, -1.43, -1.33, -1.19, -1.17, -1.07, -0.93, -0.91, -0.79, -0.67, -0.55, -0.45, -0.35, -0.33, -0.29, -0.27, -0.25, -0.24, -0.23, -0.21, -0.2, -0.11, -0.09, -0.06, -0.05, -0.02, 0.0, 0.02, 0.025, 0.03, 0.045, 0.049, 0.061, 0.089, 0.098, 0.101, 0.116, 0.119, 0.121, 0.123, 0.135, 0.139, 0.143, 0.15, 0.158, 0.159, 0.165, 0.166, 0.172, 0.173, 0.18, 0.187, 0.189, 0.193, 0.201, 0.203, 0.209, 0.223, 0.231, 0.233, 0.237, 0.245, 0.247, 0.249, 0.263, 0.279, 0.281, 0.289, 0.295, 0.298, 0.304, 0.307, 0.313, 0.316, 0.325, 0.346, 0.349, 0.355, 0.358, 0.364, 0.367, 0.376, 0.394, 0.406, 0.409, 0.415, 0.418, 0.427, 0.445, 0.457, 0.46, 0.466, 0.469, 0.478, 0.496, 0.499, 0.517, 0.535, 0.55, 0.568, 0.586, 0.589, 0.591, 0.593, 0.603, 0.609, 0.613, 0.619, 0.621, 0.631, 0.637, 0.641, 0.647, 0.649, 0.659, 0.665, 0.667, 0.677, 0.683, 0.687, 0.693, 0.695, 0.705, 0.711, 0.715, 0.721, 0.723, 0.733, 0.739, 0.743, 0.749, 0.751, 0.757, 0.761, 0.767, 0.769, 0.779, 0.785, 0.789, 0.79, 0.793, 0.798, 0.803, 0.807, 0.808, 0.812, 0.813, 0.817, 0.818, 0.821, 0.826, 0.831, 0.835, 0.836, 0.84, 0.841, 0.844, 0.849, 0.854, 0.858, 0.859, 0.863, 0.864, 0.868, 0.869, 0.872, 0.877, 0.881, 0.882, 0.886, 0.887, 0.891, 0.892, 0.895, 0.9, 0.905, 0.909, 0.91, 0.914, 0.915, 0.918, 0.923, 0.928, 0.932, 0.933, 0.937, 0.938, 0.939],
initStatsCardsMiscToggles(); // Toggles for misc (costs/tags)
    type: 'scatter'
};


var data = [PhysicalReductionGraph];


Plotly.newPlot('PhysicalReductionGraph', data);
// 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]' );


var SpellCapacityGraph = {
if ( !$containers.length )
    x: [0.0, 1.0, 9.0, 13.0, 17.0, 19.0, 21.0, 22.0, 24.0, 27.0, 28.0, 30.0, 33.0, 36.0, 37.0, 40.0, 42.0, 48.0, 53.0, 54.0, 59.0, 65.0, 66.0, 71.0, 78.0, 79.0, 84.0, 90.0, 91.0, 96.0, 100.0, 0.0, 2.0, 7.0, 8.0, 12.0, 14.0, 15.0, 18.0, 21.0, 25.0, 28.0, 32.0, 33.0, 34.0, 35.0, 40.0, 41.0, 46.0, 53.0, 54.0, 59.0, 65.0, 66.0, 71.0, 81.0, 82.0, 84.0, 85.0, 86.0, 93.0, 100.0, 0.0, 100.0],
{
    y: [-0.95, -0.95, -0.55, -0.35, -0.15, -0.05, 0.05, 0.1, 0.2, 0.35, 0.4, 0.5, 0.59, 0.68, 0.71, 0.8, 0.84, 0.96, 1.06, 1.08, 1.18, 1.3, 1.32, 1.42, 1.56, 1.58, 1.68, 1.8, 1.82, 1.92, 2.0, -0.75, -0.65, -0.4, -0.35, -0.15, -0.05, 0.0, 0.21, 0.42, 0.7, 0.85, 1.05, 1.1, 1.15, 1.2, 1.3, 1.32, 1.42, 1.56, 1.58, 1.68, 1.8, 1.82, 1.92, 2.12, 2.14, 2.18, 2.19, 2.22, 2.36, 2.5, 0.0, 100.0],
return;
    type: 'scatter'
}
};


var data = [SpellCapacityGraph];
// Loop over every container
$containers.each( function( i1, containerEl )
{
var $tabs = $( containerEl );


Plotly.newPlot('SpellCapacityGraph', data);
// 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';


var MagicalDamageModGraph = {
// Disabled buttons use "-1" for their numbers
    x: [0.0, 1.0, 2.0, 3.0, 5.0, 7.0, 8.0, 12.0, 14.0, 15.0, 17.0, 18.0, 19.0, 21.0, 22.0, 23.0, 25.0, 30.0, 31.0, 33.0, 34.0, 39.0, 40.0, 45.0, 46.0, 50.0, 53.0, 66.0, 67.0, 78.0, 91.0, 92.0, 100.0],
if ( btnNum === '-1' )
    y: [-0.9, -0.9, -0.8, -0.7, -0.5, -0.4, -0.35, -0.15, -0.05, 0.0, 0.06, 0.09, 0.12, 0.18, 0.21, 0.24, 0.3, 0.4, 0.42, 0.46, 0.48, 0.58, 0.6, 0.65, 0.66, 0.7, 0.715, 0.78, 0.785, 0.84, 0.905, 0.91, 0.95],
{
    type: 'scatter'
return;
};
}


var data = [MagicalDamageModGraph];
$btn.on( 'click', function()
{
// Hide all other panels, then show the button's own panel
$panels.addClass( panelHideCls );
$panel.removeClass( panelHideCls );


Plotly.newPlot('MagicalDamageModGraph', data);
$btns.removeClass( btnActiveCls );
$btn.addClass( btnActiveCls );
});
});
});


// Tier toggles
// ---------------------------------------------------------------------


var MagicalReductionGraph = {
// Example:
    x: [-300.0, -278.0, -253.0, -228.0, -197.0, -184.0, -183.0, -172.0, -159.0, -158.0, -147.0, -134.0, -133.0, -122.0, -109.0, -108.0, -100.0, -99.0, -94.0, -87.0, -86.0, -81.0, -75.0, -74.0, -69.0, -62.0, -61.0, -56.0, -49.0, -48.0, -42.0, -36.0, -30.0, -25.0, -20.0, -19.0, -17.0, -16.0, -15.0, -14.0, -13.0, -11.0, -10.0, -1.0, 1.0, 4.0, 5.0, 8.0, 10.0, 14.0, 15.0, 16.0, 19.0, 20.0, 23.0, 30.0, 33.0, 34.0, 39.0, 40.0, 41.0, 42.0, 48.0, 50.0, 54.0, 61.0, 69.0, 70.0, 76.0, 77.0, 83.0, 84.0, 91.0, 98.0, 100.0, 102.0, 106.0, 107.0, 110.0, 117.0, 121.0, 122.0, 124.0, 128.0, 129.0, 130.0, 137.0, 145.0, 146.0, 150.0, 152.0, 153.0, 155.0, 156.0, 158.0, 159.0, 162.0, 169.0, 170.0, 172.0, 173.0, 175.0, 176.0, 179.0, 185.0, 189.0, 190.0, 192.0, 193.0, 196.0, 202.0, 206.0, 207.0, 209.0, 210.0, 213.0, 219.0, 220.0, 226.0, 232.0, 237.0, 243.0, 249.0, 250.0, 251.0, 252.0, 257.0, 260.0, 262.0, 265.0, 266.0, 271.0, 274.0, 276.0, 279.0, 280.0, 285.0, 288.0, 289.0, 294.0, 297.0, 299.0, 302.0, 303.0, 308.0, 311.0, 313.0, 316.0, 317.0, 322.0, 325.0, 327.0, 330.0, 331.0, 334.0, 336.0, 339.0, 340.0, 345.0, 348.0, 350.0, 351.0, 354.0, 359.0, 364.0, 368.0, 369.0, 373.0, 374.0, 378.0, 379.0, 382.0, 387.0, 392.0, 396.0, 397.0, 401.0, 402.0, 405.0, 410.0, 415.0, 419.0, 420.0, 424.0, 425.0, 429.0, 430.0, 433.0, 438.0, 442.0, 443.0, 447.0, 448.0, 452.0, 453.0, 456.0, 461.0, 466.0, 470.0, 471.0, 475.0, 476.0, 479.0, 484.0, 489.0, 493.0, 494.0, 498.0, 499.0, 500.0],
// <span class="btn btn--active" data-weapon-toggle="1">Tier 1</span>
    y: [-5.95, -5.51, -5.01, -4.51, -3.89, -3.63, -3.61, -3.39, -3.13, -3.11, -2.89, -2.63, -2.61, -2.39, -2.13, -2.11, -1.95, -1.93, -1.83, -1.69, -1.67, -1.57, -1.45, -1.43, -1.33, -1.19, -1.17, -1.07, -0.93, -0.91, -0.79, -0.67, -0.55, -0.45, -0.35, -0.33, -0.29, -0.27, -0.25, -0.24, -0.23, -0.21, -0.2, -0.11, -0.09, -0.06, -0.05, -0.02, 0.0, 0.02, 0.025, 0.03, 0.045, 0.049, 0.061, 0.089, 0.098, 0.101, 0.116, 0.119, 0.121, 0.123, 0.135, 0.139, 0.143, 0.15, 0.158, 0.159, 0.165, 0.166, 0.172, 0.173, 0.18, 0.187, 0.189, 0.193, 0.201, 0.203, 0.209, 0.223, 0.231, 0.233, 0.237, 0.245, 0.247, 0.249, 0.263, 0.279, 0.281, 0.289, 0.295, 0.298, 0.304, 0.307, 0.313, 0.316, 0.325, 0.346, 0.349, 0.355, 0.358, 0.364, 0.367, 0.376, 0.394, 0.406, 0.409, 0.415, 0.418, 0.427, 0.445, 0.457, 0.46, 0.466, 0.469, 0.478, 0.496, 0.499, 0.517, 0.535, 0.55, 0.568, 0.586, 0.589, 0.591, 0.593, 0.603, 0.609, 0.613, 0.619, 0.621, 0.631, 0.637, 0.641, 0.647, 0.649, 0.659, 0.665, 0.667, 0.677, 0.683, 0.687, 0.693, 0.695, 0.705, 0.711, 0.715, 0.721, 0.723, 0.733, 0.739, 0.743, 0.749, 0.751, 0.757, 0.761, 0.767, 0.769, 0.779, 0.785, 0.789, 0.79, 0.793, 0.798, 0.803, 0.807, 0.808, 0.812, 0.813, 0.817, 0.818, 0.821, 0.826, 0.831, 0.835, 0.836, 0.84, 0.841, 0.844, 0.849, 0.854, 0.858, 0.859, 0.863, 0.864, 0.868, 0.869, 0.872, 0.877, 0.881, 0.882, 0.886, 0.887, 0.891, 0.892, 0.895, 0.9, 0.905, 0.909, 0.91, 0.914, 0.915, 0.918, 0.923, 0.928, 0.932, 0.933, 0.937, 0.938, 0.939],
// <span class="btn btn--inactive" data-weapon-toggle="2">Tier 2</span>
    type: 'scatter'
// <span class="btn btn--inactive" data-weapon-toggle="3">Tier 3</span>
};
// <span class="btn btn--inactive" data-weapon-toggle="4">Tier 4</span>


var data = [MagicalReductionGraph];
var $tierToggles = $( '[data-weapon-toggle]' );


Plotly.newPlot('MagicalReductionGraph', data);
$tierToggles.each( function( i1, el )
{
var $toggle = $( el );
var tierNum = $toggle.attr( 'data-weapon-toggle' );


$toggle.on( 'click', function( ev, el )
{
$tierToggles.not( $toggle ).addClass( 'btn--inactive' );
$tierToggles.not( $toggle ).removeClass( 'btn--active' );
$toggle.addClass( 'btn--active' );
$toggle.removeClass( 'btn--inactive' );


var PhysicalDamageModGraph = {
$containers.each( function( i2, el )
    x: [0.0, 1.0, 5.0, 7.0, 11.0, 15.0, 19.0, 20.0, 21.0, 27.0, 30.0, 35.0, 36.0, 38.0, 39.0, 44.0, 50.0, 51.0, 58.0, 59.0, 64.0, 70.0, 71.0, 76.0, 86.0, 87.0, 98.0, 100.0],
{
    y: [-0.8, -0.7, -0.3, -0.2, -0.08, 0.0, 0.04, 0.05, 0.06, 0.12, 0.15, 0.2, 0.21, 0.23, 0.24, 0.29, 0.35, 0.355, 0.39, 0.395, 0.42, 0.45, 0.455, 0.48, 0.53, 0.535, 0.59, 0.6],
var $tabs  = $( el );
    type: 'scatter'
var btnNum = tierNum;
};


var data = [PhysicalDamageModGraph];
// @todo: Maybe refactor this to remove the stuff duped from above?
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]' );


Plotly.newPlot('PhysicalDamageModGraph', data);
var $btn = $btns.filter( '[data-cardtabs-btn="' + btnNum + '"]' );


if ( !$btn.length )
{
// If not button was found, it must have been a -1 button
// (ie. a disabled tab), so let's find the next lowest tier
for (var checkedNum = btnNum; checkedNum < 4; checkedNum++)
{
$btn = $btns.filter( '[data-cardtabs-btn="' + checkedNum + '"]' );
console.log($btn.length);


var RegularInteractionSpeedGraph = {
if ( $btn.length )
    x: [0.0, 2.0, 7.0, 8.0, 12.0, 14.0, 15.0, 18.0, 21.0, 25.0, 28.0, 32.0, 33.0, 34.0, 35.0, 40.0, 41.0, 46.0, 53.0, 54.0, 59.0, 65.0, 66.0, 71.0, 81.0, 82.0, 84.0, 85.0, 86.0, 93.0, 100.0],
{
    y: [-0.75, -0.65, -0.4, -0.35, -0.15, -0.05, 0.0, 0.21, 0.42, 0.7, 0.85, 1.05, 1.1, 1.15, 1.2, 1.3, 1.32, 1.42, 1.56, 1.58, 1.68, 1.8, 1.82, 1.92, 2.12, 2.14, 2.18, 2.19, 2.22, 2.36, 2.5],
btnNum = checkedNum;
    type: 'scatter'
break;
};
}
}


var data = [RegularInteractionSpeedGraph];
if ( !$btn.length )
{
// If we still haven't found a button, just exit.
// Should never get to this point though, unless
// the ibox has hidden tiers that aren't in order
return;
}
}


Plotly.newPlot('RegularInteractionSpeedGraph', data);
var $panel  = $panels.filter( '[data-cardtabs-panel="' + btnNum + '"]' );
var btnActiveCls = 'cardtabs__button--active';
var panelHideCls = 'cardtabs__panel--js-hidden';


// Hide all other panels, then show the button's own panel
$panels.addClass( panelHideCls );
$panel.removeClass( panelHideCls );


var MaxHealthBaseGraph = {
$btns.removeClass( btnActiveCls );
    x: [0.0, 100.0, 0.0, 10.0, 50.0, 75.0, 100.0],
$btn.addClass( btnActiveCls );
    y: [0.0, 100.0, 60.0, 90.0, 170.0, 195.0, 207.5],
});
    type: 'scatter'
});
};
});


var data = [MaxHealthBaseGraph];
}//end:initCardTabs


Plotly.newPlot('MaxHealthBaseGraph', data);


/**
* Toggle a StatsCard box (.ibox)
*
* Targets elements with [data-ibox-type="item"], selecting them by the
* given class (eg. rarity1), which should be applied to the element with
* the data-ibox-type data attr
*
* @todo: Use the CSS class (ibox--hidden) instead of JS-injected opacity
*
* @return  {void}
*/
function initStatsCardsToggles()
{
var $allBtns  = $( '[data-hide-type="item"]' );
var $bulkBtns = $( '[data-hide-target="show-all"], [data-hide-target="show-none"]' );
var $nonBulkBtns = $allBtns.not( $bulkBtns );
var $allTargets = $( '[data-ibox-type="item"]' );


var DebuffDurationModGraph = {
// Stores all target strings
    x: [0.0, 100.0, 0.0, 5.0, 35.0, 55.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, 80.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0, 89.0, 90.0, 91.0, 92.0, 94.0, 95.0, 96.0, 97.0, 98.0, 99.0, 100.0, 0.0, 1.0, 5.0, 7.0, 11.0, 15.0, 19.0, 20.0, 21.0, 27.0, 30.0, 35.0, 36.0, 38.0, 39.0, 44.0, 50.0, 51.0, 58.0, 59.0, 64.0, 70.0, 71.0, 76.0, 86.0, 87.0, 98.0, 100.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 17.0, 19.0, 20.0, 21.0, 22.0, 24.0, 29.0, 30.0, 31.0, 32.0, 33.0, 36.0, 37.0, 39.0, 41.0, 42.0, 44.0, 46.0, 47.0, 49.0, 50.0, 52.0, 53.0, 54.0, 55.0, 56.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, 64.0, 65.0, 66.0, 67.0, 68.0, 70.0, 71.0, 73.0, 74.0, 76.0, 77.0, 80.0, 81.0, 85.0, 86.0, 87.0, 96.0, 97.0, 100.0],
// Used to prevent iboxs from being hidden when they shouldn't be
    y: [0.0, 100.0, -20.0, 0.0, 90.0, 130.0, 141.0, 141.0, 142.0, 142.0, 143.0, 143.0, 144.0, 144.0, 145.0, 145.0, 146.0, 146.0, 147.0, 147.0, 148.0, 148.0, 149.0, 149.0, 150.0, 150.0, 151.0, 151.0, 152.0, 152.0, 153.0, 152.0, 154.0, 154.0, 155.0, 155.0, 156.0, 156.0, 157.0, -0.8, -0.7, -0.3, -0.2, -0.08, 0.0, 0.04, 0.05, 0.06, 0.12, 0.15, 0.2, 0.21, 0.23, 0.24, 0.29, 0.35, 0.355, 0.39, 0.395, 0.42, 0.45, 0.455, 0.48, 0.53, 0.535, 0.59, 0.6, 4.0, 2.333, 1.5, 1.0, 0.667, 0.429, 0.333, 0.25, 0.205, 0.163, 0.124, 0.087, 0.064, 0.042, 0.02, 0.0, -0.02, -0.038, -0.048, -0.057, -0.065, -0.083, -0.123, -0.13, -0.138, -0.145, -0.153, -0.174, -0.18, -0.194, -0.206, -0.213, -0.225, -0.237, -0.242, -0.254, -0.259, -0.265, -0.267, -0.27, -0.273, -0.275, -0.281, -0.283, -0.286, -0.288, -0.291, -0.293, -0.296, -0.298, -0.301, -0.303, -0.306, -0.31, -0.313, -0.317, -0.32, -0.324, -0.327, -0.333, -0.336, -0.344, -0.346, -0.349, -0.367, -0.369, -0.375],
var allTargetStrs = [];
    type: 'scatter'
var activeTargetStrs = []
};


var data = [DebuffDurationModGraph];
var specialFilters = [
'show-all',
'show-none'
];


Plotly.newPlot('DebuffDurationModGraph', data);
$allBtns.each( function( i, el )
{
var $btn = $( el );
var filterStr = $btn.attr( 'data-hide-target' ); // eg "rarity3"
 
// ES5 version of Array.prototype.includes()
if ( ( allTargetStrs.indexOf( filterStr ) === -1 ) && ( specialFilters.indexOf( filterStr ) === -1 ) )
{
allTargetStrs.push( filterStr );
}
});
 
activeTargetStrs = allTargetStrs;
 
$allBtns.on( 'click', function( ev )
{
var $btn      = $( ev.currentTarget );
var filterStr = $btn.attr( 'data-hide-target' ); // eg "rarity3"
var $targets  = $( '[data-ibox-type="item"]' + filterStr );
var $all      = $( '[data-ibox-type="item"]' );
 
if ( filterStr === 'show-all' || filterStr === 'show-none' )
{
// Bulk toggle ALL targets
$targets = $all;
 
switch( filterStr )
{
case 'show-all':
$targets.removeClass( 'ibox--hidden' );
$targets.css( { opacity: 1 } );
$nonBulkBtns.addClass( 'btn--active' );
$nonBulkBtns.removeClass( 'btn--inactive' );
activeTargetStrs = allTargetStrs;
break;
 
case 'show-none':
$targets.addClass( 'ibox--hidden' );
$targets.css( { opacity: 0.2 } );
$nonBulkBtns.removeClass( 'btn--active' );
$nonBulkBtns.addClass( 'btn--inactive' );
activeTargetStrs = [];
break;
}
}
else
{
var strIndex = activeTargetStrs.indexOf( filterStr );
 
if ( $btn.hasClass( 'btn--active' ) )
{
// Button was active, so it's now INACTIVE
 
// If all other buttons are active (ie. no buttons have been
// selected yet), make this one active and all others disabled
if ( activeTargetStrs.length === allTargetStrs.length )
{
// Disable all others, keep only this one
$nonBulkBtns.not( $btn ).removeClass( 'btn--active' );
$nonBulkBtns.not( $btn ).addClass( 'btn--inactive' );
activeTargetStrs = [];
activeTargetStrs.push( filterStr );
}
// Or, if this was the last (ie. only) active button and it
// was just disabled, enable every button
else if ( activeTargetStrs.length === 1 )
{
$nonBulkBtns.removeClass( 'btn--inactive' );
$nonBulkBtns.addClass( 'btn--active' );
activeTargetStrs = allTargetStrs;
}
// Otherwise function normally: Just disable this button
else
{
$btn.removeClass( 'btn--active' );
$btn.addClass( 'btn--inactive' );
activeTargetStrs.splice( strIndex, 1 );
}
}
else
{
// Button was inactive, so it's now ACTIVE
$btn.removeClass( 'btn--inactive' );
$btn.addClass( 'btn--active' );
activeTargetStrs.push( filterStr );
}
 
// Apply filters
 
// Show all, if every filter is active (ie. if every ibox should be shown)
if ( activeTargetStrs.length === allTargetStrs.length )
{
$allTargets.removeClass( 'ibox--hidden' );
$allTargets.css( { opacity: 1 } );
}
// Otherwise, apply the actual filters
else
{
// Hide all to start with
$allTargets.addClass( 'ibox--hidden' );
$allTargets.css( { opacity: 0.2 } );
 
// Show any that match the currently active filters
for (var i = 0; i < activeTargetStrs.length; i++)
{
var targetStr = activeTargetStrs[i];
var $currentTargets = $allTargets.filter( '[data-ibox-type="item"].' + targetStr );
$currentTargets.removeClass( 'ibox--hidden' );
$currentTargets.css( { opacity: 1 } );
}
}
}
});
}//end:initStatsCardsToggles
 
 
/**
* Toggle "misc" (costs/tags)
*
* Buttons: <span class="btn btn--active" data-hide-type="misc" data-hide-target=".myelement">
* Targets: <span class="myelement" data-target-type"misc">
*
* @return  {void}
*/
function initStatsCardsMiscToggles()
{
var $btns = $( '[data-hide-type="misc"]' );
 
$btns.each( function( i, el )
{
var $btn = $( el );
var targetStr = $btn.attr( 'data-hide-target' );
var $targets = $( '[data-target-type="misc"]' + targetStr );
 
if ( !$targets.length )
{
return;
}
 
$btn.on( 'click', function( ev )
{
$btn.toggleClass( 'btn--active' );
$btn.toggleClass( 'btn--inactive' );
 
$targets.toggle();
});
});
}
}); // end:$(document).ready
 
$(document).ready( function()
{
//WIP tab toggler
$tabList = $('.tab-toggle');
if (! $tabList.length) {
return;
}
 
//Toggles contents of the given tabs with display
function togglecontent(tab, display) {
$('.' + tab + '-data').each(function() {
$(this).css('display', display);
});
}
 
    //Resets all display of content and sets it to a new one
function setTab(element,tabid) {
$tabList.each(function() {
if ($(this).attr('data-tabid') === tabid){
$(this).removeClass('selected-tab');
togglecontent($(this).attr('data-tab'), 'none');
}
});
$(element).addClass('selected-tab');
togglecontent($(element).attr('data-tab'),'');
}
$tabList.each(function(index) {
$(this).click(function() {
setTab(this, $(this).attr('data-tabid'));
});
});
 
}); // end:$(document).ready

Latest revision as of 02:30, 29 November 2023

/* 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)
	initStatsCardsMiscToggles(); // Toggles for misc (costs/tags)


	// 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 );
				});
			});
		});

		// Tier toggles
		// ---------------------------------------------------------------------

		// Example:
		// <span class="btn btn--active" data-weapon-toggle="1">Tier 1</span>
		// <span class="btn btn--inactive" data-weapon-toggle="2">Tier 2</span>
		// <span class="btn btn--inactive" data-weapon-toggle="3">Tier 3</span>
		// <span class="btn btn--inactive" data-weapon-toggle="4">Tier 4</span>

		var $tierToggles = $( '[data-weapon-toggle]' );

		$tierToggles.each( function( i1, el )
		{
			var $toggle = $( el );
			var tierNum = $toggle.attr( 'data-weapon-toggle' );

			$toggle.on( 'click', function( ev, el )
			{
				$tierToggles.not( $toggle ).addClass( 'btn--inactive' );
				$tierToggles.not( $toggle ).removeClass( 'btn--active' );
				$toggle.addClass( 'btn--active' );
				$toggle.removeClass( 'btn--inactive' );

				$containers.each( function( i2, el )
				{
					var $tabs  = $( el );
					var btnNum = tierNum;

					// @todo: Maybe refactor this to remove the stuff duped from above?
					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]' );

					var $btn = $btns.filter( '[data-cardtabs-btn="' + btnNum + '"]' );

					if ( !$btn.length )
					{
						// If not button was found, it must have been a -1 button
						// (ie. a disabled tab), so let's find the next lowest tier
						for (var checkedNum = btnNum; checkedNum < 4; checkedNum++)
						{
							$btn = $btns.filter( '[data-cardtabs-btn="' + checkedNum + '"]' );
							console.log($btn.length);

							if ( $btn.length )
							{
								btnNum = checkedNum;
								break;
							}
						}

						if ( !$btn.length )
						{
							// If we still haven't found a button, just exit.
							// Should never get to this point though, unless
							// the ibox has hidden tiers that aren't in order
							return;
						}
					}

					var $panel   = $panels.filter( '[data-cardtabs-panel="' + btnNum + '"]' );
					var btnActiveCls = 'cardtabs__button--active';
					var panelHideCls = 'cardtabs__panel--js-hidden';

					// 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)
	 *
	 * Targets elements with [data-ibox-type="item"], selecting them by the
	 * given class (eg. rarity1), which should be applied to the element with
	 * the data-ibox-type data attr
	 *
	 * @todo: Use the CSS class (ibox--hidden) instead of JS-injected opacity
	 *
	 * @return  {void}
	 */
	function initStatsCardsToggles()
	{
		var $allBtns  = $( '[data-hide-type="item"]' );
		var $bulkBtns = $( '[data-hide-target="show-all"], [data-hide-target="show-none"]' );
		var $nonBulkBtns = $allBtns.not( $bulkBtns );
		var $allTargets = $( '[data-ibox-type="item"]' );

		// Stores all target strings
		// Used to prevent iboxs from being hidden when they shouldn't be
		var allTargetStrs = [];
		var activeTargetStrs = []

		var specialFilters = [
			'show-all',
			'show-none'
		];

		$allBtns.each( function( i, el )
		{
			var $btn = $( el );
			var filterStr = $btn.attr( 'data-hide-target' ); // eg "rarity3"

			// ES5 version of Array.prototype.includes()
			if ( ( allTargetStrs.indexOf( filterStr ) === -1 ) && ( specialFilters.indexOf( filterStr ) === -1 ) )
			{
				allTargetStrs.push( filterStr );
			}
		});

		activeTargetStrs = allTargetStrs;

		$allBtns.on( 'click', function( ev )
		{
			var $btn      = $( ev.currentTarget );
			var filterStr = $btn.attr( 'data-hide-target' ); // eg "rarity3"
			var $targets  = $( '[data-ibox-type="item"]' + filterStr );
			var $all      = $( '[data-ibox-type="item"]' );

			if ( filterStr === 'show-all' || filterStr === 'show-none' )
			{
				// Bulk toggle ALL targets
				$targets = $all;

				switch( filterStr )
				{
					case 'show-all':
						$targets.removeClass( 'ibox--hidden' );
						$targets.css( { opacity: 1 } );
						$nonBulkBtns.addClass( 'btn--active' );
						$nonBulkBtns.removeClass( 'btn--inactive' );
						activeTargetStrs = allTargetStrs;
						break;

					case 'show-none':
						$targets.addClass( 'ibox--hidden' );
						$targets.css( { opacity: 0.2 } );
						$nonBulkBtns.removeClass( 'btn--active' );
						$nonBulkBtns.addClass( 'btn--inactive' );
						activeTargetStrs = [];
						break;
				}
			}
			else
			{
				var strIndex = activeTargetStrs.indexOf( filterStr );

				if ( $btn.hasClass( 'btn--active' ) )
				{
					// Button was active, so it's now INACTIVE

					// If all other buttons are active (ie. no buttons have been
					// selected yet), make this one active and all others disabled
					if ( activeTargetStrs.length === allTargetStrs.length )
					{
						// Disable all others, keep only this one
						$nonBulkBtns.not( $btn ).removeClass( 'btn--active' );
						$nonBulkBtns.not( $btn ).addClass( 'btn--inactive' );
						activeTargetStrs = [];
						activeTargetStrs.push( filterStr );
					}
					// Or, if this was the last (ie. only) active button and it
					// was just disabled, enable every button
					else if ( activeTargetStrs.length === 1 )
					{
						$nonBulkBtns.removeClass( 'btn--inactive' );
						$nonBulkBtns.addClass( 'btn--active' );
						activeTargetStrs = allTargetStrs;
					}
					// Otherwise function normally: Just disable this button
					else
					{
						$btn.removeClass( 'btn--active' );
						$btn.addClass( 'btn--inactive' );
						activeTargetStrs.splice( strIndex, 1 );
					}
				}
				else
				{
					// Button was inactive, so it's now ACTIVE
					$btn.removeClass( 'btn--inactive' );
					$btn.addClass( 'btn--active' );
					activeTargetStrs.push( filterStr );
				}

				// Apply filters

				// Show all, if every filter is active (ie. if every ibox should be shown)
				if ( activeTargetStrs.length === allTargetStrs.length )
				{
					$allTargets.removeClass( 'ibox--hidden' );
					$allTargets.css( { opacity: 1 } );
				}
				// Otherwise, apply the actual filters
				else
				{
					// Hide all to start with
					$allTargets.addClass( 'ibox--hidden' );
					$allTargets.css( { opacity: 0.2 } );

					// Show any that match the currently active filters
					for (var i = 0; i < activeTargetStrs.length; i++)
					{
						var targetStr = activeTargetStrs[i];
						var $currentTargets = $allTargets.filter( '[data-ibox-type="item"].' + targetStr );
						$currentTargets.removeClass( 'ibox--hidden' );
						$currentTargets.css( { opacity: 1 } );
					}
				}
			}
		});
	}//end:initStatsCardsToggles


	/**
	 * Toggle "misc" (costs/tags)
	 *
	 * Buttons: <span class="btn btn--active" data-hide-type="misc" data-hide-target=".myelement">
	 * Targets: <span class="myelement" data-target-type"misc">
	 *
	 * @return  {void}
	 */
	function initStatsCardsMiscToggles()
	{
		var $btns = $( '[data-hide-type="misc"]' );

		$btns.each( function( i, el )
		{
			var $btn = $( el );
			var targetStr = $btn.attr( 'data-hide-target' );
			var $targets = $( '[data-target-type="misc"]' + targetStr );

			if ( !$targets.length )
			{
				return;
			}

			$btn.on( 'click', function( ev )
			{
				$btn.toggleClass( 'btn--active' );
				$btn.toggleClass( 'btn--inactive' );

				$targets.toggle();
			});
		});
	}
}); // end:$(document).ready

$(document).ready( function()
{
	//WIP tab toggler
	$tabList = $('.tab-toggle');
	
	if (! $tabList.length) {
		return;
	}

	//Toggles contents of the given tabs with display
	function togglecontent(tab, display) {
		$('.' + tab + '-data').each(function() {
			$(this).css('display', display);
		});
	}

    //Resets all display of content and sets it to a new one
	function setTab(element,tabid) {
	$tabList.each(function() {
		if ($(this).attr('data-tabid') === tabid){
		$(this).removeClass('selected-tab');
		togglecontent($(this).attr('data-tab'), 'none');
		}
		});
		$(element).addClass('selected-tab');
		togglecontent($(element).attr('data-tab'),'');
	}
	
	$tabList.each(function(index) {
		$(this).click(function() {
			setTab(this, $(this).attr('data-tabid'));
		});
	});

}); // end:$(document).ready