User:Ruthven/MyGadget-toolbar.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.
var customizeToolbar = function () {
	/* Your code goes here */
	// Add a section
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'sections': {
		'sec-templates': {
			'type': 'toolbar', // Can also be 'booklet'
			'label': 'Templates'
			// or 'labelMsg': 'section-emoticons-label' for a localized label
		}
	}
	} );
	// Add a group to an existing toolbar section
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'sec-templates',
	'groups': {
		'gr-utilities': {
			'label': 'Utils' // or use labelMsg for a localized label, see above
		}
	}
	} );
	// Add a tool
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'sec-templates',
		'group': 'gr-utilities',
		'tools': {
			'consent': {
				label: 'Consent', // or use labelMsg for a localized label, see above
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/thumb/a/a6/Gruener_Punkt.svg/22px-Gruener_Punkt.svg.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{consent}}" // text to be inserted
					}
				}
			}
		}
	} );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'sec-templates',
		'group': 'gr-utilities',
		'tools': {
			'consent': {
				label: 'Personality rights', // or use labelMsg for a localized label, see above
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/thumb/0/06/Ping_fm.svg/24px-Ping_fm.svg.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{personality rights}}" // text to be inserted
					}
				}
			}
		}
	} );	
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'sec-templates',
		'group': 'gr-utilities',
		'summary': 'added Italy MiBAC disclaimer ', 
		'tools': {
			'consent': {
				label: 'MiBAC', // or use labelMsg for a localized label, see above
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/thumb/9/97/Italy_cockade.svg/24px-Italy_cockade.svg.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{Italy-MiBAC-disclaimer}}" // text to be inserted
					}
				}
			}
		}
	} );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'sec-templates',
		'group': 'gr-utilities',
		'summary': 'de minimis',
		'tools': {
			'consent': {
				label: 'De minimis', // or use labelMsg for a localized label, see above
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/thumb/f/f7/Commons-emblem-restricted-permission.svg/22px-Commons-emblem-restricted-permission.svg.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{De minimis}}" // text to be inserted
					}
				}
			}
		}
	} );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'sec-templates',
		'group': 'gr-utilities',
		'summary': 'PD-Italy',
		'tools': {
			'consent': {
				label: 'PD italy', // or use labelMsg for a localized label, see above
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/thumb/a/ac/Printable_Flag_of_Italy.svg/28px-Printable_Flag_of_Italy.svg.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{PD-Italy}}{{PD-1996}}" // text to be inserted
					}
				}
			}
		}
	} );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'sec-templates',
		'group': 'gr-utilities',
		'summary': '+watermarked ',
		'tools': {
			'consent': {
				label: 'Watermark', // or use labelMsg for a localized label, see above
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/thumb/9/9c/Round_Landmark_Icon_Ocean.svg/22px-Round_Landmark_Icon_Ocean.svg.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{Watermarked}}" // text to be inserted
					}
				}
			}
		}
	} );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'sec-templates',
		'group': 'gr-utilities',
		'tools': {
			'consent': {
				label: 'Date', // or use labelMsg for a localized label, see above
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Icons8_flat_overtime.svg/24px-Icons8_flat_overtime.svg.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{subst:"+"#time: Y-m-d}}"
					}
				}
			}
		}
	} );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'sec-templates',
		'group': 'gr-utilities',
		'tools': {
			'consent': {
				label: 'License review', // or use labelMsg for a localized label, see above
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Examine_copyright_icon.svg/32px-Examine_copyright_icon.svg.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{Licensereview}}" // text to be inserted
					}
				}
			}
		}
	} );	
};

/* 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' ).then( 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( customizeToolbar );
		}
	} );
}