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

From Industrial-Craft-Wiki
Jump to navigation Jump to search
m (Uhhhhh...)
m (Added userbox and changed the layout to be nicer)
Line 33: Line 33:
type: 'button',
type: 'button',
icon: '/images/a/a6/Grid_Stone.png',
icon: '/images/a/a6/Grid_Stone.png',
filters: [ 'body.ns-0' ],
filters: [ 'body.ns-0' ], //Namespaceless things only -  100, 102, 104 could also fit in
action: {
action: {
type: 'encapsulate',
type: 'encapsulate',
options: {
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=",
'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>"
'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}}"
}
}
}
}

Revision as of 22:21, 21 February 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}}"
					}
				}
			}
		}
	} );
};

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

/******************************************
 * Tooltip Testing                        *
 *****************************************/
$(function() {
	var mc_tooltip = null;
 
	$(".a1, .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.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();
	    },
	});
});