User:Ultimate Dark Carnage/chat.js

importArticles(/*{   type: 'script',    articles: [        "u:dev:MessageBlocker/code.js",        "u:c:User:Ultimate_Dark_Carnage/commands.js",        "u:c:User:Ultimate_Dark_Carnage/test.js",        "u:c:User:Ultimate_Dark_Carnage/sandbox2.js"    ] }, */{    'type': 'style',    articles: [        'u:c:User:Ultimate_Dark_Carnage/chat2.css'    ] });

$(document).ready(function{   var msg_no = 0;    localStorage.setItem('title', document.title);    $(window).on('blur', function{ $('.ChatWindow').on('DOMNodeInserted', '.Chat ul > li .message', function(event){           msg_no = msg_no + 1;            var original_title = localStorage.getItem('title');            document.title = '(' + msg_no + ') ' + original_title;        }); });   $(window).on('focus', function{ $('.ChatWindow').off('DOMNodeInserted'); msg_no = 0; var original_title = localStorage.getItem('title'); document.title = original_title; }); });

/** * Chat Navigation **/

// Part I window.chat_nav = function chat_nav{ this.loaded = false; this.active = false; this.items = []; if (this.loaded === false) this.load; return this; };

// Part II chat_nav.prototype.emoticons = function emoticons{ var $body = $(document.body), Emoticons = {}, RecentEmoticons = {}, create_emote = function CreateEmote($elem, emote){ var $emote_el = $(' ').addClass('emoticon emote'), $emote_img = $emote_el.find('img'); $emote_img.attr({               'src': Emoticons[emote],                'data-title': emote            }).on('click', function insert(event){                var $txt = $('.Write [name="message"]').last;                $txt.val($txt.val ? $txt.val + ' ' + emote : emote);               if ($('.EmoticonPanel').length) $('.EmoticonPanel').hide;                update_recent_emoticons($elem, emote);            }); },       update_recent_emoticons = function UpdateRecentEmoticons($elem, emote){ var $emote_el = $(' ').addClass('emoticon emote'), $emote_img = $emote_el.find('img'); $emote_img.attr({               'src': Emoticons[emote],                'data-title': emote            }).on('click', function insert(event){                var $txt = $('.Write [name="message"]').last;                $txt.val($txt.val ? $txt.val + ' ' + emote : emote);               if ($('.EmoticonPanel').length) $('.EmoticonPanel').hide;                update_recent_emoticons($elem, emote);            }); if (!$('.panel-recent img[src="' + Emoticons[emote] + '"]').length){ //TODO: Save the recent emoticons using local storage if ($('.panel-recent .panel-main .emote').length < 13){ $('.EmoticonPanel').find('.panel-recent .panel-main').prepend($emote_el); } else { $('.EmoticonPanel').find('.panel-recent .panel-main .emote').last.remove; $('.EmoticonPanel').find('.panel-recent .panel-main').prepend($emote_el); }           }        },        $panel = ($body.hasClass('ChatWindow')) ? $('    ').addClass('EmoticonPanel emoticon-panel panel') : null, _emoticons = mw.config.get('wgChatEmoticons', wgChatEmoticons); Array.prototype.forEach.call(_emoticons.split(/\n/gi), function createObj(el, index, arr){       if (el[0] === '*' && el[1] !== '*')            Emoticons[arr[index + 1].substring(2).trim] = el.substring(1).trim;    }, this); $panel.find('> header') .addClass('panel-header') .html([           $(' ')                .addClass('panel-heading panel-title')                .text('Emoticon Panel'),            $('')                .addClass('panel-close')                .attr('href', 'javascript:void(0);')                .text('&times;')                .on('click', function close(ev){ $('.EmoticonPanel').hide; })       ]);    $panel.find('> div').eq(0) .addClass('panel-section panel-emoticons') .html([           $(' ')                .addClass('panel-heading panel-subtitle')                .text('Emoticons'),            $(' ')                .addClass('panel-main')        ]); $panel.find('> div').eq(1) .addClass('panel-section panel-recent') .html([           $(' ')                .addClass('panel-heading panel-subtitle')                .text('Recent Emoticons'),            $(' ')                .addClass('panel-main')        ]); this.insertLink('Emoticon Panel', {       id: 'EmoticonPanelTrigger',        handler: function trigger(event){            if (!$('.EmoticonPanel').length){                $body.append($panel);                for (var emote in Emoticons)                    if (Emoticons.hasOwnProperty(emote))                        CreateEmote($('.EmoticonPanel .panel-emoticons'), emote);            } else {                $('.EmoticonPanel').show;            }        }    }); };

// chat_nav.prototype.insertLink = function insertLink(name, config){ var $link = $('') .attr('id', config.id) .find('> a[href]') .text(name) .on('click', config.handler); this.items[this.items.length] = $link; };

// chat_nav.prototype.load = function load{ var $html = $(' &times;   ').addClass('hidden'), $wordmark = $('.ChatHeader').find('.wordmark img'), _src = $wordmark.attr('src'); $html.find('> .wordmark-wrapper .wordmark img').attr('src', _src); $html.find('> .chat-nav-close').on('click', function close(event){       $(event.target).parent.addClass('hidden');    }); if (this.emoticons instanceof Function || typeof this.emoticons == 'function') this.emoticons; $html.find('> .menu > .menu-list').html(this.items); $('.public.wordmark').first.append(       $('')            .text('Options')            .on('click', function showNav(ev){ $('#ChatNavigation').removeClass('hidden'); })   );    this.loaded = true; };

var C = new chat_nav;

/** * This version of the * Emoticon Panel is made * specifically for this * wiki. Please do not copy * unless you are given * permission to by an * administrator. * * - Ultimate Dark Carnage **/ $(document).ready(function{   var $body = $(document.body),        Emoticons = {};    function CreateEmote($elem, emote){        var $emote_el_main = $(' ').addClass('emoticon-icon emote'),            $emote_el = $emote_el_main.find('img');        $emote_el.attr('src', Emoticons[emote]);        $emote_el.attr('data-tooltip', emote);        $emote_el.on('click', function(ev){ var $txt = $('.Write [name="message"]').last; $txt.val($txt.val ? $txt.val + ' ' + emote : emote); if ($('.EmoticonPanel').length) $('.EmoticonPanel').hide; UpdateRecentEmoticons($elem, emote); });       // Prevents element from        // duplicating.        if (!$('.panel-emoticons img[src="' + Emoticons[emote] + '"]').length) $('.EmoticonPanel').find('.panel-emoticons .panel-main').append($emote_el_main);    }    function UpdateRecentEmoticons($elem, emote){        var $emote_el_main = $(' ').addClass('emoticon-icon emote'),            $emote_el = $emote_el_main.find('img');        $emote_el.attr('src', Emoticons[emote]);        $emote_el.attr('data-tooltip', emote);        $emote_el.on('click', function(ev){ var $txt = $('.Write [name="message"]').last; $txt.val($txt.val ? $txt.val + ' ' + emote : emote); if ($('.EmoticonPanel').length) $('.EmoticonPanel').hide; UpdateRecentEmoticons($elem, emote); });       if (!$('.panel-recent img[src="' + Emoticons[emote] + '"]').length){            if ($('.panel-recent .panel-main .emote').length < 13)                $('.EmoticonPanel').find('.panel-recent .panel-main').prepend($emote_el_main);            else {                $('.EmoticonPanel').find('.panel-recent .panel-main .emote').last.remove;                $('.EmoticonPanel').find('.panel-recent .panel-main').prepend($emote_el_main);            }        }    }

if ($body.hasClass('ChatWindow')){ var $panel = $(' ').addClass('EmoticonPanel panel'), emoticons = mw.config.get('wgChatEmoticons', wgChatEmoticons), $panel_button = $('').attr('href', '#').addClass('panel-button').text('Emoticons'); emoticons.split("\n").forEach(function(el, index, arr){            if(el[0] === "*" && el[1] !== "*")                 Emoticons[arr[index + 1].substring(2).trim] = el.substring(1).trim;        }, this); $panel.html([           $(' ').addClass('panel-header')                .html([ $(' ').addClass('panel-heading panel-title').text('Emoticon Panel'), $('').attr('href', '#').addClass('panel-close') ]),           $(' ').addClass('panel-section panel-emoticons')                .html([ $(' ').addClass('panel-heading panel-subtitle').text('Emoticons'), $(' ').addClass('panel-main') ]),           $(' ').addClass('panel-section panel-recent')                .html([ $(' ').addClass('panel-heading panel-subtitle').text('Recent Emoticons'), $(' ').addClass('panel-main') ])       ]);        $panel_button.on('click', function(e){            if (!$('.EmoticonPanel').length){$body.append($panel);                for (var emote in Emoticons){                    if (Emoticons.hasOwnProperty(emote))                        CreateEmote($('.EmoticonPanel .panel-emoticons'), emote);                }            } else {                $('.EmoticonPanel').show;            }        }); $('.public.wordmark').first.append($panel_button); $('.panel-recent .emote').each(function{           $(this).parent.append( $(' ')               .addClass('emote-tooltip') .attr('data-title', emote) .text(emote) .hide .css('opacity', '0') .siblings('img[data-tooltip]') .hover(function(event){                   var $t = $(this);                    if ($t.siblings('.emote-tooltip').is(':hidden'))                        $t.siblings('.emote-tooltip').show.animate({ 'opacity': '1' }, 500);               }, function(event){                    var $t = $(this);                    if ($t.siblings('.emote-tooltip').is(':visible'))                        $t.siblings('.emote-tooltip').animate({ 'opacity': '0' }, 500, function{ $(this).hide; });               })            );        });    } });