User:ערן/veReplace
Appearance
< User:ערן
The replace gadget is outdated. There is a built in find&replace in VE |
This script adds option for replace and replace all in VisualEditor.
Usage
[edit]The script adds replace option in VE toolbar, which opens dialog for replacing term:
Setup
[edit]User setup
[edit]Copy the following code to your Special:MyPage/common.js:
//translate the following:
mw.messages.set({
've-SearchAndReplaceDialog-title': 'Search and replace',
've-SearchAndReplaceDialog-from-label': 'From:',
've-SearchAndReplaceDialog-to-label': 'To:',
've-SearchAndReplaceDialog-from-placeholder': 'From text',
've-SearchAndReplaceDialog-to-placeholder': 'To text',
've-SearchAndReplaceDialog-replaceAll': 'Replace all',
've-SearchAndReplaceDialog-replace': 'Replace',
've-SearchAndReplaceDialog-matchcase': 'Match case',
've-SearchAndReplaceDialog-replace-complete': 'Found and replaced $1 occurrences',
've-ReplaceTool-ToolbarButton': 'Replace'
});
//end of translations
mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init', function(){
mw.libs.ve.addPlugin( function() {
return $.getScript('https://en.wikipedia.org/w/index.php?title=User:ערן/veReplace.js&action=raw&ctype=text/javascript');
} );
});
Project setup
[edit]To turn it as a gadget that user can select in their preferences (requires sysop rights):
- create MediaWiki:Gadget-veReplaceLoader.js with the following code:
mw.libs.ve.addPlugin('ext.gadget.veReplace');
- create MediaWiki:Gadget-veReplaceLoader with short description (example: "Adds replace button to VisualEditor")
- create MediaWiki:Gadget-veReplace.js and copy the code from User:ערן/veReplace.js.
- add the following to MediaWiki:Gadgets-definition:
*veReplaceLoader[ResourceLoader|dependencies=ext.visualEditor.viewPageTarget.init]|veReplaceLoader.js *veReplace[ResourceLoader|rights=hidden|hidden|dependencies=ext.visualEditor.core]|veReplace.js
(notice the first line is just a loader for the real script which is declared in the second line - this way it is possible to load the replace option only once VE is activated)