Widget:Item infobox slider

 var itemSlider = { item : null, initialize : function { itemSlider.item = itemSlider.parseConstants( '' ); if ( !$.isEmptyObject( itemSlider.item ) ) { mw.loader.using( 'jquery.ui.slider', function {        $( "#itemslider-quality" ).html( 'Quality: 0 (common)' );        $( "#itemslider" ).slider( { range: "min", min: 0, max: 30, value: 0, slide: itemSlider.updateStats, change: itemSlider.updateStats, create: itemSlider.updateStats }                                );      } );    }  },  parseConstants : function ( constantsList ) { var constants = {}; var constantsLines = constantsList.split( '\n' ); var constantParts; for ( var i = 0; i < constantsLines.length; ++i ) { constantParts = constantsLines[i].split( ';' ); constants[constantParts[0]] = {}; constants[constantParts[0]].baseValue = ( constantParts.length > 2 ? parseFloat( constantParts[2] ) : 0 ); constants[constantParts[0]].tier = ( constantParts.length > 3 ? constantParts[3] : "" ); constants[constantParts[0]].modifier = ( constantParts.length > 4 ? parseFloat( constantParts[4] ) : 0 ); constants[constantParts[0]].operation = ( constantParts.length > 5 ? constantParts[5] : "" ); }   return constants; }, tier : function ( quality ) { if ( quality >= 0 && quality < 10 ) { return 'common'; } else if ( quality >= 10 && quality < 20 ) { return 'rare'; } else if ( quality >= 20 && quality <= 30 ) { return 'legendary'; } else { return ''; } },  modifierMultiplier : function( quality, tier ) { switch ( tier.toLowerCase ) { case "common": return Math.max( 0, Math.min( 10, quality ) ); case "rare": return Math.max( 0, Math.min( 10, quality - 10 ) ); case "legendary": return Math.max( 0, Math.min( 10, quality - 20 ) ); } },  updateStats : function  { if ( itemSlider.item != null ) { var quality = $( "#itemslider" ).slider( "value" ); var statsAreas = $( ".itemstatsarea" ); var constant, value; $( "#itemslider-quality" ).html( 'Quality: ' + quality + ' (' + itemSlider.tier( quality ) + ')' ); for ( var constantId in itemSlider.item ) { constant = itemSlider.item[constantId]; switch ( constant.operation.toLowerCase ) { case "add": value = constant.baseValue + ( ( constant.modifier * itemSlider.modifierMultiplier( quality, constant.tier ) ) / 10 ); break; case "sub": value = constant.baseValue - ( ( constant.modifier * itemSlider.modifierMultiplier( quality, constant.tier ) ) / 10 ); break; }       statsAreas.find( '.strife-formatted-' + constantId ).html( value ); }   }  } } $( document ).ready( itemSlider.initialize );