Here naverokê

MediaWiki:Gadget-AjaxEdit.js

Ji Wîkîferhengê

Zanibe: Piştî weşandinê, ji bo dîtina guhartinan dibe ku hewce be "cache"ya geroka xwe paqij bikî.

  • Firefox / Safari: Pê li Shift û Reload bike an jî Ctrl-F5 an Ctrl-R bike (ji bo Mac: ⌘-R)
  • Google Chrome: Pê li Ctrl-Shift-R (ji bo Mac: ⌘-Shift-R) bike
  • Internet Explorer / Edge: Pê li Ctrl û Refresh bike, an jî Ctrl-F5 bike
  • Opera: Pê li Ctrl-F5 bike.
"use strict";

// Çavkanî: [[en:MediaWiki:Gadget-AjaxEdit.js]]
// Description         : With a new button "Æbiguherîne" one can edit specific sections without reloading the whole page. 
// Ji bo çalakkirina vê amûrê here [[Special:Preferences#mw-prefsection-gadgets|beşa Amûr ya Tercîhên mîn]] û li qutiya li gel "Amûrek e ku ji bo guhartina beşekê bi butona "Æbiguherîne" bêyî barkirina hemû rûpelê tê bikaranîn." bitikîne
//                       Supports TabbedLanguages gadget
// Dependencies: mediawiki.util, mediawiki.Uri, mediawiki.user, mediawiki.api
/* jshint maxerr:1048576, strict:true, undef:true, latedef:true, sub:true */
/* global mw, $ */

window.AjaxEdit = {};

window.AjaxEdit.Click = function (ajaxEditAnchor) {
	var _query = new mw.Uri($(ajaxEditAnchor).parent().find("a[href*='action=edit']").attr("href")).query,
	    title = _query.title,
	    section = _query.section;

	section = section.replace("T-", ""); //translcusions...
	var hdr = $(ajaxEditAnchor).parent().parent();
	var sectionName = hdr.children(".mw-headline").first().text();
	if (window.tabbedLanguages && !hdr.is(":header")) {
		sectionName = window.tabbedLanguages[window.currentLanguageTab];
	}

	$("#ajaxedit-wrapper").remove();

	var data = { action: 'raw', title: title, section: section };
	$.get(mw.util.wikiScript('index'), data).then(function (wikitext) {
		var rowHeight = Math.min(15, 1   wikitext.split("\n").length);
		var textarea = $("<textarea></textarea>").attr({ rows: rowHeight }).text(wikitext);
		var saveButton = $('<button>Tomar bike</button>').click(function () {
			window.AjaxEdit.Save(section, sectionName, textarea.val(), title).then(function () {
				new mw.Api().parse(new mw.Title(mw.config.get("wgPageName"))).then(function (newHtml) {
					$("#mw-content-text").html(newHtml);

					mw.loader.moduleRegistry["site"].state = "registered";
					//mw.loader.moduleRegistry["site"].version="generate-unique-guid-here";
					mw.loader.moduleRegistry["site"].script = undefined;
					mw.loader.using("site", function () {});

					window.AjaxEdit.Main();
					// run NavToggle stuff
				});
			});
		}).css("margin-left", "3px");
		var cancelButton = $('<button>Betal bike</button>').click(function () {
			$("#ajaxedit-wrapper").remove();
		});
		var previewDiv = $("<div></div>").css({
			"border-style": "solid", "border-width": "1px 1px 1px 4px",
			"border-radius": "0.33em", "border-color": "#a3d3ff" }).hide();

		var loadPreview = function loadPreview() {
			new mw.Api().parse(textarea.val(), { title: mw.config.get("wgPageName") }).done(function (html) {
				previewDiv.html(html);
			});
		};
		var previewIntervalId = -1;
		var livePreviewCheckbox = $("<input type='checkbox'/>").attr("id", "ajaxedit-live-preview-checkbox").on("change", function () {
			if ($(this).is(':checked')) {
				previewDiv.show("slow");
				loadPreview();
				previewIntervalId = setInterval(loadPreview, 500);
			} else {
				clearInterval(previewIntervalId);
				previewDiv.hide("fast");
				previewDiv.empty();
			}
		});

		var wrapper = $("<div></div>").attr("id", "ajaxedit-wrapper").css({ width: "auto", "margin": 0, "overflow": "hidden" }).append(textarea).append(saveButton).append(livePreviewCheckbox).append(' <label for="ajaxedit-live-preview-checkbox">Pêşdîtina zindî </label>').append(cancelButton).append(previewDiv);

		//tabbed languages support
		if ($(ajaxEditAnchor).is("#tabstable .editlangsection a")) $(".languageContainer:not(:hidden)").first().prepend(wrapper);else hdr.after(wrapper);
	});
};

window.AjaxEdit.Save = function (sectionID, sectionName, sectionText, title) {
	var scriptLink = "";
	if (mw.config.get("wgSiteName") !== "Wîkîferheng")
		scriptLink  = "wikt:";
	if (mw.config.get("wgContentLanguage") !== "ku")
		scriptLink  = "ku:";
	scriptLink  = "MediaWiki:Gadget-AjaxEdit.js";
	var data = {
		format: 'json',
		action: 'edit',
		title: title,
		section: sectionID,
		summary: "/* "   sectionName   " */ bi [["   scriptLink   "|AjaxEdit]]ê re",
		text: sectionText,
		token: mw.user.tokens.get('csrfToken')
	};
	return $.post(mw.util.wikiScript('api'), data, function (data) {
		if (data && data.edit && data.edit.result == 'Success') {
			mw.notify("serketî");
		} else if (data && data.error) {
			mw.notify('Xeletî: API koda xeletiyê ya "'   data.error.code   '" şand: '   data.error.info);
		}
	}).fail(function (xhr) {
		mw.notify('Xeletî: Daxwaz pêk neanî.');
	}, "json");
};

window.AjaxEdit.Main = function () {
	$(".mw-editsection > .mw-editsection-bracket:contains(']')").each(function () {
		var btn = $('<a>Æbiguherîne</a>').attr("onclick", "AjaxEdit.Click(this)");
		$(this).before(", ").before(btn);
	});
};

if (mw.config.get('wgAction') == "view")
	$(window.AjaxEdit.Main);