User:Ivanhercaz/common.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
mw.loader.load('//commons.wikimedia.org/w/index.php?title=User:Ivanhercaz/toolbarPlus.js&action=raw&ctype=text/javascript');

var toolbarPlus = function() {
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'format',
        'tools': {
    		'categoria': {
				label: 'Nueva categoria',
				filters: [ 'body.ns-14' ],
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/6/64/Add_category_toolbar_button.svg',
				action: {
					type: 'encapsulate',
					options: {
						pre: "[[{{",
                        peri: "SUBST:ns:14}}:",
                        post: "]]"
					}
				}
			},
			'BIC': {
				label: 'BIC',
				filters: [ 'body.ns-14' ],
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/3/33/Mw-unwatch-icon.svg',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{BIC|",
                        //peri: "SUBST:ns:14}}:",
                        post: "}}"
					}
				}
			},
			'credit': {
				label: 'credit',
				filters: [ 'body.ns-6' ],
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/1/1d/Camera_aabb.svg',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{User:Ivanhercaz/credit",
                                                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 () {
		// This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
		if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor' ), $.ready
			).then( toolbarPlus );
		}
	} );
}
// Add the customizations to LiquidThreads' edit toolbar, if available
mw.hook( 'ext.lqt.textareaCreated' ).add( toolbarPlus );