User:Cacycle/vector.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 is at User:Cacycle/vector.css. |
// wikEd configurations
var wikEdConfig = {};
wikEdConfig['buttonKey'] = {
26: [], // undefine shift-alt-b: wikify
3: ['b', 66], // shift-alt-b: bold
82: ['p', 80] // shift-alt-p: wikEd preview button shortcut
};
// The example implements a "<nowiki><div>...</div></nowiki>" button but can easily be adjusted for other needs:
// define custom buttons
// button number: [id, class, tooltip, image url, width, height, alt text, onclick handler code were obj is the button element]
wikEdConfig.button = {
100: ['wikEdDiv', 'wikEdButton', 'Make the selection a html DIV element', '/media/wikipedia/commons/6/67/WikEd_logo.png', '16', '16', 'DIV', 'wikEd.EditButton(this, this.id, null, TestHandler);' ],
101: ['wikEdTest', 'wikEdButton', 'This is a test button', '/media/wikipedia/commons/0/07/WikEd_disabled.png', '16', '16', 'Test', 'wikEd.EditButton(this, this.id, null, TestHandler);' ]
};
// define custom button bars
// button name: [id outer, class outer, id inner, class inner, height, grip title, button numbers]
wikEdConfig.buttonBar = {
'custom1': ['wikEdButtonBarCustom1', 'wikEdButtonBarCustom1', 'wikEdButtonsCustom1', 'wikEdButtonsCustom1', 44, 'My custom buttons', [100, 'br', 101] ],
'custom2': ['wikEdButtonBarCustom2', 'wikEdButtonBarCustom2', 'wikEdButtonsCustom2', 'wikEdButtonsCustom2', 44, 'My custom buttons', [100, 'br', 101] ]
};
// define the function which is called upon clicking the custom button
// this example code adds or removes div tags around the selected text
function TestHandler(obj) {
// select the appropriate text change target (whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine)
// focus... refers to the text under the cursor; ...Word and ...Line extend the target to the start/end of the word or line
wikEd.GetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
obj.changed = obj.cursor;
}
// make the changes to the plain target text
if ( /<div>([\s\S]*?)<\/div>/i.test(obj.changed.plain) ) {
// remove the previously added formatting
obj.changed.plain = obj.changed.plain.replace(/<div>([\s\S]*?)<\/div>/gi, '$1');
}
else {
// add the text formatting
obj.changed.plain = '<div>' + obj.changed.plain + '</div>';
// move spaces outside
obj.changed.plain = obj.changed.plain.replace(/(<div>)( *)([\s\S]*?)( *)(<\/div>)/, '$2$1$3$5$4');
}
// keep the changed text selected, needed to remove the formatting with a second custom button click
obj.changed.keepSel = true;
return;
}
//importScript('User:Cacycle/wikEdDiff.js');
//importScript('User:Cacycle/wikEd.js');
//importScript('User:Cacycle/wikEd.js');
//importScript('User:Cacycle/navbox.js');
//importScript('User:Cacycle/recent2.js');
wikEdConfig.showSourceButton = true;
//wikEdConfig.regExTypoFix = true;
//wikEdConfig.regExTypoFixURL = '//en.wikipedia.org/w/index.php?title=User:Cacycle/test&action=raw';
//wikEdConfig.showTableModeButton = true;
//wikEdConfig.loadDiffScript = false;
//wikEdConfig.loadDiff = false;
wikEdConfig.skipBrowserTest = true;
wikEdConfig.debugging = true;
/*
// install [[User:Cacycle/wikEd]] in-browser text editor
( function () { var script = document.createElement( 'script' ); script.src = '//en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js&action=raw&ctype=text/javascript'; script.async = true; document.getElementsByTagName( 'head' )[ 0 ].appendChild( script ); } ) ();
*/
/*
// install [[User:Cacycle/wikEd international]] English example translation
document.write('<script type="text/javascript" src="'
+ '//en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd_international_en.js'
+ '&action=raw&ctype=text/javascript"></script>');
*/
/*
// install [[User:Cacycle/wikEd]] editing page extension - DEV
document.write('<script type="text/javascript" src="'
+ '//en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd_dev.js'
+ '&action=raw&ctype=text/javascript"></script>');
*/
/*
// install [[User:Cacycle/wikEdDiff]]
document.write('<script type="text/javascript" src="'
+ '//en.wikipedia.org/w/index.php?title=User:Cacycle/wikEdDiff.js'
+ '&action=raw&ctype=text/javascript"></script>');
*/
jQuery( function($) {
mw.util.addPortletLink('p-personal', '/wiki/User:Cacycle/tricks', 'tricks', '', '', '', '');
mw.util.addPortletLink('p-personal', '/w/index.php?title=User:Cacycle/test&action=edit', 'test', '', '', '', '');
mw.util.addPortletLink('p-personal', '/wiki/User:Cacycle/vector.js', 'vector.js', '', '', '', '');
mw.util.addPortletLink('p-personal', '/wiki/User:Cacycle/common.js', 'common.js', '', '', '', '');
mw.util.addPortletLink('p-personal', '/wiki/User_talk:Cacycle/wikEd', 'wikEd talk', '', '', '', '');
mw.util.addPortletLink('p-personal', '/w/index.php?title=User:Cacycle/wikEd.js&action=edit', 'wikEd', '', '', '', '');
mw.util.addPortletLink('p-personal', '/w/index.php?title=User:Cacycle/wikEd.user.js&action=edit', 'wikEd.user.js', '', '', '', '');
mw.util.addPortletLink('p-personal', '/w/index.php?title=User:Cacycle/diff.js&action=edit', 'diff.js', '', '', '', '');
mw.util.addPortletLink('p-personal', '/w/index.php?title=User talk:Cacycle/wikEdDiff&action=edit', 'diff talk', '', '', '', '');
mw.util.addPortletLink('p-personal', '/w/index.php?title=User:Cacycle/wikEdDiff.js&action=edit', 'wikEdDiff.js', '', '', '', '');
mw.util.addPortletLink('p-personal', '/w/index.php?title=User_talk:Cacycle/wikEdDiff&action=edit', 'wikEdDiff talk', '', '', '', '');
mw.util.addPortletLink('p-personal', '/w/index.php?title=User:Cacycle/wikEd_current_version&action=edit', 'version', '', '', '', '');
});