User:Ultimate Dark Carnage/chat.js

// Chat User Menu var enableUserMenu = true, avatarSize = 30;

/** var showStatsMenu = window.showStatsMenu || {}; showStatsMenu.init = function init{ this.you = mw.config.get('wgUserName', wgUserName); this.groups = mw.config.get('wgUserGroups', wgUserGroups); this.bind; };

showStatsMenu.bind = function bind{ var _ = this; setTimeout(this.createStats, 500); mainRoom.model.chats.bind('afteradd', function(child){       if (typeof window.mainRoom.roomId === 'undefined') return;        var $chatLi = $('#Chat_' + window.mainRoom.roomId + ' li[data-user]:last');        if ($chatLi.hasClass('inline-alert')) return;        $chatLi.find('> img.avatar').on('click', _.createUserStats(child.attributes.name));    }); };

showStatsMenu.createStats = function createStats{ var $chatLi = mainRoom.viewDiscussion.chatUL.find('> li'), _ = this; $chatLi.each(function(index){       var $this = $(this);        if ($this.hasClass('inline-alert')) return;        $this.find('> img.avatar').on('click', _.createUserStats($this.attr('data-user')));    }); };

showStatsMenu.createUserStats = function _create(user){ var _ = this; return function _createStats(event){ var $stats_menu = '', user_data = mainRoom.models.chats.findByName(user); $stats_menu += ''; $stats_menu += ''; $stats_menu += ''; $stats_menu += '' + user_data.attributes.name + ' '; $stats_menu += ' ' + user_data.attributes.editcount + ' edits '; }; };**/

// Random Commands var ChatTools = window.ChatTools || {} IS_AWAY = false;

ChatTools.init = function init{ var _ = this; this.msg = { 'away': ' is now away.', 'here': ' is no longer away.' };   this.statusMessage = ''; this.createTools({       'AFK': function afk(event){            var msg = _.msg,                statusCommand = null;            if (IS_AWAY === false){                statusCommand = new models.SetStatusCommand({ statusState: STATUS_STATE_AWAY, statusMessage: '' });               _.inlineAlert({ type: 'message', message: msg['away'].replace(/ /g, wgUserName) });               mainRoom.socket.send(statusCommand.xport);                statusCommand = null;                IS_AWAY = true;            } else {                statusCommand = new models.SetStatusCommand({ statusState: STATUS_STATE_PRESENT, statusMessage: '' });               _.inlineAlert({ type: 'message', message: msg['here'].replace(/ /g, wgUserName) });               mainRoom.socket.send(statusCommand.xport);                statusCommand = null;                IS_AWAY = false;            }        },        'Options': function options(event){        },        'Clear': function clear(event){            if (_.isCleared === false){                mainRoom.viewDiscussion.clear;                _.isCleared = true;                setTimeout(function toggle{ _.isCleared = false; }, 1000*60);           }        },        'Emoticons': function emoticons{        }    }); };

ChatTools.inlineAlert = function inlineAlert(config){ if (typeof config === 'undefined') return; var $inlineAlert = $(''), message = config.message; switch (config.type){ case 'message': message = this.parseEnabled === 0 ? message : this.parse(message); if (this.parseEnabled === 0) $inlineAlert.text(message); else $inlineAlert.html(message); break; default: $inlineAlert.addClass(config.type); message = this.parseEnabled === 0 ? message : this.parse(message); if (this.parseEnabled === 0) $inlineAlert.text(message); else $inlineAlert.html(message); }   mainRoom.viewDiscussion.chatUL.append($inlineAlert); };

/* ChatTools.parse = function parse(text){ var _regex = { 'link': /\[\[(.*)\]\]/g, 'italic': /\'\'(.*)\]\]/g, 'bold': /\'\'\'(.*)\'\'\'/g },       _replace = { 'link': function(key, match){ var link = ' -1){                    match = match.split('|');                    _char = match[0].split(':');                    if (_char[0] == _char[0].toLowerCase){                        link += 'http://' + _char[0] + '.wikia.com/wiki/' + encodeURIComponent(_char[1]);                        link += '">' + match[1] + ''; } else { _char = _char.join(':'); link += '/wiki/' + encodeURIComponent(_char); link += '">' + match[1] + '';                   }                } else {                    match = match.split(':');                    if (match[0] == match[0].toLowerCase){                        link += 'http://' + match[0] + '.wikia.com/wiki/' + encodeURIComponent(match[1]);                        link += '">' + match.join(':') + ''; } else { match = match.join(':'); link += '/wiki/' + encodeURIComponent(match); link += '">' + match + '';                   }                }                link = parse(link);                return link;            },            'italic': function(key, match){                var txt = ' ' + match + ' ';                txt = parse(txt);                return txt;            },            'bold': function(key, match){                var txt = ' ' + match + ' ';                txt = parse(txt);                return txt;            }        };    for (var type in _regex){    } };*/

ChatTools.createTools = function createTools(tools){ if (typeof tools != 'object') return; if (!$('#ChatTools').length){ var $tools = $(''); for (var name in tools){ var $item = $(''); if (tools[name] instanceof Object || typeof tools[name] == 'object'){ $item.attr('data-name', name); $item.html(''); $item.on('click', tools[name].handler); } else if (tools[name] instanceof Function || typeof tools[name] == 'function'){ $item.attr('data-name', name); $item.text(name); $item.on('click', tools[name]); }           $tools.append($item); }       $('.Write .message').append($tools); } else { var $_tools = $('#ChatTools'); for (var n in tools){ var $_item = $(''); if (tools[n] instanceof Object || typeof tools[n] == 'object'){ $_item.attr('data-name', n); $_item.html(''); $_item.on('click', tools[n].handler); } else if (tools[n] instanceof Function || typeof tools[name] == 'function'){ $_item.attr('data-name', n); $_item.text(n); $_item.on('click', tools[n]); }           $_tools.append($_item); }   } };

ChatTools.init;