MediaWiki:Gadget-EditButtonGuide.js: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
Ostrzyciel (dyskusja • edycje) M |
Ostrzyciel (dyskusja • edycje) M (haaaaaaaxxx) |
||
Linia 18: | Linia 18: | ||
$("#ca-editsection").removeClass("wyrTab"); |
$("#ca-editsection").removeClass("wyrTab"); |
||
}, 3000); |
}, 3000); |
||
} |
|||
function showEditTab() { |
|||
var eButton = $( '#ca-edit' ); |
|||
var loc = eButton.offset(); |
|||
var y = loc.top + eButton.outerHeight() - 5; |
|||
var x = loc.left + eButton.outerWidth() / 2; |
|||
createCSSSelector('.editpopup', 'position: absolute; left: ' + x + '; top: ' + y + ';'); |
|||
var popup = new OO.ui.PopupWidget( { |
|||
$content: $( '<p>Test.</p>' ), |
|||
padded: true, |
|||
width: 300 |
|||
} ); |
|||
$( document.body ).append( popup.$element ); |
|||
popup.toggle( true ); |
|||
} |
} |
||
Linia 32: | Linia 49: | ||
$(document).ready( function() { |
$(document).ready( function() { |
||
//if (mw.config.get("wgUserGroups").indexOf("user") !== -1) return; |
//if (mw.config.get("wgUserGroups").indexOf("user") !== -1) return; |
||
if (mw.config.get("wgAction") !== "view") 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; |
||
Linia 58: | Linia 76: | ||
} |
} |
||
} ); |
} ); |
||
// funky code from stackoverflow for setting new CSS classes |
|||
// it's admittedly horrible, but there doesn't seem to be a better solution for OOUI's popups |
|||
function createCSSSelector (selector, style) { |
|||
if (!document.styleSheets) return; |
|||
if (document.getElementsByTagName('head').length === 0) return; |
|||
var styleSheet,mediaType; |
|||
if (document.styleSheets.length > 0) { |
|||
for (var i = 0, l = document.styleSheets.length; i < l; i++) { |
|||
if (document.styleSheets[i].disabled) |
|||
continue; |
|||
var media = document.styleSheets[i].media; |
|||
mediaType = typeof media; |
|||
if (mediaType === 'string') { |
|||
if (media === '' || (media.indexOf('screen') !== -1)) { |
|||
styleSheet = document.styleSheets[i]; |
|||
} |
|||
} |
|||
else if (mediaType=='object') { |
|||
if (media.mediaText === '' || (media.mediaText.indexOf('screen') !== -1)) { |
|||
styleSheet = document.styleSheets[i]; |
|||
} |
|||
} |
|||
if (typeof styleSheet !== 'undefined') |
|||
break; |
|||
} |
|||
} |
|||
if (typeof styleSheet === 'undefined') { |
|||
var styleSheetElement = document.createElement('style'); |
|||
styleSheetElement.type = 'text/css'; |
|||
document.getElementsByTagName('head')[0].appendChild(styleSheetElement); |
|||
for (i = 0; i < document.styleSheets.length; i++) { |
|||
if (document.styleSheets[i].disabled) { |
|||
continue; |
|||
} |
|||
styleSheet = document.styleSheets[i]; |
|||
} |
|||
mediaType = typeof styleSheet.media; |
|||
} |
|||
if (mediaType === 'string') { |
|||
for (var i = 0, l = styleSheet.rules.length; i < l; i++) { |
|||
if(styleSheet.rules[i].selectorText && styleSheet.rules[i].selectorText.toLowerCase()==selector.toLowerCase()) { |
|||
styleSheet.rules[i].style.cssText = style; |
|||
return; |
|||
} |
|||
} |
|||
styleSheet.addRule(selector,style); |
|||
} |
|||
else if (mediaType === 'object') { |
|||
var styleSheetLength = (styleSheet.cssRules) ? styleSheet.cssRules.length : 0; |
|||
for (var i = 0; i < styleSheetLength; i++) { |
|||
if (styleSheet.cssRules[i].selectorText && styleSheet.cssRules[i].selectorText.toLowerCase() == selector.toLowerCase()) { |
|||
styleSheet.cssRules[i].style.cssText = style; |
|||
return; |
|||
} |
|||
} |
|||
styleSheet.insertRule(selector + '{' + style + '}', styleSheetLength); |
|||
} |
|||
} |
Wersja z 13:43, 9 kwi 2020
/*
Autorzy: [[User:Polskacafe]], [[User:Ostrzyciel]]
*/
// constants
const message = 'Czy wiesz, że nie musisz nikogo prosić o wprowadzanie poprawek, bo sam możesz to zrobić?' +
' Wystarczy, że klikniesz jeden z przycisków edycji! Pokażemy ci je, gdy zaakceptujesz tą wiadomość.';
const cookieCounter = 'uceCounter';
const cookieClosed = 'uceDialogClosed';
const forever = new Date('2038-01-01 00:00'); // close enough
// helper functions
function applyChanges() {
$(".mw-editsection > a").addClass("wyr");
$("#ca-editsection").addClass("wyrTab");
setTimeout(function () {
$(".mw-editsection > a").removeClass("wyr");
$("#ca-editsection").removeClass("wyrTab");
}, 3000);
}
function showEditTab() {
var eButton = $( '#ca-edit' );
var loc = eButton.offset();
var y = loc.top + eButton.outerHeight() - 5;
var x = loc.left + eButton.outerWidth() / 2;
createCSSSelector('.editpopup', 'position: absolute; left: ' + x + '; top: ' + y + ';');
var popup = new OO.ui.PopupWidget( {
$content: $( '<p>Test.</p>' ),
padded: true,
width: 300
} );
$( document.body ).append( popup.$element );
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("wgAction") !== "view") return;
if (mw.config.get("wgNamespaceNumber") == -1) return;
if (!mw.config.get("wgIsProbablyEditable")) return;
if (mw.cookie.get(cookieClosed)) return;
console.debug('elo');
incrementCounter();
if (parseInt(getCounter()) >= 4) {
var windowManager = new OO.ui.WindowManager();
$( 'body' ).append( windowManager.$element );
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);
mw.cookie.set(cookieClosed, true, forever);
}
} );
// funky code from stackoverflow for setting new CSS classes
// it's admittedly horrible, but there doesn't seem to be a better solution for OOUI's popups
function createCSSSelector (selector, style) {
if (!document.styleSheets) return;
if (document.getElementsByTagName('head').length === 0) return;
var styleSheet,mediaType;
if (document.styleSheets.length > 0) {
for (var i = 0, l = document.styleSheets.length; i < l; i++) {
if (document.styleSheets[i].disabled)
continue;
var media = document.styleSheets[i].media;
mediaType = typeof media;
if (mediaType === 'string') {
if (media === '' || (media.indexOf('screen') !== -1)) {
styleSheet = document.styleSheets[i];
}
}
else if (mediaType=='object') {
if (media.mediaText === '' || (media.mediaText.indexOf('screen') !== -1)) {
styleSheet = document.styleSheets[i];
}
}
if (typeof styleSheet !== 'undefined')
break;
}
}
if (typeof styleSheet === 'undefined') {
var styleSheetElement = document.createElement('style');
styleSheetElement.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(styleSheetElement);
for (i = 0; i < document.styleSheets.length; i++) {
if (document.styleSheets[i].disabled) {
continue;
}
styleSheet = document.styleSheets[i];
}
mediaType = typeof styleSheet.media;
}
if (mediaType === 'string') {
for (var i = 0, l = styleSheet.rules.length; i < l; i++) {
if(styleSheet.rules[i].selectorText && styleSheet.rules[i].selectorText.toLowerCase()==selector.toLowerCase()) {
styleSheet.rules[i].style.cssText = style;
return;
}
}
styleSheet.addRule(selector,style);
}
else if (mediaType === 'object') {
var styleSheetLength = (styleSheet.cssRules) ? styleSheet.cssRules.length : 0;
for (var i = 0; i < styleSheetLength; i++) {
if (styleSheet.cssRules[i].selectorText && styleSheet.cssRules[i].selectorText.toLowerCase() == selector.toLowerCase()) {
styleSheet.cssRules[i].style.cssText = style;
return;
}
}
styleSheet.insertRule(selector + '{' + style + '}', styleSheetLength);
}
}