FANDOM


(Possible to add a class to the notification contents DIV?: new section)
Line 231: Line 231:
 
:'''Agent Zuri [[:User:Agent_Zuri|<span class="button">Profile</span>]] [[:User talk:Agent_Zuri|<span class="button">Message Wall</span>]] [[:User Blog:Agent Zuri|<span class="button">Blog</span>]]''' 11:33, July 21, 2017 (UTC)
 
:'''Agent Zuri [[:User:Agent_Zuri|<span class="button">Profile</span>]] [[:User talk:Agent_Zuri|<span class="button">Message Wall</span>]] [[:User Blog:Agent Zuri|<span class="button">Blog</span>]]''' 11:33, July 21, 2017 (UTC)
 
::It is still displaying a blank notification.--[[User:Luma.dash|Luma.dash]] ([[User talk:Luma.dash|talk]]) 07:24, July 22, 2017 (UTC)
 
::It is still displaying a blank notification.--[[User:Luma.dash|Luma.dash]] ([[User talk:Luma.dash|talk]]) 07:24, July 22, 2017 (UTC)
  +
  +
== Possible to add a class to the notification contents DIV? ==
  +
  +
This would allow for easier styling of the notification like making the box bigger with padding or maybe larger text size via CSS. --&nbsp;[[User:Fandyllic|<span style="border-bottom:1px dotted; cursor:help;" title="Former WoWWiki Admin">Fandyllic</span>]]<small> ([[User talk:Fandyllic|talk]] &middot; [[Special:Contributions/Fandyllic|contr]])</small> 13 Sep 2017 3:54 PM Pacific

Revision as of 23:54, September 13, 2017

Adding links

¡Hi! I like this code, but I have one cuestion: how will add the links?

  • Using <a href="/wiki/PAGE_NAME">PAGE</a>?
  • Or using [[PAGE NAME|PAGE]]?

Regards! P[ntor Kagam]ne [ talk me!117 contribs.] 03:13, April 4, 2014 (UTC)

Hi Kagamine,
I tested both, and only the 2nd is working. However, you will have to add a « \ » before every « " » to make it work.
Hulothe (discussion) 13:13, April 4, 2014 (UTC)
Right. Wikitext won't work in a non-wiki environment such as an HTML document, you have to use HTML. You can either use <a href=\"/wiki/PAGE_NAME\">PAGE</a> or, to make it simple, just use ' instead of " (<a href='/wiki/PAGE_NAME'>PAGE</a>) Jak Himself (talk) 16:02, April 4, 2014 (UTC)

Cookies

Hello,

I've tried to add cookies to the code in order to avoid the come back of the pop-up at each refreshs. If someone would like to continue the code below, he can. I am not good at javascript, this is why I share this code :

Sorry for my english, I am not a native.

/*!
 * WikiaNotification JS by User:Jak Himself
 * http://dev.wikia.com/wiki/WikiaNotification
 * requires jQuery
 * version 0.2
!*/
 
function WikiaNotification() {
    var notif = document.createElement("ul");
    notif.setAttribute("id", "WikiaNotifications");
    notif.setAttribute("class", "WikiaNotifications");
 
    var innerLi = document.createElement("li");
 
    var dataType = document.createElement("div");
    dataType.setAttribute("data-type", "2");
 
    var close = document.createElement("a");
    $(close).addClass("sprite close-notification");
 
    $(notif).append(innerLi);
    $(innerLi).append(dataType);
    $(dataType).append(close);
    $(dataType).append(WikiaNotificationMessage);
    $(".WikiaSiteWrapper").append(notif);
 }
    $(function() {
    if( WikiaNotificationMessage.length > 0 ) {
        var cook = getcookie();
		if (cook==null) {
		WikiaNotification();
}
}
    else if( WikiaNotificationMessage.length < 1 || WikiaNotificationMessage === "undefined") {
        console.log("WikiaNotification error: Message empty.");
    }
    $(".sprite.close-notification").on("click", function() {
        $("#WikiaNotifications.WikiaNotifications").hide();
        setCookie();
    });
});
function setCookie(WikiaNotification, sValue) {
        var today = new Date(), expires = new Date();
        expires.setTime(today.getTime() + (60*1000));
        document.cookie = sName + "=" + encodeURIComponent(sValue) + ";expires=" + expires.toGMTString();
}
function getCookie(sName) {
        var oRegex = new RegExp("(?:; )?" + sName + "=([^;]*);?");
 
        if (oRegex.test(document.cookie)) {
                return decodeURIComponent(RegExp["$1"]);
        } else {
                return null;
        }
}
//

Gguigui1 (talk) 12:18, April 21, 2014 (UTC)

Ah, thank you very much for this! I'm not that great at javascript either (only jQuery when I need it) so this is very helpful. I'll test it out! Jak Himself (talk) 14:21, April 22, 2014 (UTC)
I edit a little the code but it's still doesn't work :( 
/*!
 * WikiaNotification JS by User:Jak Himself
 * http://dev.wikia.com/wiki/WikiaNotification
 * requires jQuery
 * version 0.2
!*/
 
function WikiaNotification() {
    var notif = document.createElement("ul");
    notif.setAttribute("id", "WikiaNotifications");
    notif.setAttribute("class", "WikiaNotifications");
 
    var innerLi = document.createElement("li");
 
    var dataType = document.createElement("div");
    dataType.setAttribute("data-type", "2");
 
    var close = document.createElement("a");
    $(close).addClass("sprite close-notification");
 
    $(notif).append(innerLi);
    $(innerLi).append(dataType);
    $(dataType).append(close);
    $(dataType).append(WikiaNotificationMessage);
    $(".WikiaSiteWrapper").append(notif);
 }
function setCookie(sName, sValue) {
        var today = new Date(), expires = new Date();
        expires.setTime(today.getTime() + (60*1000));
        document.cookie = sName + "=" + encodeURIComponent(sValue) + ";expires=" + expires.toGMTString();
}
function getCookie(sName) {
        var oRegex = new RegExp("(?:; )?" + sName + "=([^;]*);?");
 
        if (oRegex.test(document.cookie)) {
                return decodeURIComponent(RegExp["$1"]);
        } else {
                return null;
        }
}
    $(function() {
    if( WikiaNotificationMessage.length > 0 ) {
        var cook = getcookie(WikiaNotification);
		if (!cook) {
		WikiaNotification();
}
}
    else if( WikiaNotificationMessage.length < 1 || WikiaNotificationMessage === "undefined") {
        console.log("WikiaNotification error: Message empty.");
    }
}
    $(".sprite.close-notification").on("click", function() {
        $("#WikiaNotifications.WikiaNotifications").hide();
        setCookie(WikiaNotification,"Ok");
    });
});
//
Gguigui1 (talk) 14:44, April 23, 2014 (UTC)
Hmm. I am also currently trying to solve this. One thing is cook = getcookie(WikiaNotification), where getcookie is supposed to be getCookie. Also it's missing an extra ); at the end of the $(function(){}); (notice the ); I've changed both of these problems in the testing environment I'm working in but it's still not working for me either. I'll continue to see if I can solve it. Thanks for your contributions, thus far! Jak Himself (talk) 17:27, April 25, 2014 (UTC)

Hello, sorry for the long delay but I have finally solve this. The notification will not appear for 2 hours. Maybe let the user choose his value and put two hours default. It's up to you. Gguigui1 (talk) 15:13, July 4, 2014 (UTC)

Thank you, very much Gguigui1! :-) Jak Himself (talk) 16:10, July 22, 2014 (UTC)

Cookies Problem

When I try to close the pop-up, it return immediately at each refreshs. Can somebody fix this issue? Thank you Dai ca superman (talk) 07:54, June 4, 2016 (UTC)

Updating?

if the text is edited, people won't see it until it is reviewed, which takes a while, and would mess things up such as a live voting system. Any ideas to fix this? ~ Thundermaker300, (Chat) 14:08, July 1, 2016 (UTC)

Fixed/Improved some things

Hi, I improved or fixed some things as follows:

  • As Thundermaker300 noted up there texts can be updated when setting WikiaNotificationMessagePage (commonly a MediaWiki page beginning with Custom-*) instead of WikiaNotificationMessage
  • There only wikicode can be used as requested up there by Pintor
  • When clicking the close icon only the affected message is closed
  • A temporary message can be added by the function outputNotification() now
  • If more than one message is present (one made by wikia itself) the won't overlay themselves any longer
  • PROPOSAL: Although messages should sparely used there should be a possibility to display more than one
  • PROPOSAL: Not everyone likes Cookies, I would suggest using localStorage

I could implement these two proposals, too, if desired ;)

function outputNotification(message) {
    if(!$('.WikiaBar').length) {
        $('.WikiaPage').after($('<div />').addClass('WikiaBar'));
    }
    if(!$('ul.WikiaNotifications#WikiaNotifications').length) {
        $('.WikiaBar').append(
            $('<ul />').addClass('WikiaNotifications').attr('id','WikiaNotifications')
        );
    }
 
    if (message.length) {
        $('ul.WikiaNotifications#WikiaNotifications').append(
            $('<li />').append(
                $('<div />')
                    .attr('data-type', '2')
                    .html(message)
                    .append(
                        $('<a />').addClass('sprite close-notification')
                )
            )
        );
    }
    else {
        if (message === "") {
            console.error("WikiaNotification error: Message empty.");
        }
    }
 
    $(".sprite.close-notification").on("click", function() {
        $(this).closest('li').hide();
        setCookie('WikiaNotification',WikiaNotificationMessage,WikiaNotificationexpiry);
    });
}
 
function setCookie( cname, cvalue, exdays ) {
	var d = new Date();
	d.setTime(d.getTime() + (exdays*24*60*60*1000));
	var expires = "expires=" + d.toGMTString();
	document.cookie = cname + "=" + cvalue + "; " + expires;
}
 
$(function() {
	var ids = $.cookie('WikiaNotification'),
        message = window.WikiaNotificationMessage || "",
        expiry = window.WikiaNotificationexpiry || 10;
 
        if(window.hasOwnProperty('WikiaNotificationMessagePage')) {
            $.get('/api.php?action=parse&page=MediaWiki:' + WikiaNotificationMessagePage + '&format=json', function(data) {
                message = data.parse.text['*'];
                outputNotification(message);
            });
        }
        else {
            outputNotification(message);
        }
});

Agent Zuri Über mich Nachrichtenseite Ankündigungen 15:13, August 17, 2016 (UTC)

Blank message

I noticed that when there is no message inputted into the MediaWiki system message, it still displays the notification on the Oasis skin, but it is small and blank. Could this be fixed?--Luma.dash (talk) 08:23, July 19, 2017 (UTC)

I let the script check this case now and submitted it for review.
Agent Zuri Profile Message Wall Blog 11:33, July 21, 2017 (UTC)
It is still displaying a blank notification.--Luma.dash (talk) 07:24, July 22, 2017 (UTC)

Possible to add a class to the notification contents DIV?

This would allow for easier styling of the notification like making the box bigger with padding or maybe larger text size via CSS. -- Fandyllic (talk · contr) 13 Sep 2017 3:54 PM Pacific

Community content is available under CC-BY-SA unless otherwise noted.