MediaWiki:Gadget-Echo-NewMessages-Union.js

Z Enviwiki
Skočit na navigaci Skočit na vyhledávání

Poznámka: Po zveřejnění musíte vyprázdnit cache vašeho prohlížeče, jinak změny neuvidíte.

  • Firefox / Safari: Při kliknutí na Aktualizovat držte Shift nebo stiskněte Ctrl-F5 nebo Ctrl-R (na Macu ⌘-R)
  • Google Chrome: Stiskněte Ctrl-Shift-R (na Macu ⌘-Shift-R)
  • Internet Explorer / Edge: Při kliknutí na Aktualizovat držte Ctrl nebo stiskněte Ctrl-F5
  • Opera: Stiskněte Ctrl-F5.
var echoUnion = {
    
    // počet notifikací
    echoNumber : 0,
    
    // počet nových zpráv
    messagesNumber : 0,
    
    // funkce zjistí počet notifikací a počet zpráv a sečte je
    count : function() {
        // počet notifikací
        echoUnion.echoNumber = parseInt($("#pt-notifications").find("a").text());
    
        // počet nových zpráv
        echoUnion.messagesNumber = 0;
        if ( /\d+/.test($("#pt-newmessages").find("a").text())) {
            echoUnion.messagesNumber = parseInt(/\d+/.exec($("#pt-newmessages").find("a").text()));
        }
    
        // součet
        sumNumber = echoUnion.echoNumber + echoUnion.messagesNumber;
        
        // zobrazit počet notifikací a počet zpráv dohromady
        $("#pt-notifications").find("a").text(sumNumber);
    },
    
    // funkce přesouvá odkaz na nové zprávy do notifikací
    messagesTransform : function() {
        // zprávy stejný styl jako notifikace
        messages = $("#pt-newmessages");
        messages.removeClass("active").addClass("mw-echo-notification");
        messages.children("a").addClass("mw-echo-notification-wrapper");

        // text se vloží do vnořeného elementu, aby měl stejný styl jako notifikace
        messages.children("a").html(
            '<div class="mw-echo-state"><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/3/39/Internet-group-chat.svg/30px-Internet-group-chat.svg.png?uselang=cs" class="mw-echo-icon" /><div class="mw-echo-content"><div class="mw-echo-title">'
            + '<b>Máte nové zprávy: ' + echoUnion.messagesNumber 
            + "</b></div></div></div>"
        );
        
        // přesunout a zobazit v overlay, pokud je ale nějaká zpráva přítomna...
        messages.detach();
        if (echoUnion.messagesNumber == 0) return;
        mw.hook('ext.echo.overlay.beforeShowingOverlay').add(function($overlay) {
            if (echoUnion.echoNumber > 0 ) { 
                // pokud má Echo má nějaké notifikace, existuje ul.mw-echo-notifications
                $overlay.children("ul.mw-echo-notifications").prepend(messages);
            } else {
                // Echo nemá žádné notifikace, musíme rovnou do $overlay
                $overlay.prepend(messages);
            }
        });
    }
}

// spustit
$(function() {
    echoUnion.count();
    echoUnion.messagesTransform();
});