summaryrefslogtreecommitdiff
path: root/static/js/pichat.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/pichat.js')
-rw-r--r--static/js/pichat.js294
1 files changed, 157 insertions, 137 deletions
diff --git a/static/js/pichat.js b/static/js/pichat.js
index ce27ebd..2cb577f 100644
--- a/static/js/pichat.js
+++ b/static/js/pichat.js
@@ -7,67 +7,67 @@ var MaxImagePosts = 40
// use e.g. "backgroundColor" not "background-color"
function isCSSPropertySupported(prop){
- return prop in document.body.style;
+ return prop in document.body.style;
}
function escapeHtml(txt) {
- if (!txt) { return ""; }
- else { return $("<span>").text(txt).html(); }
+ if (!txt) { return ""; }
+ else { return $("<span>").text(txt).html(); }
}
function linkify(text) {
- LastMsgContainsImage = false
- 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(url){
- var PicRegex = /\.(jpg|jpeg|png|gif|bmp)$/i;
- var urlWithoutParams = url.replace(/\?.*$/i, "");
-
- if (url.indexOf('http://') == 0 || url.indexOf('https://') == 0 || url.indexOf('ftp://') == 0)
- linkUrl = url;
- else
- linkUrl = 'http://' + url;
-
- if (PicRegex.test(urlWithoutParams)){
- LastMsgContainsImage = true
- return "<a target='_blank' href='" + linkUrl + "'><img src='" + linkUrl + "'></a>"
- } else {
- return "<a target='_blank' href='" + linkUrl + "'>" + url + "</a>"
- }
+function linkReplace(url) {
+ var PicRegex = /\.(jpg|jpeg|png|gif|bmp)$/i;
+ var urlWithoutParams = url.replace(/\?.*$/i, "");
+
+ if (url.indexOf('http://') == 0 || url.indexOf('https://') == 0 || url.indexOf('ftp://') == 0)
+ linkUrl = url;
+ else
+ linkUrl = 'http://' + url;
+
+ if (PicRegex.test(urlWithoutParams)){
+ LastMsgContainsImage = true
+ return "<a target='_blank' href='" + linkUrl + "'><img src='" + linkUrl + "'></a>"
+ } else {
+ return "<a target='_blank' href='" + linkUrl + "'>" + url + "</a>"
+ }
}
function linkifyWithoutImage(text) {
- LastMsgContainsImage = false
- var URLRegex = /((\b(http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
- return text.replace(URLRegex, linkReplaceWithoutImage);
+ LastMsgContainsImage = false
+ var URLRegex = /((\b(http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
+ return text.replace(URLRegex, linkReplaceWithoutImage);
}
function linkReplaceWithoutImage(url){
- var PicRegex = /\.(jpg|jpeg|png|gif|bmp)$/i;
- var urlWithoutParams = url.replace(/\?.*$/i, "");
- linkUrl = url.indexOf('http://') == 0 ? url : 'http://' + url;
+ var PicRegex = /\.(jpg|jpeg|png|gif|bmp)$/i;
+ var urlWithoutParams = url.replace(/\?.*$/i, "");
+ linkUrl = url.indexOf('http://') == 0 ? url : 'http://' + url;
- return "<a target='_blank' href='" + linkUrl + "'>" + url + "</a>"
+ return "<a target='_blank' href='" + linkUrl + "'>" + url + "</a>"
}
// 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;
- }
+ // 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) {
@@ -75,15 +75,15 @@ function buildMsgContent(content) {
}
function buildMessageDiv(msg, isLoading) {
- removeOldMessages()
- var nick = escapeHtml(msg.nick);
- var msgId = !isLoading ? 'id="message-' + msg.msg_id + '"' : '';
- var loadingClass = isLoading ? ' loading' : '';
- var containsImageClass = LastMsgContainsImage ? ' contains-image' : '';
- return '<div class="msgDiv ' + loadingClass + containsImageClass + '" ' + msgId + '>'
- + '<b><a href="/u/' + nick + ' ">' + nick + '</a>: </b>'
- + buildMsgContent(msg.content)
- + '</div>';
+ removeOldMessages()
+ var nick = escapeHtml(msg.nick);
+ var msgId = !isLoading ? 'id="message-' + msg.msg_id + '"' : '';
+ var loadingClass = isLoading ? ' loading' : '';
+ var containsImageClass = LastMsgContainsImage ? ' contains-image' : '';
+ return '<div class="msgDiv ' + loadingClass + containsImageClass + '" ' + msgId + '>'
+ + '<b><a href="/u/' + nick + ' ">' + nick + '</a>: </b>'
+ + buildMsgContent(msg.content)
+ + '</div>';
}
function buildUserDiv(user) {
@@ -95,6 +95,7 @@ function buildUserDiv(user) {
} else {
return '<div class="username">'
+ '<a href="/u/' + escapeHtml(user.nick) + '" target="_blank">'
+ + '<img src="/static/noinfo.png" width="50" height="50">'
+ escapeHtml(user.nick) + '</a></div>';
}
}
@@ -139,8 +140,8 @@ function submitMessage() {
var div = addNewMessage(msg, true);
var onSuccess = function(json) {
- if (typeof pageTracker !== 'undefined') {
- pageTracker._trackEvent('Message', 'Submit', typeof Room !== 'undefined' ? Room : 'UnknownRoom');
+ if (typeof pageTracker !== 'undefined') {
+ pageTracker._trackEvent('Message', 'Submit', typeof Room !== 'undefined' ? Room : 'UnknownRoom');
}
div.attr('id', 'message-' + json)
.removeClass('loading').addClass('loaded');
@@ -207,11 +208,11 @@ function updateUI(msgs, users) {
}
function sortUsersByAlpha(a, b){
- var nickA = a.nick.toLowerCase()
- var nickB = b.nick.toLowerCase()
- if (nickA > nickB) return 1
- else if (nickA < nickB) return -1
- return 0
+ var nickA = a.nick.toLowerCase()
+ var nickB = b.nick.toLowerCase()
+ if (nickA > nickB) return 1
+ else if (nickA < nickB) return -1
+ return 0
}
function isDuplicateMessage(m) {
@@ -312,7 +313,7 @@ function activateProfileEditable() {
var onSubmit = function(attr, newVal, oldVal) {
newVal = $.trim(newVal);
if (newVal == oldVal) { return oldVal };
-
+
$.ajax({
type: "POST",
timeout: 5000,
@@ -433,13 +434,29 @@ function favoriteImage() {};
function setupUpload(elementId, roomKey) {
var onSubmit = function(file, ext) {
if (!(ext && /^(jpg|png|jpeg|gif|bmp)$/i.test(ext))) {
- alert('SORRY, NOT AN IMAGE DUDE... ');
- return false;
+ alert('SORRY, NOT AN IMAGE DUDE... ');
+ return false;
}
};
var onComplete = function(file, response) {
- if (typeof pageTracker !== 'undefined') {
- pageTracker._trackEvent('Message', 'Upload', typeof Room !== 'undefined' ? Room : 'UnknownRoom');
+ if (response.match(/FILE_TOO_BIG/)) {
+ var maxSize = response.split(" ")[1] / 1024;
+ alert("Sorry. Your file is just too fucking big. "
+ + maxSize + "KB or less please.");
+ return;
+ } else if (response.match(/FILE_NOT_IMAGE/)) {
+ alert("What did you upload? Doesn't seem like an image. Sorry.");
+ return;
+ } else if (response.match(/INVALID_RESOLUTION/)) {
+ var maxWidth = response.split(" ")[1];
+ var maxHeight = response.split(" ")[2];
+ alert("Sorry, the maximum image resolution is "
+ + maxWidth + "x" + maxHeight);
+ return;
+ }
+ if (typeof pageTracker !== 'undefined') {
+ var r = typeof Room !== 'undefined' ? Room : 'UnknownRoom';
+ pageTracker._trackEvent('Message', 'Upload', r);
}
}
new AjaxUpload(elementId, {
@@ -447,7 +464,7 @@ function setupUpload(elementId, roomKey) {
autoSubmit: true,
name: 'image',
data: { room: roomKey },
- onSubmit: onSubmit,
+ onSubmit: onSubmit,
onComplete: onComplete
});
}
@@ -479,50 +496,50 @@ function setupUploadAvatar(elementId) {
onComplete: onComplete
});
}
-
+
// 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 threshold = 15;
+
+ var containerHeight = messageList.style.pixelHeight || messageList.offsetHeight
+ var currentHeight = (messageList.scrollHeight > 0) ? messageList.scrollHeight : 0
- var result = (currentHeight - messageList.scrollTop - containerHeight < threshold);
+ var result = (currentHeight - messageList.scrollTop - containerHeight < threshold);
- return result;
+ return result;
}
function scrollIfPossible(){
- if (lastScriptedScrolledPosition <= messageList.scrollTop || isScrolledToBottom())
- scrollToEnd()
+ if (lastScriptedScrolledPosition <= messageList.scrollTop || isScrolledToBottom())
+ scrollToEnd()
}
var lastScriptedScrolledPosition = 0
function scrollToEnd(){
- messageList.scrollTop = messageList.scrollHeight
- lastScriptedScrolledPosition = messageList.scrollTop
+ messageList.scrollTop = messageList.scrollHeight
+ lastScriptedScrolledPosition = messageList.scrollTop
}
function scrollWatcher(){
- scrollIfPossible()
- setTimeout(scrollWatcher, 500)
+ scrollIfPossible()
+ setTimeout(scrollWatcher, 500)
}
// well fuck webkit for not supporting {text-decoration: blink}
function blinkStart(){
- blinkTimer = setInterval(function(){
- $(".blink").removeClass("blink").addClass("blink-turning-off")
- $(".blink-off").removeClass("blink-off").addClass("blink")
- $(".blink-turning-off").removeClass("blink-turning-off").addClass("blink-off")
- },500);
+ blinkTimer = setInterval(function(){
+ $(".blink").removeClass("blink").addClass("blink-turning-off")
+ $(".blink-off").removeClass("blink-off").addClass("blink")
+ $(".blink-turning-off").removeClass("blink-turning-off").addClass("blink-off")
+ },500);
}
function blinkStop(){
- clearInterval(blinkTimer);
+ clearInterval(blinkTimer);
}
function initDirectory() {
@@ -536,71 +553,72 @@ function initDirectory() {
// TODO: replace this with simple pointer-events thing.
function initBigHand(id){
- var cursorId = "#cursor-big"
- var cursor = $(cursorId)[0]
-
- // jquery's reported element sizes are not exactly the same as the browser's 'mouseover' target sizes
- // so we'll allow a few pixels extra
- var fudgeFactor = 2
+ var cursorId = "#cursor-big"
+ var cursor = $(cursorId)[0]
+
+ // jquery's reported element sizes are not exactly the same as the browser's 'mouseover' target sizes
+ // so we'll allow a few pixels extra
+ var fudgeFactor = 2
- $(id).addClass("no-cursor")
+ $(id).addClass("no-cursor")
- // i have to do this weirdly bc putting the cursor image where the mouse cursor is causes problems with mouse events:
- // * it stops mousemove events on the image below the mouse cursor
- // * it fucks up mouseover/out and even mouseenter/leave events, as well as click
-
- // so i am doing this:
- // on mousing over the image:
- // make cursor visible
- // find image co-ords
- // bind a global mousemove func
- // bind cursor click event
- // unbind mouseover
- // mousemove func:
- // move image to mouse co-ords
- // if mouse co-ords are outside the image co-ords:
- // make cursor invisible
- // unbind mousemove func
- // unbind cursor click event
+ // i have to do this weirdly bc putting the cursor image where the mouse cursor is causes problems with mouse events:
+ // * it stops mousemove events on the image below the mouse cursor
+ // * it fucks up mouseover/out and even mouseenter/leave events, as well as click
+
+ // so i am doing this:
+ // on mousing over the image:
+ // make cursor visible
+ // find image co-ords
+ // bind a global mousemove func
+ // bind cursor click event
+ // unbind mouseover
+ // mousemove func:
+ // move image to mouse co-ords
+ // if mouse co-ords are outside the image co-ords:
+ // make cursor invisible
+ // unbind mousemove func
+ // unbind cursor click event
- var mousemove = function(e){
- var y = e.pageY, x = e.pageX, coords = initBigHand.coords
+ var mousemove = function(e){
+ var y = e.pageY, x = e.pageX, coords = initBigHand.coords
+
+ cursor.style.top = y + "px"
+ cursor.style.left = x - 32 + "px" // 32: (4 pixels * 8 pixels per big pixel) to line up pointy finger with cursor
+ if (y < coords.top ||
+ y > coords.bottom ||
+ x < coords.left ||
+ x > coords.right) {
+ $(cursorId).addClass('invisible')
+ $(cursorId).css({"top": 0, "left": 0 })
+ $(cursorId).unbind('click', cursorClick)
+ $('logo7').unbind('mousemove', mousemove)
+ $(id).mouseover(imageMouseOver)
+ }
+ }
- cursor.style.top = y + "px"
- cursor.style.left = x - 32 + "px" // 32: (4 pixels * 8 pixels per big pixel) to line up pointy finger with cursor
- if (y < coords.top ||
- y > coords.bottom ||
- x < coords.left ||
- x > coords.right) {
- $(cursorId).addClass('invisible')
- $(cursorId).css({"top": 0, "left": 0 })
- $(cursorId).unbind('click', cursorClick)
- $('logo7').unbind('mousemove', mousemove)
- $(id).mouseover(imageMouseOver)
- }
- }
-
- var cursorClick = function(){ $(id).click() }
-
- var imageMouseOver = function(){
- //console.log("moused over...")
- initBigHand.coords = {
- "left": $(id).offset().left - fudgeFactor,
- "top": $(id).offset().top - fudgeFactor,
- "right": $(id).offset().left + $(id).width() + fudgeFactor,
- "bottom": $(id).offset().top + $(id).height() + fudgeFactor
+ var cursorClick = function(){ $(id).click() }
+
+ var imageMouseOver = function(){
+ //console.log("moused over...")
+ initBigHand.coords = {
+ "left": $(id).offset().left - fudgeFactor,
+ "top": $(id).offset().top - fudgeFactor,
+ "right": $(id).offset().left + $(id).width() + fudgeFactor,
+ "bottom": $(id).offset().top + $(id).height() + fudgeFactor
+ }
+ $('body').mousemove(mousemove)
+ $(cursorId).click(cursorClick)
+ $(cursorId).removeClass('invisible')
+ $(id).unbind('mouseover', imageMouseOver)
}
- $('body').mousemove(mousemove)
- $(cursorId).click(cursorClick)
- $(cursorId).removeClass('invisible')
- $(id).unbind('mouseover', imageMouseOver)
- }
-
- $(id).mouseover(imageMouseOver)
-
+
+ $(id).mouseover(imageMouseOver)
+
}
Share = {
+<<<<<<< HEAD
"getMessage": function(button){
var message = $(button).parents(".logged-dump")
var id = message.attr("id").substr(8) // cut "message-001" to "001"
@@ -650,7 +668,9 @@ Tag = {
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": content, "img": encodeURIComponent(img), "via": encodeURIComponent(via)}
+ return {"nick": nick, "id": id, "link": encodeURIComponent(link),
+ "content": content, "img": encodeURIComponent(img),
+ "via": encodeURIComponent(via)}
},
"favorite": function(button){
var message = Share.getMessage(button)