User:Vprajkumar/monobook.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
The accompanying .css page for this skin can be added at User:Vprajkumar/monobook.css. |
//<nowiki>
//define custom buttons (id, class, popup title, image src, width, height, alt text, onClick and parameters)
var wikEdButton = {};
wikEdButton[100] = ['wikEdBraces', 'wikEdButton', 'Enclose the selection with Braces', 'http://upload.wikimedia.org/wikipedia/commons/6/67/WikEd_logo.png', '16', '16', 'Braces', 'javascript:WikEdEditButton(this, this.id, null, BracesHandler);' ];
wikEdButton[101] = ['wikEdBrackets', 'wikEdButton', 'Enclose the selection with Brackets', 'http://upload.wikimedia.org/wikipedia/commons/0/07/WikEd_disabled.png', '16', '16', 'Brackets', 'javascript:WikEdEditButton(this, this.id, null, BracketsHandler);' ];
wikEdButton[102] = ['wikEdRefSect', 'wikEdButton', 'Insert the reference section', 'http://upload.wikimedia.org/wikipedia/commons/0/07/WikEd_disabled.png', '16', '16', 'RefSect', 'javascript:WikEdEditButton(this, this.id, null, RefSectionHandler);' ];
//define custom button bars (id outer, class outer, id inner, class inner, height, grip title, button numbers)
var wikEdButtonBar = {};
wikEdButtonBar['custom1'] = ['wikEdButtonBarCustom1', 'wikEdButtonBarCustom1', 'wikEdButtonsCustom1', 'wikEdButtonsCustom1', 44, 'My custom buttons1', [100, 101, 102] ];
//==========================================================
//This function adds or removes Brackets around the selected text
//==========================================================
function BracketsHandler(obj) {
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
obj.changed = obj.cursor;
}
if ( /\((.*?)\)/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/\((.*?)\)/gi, '$1');
}
// add the text formatting
else {
obj.changed.plain = '(' + obj.changed.plain + ')';
obj.changed.plain = obj.changed.plain.replace(/(\()( *)(.*?)( *)(\))/, '$2$1$3$5$4');
}
// keep the changed text selected
obj.changed.keepSel = true;
return;
}
//==========================================================
//This function adds or removes braces around the selected text
//==========================================================
function BracesHandler(obj) {
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
obj.changed = obj.cursor;
}
if ( /{{(.*?)}}/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/{{(.*?)}}/gi, '$1');
}
// add the text formatting
else {
obj.changed.plain = '{{' + obj.changed.plain + '}}';
obj.changed.plain = obj.changed.plain.replace(/({{)( *)(.*?)( *)(}})/, '$2$1$3$5$4');
}
// keep the changed text selected
obj.changed.keepSel = true;
return;
}
//==========================================================
//This function adds or removes ref section
//==========================================================
function RefSectionHandler(obj) {
//select the appropriate text change target (whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine)
//focus... is the text under the cursor; ...Word and ...Line extend the target to the start/end of the word or line
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
obj.changed = obj.cursor;
}
// make your changes to the plain target text in obj.changed.plain
// add the text formatting
obj.changed.plain = '==References==\n {{reflist}}' + obj.changed.plain + '';
// obj.changed.plain = obj.changed.plain.replace(/(<div>)( *)(.*?)( *)(<\/div>)/, '$2$1$3$5$4');
// keep the changed text selected
obj.changed.keepSel = true;
// return to WikEdEditButton() to apply changes
return;
}
//===============================
// End of Custom features
//===============================
// addPurge
$(function () {
var hist; var url;
if (!(hist = document.getElementById('ca-history') )) return;
if (!(url = hist.getElementsByTagName('a')[0] )) return;
if (!(url = url.href )) return;
mw.util.addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),
'purge', 'ca-purge', 'Purge server cache for this page', '0');
});
//</nowiki>