Jump to content

User:Writ Keeper/Scripts/previewAndDiff.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Writ Keeper (talk | contribs) at 10:03, 17 December 2013 (test). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
$(document).ready(function()
{
	if($("form#editform").length == 1)
	{
		if(/previewanddiff=true/.test(window.location.href))
		{
			$("wikiPreview").after('<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="+ $("textarea#wpTextbox1").text();
			if($("input[name='wpSection']").attr("value") !== "")
			{
				var = var + "rvSection=" + $("input[name='wpSection']").attr("value");
			}
			$.getJSON(requestString, function(response, status)
			{
				$("#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">');
		$("#wpPreviewAndDiff").click(function()
		{
			var formAction = $("#editform").attr("action");
			$("#editform").attr("action", formAction+"&previewanddiff=true");
		});
	}
});