MediaWiki:Common.js: Difference between revisions

From Teopedia
mNo edit summary
mNo edit summary
(33 intermediate revisions by the same user not shown)
Line 3: Line 3:
mw.loader.using('common.site.styles');
mw.loader.using('common.site.styles');


/** -pm- WikiEditor additional features**/
/** -pm- WikiEditor additional features **/
/** list of images: https://www.mediawiki.org/wiki/User:24pm/Icons **/
var customizeToolbar = function () {
var customizeToolbar = function () {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
Line 9: Line 10:
group: 'format',
group: 'format',
tools: {
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: "}}"
}
}
},
"strike_out": {
label: 'Strike out',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/c/c9/Button_strike.png',
action: {
type: 'encapsulate',
options: {
pre: "<s>",
post: "</s>"
}
}
},
"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: "{{Style P-Align right|",
post: "}}"
}
}
},
"no_indent": {
label: 'No indent for first line',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/2/29/Button_justify.png',
action: {
type: 'encapsulate',
options: {
pre: "{{Style P-No indent|",
post: "}}"
}
}
},
"columns": {
label: 'Slit text on columns',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/0/04/Button_multicol.png',
action: {
type: 'encapsulate',
options: {
pre: "{{Columns start|2|width=|font size=}}",
post: "{{Columns end}}"
}
}
},
"category": {
"category": {
label: 'Category',
label: 'Category',
Line 18: Line 103:
pre: "[[Category: ",
pre: "[[Category: ",
post: "]]"
post: "]]"
}
}
},
"nbsp": {
label: 'Not breakable space',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/6/64/Button_nbsp_bold.png',
action: {
type: 'encapsulate',
options: {
pre: "&nbsp;",
post: ""
}
}
},
"dash": {
label: 'Dash',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/c/cd/Button_mdash.png',
action: {
type: 'encapsulate',
options: {
pre: "–",
post: ""
}
}
},
"vertical_space": {
label: 'Vertical space (paragraph indent), default 1em',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/7/71/TableCell.png',
action: {
type: 'encapsulate',
options: {
pre: "{{Vertical space|",
post: "}}"
}
}
},
"small_capitals": {
label: 'Small capitals',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/8/89/Button_bigger.png',
action: {
type: 'encapsulate',
options: {
pre: "{{Style S-Small capitals|",
post: "}}"
}
}
},
"quot_main": {
label: 'Main quotation marks',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/1/18/Button_quotes_2.png',
action: {
type: 'encapsulate',
options: {
pre: "“",
post: "”"
}
}
}
}
}
}
}
}
} );
} );


Line 30: Line 175:
tools: {
tools: {
templatesP: {
templatesP: {
label: 'Paragraph styles',
label: 'Paragraph',
type: 'select',
type: 'select',
list: {
list: {
Line 43: Line 188:
'Style-P-Quote': {label: 'Quote', action: {type: 'encapsulate',
'Style-P-Quote': {label: 'Quote', action: {type: 'encapsulate',
options: {pre: '{{Style P-Quote|', post: '}}'} } },
options: {pre: '{{Style P-Quote|', post: '}}'} } },
'Style-P-Page': {label: 'Page', action: {type: 'encapsulate',
options: {pre: '{{Page|', post: '|}}'} } },
'Style-P-Page-aside': {label: 'Page aside', action: {type: 'encapsulate',
options: {pre: '{{Page aside|', post: '}}'} } },
'Style-P-Page-aside-continues': {label: 'Page aside continues', action: {type: 'encapsulate',
options: {pre: '{{Page aside continues|', post: '}}'} } },
'Style-P-Poem': {label: 'Poem', action: {type: 'encapsulate',
'Style-P-Poem': {label: 'Poem', action: {type: 'encapsulate',
options: {pre: '{{Style P-Poem|poem=|', post: '|signature=}}'} } },
options: {pre: '{{Style P-Poem|poem=', post: '}}'} } },
'Style-P-Signature': {label: 'Signature', action: {type: 'encapsulate',
'Style-P-Signature': {label: 'Signature', action: {type: 'encapsulate',
options: {pre: '{{Style P-Signature|', post: '}}'} } },
options: {pre: '{{Style P-Signature|', post: '}}'} } },
'Style-P-Signature-caps': {label: 'Signature in capitals', action: {type: 'encapsulate',
'Style-P-Signature-caps': {label: 'Signature in capitals', action: {type: 'encapsulate',
options: {pre: '{{Style P-Signature in capitals|', post: '}}'} } },
options: {pre: '{{Style P-Signature in capitals|', post: '}}'} } },
'Style-P-Align-right': {label: 'Align right', action: {type: 'encapsulate',
'Close-DIV': {label: 'Close div', action: {type: 'encapsulate',
options: {pre: '{{Style P-Align right|', post: '}}'} } },
options: {pre: '{{Close div}}'} } }
'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: {
templatesS: {
label: 'Symbol styles',
label: 'Symbol',
type: 'select',
type: 'select',
list: {
list: {
'Style-S-Small-capitals': {label: 'Small capitals', action: {type: 'encapsulate',
'Style-S-Hebrew': {label: 'Text in Hebrew', action: {type: 'encapsulate',
options: {pre: '{{Style S-Small capitals|', post: '}}'} } },
options: {pre: '{{Style S-Hebrew|', post: '}}'} } },
'Style-S-Double-underline': {label: 'Double underline', action: {type: 'encapsulate',
'Style-S-Lost': {label: 'Lost fragment', action: {type: 'encapsulate',
options: {pre: '{{Style S-Double underline|', post: '}}'} } },
options: {pre: '{{Style S-Lost|', post: '}}'} } },
'Style-S-Dialog-speaker': {label: 'Dialog speaker', action: {type: 'encapsulate',
'Footnote-Mark': {label: 'Footnote mark', action: {type: 'encapsulate',
options: {pre: '{{Style S-Dialog speaker|', post: '}}'} } },
options: {pre: '{{Footnote mark|', post: '|}}'} } },
'Footnote-Return': {label: 'Footnote return', action: {type: 'encapsulate',
options: {pre: '{{Footnote return|', post: '}}'} } },
'Footnote-Text': {label: 'Footnote text', action: {type: 'encapsulate',
options: {pre: '{{Footnotes start}}\n{{Footnote return|}}', post: '\n{{Footnotes end}}'} } }
}
},
templatesHPB: {
label: 'HPB',
type: 'select',
list: {
'UI-page': {label: 'UI. Page', action: {type: 'encapsulate',
options: {pre: '{{IU-page|v=1|p=', post: '|title=}}'} } },
'SD-correction': {label: 'SD. Correction', action: {type: 'encapsulate',
options: {pre: '{{SD-correction|text=', post: '|edition1=|note=}}'} } },
'HPB-CW-comment': {label: 'CW. Comment', action: {type: 'encapsulate',
options: {pre: '{{HPB-CW-comment|', post: '}}'} } },
'HPB-CW-separator': {label: 'CW. Separator', action: {type: 'encapsulate',
options: {pre: '{{HPB-CW-separator', post: '}}'} } },
'Style-S-HPB-SB-HPB-note': {label: 'HPB SB. HPB note', action: {type: 'encapsulate',
'Style-S-HPB-SB-HPB-note': {label: 'HPB SB. HPB note', action: {type: 'encapsulate',
options: {pre: '{{Style S-HPB SB. HPB note|', post: '|center}}'} } },
options: {pre: '{{Style S-HPB SB. HPB note|', post: '|center}}'} } },
'Style-S-HPB-SB-HPB-highlighted': {label: 'HPB SB. HPB highlighted', action: {type: 'encapsulate',
options: {pre: '{{Style S-HPB SB. HPB highlighted|', post: '}}'} } },
'Style-S-HPB-SB-HPB-underlined': {label: 'HPB SB. HPB underlined', action: {type: 'encapsulate',
'Style-S-HPB-SB-HPB-underlined': {label: 'HPB SB. HPB underlined', action: {type: 'encapsulate',
options: {pre: '{{Style S-HPB SB. HPB underlined|', post: '}}'} } },
options: {pre: '{{Style S-HPB SB. HPB underlined|', post: '}}'} } },
Line 77: Line 244:
'Style-S-HPB-SB-Editors-note': {label: 'HPB SB. Editors note', action: {type: 'encapsulate',
'Style-S-HPB-SB-Editors-note': {label: 'HPB SB. Editors note', action: {type: 'encapsulate',
options: {pre: '{{Style S-HPB SB. Editors note|', post: '|center}}'} } },
options: {pre: '{{Style S-HPB SB. Editors note|', post: '|center}}'} } },
'Style-S-Restored': {label: 'HPB SB. Restored', action: {type: 'encapsulate',
options: {pre: '{{Style S-HPB SB. Restored}}', post: '{{Close div}}'} } },
'HPB-SB-footer-footnotes': {label: 'HPB SB. Footnotes', action: {type: 'encapsulate',
options: {pre: '{{HPB-SB-footer-footnotes}}', post: ''} } },
'HPB-SB-footer-sources': {label: 'HPB SB. Sources', action: {type: 'encapsulate',
options: {pre: '{{HPB-SB-footer-sources}}\n<gallery widths=200px heights=200px>\n', post: 'file.pdf|page=9|Description\n</gallery>'} } },
'Style-S-HPB-SB-Continues-on': {label: 'HPB SB. Continues on', action: {type: 'encapsulate',
'Style-S-HPB-SB-Continues-on': {label: 'HPB SB. Continues on', action: {type: 'encapsulate',
options: {pre: '{{Style S-HPB SB. Continues on|1-', post: '}}'} } },
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: '}}'} } }
},
templatesLinks: {
label: 'Links',
type: 'select',
list: {
'BCW-page': {label: 'BCW page', action: {type: 'encapsulate',
options: {pre: '{{BCW-page|v=|p=|text=', post: '}}'} } },
'SB-page': {label: 'SB page', action: {type: 'encapsulate',
options: {pre: '{{SB-page|v=|p=|text=', post: '}}'} } },
'SD-page': {label: 'SD page', action: {type: 'encapsulate',
options: {pre: '{{SD-page|v=|p=|ed=|text=', post: '}}'} } }
}
}
}
}

Revision as of 03:11, 18 March 2024

/* Any JavaScript here will be loaded for all users on every page load. */

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

/** -pm- WikiEditor additional features **/
/** list of images: https://www.mediawiki.org/wiki/User:24pm/Icons **/
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: "}}"
				}
			}
		},
		"strike_out": {
			label: 'Strike out',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c9/Button_strike.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "<s>",
					post: "</s>"
				}
			}
		},
		"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: "{{Style P-Align right|",
					post: "}}"
				}
			}
		},
		"no_indent": {
			label: 'No indent for first line',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/2/29/Button_justify.png',
			action: { 
				type: 'encapsulate',
				options: {
					pre: "{{Style P-No indent|",
					post: "}}"
				}
			}
		},
		"columns": {
			label: 'Slit text on columns',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/0/04/Button_multicol.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{Columns start|2|width=|font size=}}",
					post: "{{Columns end}}"
				}
			}
		},
		"category": {
			label: 'Category',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/c4/Toolbar_category.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "[[Category: ",
					post: "]]"
				}
			}
		},
		"nbsp": {
			label: 'Not breakable space',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/6/64/Button_nbsp_bold.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "&nbsp;",
					post: ""
				}
			}
		},
		"dash": {
			label: 'Dash',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/c/cd/Button_mdash.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "–",
					post: ""
				}
			}
		},
		"vertical_space": {
			label: 'Vertical space (paragraph indent), default 1em',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/7/71/TableCell.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{Vertical space|",
					post: "}}"
				}
			}
		},
		"small_capitals": {
			label: 'Small capitals',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/8/89/Button_bigger.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{Style S-Small capitals|",
					post: "}}"
				}
			}
		},
		"quot_main": {
			label: 'Main quotation marks',
			type: 'button',
			icon: '//upload.wikimedia.org/wikipedia/commons/1/18/Button_quotes_2.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "“",
					post: "”"
				}
			}
		}
}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	section: 'main',
	groups: {
		list: {
			tools: {
				templatesP: {
					label: 'Paragraph',
					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-Page-aside': {label: 'Page aside', action: {type: 'encapsulate',
							options: {pre: '{{Page aside|', post: '}}'} } },
						'Style-P-Page-aside-continues': {label: 'Page aside continues', action: {type: 'encapsulate',
							options: {pre: '{{Page aside continues|', post: '}}'} } },
						'Style-P-Poem': {label: 'Poem', action: {type: 'encapsulate',
							options: {pre: '{{Style P-Poem|poem=', post: '}}'} } },
						'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: '}}'} } },
						'Close-DIV': {label: 'Close div', action: {type: 'encapsulate',
							options: {pre: '{{Close div}}'} } }
					}
				},
				templatesS: {
					label: 'Symbol',
					type: 'select',
					list: {
						'Style-S-Hebrew': {label: 'Text in Hebrew', action: {type: 'encapsulate',
							options: {pre: '{{Style S-Hebrew|', post: '}}'} } },
						'Style-S-Lost': {label: 'Lost fragment', action: {type: 'encapsulate',
							options: {pre: '{{Style S-Lost|', post: '}}'} } },
						'Footnote-Mark': {label: 'Footnote mark', action: {type: 'encapsulate',
							options: {pre: '{{Footnote mark|', post: '|}}'} } },
						'Footnote-Return': {label: 'Footnote return', action: {type: 'encapsulate',
							options: {pre: '{{Footnote return|', post: '}}'} } },
						'Footnote-Text': {label: 'Footnote text', action: {type: 'encapsulate',
							options: {pre: '{{Footnotes start}}\n{{Footnote return|}}', post: '\n{{Footnotes end}}'} } }
					}
				},
				templatesHPB: {
					label: 'HPB',
					type: 'select',
					list: {
						'UI-page': {label: 'UI. Page', action: {type: 'encapsulate',
							options: {pre: '{{IU-page|v=1|p=', post: '|title=}}'} } },
						'SD-correction': {label: 'SD. Correction', action: {type: 'encapsulate',
							options: {pre: '{{SD-correction|text=', post: '|edition1=|note=}}'} } },
						'HPB-CW-comment': {label: 'CW. Comment', action: {type: 'encapsulate',
							options: {pre: '{{HPB-CW-comment|', post: '}}'} } },
						'HPB-CW-separator': {label: 'CW. Separator', action: {type: 'encapsulate',
							options: {pre: '{{HPB-CW-separator', 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-highlighted': {label: 'HPB SB. HPB highlighted', action: {type: 'encapsulate',
							options: {pre: '{{Style S-HPB SB. HPB highlighted|', post: '}}'} } },
						'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-Restored': {label: 'HPB SB. Restored', action: {type: 'encapsulate',
							options: {pre: '{{Style S-HPB SB. Restored}}', post: '{{Close div}}'} } },
						'HPB-SB-footer-footnotes': {label: 'HPB SB. Footnotes', action: {type: 'encapsulate',
							options: {pre: '{{HPB-SB-footer-footnotes}}', post: ''} } },
						'HPB-SB-footer-sources': {label: 'HPB SB. Sources', action: {type: 'encapsulate',
							options: {pre: '{{HPB-SB-footer-sources}}\n<gallery widths=200px heights=200px>\n', post: 'file.pdf|page=9|Description\n</gallery>'} } },
						'Style-S-HPB-SB-Continues-on': {label: 'HPB SB. Continues on', action: {type: 'encapsulate',
							options: {pre: '{{Style S-HPB SB. Continues on|1-', post: '}}'} } }
					}
				},
				templatesLinks: {
					label: 'Links',
					type: 'select',
					list: {
						'BCW-page': {label: 'BCW page', action: {type: 'encapsulate',
							options: {pre: '{{BCW-page|v=|p=|text=', post: '}}'} } },
						'SB-page': {label: 'SB page', action: {type: 'encapsulate',
							options: {pre: '{{SB-page|v=|p=|text=', post: '}}'} } },
						'SD-page': {label: 'SD page', action: {type: 'encapsulate',
							options: {pre: '{{SD-page|v=|p=|ed=|text=', 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 );
		}
	} );
}