From beb2a433bf18fd1d474314329bd6ee8f40f5bf10 Mon Sep 17 00:00:00 2001 From: timb Date: Mon, 15 Feb 2010 03:35:27 -0800 Subject: attempt to fix scrolling --- static/js/pichat.js | 79 +++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 38 deletions(-) (limited to 'static/js') diff --git a/static/js/pichat.js b/static/js/pichat.js index d3da949..33788e2 100755 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -1,24 +1,44 @@ var cache = {} var pendingMessages = {} +var MaxImagePosts = 40 + function escapeHtml(txt) { - if (!txt) { return ""; } - else { return $("").text(txt).html(); } + if (!txt) { return ""; } + else { return $("").text(txt).html(); } } function linkify(text) { - var URLRegex = /((\b(http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi; - return text.replace(URLRegex, linkReplace); + LastMsgContainsImage = false + var URLRegex = /((\b(http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi; + return text.replace(URLRegex, linkReplace); } +// durty hack to use a global to check this... but otherwise i'd have to rewrite the String.replace function? :/ +var LastMsgContainsImage = false function linkReplace(match){ - var PicRegex = /\.(jpg|jpeg|png|gif|bmp)$/i; - var matchWithoutParams = match.replace(/\?.*$/i, "") - if (PicRegex.test(matchWithoutParams)){ - return "" - } else { - return "" + match + "" - } + var PicRegex = /\.(jpg|jpeg|png|gif|bmp)$/i; + var matchWithoutParams = match.replace(/\?.*$/i, "") + if (PicRegex.test(matchWithoutParams)){ + LastMsgContainsImage = true + return "" + } else { + return "" + match + "" + } +} + +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; + } } function buildMsgContent(content) { @@ -26,13 +46,15 @@ function buildMsgContent(content) { } function buildMessageDiv(msg, isLoading) { - var nick = escapeHtml(msg.nick); - var msgId = !isLoading ? 'id="message-' + msg.msg_id + '"' : ''; - var loadingClass = isLoading ? ' loading' : ''; - return '
' - + '' + nick + ': ' - + buildMsgContent(msg.content) - + '
'; + removeOldMessages() + var nick = escapeHtml(msg.nick); + var msgId = !isLoading ? 'id="message-' + msg.msg_id + '"' : ''; + var loadingClass = isLoading ? ' loading' : ''; + var containsImageClass = LastMsgContainsImage ? ' contains-image' : ''; + return '
' + + '' + nick + ': ' + + buildMsgContent(msg.content) + + '
'; } function buildUserDiv(user) { @@ -106,30 +128,12 @@ function ifEnter(fn) { }; } -/* -function isScrolledToBottom(div) { - return Math.abs(div.scrollTop - (div.scrollHeight - div.offsetHeight)) <= 3; -} - -function scrollToBottom(div) { - div.scrollTop = div.scrollHeight; -} - -// Give images time to start loading before scrolling. -// Needed until server knows size of images. -function delayedScrollToBottom(delay) { - setTimeout(scrollToBottom, delay, $('#messageList')[0]); -} -*/ - function addNewMessages(msgs) { - //var wasScrolledToBottom = isScrolledToBottom($('#messageList')[0]); var msgStr = $.map(msgs, buildMessageDiv).join(''); $('#messageList').append(msgStr); } function addNewMessage(msg, isLoading) { - //var wasScrolledToBottom = isScrolledToBottom($('#messageList')[0]); var msgStr = buildMessageDiv(msg, isLoading); var div = $(msgStr).appendTo('#messageList'); return div; @@ -217,7 +221,6 @@ function initChat() { // see /static/webcam/webcam.js if ('webcam' in window) webcam.init() - setTimeout(refresh, 1000); } @@ -297,7 +300,7 @@ function isScrolledToBottom(){ } function scrollIfPossible(){ - if (lastScriptedScrolledPosition == messageList.scrollTop || isScrolledToBottom()) + if (lastScriptedScrolledPosition <= messageList.scrollTop || isScrolledToBottom()) scrollToEnd() } -- cgit v1.2.3-70-g09d2 From 99e9cbe532166b154314b6107ce269162359f660 Mon Sep 17 00:00:00 2001 From: sostler Date: Tue, 16 Feb 2010 01:40:34 -0500 Subject: Add stats-tracking --- static/js/stats.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ template/chat.st | 56 +++++++++++++++++++++----------------- 2 files changed, 111 insertions(+), 24 deletions(-) create mode 100755 static/js/stats.js (limited to 'static/js') diff --git a/static/js/stats.js b/static/js/stats.js new file mode 100755 index 0000000..00e00a0 --- /dev/null +++ b/static/js/stats.js @@ -0,0 +1,79 @@ +var CurrentStats = ['msgs', 'today']; + +function refreshStats() { + $('a.statname, a.timescale').addClass('disabled'); + $('#statschart').empty().append(''); + + var onSuccess = function(json) { + var dataString = "Date,Count\n"; + $.each(json, function(i, v) { + dataString += v.created_on + "," + v.count + "\n"; + }); + $('#statschart').empty(); + new Dygraph($('#statschart')[0], + dataString, + { showRoller: false} + ); + + $('a.statname, a.timescale').removeClass('disabled'); + }; + + var onError = function(resp, textStatus, errorThrown) { + $('a.statname, a.timescale').removeClass('disabled'); + }; + + $.ajax({ + type: 'GET', + timeout: 5000, + url: '/stats', + data: { 'stat': CurrentStats[0], 'ts': CurrentStats[1] }, + cache: false, + dataType: 'json', + success: onSuccess, + error: onError + }); +} + +function makeStatsWindow() { + var statBox= $('
'); + var choices = ['msgs', 'new users']; + $(choices).map(function(i, c) { + return link = $('') + .text(c) + .attr('href', '#') + .addClass('statname') + .addClass(i == 0 ? 'active' : 'inactive') + .click(function() { + if ($(this).hasClass('disabled') || + CurrentStats[0] == c) { return }; + $('.statname').removeClass('active'); + $(this).addClass('active'); + CurrentStats[0] = c; + refreshStats(); + }); + }).appendTo(statBox); + $('
').appendTo(statBox); + var timescales = ['today', 'all time']; + $(timescales).map(function(i, c) { + return link = $('') + .text(c) + .attr('href', '#') + .addClass('timescale') + .addClass(i == 0 ? 'active' : 'inactive') + .click(function() { + if ($(this).hasClass('disabled') || + CurrentStats[1] == c) { return }; + $('.timescale').removeClass('active'); + $(this).addClass('active'); + CurrentStats[1] = c; + refreshStats(); + }); + })//.appendTo(statBox); + return statBox; +} + +function initStats() { + makeStatsWindow().appendTo('body'); + refreshStats(); +} + diff --git a/template/chat.st b/template/chat.st index 90e2602..4d792ae 100755 --- a/template/chat.st +++ b/template/chat.st @@ -16,36 +16,13 @@ $endif$ $if(isadminroom)$ @@ -60,6 +37,37 @@ function MM_swapImage() { //v3.0 }); } + $if(isadminroom)$ + + + + + $endif$ $banner()$ -- cgit v1.2.3-70-g09d2 From a85f1102a74b7bb9b2adf9b21ef8c7c56dce781a Mon Sep 17 00:00:00 2001 From: dumpfmprod Date: Sun, 21 Feb 2010 15:22:15 -0500 Subject: Added event tracking and registration codes --- static/js/home.js | 3 +++ static/js/register.js | 17 +++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'static/js') diff --git a/static/js/home.js b/static/js/home.js index b37bc8d..107486c 100755 --- a/static/js/home.js +++ b/static/js/home.js @@ -152,6 +152,9 @@ function login() { var hash = hex_sha1(nick + '$' + password + '$dumpfm'); var onSuccess = function(json) { + if (typeof pageTracker !== 'undefined') { + pageTracker._setCustomVar(1, "logged-in", nick, 1); + } location.href = "/chat"; }; diff --git a/static/js/register.js b/static/js/register.js index 682efcb..1739ed6 100755 --- a/static/js/register.js +++ b/static/js/register.js @@ -13,20 +13,25 @@ function submitRegistration() { var email = $('#emailInput').val(); var password = $('#passwordInput').val() || ""; var code = $('#codeInput').val(); - if ($.inArray(code.toUpperCase(), ValidCodes) == -1) { - alert("Bad registration code! Try again dude...." ); - return; - } - if (nick.length < 3) { - alert("Nicks must be at least 3 characters long."); + + if (nick.length < 3 || nick.length > 12) { + alert("Nicks must be between 3 and 12 characters long."); return; } else if (password.length < 5) { alert("Password must be at least 5 characters long."); return; } + if ($.inArray(code.toUpperCase(), ValidCodes) == -1) { + alert("Bad registration code! Try again dude...." ); + return; + } + var hash = hex_sha1(nick + '$' + password + '$dumpfm'); var onSuccess = function() { + if (typeof pageTracker !== 'undefined') { + pageTracker._trackEvent('User', 'Register', nick); + } location.href = "/"; }; -- cgit v1.2.3-70-g09d2 From 1656fdf68387f7966d9caff9ee1a4f03436b6c51 Mon Sep 17 00:00:00 2001 From: dumpfmprod Date: Sun, 21 Feb 2010 15:25:02 -0500 Subject: Added event tracking, upload filename checking, and fixed linkifying --- static/js/pichat.js | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'static/js') diff --git a/static/js/pichat.js b/static/js/pichat.js index 33788e2..3137ac4 100755 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -16,14 +16,17 @@ function linkify(text) { // durty hack to use a global to check this... but otherwise i'd have to rewrite the String.replace function? :/ var LastMsgContainsImage = false -function linkReplace(match){ +function linkReplace(url){ var PicRegex = /\.(jpg|jpeg|png|gif|bmp)$/i; - var matchWithoutParams = match.replace(/\?.*$/i, "") - if (PicRegex.test(matchWithoutParams)){ + var urlWithoutParams = url.replace(/\?.*$/i, ""); + + linkUrl = url.indexOf('http://') == 0 ? url : 'http://' + url; + + if (PicRegex.test(url)){ LastMsgContainsImage = true - return "" + return "" } else { - return "" + match + "" + return "" + url + "" } } @@ -102,6 +105,9 @@ function submitMessage() { var div = addNewMessage(msg, true); var onSuccess = function(json) { + if (typeof pageTracker !== 'undefined') { + pageTracker._trackEvent('Message', 'Submit', typeof Room !== 'undefined' ? Room : 'UnknownRoom'); + } div.attr('id', 'message-' + json) .removeClass('loading').addClass('loaded'); }; @@ -225,6 +231,13 @@ function initChat() { } function initProfile() { + + jQuery(".linkify").each(function() { + var text = jQuery(this).text(); + jQuery(this).html(linkify(text)); + }); + + $('.logged-dump .content').each(function() { var t = $(this); t.html(buildMsgContent(t.text())); @@ -277,11 +290,24 @@ function initLog() { function favoriteImage() {}; function setupUpload(elementId, roomKey) { + var onSubmit = function(file, ext) { + if (!(ext && /^(jpg|png|jpeg|gif)$/i.test(ext))) { + alert('Error: invalid file extension ' + ext); + return false; + } + }; + var onComplete = function(file, response) { + if (typeof pageTracker !== 'undefined') { + pageTracker._trackEvent('Message', 'Upload', typeof Room !== 'undefined' ? Room : 'UnknownRoom'); + } + } new AjaxUpload(elementId, { action: '/upload', autoSubmit: true, name: 'image', - data: { room: roomKey } + data: { room: roomKey }, + onSubmit: onSubmit, + onComplete: onComplete }); } -- cgit v1.2.3-70-g09d2