https://de.wikipedia.org/w/index.php?action=history&feed=atom&title=User%3AJohn_Vandenberg%2Fswitch_editor.jsBenutzer:John Vandenberg/switch editor.js - Versionsgeschichte2025-07-30T21:12:32ZVersionsgeschichte dieser Seite in WikipediaMediaWiki 1.45.0-wmf.11https://de.wikipedia.org/w/index.php?title=Benutzer:John_Vandenberg/switch_editor.js&diff=120962965&oldid=prevJohn Vandenberg: copy en:User:John_Vandenberg/switch_editor.js2013-07-28T06:46:59Z<p>copy <a href="https://en.wikipedia.org/wiki/User:John_Vandenberg/switch_editor.js" class="extiw" title="en:User:John Vandenberg/switch editor.js">en:User:John_Vandenberg/switch_editor.js</a></p>
<p><b>Neue Seite</b></p><div><br />
// This script adds a 'source' checkbox which, when pressed, causes the 'diff' button to load the Source Editor, with a diff.<br />
<br />
// It could break with changes to VE.<br />
// Use at your own risk, and pester the VE team to add this feature.<br />
<br />
// This hook is fired when the first 'Save' is loaded.<br />
// There are better hooks to load the editor switcher earlier, but <br />
// This is the most reliable hook at present. However this hook is fired<br />
// frequently, so the code needs to be further optimised.<br />
// The save dialog is built from a template, and we dont want to be invoked<br />
// before the save dialog has been properly instantiated.<br />
// TODO: document the other hooks and related problems in more detail, and<br />
// raise bugs if appropriate.<br />
<br />
// Changes:<br />
// - update checkbox insertion after VE change<br />
// - set wpStarttime to avoid previously deleted page warning<br />
// - move checkbox near Review button, fixing bug with en-gb and character count<br />
<br />
mw.hook( 've.saveDialog.stateChanged' ).add( function() {<br />
// If the editor switch UI hasnt been added, add the UI and associated hooks.<br />
if ($('#jv_switch_editor').length==0) {<br />
// Add a checkbox.<br />
ve.init.mw.targets[0].saveDialogReviewButton.$label.parent().after('<input type="checkbox" name="sourceDiff" id="jv_switch_editor" title="Review your changes in the source editor" style="float:right; line-height: 1.5em;height: 3em;margin: 0;">');<br />
<br />
ve.init.mw.targets[0].onSaveDialogReviewButtonClick = function () {<br />
// Detect if the new checkbox has been ticked.<br />
var source = $( '#jv_switch_editor' ).prop( 'checked' );<br />
<br />
if (!source)<br />
this.swapSaveDialog( 'review' );<br />
else {<br />
// Build a 'document' from the VE, ready to be serialised.<br />
var doc = this.surface.getModel().getDocument();<br />
doc = ve.dm.converter.getDomFromData( doc.getFullData(), doc.getStore(), doc.getInternalList() );<br />
<br />
// Copy VE save form buttons into SE form<br />
var saveOptions = this.getSaveOptions();<br />
minorChecked = '';<br />
watchChecked = '';<br />
if ( saveOptions.minor ) {<br />
minorChecked = 'checked="checked" ';<br />
}<br />
if ( saveOptions.watch ) {<br />
watchChecked = 'checked="checked" ';<br />
}<br />
<br />
// The serialize function checks this variable to avoid multiple ajax requests<br />
this.serializing = false;<br />
<br />
this.serialize( doc, <br />
function( content ) {<br />
// Remove form if it already exists<br />
if ($('#editform').length!=0) {<br />
$('#editform').remove();<br />
}<br />
<br />
// Inject a source editor form, populated with values.<br />
// It isnt hidden yet, as it shouldn't be too visually annoying<br />
// and keeping it visible may help with debugging if the op fails.<br />
$("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" value="'+mw.html.escape(saveOptions.summary)+'"/><input name="wpMinoredit" value="1" '+ minorChecked + ' type="checkbox"/><input name="wpWatchthis" value="1" ' + watchChecked + ' type="checkbox"/><input name="wpStarttime" value="' + (new Date).toISOString().replace(/([-:ZT]|\.[0-9]{3})/g,'') + '"/><input name="wpEdittime"/><input name="model" value="wikitext"/><input name="format" value="text/x-wiki"/><input name="wpAntispam" value=""/><input type="hidden" value="' + ve.init.mw.targets[0].editToken + '" name="wpEditToken" /></form>' );<br />
<br />
// This disables the "unsaved data" warning<br />
window.onbeforeunload = function (){};<br />
<br />
// add wikitext to form and click the diff button<br />
$("textarea#wpTextbox1").val(content).parent().children("#wpDiff").click();<br />
<br />
}<br />
);<br />
};<br />
};<br />
<br />
// This changes the button click binding.<br />
// It is probably fragile.<br />
ve.init.mw.targets[0].saveDialogReviewButton.bindings.click[0].callback = ve.init.mw.targets[0].onSaveDialogReviewButtonClick;<br />
}<br />
});</div>John Vandenberg