summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authordumpfmprod <dumpfmprod@ubuntu.(none)>2010-02-21 15:25:02 -0500
committerdumpfmprod <dumpfmprod@ubuntu.(none)>2010-02-21 15:25:02 -0500
commit1656fdf68387f7966d9caff9ee1a4f03436b6c51 (patch)
tree73713174d3b3f22c1cc3439309869de5c4c0bdb5 /static
parenta85f1102a74b7bb9b2adf9b21ef8c7c56dce781a (diff)
Added event tracking, upload filename checking, and fixed linkifying
Diffstat (limited to 'static')
-rwxr-xr-xstatic/js/pichat.js38
1 files changed, 32 insertions, 6 deletions
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 "<a target='_blank' href='" + match + "'><img src='" + match + "'></a>"
+ return "<a target='_blank' href='" + linkUrl + "'><img src='" + linkUrl + "'></a>"
} else {
- return "<a target='_blank' href='" + match + "'>" + match + "</a>"
+ return "<a target='_blank' href='" + linkUrl + "'>" + url + "</a>"
}
}
@@ -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
});
}