MediaWiki:Common.js

Revision as of 07:57, 7 December 2021 by Pavel Malakhov (addition | contribs) (+Page)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

mw.loader.using('common.site.styles');

/** -pm- WikiEditor additional features**/
var customizeToolbar = function () {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"underline": {
			label: 'Underline',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/f/fd/Button_underline.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "<u>",
					post: "</u>"
				}
			}
		},
		"double_underline": {
			label: 'Double underline',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/4/45/Button_double.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{Style S-Double underline|",
					post: "}}"
				}
			}
		},
		"justify-center": {
			label: 'Centered',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/5/5f/Button_center.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "<center>",
					post: "</center>"
				}
			}
		},
		"justify-right": {
			label: 'Allign to the right',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/a/a5/Button_align_right.png',
			action: { 
				type: 'encapsulate',
				options: {
					pre: "{{Стиль А-Текст справа|",
					post: "}}"
				}
			}
		},
		"category": {
			label: 'Category',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c4/Toolbar_category.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "[[Category: ",
					post: "]]"
				}
			}
		},
			"dash": {
			label: 'Dash',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/cd/Button_mdash.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "–",
					post: ""
				}
			}
		}
}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	section: 'main',
	groups: {
		list: {
			tools: {
				templatesP: {
					label: 'Paragraph styles',
					type: 'select',
					list: {
						'Style-P-Article-separator': {label: 'Article separator', action: {type: 'encapsulate',
							options: {pre: '{{Style P-HPB SB. Article separator', post: '}}'} } },
						'Style-P-Title': {label: 'Title', action: {type: 'encapsulate',
							options: {pre: '{{Style P-Title|', post: '}}'} } },
						'Style-P-Subtitle': {label: 'Subtitle', action: {type: 'encapsulate',
							options: {pre: '{{Style P-Subtitle|', post: '}}'} } },
						'Style-P-Epigraph': {label: 'Epigraph', action: {type: 'encapsulate',
							options: {pre: '{{Style P-Epigraph|', post: '||}}'} } },
						'Style-P-Quote': {label: 'Quote', action: {type: 'encapsulate',
							options: {pre: '{{Style P-Quote|', post: '}}'} } },
						'Style-P-Page': {label: 'Page', action: {type: 'encapsulate',
							options: {pre: '{{Page|', post: '|}}'} } },
						'Style-P-Poem': {label: 'Poem', action: {type: 'encapsulate',
							options: {pre: '{{Style P-Poem|poem=', post: '|signature=}}'} } },
						'Style-P-Signature': {label: 'Signature', action: {type: 'encapsulate',
							options: {pre: '{{Style P-Signature|', post: '}}'} } },
						'Style-P-Signature-caps': {label: 'Signature in capitals', action: {type: 'encapsulate',
							options: {pre: '{{Style P-Signature in capitals|', post: '}}'} } },
						'Style-P-Align-right': {label: 'Align right', action: {type: 'encapsulate',
							options: {pre: '{{Style P-Align right|', post: '}}'} } },
						'Style-P-HPB-SB-Title-continued': {label: 'HPB SB. Title continued', action: {type: 'encapsulate',
							options: {pre: '{{Style P-HPB SB. Title continued|', post: '|1-}}'} } },
						'Style-P-HPB-SB-Object-title': {label: 'HPB SB. Object title', action: {type: 'encapsulate',
							options: {pre: '{{Style P-HPB SB. Object title|', post: '}}'} } }
					}
				},
				templatesS: {
					label: 'Symbol styles',
					type: 'select',
					list: {
						'Style-S-Small-capitals': {label: 'Small capitals', action: {type: 'encapsulate',
							options: {pre: '{{Style S-Small capitals|', post: '}}'} } },
						'Style-S-Double-underline': {label: 'Double underline', action: {type: 'encapsulate',
							options: {pre: '{{Style S-Double underline|', post: '}}'} } },
						'Style-S-Dialog-speaker': {label: 'Dialog speaker', action: {type: 'encapsulate',
							options: {pre: '{{Style S-Dialog speaker|', post: '}}'} } },
						'Style-S-HPB-SB-HPB-note': {label: 'HPB SB. HPB note', action: {type: 'encapsulate',
							options: {pre: '{{Style S-HPB SB. HPB note|', post: '|center}}'} } },
						'Style-S-HPB-SB-HPB-underlined': {label: 'HPB SB. HPB underlined', action: {type: 'encapsulate',
							options: {pre: '{{Style S-HPB SB. HPB underlined|', post: '}}'} } },
						'Style-S-HPB-SB-HPB-crossed-out': {label: 'HPB SB. HPB crossed out', action: {type: 'encapsulate',
							options: {pre: '{{Style S-HPB SB. HPB crossed out|', post: '}}'} } },
						'Style-S-HPB-SB-Archivist-note': {label: 'HPB SB. Archivist note', action: {type: 'encapsulate',
							options: {pre: '{{Style S-HPB SB. Archivist note|', post: '|center}}'} } },
						'Style-S-HPB-SB-Editors-note': {label: 'HPB SB. Editors note', action: {type: 'encapsulate',
							options: {pre: '{{Style S-HPB SB. Editors note|', post: '|center}}'} } },
						'Style-S-HPB-SB-Continues-on': {label: 'HPB SB. Continues on', action: {type: 'encapsulate',
							options: {pre: '{{Style S-HPB SB. Continues on|1-', post: '}}'} } },
						'Style-S-HPB-SB-Lost': {label: 'HPB SB. Lost', action: {type: 'encapsulate',
							options: {pre: '{{Style S-HPB SB. Lost|', 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' ).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 );
		}
	} );
}