MediaWiki:Gadget-EditButtonGuide.js

Z Nonsensopedii, polskiej encyklopedii humoru

Uwaga: aby zobaczyć zmiany po zapisaniu, 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: Przytrzymaj Ctrl jednocześnie klikając Odśwież lub naciśnij klawisze Ctrl+F5
  • Konqueror: Kliknij polecenie Odśwież lub naciśnij klawisz F5
  • Opera: Wyczyść pamięć podręczną w Narzędzia → Preferencje
/**
 * Autorzy: [[User:Polskacafe]], [[User:Ostrzyciel]]
 * <nowiki>
 */

// constants
const cookieCounter = 'ebgCounter';
const cookieClosed = 'ebgDialogClosed';
const cookieEdited = 'ebgEdited';
const month = 30 * 24 * 60 * 60;
const editButtonMsg = '<p>Nonsensopedię może edytować każdy? Wystarczy kliknąć przycisk <i>Edytuj</i> na górze strony.</p>';

// helper functions
function showEditTab() {
	var eButton;
	
	// VE działa od 550px
	if ( window.innerWidth > 550 ) {
		eButton = $( '#ca-ve-edit' );
		if (eButton.length === 0) eButton = $( '#ca-edit' );
	} else {
		eButton = $( '#ca-edit' );
	}
	
	var loc = eButton.offset();
	var w = eButton.outerWidth();
	
	// align to right to at least pretend we're handling this correctly
	var right = $(document).width() - loc.left - w;
	var overlay = $( '<div />', {
		class: "ebg-overlay",
		style: "width:" + w + "px;height:" + eButton.outerHeight() +
			"px;top:" + loc.top + "px;right:" + right + "px;"
	} );
	$(document.body).append(overlay);
	
	var popup = new OO.ui.PopupWidget( {
		$content: $( editButtonMsg ),
		padded: true,
		width: 300,
		head: true,
		label: 'Czy nie wiesz, że…',
		classes: [ 'ebg-popup' ]
	} );
	
	overlay.append( popup.$element );
	
	// no, there is no proper popup closed event
	$('.ebg-popup a.oo-ui-buttonElement-button').click( function() {
		mw.cookie.set(cookieClosed, true, 3 * month);
	} );
	
	// hide the popup when VE kicks in
	$( '#ca-ve-edit' ).click( function() {
		popup.toggle( false );
		mw.cookie.set(cookieClosed, true, 6 * month);
	} );
	
	popup.toggle( true );
}

function getCounter() {
	return mw.cookie.get(cookieCounter) || "0";
}

function incrementCounter() {
	var cVal = parseInt(getCounter()) + 1;
	mw.cookie.set(cookieCounter, cVal, 0);		// this is a per-session cookie
}

// main jazz
$(document).ready( function() {
	if (mw.config.get("wgUserGroups").indexOf("user") !== -1) return;
	if (mw.config.get("wgNamespaceNumber") == -1) return;
	if (!mw.config.get("wgIsProbablyEditable")) return;
	
	var action = mw.config.get("wgAction");
	if (action === "edit" || window.location.search.indexOf('veaction=edit') !== -1) {
		mw.cookie.set(cookieEdited, true, 6 * month);
	} else if (action === "view") {
		if (mw.cookie.get(cookieClosed)) return;
		if (mw.cookie.get(cookieEdited)) return;
		
		incrementCounter();
	
		if (parseInt(getCounter()) >= 4) {
			showEditTab();
		}
	}
} );

/**
 * </nowiki>
 */