User:Mpaa/vector.js

From Wikisource
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

//<source lang="javascript">
/* ProofreadPage extension specific */
self.layout_overrides_have_precedence = true;
/* Hebrew Fix ? - false seems to whack dynamic layouts */
//	self.proofreadpage_source_href = true;
//	self.proofreadpage_disable_ocr = true;
/* CharInsert specific */
//	window.charinsertDontMove = true;
//	window.charinsertMoveTop = true;
window.editToolsRecall = true;
window.charinsertCustom = {
	"User": '|  =  ⒜  {{+}}  [[+|]]  —  “+”  &#13;  ‽  ℩  <code><nowiki>+</nowiki></code>  {{hws|+|+}}  {{hwe|+|+}}  <section.begin="+"_/>  <section.end="+"_/> '
};
window.charinsertCustom = {
	"User1": '|  =  ⒜  {{+}}  [[+|]]  —  “+”  &#13;  ‽  ℩  <code><nowiki>+</nowiki></code>  {{hws|+|+}}  {{hwe|+|+}}  <section.begin="+"_/>  <section.end="+"_/> '
};
//	if(window.updateEditTools) window.updateEditTools();
/**
 * WikiEditor specific
 *
 * Custom buttons ONLY when Prefs set to - Enable enhanced editing toolbar - is selected,
 * Enable wizards for... - must not be selected. Show [old]edit toolbar - should be off.
 * based upon - https://github.com/he7d3r/mw-gadget-ExtraEditButtons
 */
var iconPathWE = mw.config.get( 'wgExtensionAssetsPath' ) + '/WikiEditor/modules/images/toolbar/';
var iconPathPRP = mw.config.get( 'wgExtensionAssetsPath' ) + '/ProofreadPage/modules/page/images/';
var fileNamespace = mw.config.get( 'wgFormattedNamespaces' )[6];
var customizeToolbar = function() {
$( '#wpTextbox1' )
//	.wikiEditor( 'removeFromToolbar', { 'section': 'help' } )
//	.wikiEditor( 'removeFromToolbar', { 'section': 'characters' } )
//	.wikiEditor( 'removeFromToolbar', { 'section': 'advanced' } )
	.wikiEditor( 'removeFromToolbar', { 'section': 'advanced', 'group': 'format', 'tool': 'nowiki' } )
	.wikiEditor( 'removeFromToolbar', { 'section': 'advanced', 'group': 'format', 'tool': 'newline' } )
	.wikiEditor( 'removeFromToolbar', { 'section': 'advanced', 'group': 'insert', 'tool': 'gallery' } )
	.wikiEditor( 'removeFromToolbar', { 'section': 'advanced', 'group': 'insert', 'tool': 'redirect' } )
	.wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'insert', 'tool': 'xlink' } )
	.wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'insert', 'tool': 'ilink' } )
	.wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'insert', 'tool': 'file' } )
	.wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'insert', 'tool': 'reference' } )
	.wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'insert', 'tool': 'signature' } )
	.wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'format', 'tool': 'italic' } )
	.wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'format', 'tool': 'bold' } );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'main',
		'group': 'format',
		'tools': {
			'bold': {
				'labelMsg': 'wikieditor-toolbar-tool-bold',
				'label': 'Bold',
				'id': 'bold',
				'filters': [ 'body:not(.ns-8, .ns-828)' ],
				'type': 'button',
				'icon': iconPathWE + 'format-bold-B.png',
				'offset': [2, -142],
				'action': {
					'type': 'encapsulate',
					'options': {
						'pre': "<b>",
						'periMsg': 'wikieditor-toolbar-tool-bold-example',
						'post': "</b>"
					}
				}
			},
			'italic': {
				'labelMsg': 'wikieditor-toolbar-tool-italic',
				'label': 'Italic',
				'id': 'italic',
				'filters': [ 'body:not(.ns-8, .ns-828)' ],
				'type': 'button',
				'icon': iconPathWE + 'format-italic-I.png',
				'offset': [2, -862],
				'action': {
					'type': 'encapsulate',
					'options': {
						'pre': "<i>",
						'periMsg': 'wikieditor-toolbar-tool-italic-example',
						'post': "</i>"
					}
				}
			},
			'underline': {
				'labelMsg': 'wikieditor-toolbar-tool-underline',
				'label': 'Underline',
				'id': 'underline',
				'filters': [ 'body:not(.ns-8, .ns-828)' ],
				'type': 'button',
				'icon': '//upload.wikimedia.org/wikipedia/commons/8/8b/Button_underline_he.png',
				'action': {
					'type': 'encapsulate',
					'options': {
						'pre': "<u>",
						'periMsg': 'wikieditor-toolbar-tool-underline-example',
						'post': "</u>"
					}
				}
			},
			'strikeout': {
				'labelMsg': 'wikieditor-toolbar-tool-strikeout',
				'label': 'Strike out',
				'id': 'strikeout',
				'filters': [ 'body:not(.ns-8, .ns-828)' ],
				'type': 'button',
				'icon': '//upload.wikimedia.org/wikipedia/commons/6/6d/Vector_strikeout.png',
				'action': {
					'type': 'encapsulate',
					'options': {
						'pre': "<s>",
						'periMsg': 'wikieditor-toolbar-tool-strikeout-example',
						'post': "</s>"
					}
				}
			},
			'newline': {
				'labelMsg': 'wikieditor-toolbar-tool-newline',
				'label': 'Break',
				'id': 'newline',
				'filters': [ 'body:not(.ns-8, .ns-828)' ],
				'type': 'button',
				'icon': '//upload.wikimedia.org/wikipedia/commons/f/f2/Button-br.png',
				'offset': [2, -1726],
				'action': {
					'type': 'replace',
					'options': {
						'peri': '<br />',
						'selectPeri': false
					}
				}
			},
			'emdash': {
				'labelMsg': 'wikieditor-toolbar-tool-emdash',
				'label': 'em-dash',
				'id': 'emdash',
				'filters': [ 'body:not(.ns-8, .ns-828)' ],
				'type': 'button',
				'icon': '//upload.wikimedia.org/wikipedia/commons/8/8b/Button_m-dash.png',
				'action': {
					'type': 'replace',
					'options': {
						'peri': '\u2014',
						'selectPeri': false
					}
				}
			},
			'togglelayout': {
				'labelMsg': 'wikieditor-toolbar-tool-togglelayout',
				'label': 'Vertical/horizontal layout',
				'id': 'togglelayout',
				'filters': [ 'body.ns-104' ],
				'type': 'button',
				'icon': iconPathPRP + 'Button_multicol.png',
				'action': {
					'type': 'callback',
					'execute': function() {
						     toggleLayout(context);
					}
				}
			}
		}
	} );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'main',
		'group': 'insert',
		'tools': {
			'ilink': {
				'labelMsg': 'wikieditor-toolbar-tool-ilink',
				'label': 'Wiki link',
				'id': 'ilink',
				'type': 'button',
				'icon': iconPathWE + 'insert-ilink.png',
				'offset': [2, -1582],
				'action': {
					'type': 'encapsulate',
					'options': {
						'pre': "[[",
						'periMsg': 'wikieditor-toolbar-tool-ilink-example',
						'post': "]]"
					}
				}
			},
			'xlink': {
				'labelMsg': 'wikieditor-toolbar-tool-xlink',
				'label': 'URL link',
				'id': 'xlink',
				'type': 'button',
				'icon': iconPathWE + 'insert-xlink.png',
				'offset': [-70, 2],
				'action': {
					'type': 'encapsulate',
					'options': {
						'pre': "[",
						'periMsg': 'wikieditor-toolbar-tool-xlink-example',
						'post': "]"
					}
				}
			},
			'nowiki': {
				'labelMsg': 'wikieditor-toolbar-tool-nowiki',
				'label': 'NoWiki',
				'id': 'nowiki',
				'type': 'button',
				'icon': iconPathWE + 'insert-nowiki.png',
				'offset': [-70, -70],
				'action': {
					'type': 'encapsulate',
					'options': {
						'pre': "<nowiki>",
						'periMsg': 'wikieditor-toolbar-tool-nowiki-example',
						'post': "</nowiki>"
					}
				}
			},
			'redirect': {
				'labelMsg': 'wikieditor-toolbar-tool-redirect',
				'label': 'ReDirect',
				'id': 'redirect',
				'filters': [ 'body:not(.ns-828, .ns-829)' ],
				'type': 'button',
				'icon': iconPathWE + 'insert-redirect.png',
				'offset': [-70, -142],
				'action': {
					'type': 'encapsulate',
					'options': {
						'pre': mw.config.get( 'wgWikiEditorMagicWords' ).redirect + ' [[',
						'periMsg': 'wikieditor-toolbar-tool-redirect-example',
						'post': "]]",
						'ownline': true
					}
				}
			},
			'signature': {
				'labelMsg': 'wikieditor-toolbar-tool-signature',
				'label': 'Your Signature',
				'id': 'signature',
				'filters': [ 'body.ns-4, body.ns-talk' ],
				'type': 'button',
				'icon': iconPathWE + 'insert-signature.png',
				'offset': [2, -1872],
				'action': {
					'type': 'encapsulate',
					'options': {
						'pre': '— ~~~~'
					}
				},
//			},
//			'ocr': {
//				'labelMsg': 'wikieditor-toolbar-tool-ocr',
//				'label': 'OCR',
//				'id': 'ocr',
//				'filters': [ 'body.ns-104' ],
//				'type': 'button',
//				'icon': '//upload.wikimedia.org/wikipedia/commons/c/c9/Toolbaricon_OCR.png',
//				'action': {
//					'type': 'callback',
//					'execute': function(context) {
//						     ocr()
//					}
//				}
			}
		}
	} );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'sections': {
		'emoticons': {
			'type': 'toolbar', // Can also be 'booklet'
			'label': 'Emoticons'
			// or 'labelMsg': 'section-emoticons-label' for a localized label
		},
		'shortcut': {
			'type': 'toolbar', // Can also be 'booklet'
			'label': 'Shortcut'
			// or 'labelMsg': 'section-emoticons-label' for a localized label
		}
	}
    } );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'emoticons',
		'groups': {
			'faces': {
				'label': 'Faces' // or use labelMsg for a localized label, see above
			}
		}
	} );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'emoticons',
		'group': 'faces',
		'tools': {
			'smile': {
				label: 'Smile!', // or use labelMsg for a localized label, see above
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Gnome-face-smile.svg/22px-Gnome-face-smile.svg.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: ":)" // text to be inserted
					}
				}
			}
		}
	} );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'shortcut',
		'groups': {
			'faces': {
				'label': 'Faces' // or use labelMsg for a localized label, see above
			}
		}
	} );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'shortcut',
		'group': 'faces',
		'tools': {
			'smile': {
				labelMsg: 'Smile!', // or use labelMsg for a localized label, see above
				type: 'button',
				icon: 'sc',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{s|", // text to be inserted
						post: "}}"
					}
				}
			}
		}
	} );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'sections': {
			'info': {
				'type': 'booklet',
				'label': 'Info'
			}
		}
	} );
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'info',
		'pages': {
			'colors': {
				'layout': 'table',
				'label': 'Colors',
				'headings': [
					{ text: 'Name' }, // or use textMsg for localization, see also above
					{ text: 'Temperature' },
					{ text: 'Swatch' }
				],
				'rows': [
					{
						'name': { text: 'Red' },
						'temp': { text: 'Warm' },
						'swatch': { html: '<div style="width:10px;height:10px;background-color:red;">' }
					},
					{
						'name': { text: 'Blue' },
						'temp': { text: 'Cold' },
						'swatch': { html: '<div style="width:10px;height:10px;background-color:blue;">' }
					},
					{
						'name': { text: 'Silver' },
						'temp': { text: 'Neutral' },
						'swatch': { html: '<div style="width:10px;height:10px;background-color:silver;">' }
					}
				]
			}
		}
	} );
};
/* Check that the required modules are available. Then, customize */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
	mw.loader.using( 'user.options', function () {
		if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
			$.when(
//				mw.loader.using( ['ext.wikiEditor.toolbar', 'schema.Edit'] ),
				mw.loader.using( ['ext.wikiEditor'] ),
				$.ready
			).then( customizeToolbar );
		}
	} );
}
//</source>