-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMsWikiEditor.js
51 lines (47 loc) · 1.22 KB
/
MsWikiEditor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const MsWikiEditor = {
init: function () {
mw.hook( 'wikiEditor.toolbarReady' ).add( MsWikiEditor.addButtons );
mw.hook( 'wikiEditor.toolbarReady' ).add( MsWikiEditor.removeButtons );
},
addButtons: function ( $textarea ) {
const buttons = mw.config.get( 'wgMsWikiEditorAdd' );
for ( const key in buttons ) {
const button = buttons[ key ];
const label = button[0];
const pre = button[1];
const peri = button[2];
const post = button[3];
const icon = button[4];
const section = button[5] || 'main';
const group = button[6] || 'insert';
$textarea.wikiEditor( 'addToToolbar', {
section: section,
group: group,
tools: {
anam: {
label: label,
type: 'button',
icon: icon,
action: {
type: 'encapsulate',
options: {
pre: pre,
peri: peri,
post: post,
}
}
}
}
} );
}
},
removeButtons: function ( $textarea ) {
const buttons = mw.config.get( 'wgMsWikiEditorRemove' );
const $wikiEditor = $textarea.closest( '.wikiEditor-ui' );
const $toolbar = $wikiEditor.find( '#wikiEditor-ui-toolbar' );
for ( const key of buttons ) {
$toolbar.find( '[rel="' + key + '"]' ).remove();
}
}
};
$( MsWikiEditor.init );