Jump to content

User:John Vandenberg/switch editor 2.js

From Wikipedia, the free encyclopedia
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.
mw.hook( 've.activationComplete' ).add( function() {
	$('#ca-editsource a').attr('href','#').bind('click', function(){
		// if you want a bookmarklet to switch, use the code below
		var target = ve.init.mw.targets[0];
		var doc = target.surface.getModel().getDocument();
		doc = ve.dm.converter.getDomFromData( doc.getFullData(), doc.getStore(), doc.getInternalList() );

		target.serializing = false;
		target.serialize( doc, 
			function( content ) {
				if ($('#editform').length!=0) $('#editform').remove();

				$("body").append('<form id="editform" name="editform" method="post" action="/w/index.php?title='+wgPageName+'&amp;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"/><input name="wpEdittime"/><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="' + target.editToken + '" name="wpEditToken" /></form>' );

				window.onbeforeunload = function (){};
		$("textarea#wpTextbox1").val(content).parent().children("#wpDiff").click();
		});
		// end of bookmarklet
	});
});