Difference between revisions of "User:Chocohead/common.js"

From Industrial-Craft-Wiki
Jump to navigation Jump to search
m (Removed unnecessary title trimming)
m (Nope)
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
/******************************************
/******************************************
  * Tooltip Testing                        *
  * Page Edit Bar Improver                *
  *****************************************/
  *****************************************/
$(function() {
var customizeToolbar = function() {
var mc_tooltip = null;
// Template subgroup
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'sections': {
'templates': {
'type': 'toolbar', // Can also be 'booklet'
'label': 'Templates'
// or 'labelMsg': 'section-templates-label' for a localized label
}
}
} );
// Infoboxes header
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'groups': {
'infoboxes': {
'label': 'Infoboxes' // or use labelMsg for a localized label, see above
}
}
} );
   
   
$(".a1, .tooltip").on({
// [[Template:Block]] for blocks
    'mouseenter.tooltip': function(e) {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        var $me = $(this);
'section': 'templates',
'group': 'infoboxes',
        // Make sure this isn't a link to upload a new file
'tools': {
        if ($me.find('.new').length > 0) {
'block': {
        // This isn't one we want to show a tooltip for
label: 'Block Infobox',
        return;
type: 'button',
        }
icon: '/images/a/a6/Grid_Stone.png',
filters: [ 'body.ns-0' ], //Namespaceless things only -  100, 102, 104 could also fit in
        // Try to get the title
action: {
        var title = $me.data('tooltip');
type: 'encapsulate',
options: {
        // See if we can find a title elsewhere
'pre':
        // Check this element or its child
"<onlyinclude>{{\
        if (title === undefined) {
{{{1|Block}}}\n\
            title = $me.attr('title') || $me.children(':first').attr('title');
|title=\n\
|image=\n\
            // Check if we found anything
|image2=\n\
            if (title) {
|image3=\n\
                // Save it for later
|invimage=\n\
                $me.data('tooltip', title);
|invimage2=\n\
            }
|invimage3=\n\
            else {
|invimage4=\n\
                // Didn't find anything, no sense continuing
|type=\n\
                return;
|dirt=\n\
            }
|maxeu=\n\
        }
|storage=\n\
|eu_use=\n\
        // Remove any title elements to avoid the default tooltip
|eu_use2=\n\
        $me.add('*', $me).filter('[title]').removeAttr('title');
|tool=\n\
|stackable=\n\
        // Check to see if we've already created the div
|data=\n\
        if (!$('#tooltip-display').length) {
|fluidspeed=\n\
            $('body').append('<div id="tooltip-display" />');
|movespeed=",
        }
'post': "\n}}</onlyinclude>"
        mc_tooltip = $('#tooltip-display');
}
}
}
        // Add the text to the tooltip
}
        mc_tooltip.html(title);
} );
 
        // Need to update the position to the cursor position
//[[Template:Userinfo]]
        $me.trigger('mousemove', e);
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
    },
'section': 'templates',
    'mousemove.tooltip': function (e) {
'group': 'infoboxes',
        // Check if the element exists already, create it if it doesn't
'tools': {
        if (!$('#tooltip-display').length) {
'user': {
            $(this).trigger('mouseenter');
label: 'User Infobox',
            return;
type: 'button',
        }
icon: '/images/a/a6/Grid_Stone.png',
filters: [ 'body.ns-2' ], //User namespaces only
        // Get dimensions for bounds checking
action: {
        var top = e.pageY - 30,
type: 'encapsulate',
            height = mc_tooltip.outerHeight(true),
options: {
            left = e.pageX + 15,
'pre': "{{\
            width = mc_tooltip.outerWidth(true);
UserInfo\n\
|width=\n\
        // Get window dimensions
|user-avatar=\n\
        var $w = $(window),
|user-ig=\n\
            win_width = $w.width(),
|section1=\n\
            win_height = $w.height();
|stat1=|value1=\n\
|section2=\n\
        // TODO: Make it so it doesn't go off the sides
|stat2=|value2=\n\
|section3=\n\
        // Apply the position
|stat3=|value3=\n\
        mc_tooltip.css({
|section4=\n\
            top: top,
|stat4=|value4=\n\
            left: left
|section5=\n\
        });
|stat5=|value5=\n\
    },
|section6=\n\
    'mouseleave.tooltip': function (e) {
|stat6=|value6=\n\
        // Make sure the tooltip is there before we use it
|section7=\n\
        if (!mc_tooltip) {
|stat7=|value7=\n\
            return;
|section8=\n\
        }
|stat8=|value8=\n\
|section9=\n\
        mc_tooltip.remove();
|stat9=|value9=",
    },
'post': "\n}}"
});
}
});
}
}
}
} );
 
// Solution for items
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'group': 'infoboxes',
'tools': {
'item': {
label: 'Item Infobox',
type: 'button',
icon: '/images/e/e9/Grid_Stick.png',
filters: [ 'body.ns-0' ], //Namespaceless things only -  100, 102, 104 could also fit in
action: {
type: 'encapsulate',
options: {
'peri': "<!-- We don't have one ;) -->"
}
}
}
}
}  );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'groups': {
'craftingtemplates': {
'label': 'Crafting Grids' // or use labelMsg for a localized label, see above
}
}
} );
// [[Template:Grid/Crafting Table]] for simple crafting recipes
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'group': 'craftingtemplates',
'tools': {
'block': {
label: 'Simple Crafting Table',
type: 'button',
icon: '/images/7/79/Grid_Crafting_Table.png',
filters: [ 'body.ns-0' ], //Namespaceless things only - 100, 102, 104 could also fit in
action: {
type: 'encapsulate',
options: {
'pre':
"{{\
Grid/Crafting Table\n\
|A1=\n\
|B1=\n\
|C1=\n\
|A2=\n\
|B2=\n\
|C2=\n\
|A3=\n\
|B3=\n\
|C3=\n\
|Output= |OA=",
'post': "\n}}"
}
}
}
}
} );
// [[Template:Grid/Crafting Table]] for complicated crafting recipes
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'group': 'craftingtemplates',
'tools': {
'block': {
label: 'Full Crafting Table',
type: 'button',
icon: '/images/7/79/Grid_Crafting_Table.png',
filters: [ 'body.ns-0' ], //Namespaceless things only -  100, 102, 104 could also fit in
action: {
type: 'encapsulate',
options: {
'pre':
"{{\
Grid/Crafting Table\n\
|A1= |A1-link= |A1-image=\n\
|B1= |B1-link= |B1-image=\n\
|C1= |C1-link= |C1-image=\n\
|A2= |A2-link= |A2-image=\n\
|B2= |B2-link= |B2-image=\n\
|C2= |C2-link= |C2-image=\n\
|A3= |A3-link= |A3-image=\n\
|B3= |B3-link= |B3-image=\n\
|C3= |C3-link= |C3-image=\n\
|Output= |OA=",
'post': "\n}}"
}
}
}
}
} );
// [[Template:Grid/Furnace]] for simple furnace recipes
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'group': 'craftingtemplates',
'tools': {
'block': {
label: 'Furnace', //Ex "Simple Furnace"
type: 'button',
icon: '/images/2/2e/Grid_Furnace.png',
filters: [ 'body.ns-0' ], //Namespaceless things only -  100, 102, 104 could also fit in
action: {
type: 'encapsulate',
options: {
'pre':
"{{\
Grid/Furnace\n\
|Input=\n\
|Output=\n\
|Fuel=\n\
|Break=\n\
}}",
'post': "\n}}"
}
}
}
}
} );
// [[Template:Grid/Furnace]] for complicated furnace recipes
/*
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'templates',
'group': 'craftingtemplates',
'tools': {
'block': {
label: 'Full Furnace',
type: 'button',
icon: '/images/2/2e/Grid_Furnace.png',
filters: [ 'body.ns-0' ], //Namespaceless things only -  100, 102, 104 could also fit in
action: {
type: 'encapsulate',
options: {
'pre':
"{{\
Grid/Furnace\n\
|Input=  |IA= \n\
|Output= |OA= \n\
|Fuel=  |FA= \n\
}}",
'post': "\n}}"
}
}
}
}
} );*/
};
 
/* 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 );
} );
}
} );
}

Latest revision as of 10:15, 5 June 2015

/******************************************
 * Page Edit Bar Improver                 *
 *****************************************/
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
			}
		}
	} );
	
 	// Infoboxes header
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'templates',
		'groups': {
			'infoboxes': {
				'label': 'Infoboxes' // or use labelMsg for a localized label, see above
			}
		}
	} );
 
	// [[Template:Block]] for blocks
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'templates',
		'group': 'infoboxes',
		'tools': {
			'block': {
				label: 'Block Infobox',
				type: 'button',
				icon: '/images/a/a6/Grid_Stone.png',
				filters: [ 'body.ns-0' ], //Namespaceless things only -  100, 102, 104 could also fit in
				action: {
					type: 'encapsulate',
					options: {
						'pre':
"<onlyinclude>{{\
{{{1|Block}}}\n\
|title=\n\
|image=\n\
|image2=\n\
|image3=\n\
|invimage=\n\
|invimage2=\n\
|invimage3=\n\
|invimage4=\n\
|type=\n\
|dirt=\n\
|maxeu=\n\
|storage=\n\
|eu_use=\n\
|eu_use2=\n\
|tool=\n\
|stackable=\n\
|data=\n\
|fluidspeed=\n\
|movespeed=",
						'post': "\n}}</onlyinclude>"
					}
				}
			}
		}
	} );

	//[[Template:Userinfo]]
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'templates',
		'group': 'infoboxes',
		'tools': {
			'user': {
				label: 'User Infobox',
				type: 'button',
				icon: '/images/a/a6/Grid_Stone.png',
				filters: [ 'body.ns-2' ], //User namespaces only
				action: {
					type: 'encapsulate',
					options: {
						'pre': "{{\
UserInfo\n\
|width=\n\
|user-avatar=\n\
|user-ig=\n\
|section1=\n\
|stat1=|value1=\n\
|section2=\n\
|stat2=|value2=\n\
|section3=\n\
|stat3=|value3=\n\
|section4=\n\
|stat4=|value4=\n\
|section5=\n\
|stat5=|value5=\n\
|section6=\n\
|stat6=|value6=\n\
|section7=\n\
|stat7=|value7=\n\
|section8=\n\
|stat8=|value8=\n\
|section9=\n\
|stat9=|value9=",
						'post': "\n}}"
					}
				}
			}
		}
	} );

	// Solution for items
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'templates',
		'group': 'infoboxes',
		'tools': {
			'item': {
				label: 'Item Infobox',
				type: 'button',
				icon: '/images/e/e9/Grid_Stick.png',
				filters: [ 'body.ns-0' ], //Namespaceless things only -  100, 102, 104 could also fit in
				action: {
					type: 'encapsulate',
					options: {
						'peri': "<!-- We don't have one ;) -->"
						}
					}
				}
			}
	}   );
	
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'templates',
		'groups': {
			'craftingtemplates': {
				'label': 'Crafting Grids' // or use labelMsg for a localized label, see above
			}
		}
	} );
	
	// [[Template:Grid/Crafting Table]] for simple crafting recipes
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'templates',
		'group': 'craftingtemplates',
		'tools': {
			'block': {
				label: 'Simple Crafting Table',
				type: 'button',
				icon: '/images/7/79/Grid_Crafting_Table.png',
				filters: [ 'body.ns-0' ], //Namespaceless things only -  100, 102, 104 could also fit in
				action: {
					type: 'encapsulate',
					options: {
						'pre':
"{{\
Grid/Crafting Table\n\
|A1=\n\
|B1=\n\
|C1=\n\
|A2=\n\
|B2=\n\
|C2=\n\
|A3=\n\
|B3=\n\
|C3=\n\
|Output= |OA=",
						'post': "\n}}"
					}
				}
			}
		}
	} );
	
	// [[Template:Grid/Crafting Table]] for complicated crafting recipes
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'templates',
		'group': 'craftingtemplates',
		'tools': {
			'block': {
				label: 'Full Crafting Table',
				type: 'button',
				icon: '/images/7/79/Grid_Crafting_Table.png',
				filters: [ 'body.ns-0' ], //Namespaceless things only -  100, 102, 104 could also fit in
				action: {
					type: 'encapsulate',
					options: {
						'pre':
"{{\
Grid/Crafting Table\n\
|A1= |A1-link= |A1-image=\n\
|B1= |B1-link= |B1-image=\n\
|C1= |C1-link= |C1-image=\n\
|A2= |A2-link= |A2-image=\n\
|B2= |B2-link= |B2-image=\n\
|C2= |C2-link= |C2-image=\n\
|A3= |A3-link= |A3-image=\n\
|B3= |B3-link= |B3-image=\n\
|C3= |C3-link= |C3-image=\n\
|Output= |OA=",
						'post': "\n}}"
					}
				}
			}
		}
	} );
	
	// [[Template:Grid/Furnace]] for simple furnace recipes
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'templates',
		'group': 'craftingtemplates',
		'tools': {
			'block': {
				label: 'Furnace', //Ex "Simple Furnace"
				type: 'button',
				icon: '/images/2/2e/Grid_Furnace.png',
				filters: [ 'body.ns-0' ], //Namespaceless things only -  100, 102, 104 could also fit in
				action: {
					type: 'encapsulate',
					options: {
						'pre':
"{{\
Grid/Furnace\n\
|Input=\n\
|Output=\n\
|Fuel=\n\
|Break=\n\
}}",
						'post': "\n}}"
					}
				}
			}
		}
	} );
	
	// [[Template:Grid/Furnace]] for complicated furnace recipes
	/*
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'templates',
		'group': 'craftingtemplates',
		'tools': {
			'block': {
				label: 'Full Furnace',
				type: 'button',
				icon: '/images/2/2e/Grid_Furnace.png',
				filters: [ 'body.ns-0' ], //Namespaceless things only -  100, 102, 104 could also fit in
				action: {
					type: 'encapsulate',
					options: {
						'pre':
"{{\
Grid/Furnace\n\
|Input=  |IA= \n\
|Output= |OA= \n\
|Fuel=   |FA= \n\
}}",
						'post': "\n}}"
					}
				}
			}
		}
	} );*/
	
};

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