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