User:Ultimate Dark Carnage/chat.js

window.EmoticonPanel = window.EmoticonPanel || { init: function init{ this.$body = $(document.body); this.Emoticons = this.parseEmoticons || {}; this._emoticons = mw.config.get('wgChatEmoticons', wgChatEmoticons); this.RecentEmoticons = {}; },   create: function create{ var Emoticons = this.Emoticons; for (var emote in Emoticons) if (Emoticons.hasOwnProperty(emote)) this.createEmote($('.EmoticonPanel .panel-emoticons'), emote); },   createEmote: 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);        }); if (!$('.panel-emoticons img[src="' + Emoticons[emote] + '"]').length) $('.emoticon-panel').find('.panel-emoticons .panel-main').append($emote_el); },   parseEmoticons: function parseEmoticons{ var emote_split = this._emoticons.split(/\n/gi), Emoticons = {}; $.each(emote_split, function createObj(el, index, arr){           if (el[0] === '*' && el[1] !== '*')                Emoticons[arr[index + 1].substring(2).trim] = el.substring(1).trim;        }); return Emoticons; },   updateRecentEmoticons: 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); }       }    } };