User:Iynque/chat.js

////////////////////////////////////////////////

/* START kocka's chat emoticons */ /* Originally copied from http://kocka.wikia.com/wiki/MediaWiki:Emoticons/code.js?oldid=226 */ /* Modified version */

$(function {   // Adding neccessary CSS    mw.util.addCSS(".kockaEmoticonsIcon{width:19px;height:19px;border:1px solid black;padding: 10px;border-radius:5px;}#kockaEmoticonsModalMain{height:400px;overflow-y:auto;}");    // Initializing variables    var obj = window.kockaEmoticons || {};    obj.emoticons = {};    obj.vocab = obj.vocab || {};    // Parsing emoticons    mw.config.get('wgChatEmoticons').split("\n").forEach(function(el, index, arr) { if(el[0] === "*" && el[1] !== "*") obj.emoticons[arr[index + 1].substring(2).trim] = el.substring(1).trim; }, this);    /**     * Function for creating an emoticon element     * @param [String] emote - Emote code     * @method     */    function createEmoteElement(emote)    {        var el = document.createElement("img");        el.className = "kockaEmoticonsIcon button";        el.src = obj.emoticons[emote];        el.setAttribute('title', emote); el.onclick = function {           var ap = $(".message textarea").last; ap.val(ap.attr("value") + " " + emote); $("#kockaEmoticonsModal").closeModal; };       $("#kockaEmoticonsModalMain").append(el); }   // Creating Emoticons button var button = document.createElement("button"); button.innerHTML = obj.vocab.emoticons || "Emoticons"; button.className = "kockaEmoticonsSpan"; button.onclick = function {       // Show modal // TODO: Fix double-initializing to make the modal loading faster. $.showCustomModal(obj.vocab.emoticons || "Emoticons", " " + (obj.help || "Choose an emoticon by clicking on it.") + " ",        {            id: "kockaEmoticonsModal",            buttons: [{                id: "kockaEmoticonsClose",                defaultButton: true,                message: obj.vocab.close || "Close",                handler: function{ $("#kockaEmoticonsModal").closeModal; }            }]        }); // Adding emoticons to modal for(var emote in obj.emoticons) if(obj.emoticons.hasOwnProperty(emote)) createEmoteElement(emote); };   // Adding button to title // Steven Universe Wiki is an exception, as requested by User:Dorumin if(wgServer === "http://steven-universe.wikia.com") $('#chatOptionsButton + .chat-button').after(button); else $('.public.wordmark').first.append(button); });

/* END kocka's chat emoticons */

////////////////////////////////////////////////

importArticles({   type: 'script',    articles: [        //'u:kocka:MediaWiki:Emoticons/code.js', //Reveals available emoticons        'u:dev:MediaWiki:ChatOptions/code.js' //Includes chathacks, searchbar, PMs, multikick    ] });

////////////////////////////////////////////////

console.info("Loaded User:Iynque/chat.js version 3.1");

////////////////////////////////////////////////