MediaWiki:Common.js
From WikiROMS
Jump to navigationJump to search
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. */
var customizeToolbar = function () {
/* Insert Transparent Background Code Box Button */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'main',
'group': 'insert',
'tools': {
'code': {
label: 'Clear Code Box',
type: 'button',
icon: '/wiki/images/toolbar/button_box.png',
action: {
type: 'encapsulate',
options: {
pre: '<div class="box">',
peri: 'Insert text/code here',
post: '</div>'
}
}
}
}
});
/* Insert Green Background Code Box Button */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'main',
'group': 'insert',
'tools': {
'code': {
label: 'Green Code Box',
type: 'button',
icon: '/wiki/images/toolbar/button_box_green.png',
action: {
type: 'encapsulate',
options: {
pre: '<div class="code">',
peri: 'Insert text/code here',
post: '</div>'
}
}
}
}
});
/* Insert Numbered Equation Button */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'main',
'group': 'insert',
'tools': {
'numbered': {
label: 'Number an equation',
type: 'button',
icon: '/wiki/images/toolbar/button_numbered.png',
action: {
type: 'encapsulate',
options: {
pre: "{| class=\"eqno\"\n|",
peri: 'Insert eq. to # here',
post: "\n|(Enter eq. # here)\n|}"
}
}
}
}
});
/* Insert Block Equation */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'main',
'group': 'insert',
'tools': {
'block_math': {
label: 'Large Equation',
type: 'button',
icon: '/wiki/images/toolbar/button_block_math.png',
action: {
type: 'encapsulate',
options: {
pre: '<math display="block">',
peri: 'Insert formula here',
post: '</math>'
}
}
}
}
});
/* Insert Inline Equation */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'main',
'group': 'insert',
'tools': {
'inline_math': {
label: 'Inline Equation',
type: 'button',
icon: '/wiki/images/toolbar/button_math.png',
action: {
type: 'encapsulate',
options: {
pre: '<math>',
peri: 'Insert formula here',
post: '</math>'
}
}
}
}
});
/* Font Color Dropdown */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'main',
'group': 'format',
'tools': {
'font_color': {
label: 'Font Color',
type: 'select',
list: {
'Default': {
label: 'Default',
color: '#000000',
action: {
type: 'encapsulate',
options: {
pre: '',
peri: 'Insert text here',
post: ''
} //options
} //action
}, //Default
'darkTurquoise': {
label: 'Dark Turquoise',
color: '#00CED1',
action: {
type: 'encapsulate',
options: {
pre: '<span class="darkTurquoise">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //darkTurquoise
'forestGreen': {
label: 'Forest Green',
color: '#22AB22',
action: {
type: 'encapsulate',
options: {
pre: '<span class="forestGreen">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //forestGreen
'limeGreen': {
label: 'Lime Green',
color: '#32CD32',
action: {
type: 'encapsulate',
options: {
pre: '<span class="limeGreen">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //limeGreen
'darkGoldenrod': {
label: 'Dark Goldenrod',
color: '#BAA60B',
action: {
type: 'encapsulate',
options: {
pre: '<span class="darkGoldenrod">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //darkGoldenrod
'peru': {
label: 'Peru',
color: '#CDA53F',
action: {
type: 'encapsulate',
options: {
pre: '<span class="peru">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //peru
'sandyBrown': {
label: 'Sandy Brown',
color: '#F4A460',
action: {
type: 'encapsulate',
options: {
pre: '<span class="sandyBrown">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //sandyBrown
'salmon': {
label: 'Salmon',
color: '#FAA072',
action: {
type: 'encapsulate',
options: {
pre: '<span class="salmon">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //salmon
'hotPink': {
label: 'Hot Pink',
color: '#FF69B4',
action: {
type: 'encapsulate',
options: {
pre: '<span class="hotPink">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //hotPink
'mediumOrchid': {
label: "Medium Orchid",
color: '#BA55D3',
action: {
type: 'encapsulate',
options: {
pre: '<span class="mediumOrchid">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //mediumOrchid
'red': {
label: "Red",
color: '#FF5555',
action: {
type: 'encapsulate',
options: {
pre: '<span class="red">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //red
'orange': {
label: "Orange",
color: '#FF6600',
action: {
type: 'encapsulate',
options: {
pre: '<span class="orange">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //orange
'brown': {
label: "Brown",
color: '#663333',
action: {
type: 'encapsulate',
options: {
pre: '<span class="brown">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //brown
'green': {
label: "Green",
color: '#009900',
action: {
type: 'encapsulate',
options: {
pre: '<span class="green">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //green
'olive': {
label: "Olive",
color: '#929205',
action: {
type: 'encapsulate',
options: {
pre: '<span class="olive">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //olive
'cyan': {
label: "Cyan",
color: '#02CBC9',
action: {
type: 'encapsulate',
options: {
pre: '<span class="cyan">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //cyan
'blue': {
label: "Blue",
color: '#0000FF',
action: {
type: 'encapsulate',
options: {
pre: '<span class="blue">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //blue
'twilightBlue': {
label: "Twilight Blue",
color: '#6666CC',
action: {
type: 'encapsulate',
options: {
pre: '<span class="twilightBlue">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //twilightBlue
'purple': {
label: "Purple",
color: '#9900CC',
action: {
type: 'encapsulate',
options: {
pre: '<span class="purple">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //purple
'violet': {
label: "Violet",
color: '#FF00FF',
action: {
type: 'encapsulate',
options: {
pre: '<span class="violet">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
}, //violet
'black': {
label: "Black",
color: 'black',
action: {
type: 'encapsulate',
options: {
pre: '<span class="black">',
peri: 'Colored text here',
post: '</span>'
} //options
} //action
} //black
} //list
} //font_color
} //tools
});
};
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -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 );
}
} );
}