Snippets/ToolboxLayer
Appearance
< Snippets
ToolboxLayer | |
---|---|
Language(s): | JavaScript |
Compatible with: | MediaWiki 1.17+ |
Description
[edit]People familiar with how to add buttons to the old toolbar may find the wikiEditor interface confusing. People can continue to add buttons to wikiEditor using the old method by including this code.
Code
[edit]/**
* Allow mwCustomEditButtons to continue to be used with wiki editor.
*
* @rev 1
* @source https://www.mediawiki.org/wiki/Snippets/ToolboxLayer
*/
(function($) {
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit','submit']) === -1 || $.fn.wikiEditor === undefined ) {
return;
}
$(document).ready( function() {
var $tb = $('#wpTextbox1');
$.each( window.mwCustomEditButtons || [], function(i) {
var wikiOptions = { section: 'main', group: 'insert', tools: {}}, tool = this;
wikiOptions.tools[ tool.name || 'mw-custom-edit-button-' + (i+1) ] = {
label: tool.speedTip,
type: 'button',
icon: tool.imageFile,
action: {
type: 'callback',
execute: function() {
$tb.textSelection( 'encapsulateSelection', {
pre: tool.tagOpen || '',
peri: tool.sampleText || '',
post: tool.tagClose || ''
});
if ( $.isFunction( tool.callbackFunct ) ) {
tool.callbackFunct.call( window );
}
}
}
}
$tb.wikiEditor( 'addToToolbar', wikiOptions );
});
});
})( jQuery );