https://de.wikipedia.org/w/index.php?action=history&feed=atom&title=User%3AJohn_Vandenberg%2Fswitch_editor.js Benutzer:John Vandenberg/switch editor.js - Versionsgeschichte 2025-07-30T21:12:32Z Versionsgeschichte dieser Seite in Wikipedia MediaWiki 1.45.0-wmf.11 https://de.wikipedia.org/w/index.php?title=Benutzer:John_Vandenberg/switch_editor.js&diff=120962965&oldid=prev John Vandenberg: copy en:User:John_Vandenberg/switch_editor.js 2013-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 &#039;source&#039; checkbox which, when pressed, causes the &#039;diff&#039; 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 &#039;Save&#039; 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( &#039;ve.saveDialog.stateChanged&#039; ).add( function() {<br /> // If the editor switch UI hasnt been added, add the UI and associated hooks.<br /> if ($(&#039;#jv_switch_editor&#039;).length==0) {<br /> // Add a checkbox.<br /> ve.init.mw.targets[0].saveDialogReviewButton.$label.parent().after(&#039;&lt;input type=&quot;checkbox&quot; name=&quot;sourceDiff&quot; id=&quot;jv_switch_editor&quot; title=&quot;Review your changes in the source editor&quot; style=&quot;float:right; line-height: 1.5em;height: 3em;margin: 0;&quot;&gt;&#039;);<br /> <br /> ve.init.mw.targets[0].onSaveDialogReviewButtonClick = function () {<br /> // Detect if the new checkbox has been ticked.<br /> var source = $( &#039;#jv_switch_editor&#039; ).prop( &#039;checked&#039; );<br /> <br /> if (!source)<br /> this.swapSaveDialog( &#039;review&#039; );<br /> else {<br /> // Build a &#039;document&#039; 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 = &#039;&#039;;<br /> watchChecked = &#039;&#039;;<br /> if ( saveOptions.minor ) {<br /> minorChecked = &#039;checked=&quot;checked&quot; &#039;;<br /> }<br /> if ( saveOptions.watch ) {<br /> watchChecked = &#039;checked=&quot;checked&quot; &#039;;<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 ($(&#039;#editform&#039;).length!=0) {<br /> $(&#039;#editform&#039;).remove();<br /> }<br /> <br /> // Inject a source editor form, populated with values.<br /> // It isnt hidden yet, as it shouldn&#039;t be too visually annoying<br /> // and keeping it visible may help with debugging if the op fails.<br /> $(&quot;body&quot;).append(&#039;&lt;form id=&quot;editform&quot; name=&quot;editform&quot; method=&quot;post&quot; action=&quot;/w/index.php?title=&#039;+wgPageName+&#039;&amp;amp;action=submit&quot; enctype=&quot;multipart/form-data&quot;&gt;&lt;textarea name=wpTextbox1 id=wpTextbox1&gt;&lt;/textarea&gt;&lt;input id=&quot;wpDiff&quot; name=&quot;wpDiff&quot; type=&quot;submit&quot; tabindex=&quot;7&quot; value=&quot;Show changes&quot;/&gt;&lt;input name=&quot;wpSummary&quot; value=&quot;&#039;+mw.html.escape(saveOptions.summary)+&#039;&quot;/&gt;&lt;input name=&quot;wpMinoredit&quot; value=&quot;1&quot; &#039;+ minorChecked + &#039; type=&quot;checkbox&quot;/&gt;&lt;input name=&quot;wpWatchthis&quot; value=&quot;1&quot; &#039; + watchChecked + &#039; type=&quot;checkbox&quot;/&gt;&lt;input name=&quot;wpStarttime&quot; value=&quot;&#039; + (new Date).toISOString().replace(/([-:ZT]|\.[0-9]{3})/g,&#039;&#039;) + &#039;&quot;/&gt;&lt;input name=&quot;wpEdittime&quot;/&gt;&lt;input name=&quot;model&quot; value=&quot;wikitext&quot;/&gt;&lt;input name=&quot;format&quot; value=&quot;text/x-wiki&quot;/&gt;&lt;input name=&quot;wpAntispam&quot; value=&quot;&quot;/&gt;&lt;input type=&quot;hidden&quot; value=&quot;&#039; + ve.init.mw.targets[0].editToken + &#039;&quot; name=&quot;wpEditToken&quot; /&gt;&lt;/form&gt;&#039; );<br /> <br /> // This disables the &quot;unsaved data&quot; warning<br /> window.onbeforeunload = function (){};<br /> <br /> // add wikitext to form and click the diff button<br /> $(&quot;textarea#wpTextbox1&quot;).val(content).parent().children(&quot;#wpDiff&quot;).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