MediaWiki:Gadget-edit-first-section.js

/*
== Dodanie linka [edytuj] dla sekcji nagłówkowej ==
; Pomysł: [[:en:User:Pile0nades]]
; Autorzy:
: Maciej Jaros [[:pl:User:Nux]]
: Skalee [[:pl:User:Skalee]]
: [[:pl:User:Matma Rex]]
<nowiki>
*/
/* global mw, jQuery */
(function ($) {

	// Liczba nagłówków drugiego, trzeciego i czwartego stopnia
	// jakie muszą się pojawić w artykule, żeby pojawił się link
	window.addEditTopLinkNumHeaders = 2; // dla 2 => dla dwóch i więcej się pojawi

	// Link do edycji sekcji wstępnej (nr=0).
	function addTopEdit() {
		let editUrl = $('#ca-edit, #ca-viewsource').find('a').attr('href');
		if (editUrl === undefined || $('h2,h3,h4').length < window.addEditTopLinkNumHeaders) {
			return;
		}

	    let sibling = document.querySelector('#firstHeading .mw-page-title-main');
	    if (sibling) {
			// Edit link
			sibling
				.insertAdjacentHTML("afterend", ''
					+`<span class="mw-editsection first-editsection" aria-hidden="true">`
					+	`<span aria-hidden="true" class="mw-editsection-bracket">[</span>`
					+	`<a href="${editUrl}&section=0" title="edytuj sekcję nagłówkową artykułu">edytuj wstęp</a>`
					+	`<span aria-hidden="true" class="mw-editsection-bracket">]</span>`
					+`</span>`
				)
			;
	    }
	}
	// Główny init (po załadowaniu strony).
	function init() {
		addTopEdit();
		// WCAG, skip-link (do przenisienia do dedykowanego gadgetu... może)
		let preSkip = document.querySelector('#firstHeading');
		if (preSkip) preSkip
			.insertAdjacentHTML("afterend", '<a class="mw-jump-link gdgt-edit-first-section" href="#mw-content-text">Przejdź do treści</a>')
		;
	}

	// Check if should init
	if (mw.config.get('wgIsArticle') &&
		mw.config.get('wgAction') === 'view' &&
		['vector', 'vector-2022', 'monobook'].indexOf( mw.config.get('skin') ) > -1) {
		// There was additional condition, but I can't believe it's needed any longer:
		// somehow it gets run twice on some pages - stop that
		// !window.addEditTopLinkDone) {
		// window.addEditTopLinkDone = true;
		$(init);
	}
})(jQuery);
// </nowiki>

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.
Kembali kehalaman sebelumnya