24,493
ARTICLES
ON THIS WIKI
ON THIS WIKI
User:VanDerProtofsky/common.js
< User:VanDerProtofsky
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/**
* Based on http://www.minecraftwiki.net/wiki/MediaWiki:Common.js
*/
/**
* Keep out of global scope
*/
window.ftbw = {};
$( function() {
'use strict';
window.ftbw.animation = function() {
/**
* Element animator
*
* Will cycle the active class on any child elements
* within an element with the animated class.
*/
if ( window.ftbw.animate === undefined && $( '.animated' ).length ) {
window.ftbw.animate = setInterval( function() {
$( '.animated' ).each( function() {
var current = $( this ).find( '.active' ).removeClass( 'active' ), next = current.next();
if ( !current.next().length ) {
next = $( this ).children().eq( 0 );
}
next.addClass( 'active' );
} );
}, 2000 );
}
/**
* Frame loader
*
* Loads a semi-colon (;) separated list of images
* to be animated by the element animator
*
* Has special support for [[Template:Grid]]
*/
var $animate = $( '.animated' ), size = {};
if ( $animate.length ) {
$animate.each( function() {
var imgs = $( this ).data( 'imgs' ), imgSize = $( this ).data( 'img-size' ),
grid = $( this ).closest( '.grid' );
if ( !imgs ) {
return true;
}
if ( grid.length ) {
grid = true;
imgSize = '32x32';
} else {
grid = false;
if ( imgSize ) {
imgSize = imgSize.split( 'x' );
imgSize[0] = imgSize[0].replace( /[\D ]/, '' );
imgSize[1] = imgSize[1].replace( /[\D ]/, '' );
if ( imgSize[1] ) {
imgSize[0] += 'x' + imgSize[1];
}
imgSize = imgSize[0];
} else {
imgSize = '';
}
}
if ( size[imgSize] === undefined ) {
size[imgSize] = [];
}
imgs = imgs.split( ';' );
imgs.shift();
$.each( imgs, function() {
if ( !this.trim() ) {
return true;
}
var parts, name;
if ( grid ) {
parts = $.map( this.split( ',' ), $.trim );
name = 'File:Grid ' + parts[0] + '.png';
if ( size[imgSize].indexOf( name ) < 0 ) {
size[imgSize].push( name );
}
} else if ( size[imgSize].indexOf( 'File:' + this.trim() ) < 0 ) {
size[imgSize].push( 'File:' + this.trim() );
}
} );
} );
var redirectPromise = [], urlPromise = [], redirects = {}, urls = {}, origurls = {};
$.each( size, function( size ) {
var titles = this;
if ( !titles ) {
return true;
}
// Split titles up into blocks of 50, which is the API's title limit for standard users
for ( var i = 0; i < titles.length; i += 50 ) {
var section = titles.slice( i, i + 50 ).join( '|' );
redirectPromise.push(
// Thanks to bug 23750 (https://bugzilla.wikimedia.org/show_bug.cgi?id=23750)
// &redirects doesn't work properly with prop=imageinfo. Some of the images
// will return without any imageinfo, even though they are valid.
// So the redirects have to be resolved in a separate request...
$.ajax( {
type: 'POST',
url: '/api.php?action=query&format=json&redirects',
data: { titles: section },
timeout: 20000
} ).done( function( data ) {
if ( data.query.redirects ) {
$.each( data.query.redirects, function() {
redirects[this.to] = this.from;
section = section.replace( this.from, this.to );
} );
}
var thumburl = '', sizes = size.split( 'x' );
if ( sizes[0] ) {
thumburl = '&iiurlwidth=' + sizes[0];
if ( sizes[1] ) {
thumburl += '&iiurlheight=' + sizes[1];
}
}
urlPromise.push(
$.ajax( {
type: 'POST',
url: '/api.php?action=query&format=json&prop=imageinfo&iiprop=url' + thumburl,
data: { titles: section },
timeout: 20000
} ).done( function( data ) {
$.each( data.query.pages, function( index ) {
if ( index < 0 ) {
return true;
}
if ( !this.imageinfo ) {
console.error( 'Imageinfo is empty' );
return true;
}
var url = this.imageinfo[0].thumburl || this.imageinfo[0].url;
var origurl = this.imageinfo[0].url;
if ( redirects.hasOwnProperty( this.title ) ) {
urls[redirects[this.title].replace( /File:(.*)/, '$1' ) + size] = url;
origurls[redirects[this.title].replace( /File:(.*)/, '$1' ) + size] = origurl;
} else {
urls[this.title.replace( /File:(.*)/, '$1' ) + size] = url;
origurls[this.title.replace( /File:(.*)/, '$1' ) + size] = origurl;
}
} );
} ).fail( function( error ) {
console.error( error );
} )
);
} ).fail( function( error ) {
console.error( error );
} )
);
}
} );
$.when.apply( $, redirectPromise ).then( function() {
$.when.apply( $, urlPromise ).then( function() {
$animate.each( function() {
var imgs = $( this ).data( 'imgs' ), imgSize = $( this ).data( 'img-size' ), html = '',
grid = $( this ).closest( '.grid' );
if ( !imgs ) {
return true;
}
if ( grid.length ) {
grid = true;
imgSize = '32x32';
} else {
grid = false;
if ( imgSize ) {
imgSize = imgSize.split( 'x' );
imgSize[0] = imgSize[0].replace( /[\D ]/, '' );
imgSize[1] = imgSize[1].replace( /[\D ]/, '' );
if ( imgSize[1] ) {
imgSize[0] += 'x' + imgSize[1];
}
imgSize = imgSize[0];
} else {
imgSize = '';
}
}
imgs = imgs.split( ';' );
imgs.shift();
$.each( imgs, function() {
if ( !this.trim() ) {
if ( grid ) {
html += '<span class="image"> </span>';
}
return true;
}
var parts, name, link, url, num;
if ( grid ) {
parts = $.map( this.split( ',' ), $.trim );
name = link = parts[0];
url = urls['Grid ' + parts[0] + '.png' + imgSize];
num = parts[1];
html += '<span class="image">';
if ( name ) {
if ( url ) {
html += '<a title="' + link + '" href="/' + link.replace( / /g, '_' ) + '"><img width="32" height="32" src="' + url + '" alt="' + name + '"></a>';
if ( num ) {
html += '<span class="number"><a title="' + link + '" href="/' + link.replace( / /g, '_' ) + '">' + num + '</a></span>';
}
} else {
html += '<a class="new" title="File:Grid ' + name + '.png" href="/index.php?title=Special:Upload&wpDestFile=Grid_' + name.replace( / /g, '_' ) + '.png"></a>';
}
} else {
html += ' ';
}
html += '</span>';
} else {
name = this.trim();
html += '<span>';
if ( urls[name + imgSize] ) {
html += '<a class="image fancybox" href="' + origurls[name + imgSize] + '" rel="group"><img src="' + urls[name + imgSize] + '" alt="' + name + '"></a>';
} else {
html += '<a class="new" title="File:' + name + '" href="/index.php?title=Special:Upload&wpDestFile=' + name.replace( / /g, '_' ) + '">File:' + name + '</a>';
}
html += '</span>';
}
} );
$( this ).append( html ).data( 'imgs', null );
} );
} );
} );
}
};
window.ftbw.animation();
/**
* Pause grid GUI templates (e.g. [[Template:Grid/Crafting Table]]) on mouseover
*
* This is so people have a chance to look at each image on the cell
* and click on pages they want to view.
*/
$( '#content' ).delegate( '.grid-Crafting_Table, .grid-furnace, .grid-Brewing_Stand', {
'mouseenter': function() {
$( this ).find( '.animated' ).removeClass( 'animated' ).addClass( 'paused' );
},
'mouseleave': function() {
$( this ).find( '.paused' ).removeClass( 'paused' ).addClass( 'animated' );
}
} );
} );
/**
* Add templates to toolbar
*/
var customizeToolbar = function() {
// Template subgroup
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'sections': {
'templates': {
'type': 'toolbar', // Can also be 'booklet'
'label': 'Templates'
// or 'labelMsg': 'section-templates-label' for a localized label
}
}
} );
// Header notes
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'groups': {
'headers': {
'label': 'Header Notes' // or use labelMsg for a localized label, see above
}
}
} );
// [[Template:Stub]]
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'group': 'headers',
'tools': {
'stub': {
label: 'Stub', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/b/bf/Grid_Wood.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{stub}}",
'post': ""
}
}
}
}
} );
// [[Template:Cleanup]]
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'group': 'headers',
'tools': {
'cleanup': {
label: 'Cleanup', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/5/58/Grid_Paint_Brush_%28RedPower_2%29.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{cleanup}}",
'post': ""
}
}
}
}
} );
// [[Template:Youmay]]
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'group': 'headers',
'tools': {
'youmay': {
label: 'You may...', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/0/06/Grid_Sign.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{youmay|this item",
'post': "|some other item}}"
}
}
}
}
} );
// Infoboxes
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'groups': {
'infoboxes': {
'label': 'Infoboxes' // or use labelMsg for a localized label, see above
}
}
} );
// [[Template:Item]] for blocks
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'group': 'infoboxes',
'tools': {
'block': {
label: 'Block infobox', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/a/a6/Grid_Stone.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Item\n|type = Block\n|physics = No\n|transparency = No\n|luminance = No\n|tool = any\n|stack = Yes (64)\n|first = MC 1.x.x\n|mod = ",
'post': "\n}}"
}
}
}
}
} );
// [[Template:Item]] for items
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'group': 'infoboxes',
'tools': {
'item': {
label: 'Item infobox', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/e/e9/Grid_Stick.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Item\n|type = Item\n|stack = Yes (64)\n|first = MC 1.x.x\n|mod = ",
'post': "\n}}"
}
}
}
}
} );
// [[Template:Infobox/Mod]]
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'group': 'infoboxes',
'tools': {
'mod': {
label: 'Mod infobox', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/3/36/Grid_Wrench_%28IndustrialCraft_2%29.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Infobox/Mod\n|author = ",
'post': "\n|version = \n|mcversion = 1.x.x\n|url = [http://example.com/ Website]\n|forum = [http://minecraftforum.net/ Minecraft Forum post]\n|type = \n}}"
}
}
}
}
} );
// [[Template:Infobox/Modpack]]
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'group': 'infoboxes',
'tools': {
'modpack': {
label: 'Modpack infobox', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/c/c1/Grid_Chest.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Infobox/Modpack\n|creator = ",
'post': "\n|launcher = \n|version = \n|mcversion = 1.x.x\n|url = [http://example.com/ Website]\n}}"
}
}
}
}
} );
// Crafting Grids subgroup
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'sections': {
'grids': {
'type': 'toolbar', // Can also be 'booklet'
'label': 'Crafting Grids'
// or 'labelMsg': 'section-templates-label' for a localized label
}
}
} );
// Vanilla Minecraft
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'groups': {
'minecraft': {
'label': 'Vanilla Minecraft' // or use labelMsg for a localized label, see above
}
}
} );
// Crafting Table
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'group': 'minecraft',
'tools': {
'craftingtable': {
label: 'Crafting Table', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/7/79/Grid_Crafting_Table.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Grid/Crafting Table\n|A1= |B1= |C1=\n|A2= |B2= |C2=\n|A3= |B3= |C3=\n|Output=",
'post': " |OA=1}}"
}
}
}
}
} );
// Furnace
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'group': 'minecraft',
'tools': {
'furnace': {
label: 'Furnace', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/2/2e/Grid_Furnace.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Grid/Furnace\n|Input=\n|Output=",
'post': "}}"
}
}
}
}
} );
// IndustrialCraft 2
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'groups': {
'ic2': {
'label': 'IC<sup>2</sup>' // or use labelMsg for a localized label, see above
}
}
} );
// Macerator
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'group': 'ic2',
'tools': {
'macerator': {
label: 'Macerator', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/b/b3/Grid_Macerator.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Grid/Macerator\n|Input=\n|Output=",
'post': "}}"
}
}
}
}
} );
// Extractor
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'group': 'ic2',
'tools': {
'extractor': {
label: 'Extractor', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/c/c2/Grid_Extractor.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Grid/Extractor\n|Input=\n|Output=",
'post': "}}"
}
}
}
}
} );
// Compressor
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'group': 'ic2',
'tools': {
'compressor': {
label: 'Compressor', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/7/74/Grid_Compressor.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Grid/Compressor\n|Top=\n|Output=",
'post': "}}"
}
}
}
}
} );
// Forestry
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'groups': {
'forestry': {
'label': 'Forestry' // or use labelMsg for a localized label, see above
}
}
} );
// Centrifuge
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'group': 'forestry',
'tools': {
'centrifuge': {
label: 'Centrifuge', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/2/2d/Grid_Centrifuge.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Grid/Centrifuge\n|Input=\n",
'post': "|A1= |A1-chance= |A2= |A2-chance= |A3= |A3-chance=\n|B1= |B1-chance= |B2= |B2-chance= |B3= |B3-chance=\n|C1= |C1-chance= |C2= |C2-chance= |C3= |C3-chance=}}"
}
}
}
}
} );
// Carpenter
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'group': 'forestry',
'tools': {
'carpenter': {
label: 'Carpenter', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/2/2c/Grid_Carpenter.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Grid/Carpenter\n|A1= |B1= |C1=\n|A2= |B2= |C2=\n|A3= |B3= |C3=\n|Liquid= |LiquidAmount=\n|Output=",
'post': " |OA=1\n}}"
}
}
}
}
} );
// Thermal Expansion
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'groups': {
'TE3': {
'label': 'Thermal Expansion' // or use labelMsg for a localized label, see above
}
}
} );
// Pulverizer
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'group': 'TE3',
'tools': {
'pulverizer': {
label: 'Pulverizer', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/1/1c/Grid_Pulverizer.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Grid/Pulverizer\n|Top=|Bottom=\n|Energy=|EnergyType=\n|Output=|OA=\n|Output2=|OA2=|Output2 Chance=",
'post': "}}"
}
}
}
}
} );
// Induction Smelter
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'group': 'TE3',
'tools': {
'inductionsmelter': {
label: 'Induction Smelter', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/e/e9/Grid_Induction_Smelter.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Grid/Induction Smelter\n|Input1 =|Input1-OA =\n|Input2 =|Input2-OA =\n|Output1 = |Output1-OA =\n|Output2 = |Output2-OA = |Output2-chance =",
'post': "}}"
}
}
}
}
} );
// Magma Crucible
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'group': 'TE3',
'tools': {
'magmacrucible': {
label: 'Magma Crucible', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/5/59/Grid_Magma_Crucible.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Grid/Magma Crucible |Input= |Output= |Amount= " ,
'post': "}}"
}
}
}
}
} );
// Fluid Transposer
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'grids',
'group': 'TE3',
'tools': {
'liquidtransposer': {
label: 'Fluid Transposer', // or use labelMsg for a localized label, see above
type: 'button',
icon: '/images/9/99/Grid_Fluid_Transposer.png',
action: {
type: 'encapsulate',
options: {
'pre': "{{Grid/Fluid Transposer|Input = |Output = |Fuel = |FuelAmount = " ,
'post': "}}"
}
}
}
}
} );
};
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar . . . */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
mw.loader.using( 'user.options', function () {
if ( mw.user.options.get('usebetatoolbar') && mw.user.options.get( 'showtoolbar' ) ) {
mw.loader.using( 'ext.wikiEditor.toolbar', function () {
$( customizeToolbar );
} );
}
} );
}
// Add the customizations to LiquidThreads' edit toolbar, if available
mw.hook( 'ext.lqt.textareaCreated' ).add( customizeToolbar );
/******************************************
* Adds Tooltips *
*****************************************/
$(function() {
var mc_tooltip = null;
$(".a1, .a2, .a3, .b1, .b2, .b3, .c1, .c2, .c3, .output, .gridbox, .tooltip").on({
'mouseenter.tooltip': function(e) {
var $me = $(this);
// Make sure this isn't a link to upload a new file
if ($me.find('.new').length > 0) {
// This isn't one we want to show a tooltip for
return;
}
// Try to get the title
var title = $me.data('tooltip');
// See if we can find a title elsewhere
// Check this element or its child
if (title === undefined) {
title = $me.children(':first').children(':first').attr('alt')
|| $me.attr('title')
|| $me.children(':first').attr('title');
// Check if we found anything
if (title) {
// Save it for later
$me.data('tooltip', title);
}
else {
// Didn't find anything, no sense continuing
return;
}
}
// Remove any title elements to avoid the default tooltip
$me.add('*', $me).filter('[title]').removeAttr('title');
// Check to see if we've already created the div
if (!$('#tooltip-display').length) {
$('body').append('<div id="tooltip-display" />');
}
mc_tooltip = $('#tooltip-display');
// Add the text to the tooltip
mc_tooltip.html(title);
// Need to update the position to the cursor position
$me.trigger('mousemove', e);
},
'mousemove.tooltip': function (e) {
// Check if the element exists already, create it if it doesn't
if (!$('#tooltip-display').length) {
$(this).trigger('mouseenter');
return;
}
// Get dimensions for bounds checking
var top = e.pageY - 30,
height = mc_tooltip.outerHeight(true),
left = e.pageX + 15,
width = mc_tooltip.outerWidth(true);
// Get window dimensions
var $w = $(window),
win_width = $w.width(),
win_height = $w.height();
// TODO: Make it so it doesn't go off the sides
// Apply the position
mc_tooltip.css({
top: top,
left: left
});
},
'mouseleave.tooltip': function (e) {
// Make sure the tooltip is there before we use it
if (!mc_tooltip) {
return;
}
mc_tooltip.remove();
},
});
});
/******************************************
* Resizes the fluid gauges *
*****************************************/
$(function() {
$('.fluid-meter').each(function() {
var meter = $(this);
var gauge = meter.find('.gauge');
// Set the background image as we can't do it directly
gauge.css('background-image', 'url(' + meter.data('image') + ')');
var amount = meter.data('amount');
var amount_px = null;
// Test what size of gauge we are using
if (meter.css('height') == '116px') {
// We are using 116px high gauges
amount_px = Math.min((amount > 0 && amount < 0.3) ? 2 : amount * 12-2, 116);
}
else {
// We are defaulting to 120px high gauges
amount_px = Math.min(amount * 12, 120);
}
gauge.css('height', amount_px);
});
})
View All FTB Twitter Feed
Discussion
To discuss the topics on this wiki, you can visit our community forums!