Jump to content

User:Vprajkumar/monobook.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Vprajkumar (talk | contribs) at 14:55, 19 January 2009. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// define  custom buttons (id, class, popup title, image src, width, height, alt text, onClick and parameters)
var wikEdButton = {};
wikEdButton[100] = ['wikEdDiv', 'wikEdButton', 'Make the selection a html DIV element', '/media/wikipedia/commons/6/67/WikEd_logo.png', '16', '16', 'DIV', 'javascript:WikEdEditButton(this, this.id, null, BracesHandler);' ];
wikEdButton[101] = ['wikEdTest', 'wikEdButton', 'This is a test button', '/media/wikipedia/commons/0/07/WikEd_disabled.png', '16', '16', 'Test', 'javascript:WikEdEditButton(this, this.id, null, BracketsHandler);' ];

// 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 buttons', [100, 'br', 101] ];


//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;
}

// make your changes to the plain target text in obj.changed.plain
// or remove the previously added formatting
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;
}

// make your changes to the plain target text in obj.changed.plain
// or remove the previously added formatting
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;
}




//===============================
// End of Custom features
//===============================


// addPurge
addOnloadHook(function () {
var hist; var url;
if (!(hist = document.getElementById('ca-history') )) return;
if (!(url = hist.getElementsByTagName('a')[0] )) return;
if (!(url = url.href )) return;
addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),
'purge', 'ca-purge', 'Purge server cache for this page', '0');
});