// Called on loading a chatroom function initChat() { Search.initInpage() $('#textbutton input').attr('checked', TextEnabled).change(setTextEnable); $('#imgbutton input').attr('checked', ImgsEnabled).change(setImgsEnable); /* $('#clearbutton input').click(function() { track('UI', 'ClearScreen'); $('.dump').remove(); $(this).removeAttr('checked'); return false; }); */ $('.oldmsg').each(function() { var dump = $(this); var content = dump.find(".content") MessageContentCache[dump.attr("id").substr(8)] = content.text() content.html(buildMsgContent(content.text(), Recips)); if ((ImgsEnabled && dump.hasClass('contains-image')) || (TextEnabled && !dump.hasClass('contains-image'))) dump.show(); else dump.hide(); }); Drag.bindImages(); $('#msgInput').keyup(ifEnter(submitMessage)); $('#msgSubmit').click(sendClicked); $('#palette-button').click(paletteClicked); messageList = $("#messageList")[0] initChatThumb(); scrollToEnd() scrollWatcher() // see /static/webcam/webcam.js if ('webcam' in window) webcam.init() startChatUpdater(); } var imgZoomThreshhold = [125, 125]; function initChatMsgs() { $('.msgDiv .content').live('mouseenter', function(e) { $(this).addClass('msg-hover'); }); $('.msgDiv .content').live('mouseleave', function(e) { $(this).removeClass('msg-hover'); }); $('.msgDiv .content .img-wrapper').live('mouseenter', function(e) { var img = $(this).find('img'); if (img.width() < imgZoomThreshhold[0] || img.height() < imgZoomThreshhold[1]) return; var zoomlink = $('') .attr({'href': img.attr('src') }) .addClass('msg-image-zoom') .append($('').attr('src', 'http://dump.fm/static/img/zoom.gif') .addClass('zoom-icon')) .click(function() { window.open(img.attr('src')); return false; }); $(this).append(zoomlink); }); $('.msgDiv .content .img-wrapper').live('mouseleave', function(e) { $(this).find('.msg-image-zoom').remove(); }); $('.content').live('click', function(e) { var tagName = e.target.tagName; if (tagName == 'A' || tagName == 'EMBED' || $(e.target).hasClass('youtube-thumb')) { return true; } var msg = $(this).parent('.msgDiv'); var wasFavorited = msg.hasClass("favorite"); var button = msg.find('.chat-thumb'); if (wasFavorited) { $(button).attr("src", Imgs.chatThumbOff); } else { $(button).attr("src", Imgs.chatThumbBig); $(button).stop().animate(Anim.chatThumbBig, 'fast').animate(Anim.chatThumb, 'fast', 'swing'); } Tag.favorite(button); return false; }); } function startChatUpdater() { setTimeout(refresh, 1000); } function makePlainText() { var j = $(this); j.text(j.text()); } function initChatThumb(){ $(".chat-thumb").live('mouseover mouseout', function(e) { var favorited = $(this).parents(".dump").hasClass("favorite") ? true : false; if (e.type == "mouseover") { if (favorited) { $(this).attr("src", Imgs.chatThumbOff); } else { $(this).attr("src", Imgs.chatThumbBig); $(this).stop().animate(Anim.chatThumbBig, 'fast') } } else { // mouseout if (favorited) { $(this).attr("src", Imgs.chatThumb); $(this).stop().animate(Anim.chatThumb, 'fast'); } else { $(this).delay(600).stop().animate(Anim.chatThumbTiny, 'fast', 'swing', function(){ $(this).attr("src", Imgs.chatThumbDot) $(this).animate(Anim.chatThumb, 0) }) } } }) } // grab message id etc from some element e that's inside a dump // (messages have something like id="message-0001" class="dump" ) function getMessageInfo(e){ var message = $(e).parents(".dump") var id = message.attr("id").substr(8) // cut "message-001" to "001" var nick = message.attr("nick") var link = "http://dump.fm/p/" + nick + "/" + id var content = message.find(".linkify") if (!content.length) content = message.find(".content") var rawContent = content.html() var img = content.find("img").attr("src") var via = "via " + nick + " on dump.fm" return {"nick": nick, "id": id, "link": encodeURIComponent(link), "content": rawContent, "img": encodeURIComponent(img), "via": encodeURIComponent(via)} } // Message Handling var ImageMsgCount = 0 function removeOldMessages(){ // don't count posts that are all text if (LastMsgContainsImage) ImageMsgCount += 1; while (ImageMsgCount > MaxImagePosts) { var imgMsg = $(".contains-image:first") if (imgMsg.length) { imgMsg.prevAll().remove() // remove all text messages before the image message imgMsg.remove() } else break; ImageMsgCount -= 1; } } var TextEnabled = Preferences.getProperty("chat.textEnabled", "true") == "none"; var ImgsEnabled = Preferences.getProperty("chat.imgsEnabled", "true") == "true"; function muteSelector() { var muted = []; for (nick in MUTES) { muted.push(".nick_" + nick); } return muted.join(","); } function setTextEnable() { var muted = muteSelector(); if ($(this).attr('checked')) { TextEnabled = true; Preferences.setProperty("chat.textEnabled", "false"); track('UI', 'TextEnabled'); $('.dump').not('.contains-image,'+muted).show(); } else { TextEnabled = false; Preferences.setProperty("chat.textEnabled", "false"); track('UI', 'TextDisabled'); $('.dump').not('.contains-image').hide() } }; function setImgsEnable() { var muted = muteSelector(); if ($(this).attr('checked')) { ImgsEnabled = true; Preferences.setProperty("chat.imgsEnabled", "true"); track('UI', 'ImgsEnabled'); $('.contains-image').not(muted).show(); } else { ImgsEnabled = false; Preferences.setProperty("chat.imgsEnabled", "false"); track('UI', 'ImgsDisabled'); $('.contains-image').hide(); } }; // scrolling stuff // this code keeps the div scrolled to the bottom, but will also let the user scroll up, without jumping down function isScrolledToBottom(){ var threshold = 15; var containerHeight = messageList.style.pixelHeight || messageList.offsetHeight var currentHeight = (messageList.scrollHeight > 0) ? messageList.scrollHeight : 0 var result = (currentHeight - messageList.scrollTop - containerHeight < threshold); return result; } function scrollIfPossible(){ if (lastScriptedScrolledPosition <= messageList.scrollTop || isScrolledToBottom()) scrollToEnd() } var lastScriptedScrolledPosition = 0 function scrollToEnd(){ messageList.scrollTop = messageList.scrollHeight lastScriptedScrolledPosition = messageList.scrollTop } function scrollWatcher(){ scrollIfPossible() setTimeout(scrollWatcher, 500) }