User:Writ Keeper/Scripts/previewAndDiff.js: Difference between revisions

Content deleted Content added
m test
apparently this is bad now
 
(27 intermediate revisions by 2 users not shown)
Line 1:
$(document).ready(function()
{
if(mw.config.get("wgAction") === "edit" || mw.config.get("wgAction") === "submit" )
if($("form#editform").length == 1)
{
if(/previewanddiff=true/.test(window.___location.href))
{
mw.loader.load('mediawiki.diff.styles');
$("#wikiPreview").afterbefore('<h2>Your changes</h2><table class="diff" id="ajaxDiff"><colgroup><col class="diff-marker"><col class="diff-content"><col class="diff-marker"><col class="diff-content"></colgroup></table>');
var requestString="/w/api.php?action=query&prop=revisions&format=json&rvcontentformat=text/x-wiki&revids=" + $("input[name='baseRevId']").attr("value") + "&rvdifftotext="+ encodeURIComponent($("textarea#wpTextbox1").text());
{
if($("input[name='wpSection']").attr("value") !== "")
var requestStringdiffData ="/w/api.php? {action=:"query&", prop=:"revisions&", format=:"json&", rvcontentformat=:"text/x-wiki&revids=", + revids:$("input[name='baseRevId']").attr("value"), + "&rvdifftotext="+ encodeURIComponent(:$("textarea#wpTextbox1").text())};
var wpSectionElement = $("input[name='wpSection']");
if($("input[name='wpSection']")typeof wpSectionElement.attr("value") !== "undefined")
{
requestStringdiffData.rvsection = requestString + "&rvsection=" + $("input[name='wpSection']")wpSectionElement.attr("value");
}
var mwApi = new mw.Api();
$.getJSON(requestString, function(response, status)
mwApi.post(diffData).done(function (response)
{
$("#ajaxDiff").append(response.query.pages[Object.keys(response.query.pages)[0]].revisions[0].diff["*"]);
});
}
 
$("#wpDiff").after('<input type="submit" title="Preview your changes and show a diff of the changes you made; please use this before saving." value="Show preview and diff" tabindex="8" name="wpPreview" id="wpPreviewAndDiff">');
$mw.loader.using("#wpPreviewAndDiff"'oojs-ui').clickthen(function () {
var previewDiffButton = new OO.ui.ButtonInputWidget({label:'Show preview and changes', useInputTag: true, value: 'wpPreview', name: 'wpPreview', type:"submit", accessKey:"o", tabIndex: ($("#wpDiff").prop("tabIndex") + 1)});
{
previewDiffButton.setTitle("Show a preview of your changes, as well as a diff of what you changed");
var formAction = $("#editform").attr("action");
$("#editform").attr("action", formAction+"&previewanddiff=true");
$("#wpDiffWidget").after(previewDiffButton.$element);
previewDiffButton.$element.children("input").click(function()
{
var formAction = $("#editform").attr("action");
$("#editform").attr("action", formAction+"&previewanddiff=true");
});
});
}