MediaWiki: Common.js

From trvlpedia
Jump to: navigation, search
var customizeToolbar = function () {
	
	$( '#wpTextbox1').wikiEditor( 'removeFromToolbar', {
		'section': 'advanced',
		'group': 'format',
		'tool': 'olist'
	});

	$( '#wpTextbox1').wikiEditor( 'removeFromToolbar', {
		'section': 'advanced',
		'group': 'format',
		'tool': 'ulist'
	});

	$( '#wpTextbox1').wikiEditor( 'removeFromToolbar', {
		'section': 'advanced',
		'group': 'insert',
	});

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'main',
		'group': 'format',
		'tools': {
			'listitem': {
				label: 'List Item',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/a/a4/H-line_icon.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "<li>",
						peri: "List Item",
						post: "</li>",
						ownline:true
					}
				}
			}
		}
	});

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'advanced',
		'group': 'format',
		'tools': {
			'listitem': {
				label: 'Link',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/9/97/Button_int_link.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{Link|",
						peri: "Page",
						post: "}}",
					}
				}
			}
		}
	});

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'advanced',
		'group': 'format',
		'tools': {
			'listitem': {
				label: 'Bullet List',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/1/11/Btn_toolbar_liste.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: '<ul class="bulletlist">',
						ownline: true
					}
				}
			}
		}
	});

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'advanced',
		'group': 'format',
		'tools': {
			'listitem': {
				label: 'Image',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/d/de/Button_image.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: '{{Image|',
						peri: 'NoImage.jpg',
						post: "}}",
						ownline: true
					}
				}
			}
		}
	});

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'advanced',
		'group': 'format',
		'tools': {
			'listitem': {
				label: 'Blockquote',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/2/23/Quotes-Lithuanian.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: '<blockquote>',
						peri: 'Blurb',
						post: "</blockquote>",
						ownline: true
					}
				}
			}
		}
	});

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'advanced',
		'group': 'format',
		'tools': {
			'listitem': {
				label: 'Label',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/d/d3/Button_definition_list.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{Label",
						peri: "|label",
						post: "}}",
					}
				}
			}
		}
	});

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'advanced',
		'group': 'format',
		'tools': {
			'listitem': {
				label: 'CardItem',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/7/78/Button_titre.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{CardItem",
						peri: "cardname",
						post: "}}",
					}
				}
			}
		}
	});

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'advanced',
		'group': 'format',
		'tools': {
			'listitem': {
				label: 'Card',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/9/98/Marco1.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{Card|",
						peri: "cardname",
						post: "|only}}",
					}
				}
			}
		}
	});

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'advanced',
		'group': 'format',
		'tools': {
			'listitem': {
				label: 'Article Page',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/1/11/Button_source_jv.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{ArticlePage|Hotel Strategies}} {{Image|NoImage.jpg|full}} {{ArticleBefore}}",
						post: "{{ArticleAfter}} {{NextPage|xxx}} {{/ArticlePage}}",
						ownline: true
					}
				}
			}
		}
	});

};

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