User:John Vandenberg/switch editor.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. |
![]() | This user script seems to have a documentation page at User:John Vandenberg/switch editor. |
// This script overrides the VE save button to load the Source Editor, with a diff.
// It could break with changes to VE.
// Use at your own risk, and pester the VE team to add this feature.
/*global $, mw */
$(document).ready(function (){
switchToWikiText = function( content ) {
form = $("#editform");
$("textarea#wpTextbox1").val( content);
$("#wpDiff").click();
};
ve.init.mw.targets[0].save = function ( doc, options) {
this.serializing = false;
$("body").append('<form id="editform" name="editform" method="post" action="/w/index.php?title='+wgPageName+'&action=submit" enctype="multipart/form-data"><textarea name=wpTextbox1 id=wpTextbox1></textarea><input id="wpDiff" name="wpDiff" type="submit" tabindex="7" value="Show changes"/><input name="wpSummary"/><input name="wpSection"/><input name="wpAutoSummary"/><input name="wpStarttime" value="20130719091607"/><input name="wpEdittime" value="20111216104251"/><input name="oldid" value="0"/><input name="model" value="wikitext"/><input name="format" value="text/x-wiki"/><input name="wpAntispam" value=""/><input name="baseRevId" value="0"/><input name="altBaseRevId" value="0"/><input name="undidRev" value="0"/><input name="wpScrolltop" value="0"/><input name="undidRev" value="0"/><input type="hidden" value="' + ve.init.mw.targets[0].editToken + '" name="wpEditToken" /></form>' );
this.serialize( doc, switchToWikiText );
}
});