MediaWiki:Gadget-EditButtonGuide.js: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
Ostrzyciel (dyskusja • edycje) M |
Ostrzyciel (dyskusja • edycje) M |
||
(Nie pokazano 20 wersji utworzonych przez 2 użytkowników) | |||
Linia 1: | Linia 1: | ||
/* |
/** |
||
Autorzy: [[User:Polskacafe]], [[User:Ostrzyciel]] |
* Autorzy: [[User:Polskacafe]], [[User:Ostrzyciel]] |
||
* <nowiki> |
|||
*/ |
*/ |
||
// constants |
// constants |
||
const cookieCounter = 'ebgCounter'; |
|||
const message = 'Czy wiesz, że nie musisz nikogo prosić o wprowadzanie poprawek, bo sam możesz to zrobić?' + |
|||
const cookieClosed = 'ebgDialogClosed'; |
|||
' Wystarczy, że klikniesz jeden z przycisków edycji! Pokażemy ci je, gdy zaakceptujesz tą wiadomość.'; |
|||
const |
const cookieEdited = 'ebgEdited'; |
||
const |
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>'; |
|||
const forever = new Date('2038-01-01 00:00'); // close enough |
|||
// helper functions |
// helper functions |
||
function |
function showEditTab() { |
||
var eButton; |
|||
$(".mw-editsection > a").addClass("wyr"); |
|||
$("#ca-editsection").addClass("wyrTab"); |
|||
// VE działa od 550px |
|||
setTimeout(function () { |
|||
if ( window.innerWidth > 550 ) { |
|||
$(".mw-editsection > a").removeClass("wyr"); |
|||
eButton = $( '#ca-ve-edit' ); |
|||
$("#ca-editsection").removeClass("wyrTab"); |
|||
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' ] |
|||
} ); |
|||
⚫ | |||
// no, there is no proper popup closed event |
|||
$('.ebg-popup a.oo-ui-buttonElement-button').click( function() { |
|||
⚫ | |||
} ); |
|||
// hide the popup when VE kicks in |
|||
$( '#ca-ve-edit' ).click( function() { |
|||
popup.toggle( false ); |
|||
⚫ | |||
} ); |
|||
popup.toggle( true ); |
|||
} |
} |
||
Linia 31: | Linia 71: | ||
// main jazz |
// main jazz |
||
$(document).ready( function() { |
$(document).ready( function() { |
||
if (mw.config.get("wgUserGroups").indexOf("user") !== -1) return; |
|||
if (mw.config.get("wgNamespaceNumber") == -1) return; |
if (mw.config.get("wgNamespaceNumber") == -1) return; |
||
if (!mw.config.get("wgIsProbablyEditable")) return; |
if (!mw.config.get("wgIsProbablyEditable")) return; |
||
⚫ | |||
var action = mw.config.get("wgAction"); |
|||
console.debug('elo'); |
|||
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; |
|||
⚫ | |||
if (parseInt(getCounter()) >= 4) { |
|||
showEditTab(); |
|||
var windowManager = new OO.ui.WindowManager(); |
|||
⚫ | |||
⚫ | |||
var messageInfo = new OO.ui.MessageDialog(); |
|||
windowManager.addWindows( [ messageInfo ] ); |
|||
windowManager.openWindow( messageInfo, { |
|||
title: 'Cześć!', |
|||
message: message, |
|||
actions: [ |
|||
{ |
|||
action: 'accept', |
|||
label: 'Zrozumiano!', |
|||
flags: 'primary' |
|||
⚫ | |||
] |
|||
} ).closing.done(applyChanges); |
|||
⚫ | |||
} |
} |
||
} ); |
} ); |
||
/** |
|||
* </nowiki> |
|||
*/ |
Aktualna wersja na dzień 18:53, 28 maj 2022
/**
* 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>
*/