Wikipedysta:Beau/dyskusja.js

Z Wikipedii, wolnej encyklopedii

Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.

  • Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
  • Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
  • Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
  • Opera: Naciśnij klawisze Ctrl+F5.
// <nowiki> -------------------------------------------
// przyciski tylko podczas edycji strony dyskusji - testy

var talkTestGadget = {
	version: 1,
	timer: null,
	trigger: null,
	selectedItem: null,
	list: [],
	summaryText: "komentarz",
	previewPanel: null,

	init: function() {
		var userSummaryButtons = document.getElementById('userSummaryButtons');

		var minoredit = document.getElementById('wpMinoredit');
		if (! userSummaryButtons) {
			var userSummaryButtons = document.createElement('div');
			userSummaryButtons.id = 'userSummaryButtons'

			var ec = jQuery("div.editCheckboxes");
			if ( !ec.length ) {
				return;
			}
			ec.before(userSummaryButtons);
		}
		else {
			userSummaryButtons.appendChild(document.createElement('br'));
		}
		var el = userSummaryButtons;

		for (var i = 0; i < this.list.length; i++) {
			var item = this.list[i];
			if (!item.type) {
				var button = this.createButton(item)
				el.appendChild(button);
			}
			else if (item.type == 'text') {
				el.appendChild(document.createTextNode(item.content));
			}
			else if (item.type == 'element') {
				el.appendChild(document.createElement(item.content));
			}
		}
		var previewPanel = document.createElement('div');
		previewPanel.style.cssText = "display: none; border: 1px dotted #AAA;";
		jQuery(userSummaryButtons).after(previewPanel);
		this.previewPanel = previewPanel;
	},

	processExpandedTemplate: function(item, data) {
		item.content = data.expandtemplates['*'];
		if (item.content) {
			this.insertTemplate(item);
		}
	},

	insertTemplate: function(item) {
		if (item.content) {
			$('#wpTextbox1').textSelection('encapsulateSelection',{
				pre: item.content + " ~~" + "~~"
			});
			if (document.editform.wpSection.value == '') {
				document.editform.wpSummary.value = this.summaryText;
			}
		}
		else {
			var request = {
				action:	'expandtemplates',
				text:	'{{' + item.template + "}}",
				format:	'json',
				requestid:	new Date().getTime()
			};

			var that = this;
			jQuery.getJSON(mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php', request, function(result) {
				that.processExpandedTemplate(item, result);
			});
		}
	},

	processParsedTemplate: function(item, data) {
		item.preview = data.parse.text['*'];
		if (item.preview && this.selectedItem == item) {
			this.showTemplate(item);
		}
	},

	showTemplate: function(item) {
		if (item.preview) {
			this.previewPanel.style.display = 'block';
			this.previewPanel.innerHTML = item.preview;
		}
		else {
			var request = {
				action:	'parse',
				text:	'{{' + item.template + "}}",
				prop:	'text',
				format:	'json',
				requestid:	new Date().getTime()
			};

			var that = this;
			jQuery.getJSON(mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php', request, function(result) {
				that.processParsedTemplate(item, result);
			});
		}
	},

	createButton: function(item) {
		var button = document.createElement('a');
		button.appendChild(document.createTextNode(item.caption));
		button.title = item.title;
		var that = this;

		button.onclick = function() {
			that.insertTemplate(item);
		}
		button.onmousemove = function() {
			if (!that.timer) {
				that.trigger = this;
				that.selectedItem = item;
				var delay = that.previewPanel.style.display != 'none' ? 100 : 500;
				that.timer = setTimeout(function() {
					that.showTemplate(item)
					that.timer = null;
				},  delay);
			}
		}
		button.onmouseout  = function() {
			if (that.timer) {
				clearTimeout(that.timer);
				that.timer = null;
			}
			that.selectedItem = null;
		}
		return button;
	}
};

talkTestGadget.list = new Array(
	{
		caption: "test",
		template: "Szablon:Test",
		title: ""
	},
	{
		caption: "stub",
		template: "Szablon:TestStub",
		title: "artykuł nie spełnia wymagań"
	},
	{
		type: "text",
		content: " "
	},
	{
		caption: "test1",
		template: "Szablon:Test1",
		title: "obraźliwe sformułowania"
	},
	{
		caption: "wandal",
		template: "Szablon:TestK",
		title: "wandalizm"
	},
	{
		caption: "testU",
		template: "Szablon:TestU",
		title: "nie usuwaj"
	},
	{
		caption: "spamer",
		template: "Szablon:Spam",
		title: "przestań wprowadzać zewnętrzne odnośniki do stron"
	},
	{
		caption: "test2",
		template: "Szablon:Test2",
		title: "nonsensowne edycje"
	},
	{
		caption: "testG",
		template: "Szablon:TestG",
		title: "tworzenie bezsensownych haseł"
	},
	{
		caption: "test3",
		template: "Szablon:Test3",
		title: "niszczenie stron"
	},
	{
		caption: "test4",
		template: "Szablon:Test4",
		title: "ostatnie ostrzeżenie"
	},
	{
		caption: "test5",
		template: "Szablon:Test5",
		title: "blokada"
	},
	{
		type: "text",
		content: " "
	},
	{
		caption: "npa",
		template: "Szablon:TestNPA",
		title: ""
	},
	{
		caption: "reklama",
		template: "Szablon:TestReklama",
		title: ""
	},
	{
		caption: "żart",
		template: "Szablon:Testżart",
		title: ""
	},
	{
		caption: "testL",
		template: "Szablon:TestL",
		title: "niszczenie linków, szablonów"
	},
	{
		caption: "PE",
		template: "Szablon:TestPE",
		title: "zabawa paskiem edycji"
	},
	{
		caption: "AD",
		template: "Szablon:TestAD",
		title: "dodawanie/kasowanie informacji"
	},
	{
		type: "element",
		content: "br"
	},
	{
		caption: "podglądaj",
		template: "Szablon:Podgląd",
		title: "używaj przycisku Pokaż podgląd przed zapisaniem artykułu"
	},
	{
		caption: "opisuj",
		template: "Szablon:Testopis",
		title: "proszę o wypełnianie pola Opis zmian"
	},
	{
		caption: "podpisuj",
		template: "Szablon:Podpisuj",
		title: "podpisywanie i odpisywanie"
	},
	{
		caption: "linkuj",
		template: "Szablon:Linkuj",
		title: "wstawiaj linki wewnętrzne"
	},
	{
		type: "text",
		content: " "
	},
	{
		caption: "grafikizew",
		template: "Szablon:Grafiki zewnętrzne",
		title: "nie zamieszczaj linków do grafik zewnętrznych"
	},
	{
		caption: "wstawiaj ek",
		template: "Wikipedysta:Beau/TestEK",
		title: "nie kasuj zawartości strony, którą chcesz usunąć"
	},
	{
		caption: "nie komentuj",
		template: "Wikipedysta:Beau/TestKomentarz",
		title: "nie umieszczaj komentarzy w treści artykułu"
	},
	{
		caption: "przenoś",
		template: "Szablon:TestPrzenieś",
		title: "nie wolno przenosić stron kopiując jedynie ich treść"
	},
	{
		caption: "ency",
		template: "Wikipedysta:Beau/TestEncy",
		title: "nie dopisuj siebie lub kolegów"
	},
	{
		caption: "nazwa uż.",
		template: "Wikipedysta:Beau/TestLogin",
		title: "zmień nazwę użytkownika"
	},
	{
		caption: "linkujące",
		template: "Wikipedysta:Beau/TestLinkujące",
		title: "adminie! sprawdzaj linkujące zanim coś skasujesz"
	},
	{
		caption: "redirect fix",
		template: "Szablon:TestRedirectFix",
		title: ""
	}
);

jQuery(document).ready(function() {
	if (
		mw.config.get("wgNamespaceNumber") === 3 &&
		['edit', 'submit'].indexOf(mw.config.get("wgAction")) !== -1
	) {
		mw.loader.using([
			'ext.gadget.style-summary-buttons',
			'jquery.textSelection'
		]).done(function() {
			talkTestGadget.init();
		});
	}
});

// </nowiki> -------------------------------------------