summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
Diffstat (limited to 'static')
-rwxr-xr-xstatic/js/pichat.js79
-rw-r--r--static/tests/scrolling.html2
-rw-r--r--static/webcam/webcam.js16
3 files changed, 45 insertions, 52 deletions
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 $("<span>").text(txt).html(); }
+ if (!txt) { return ""; }
+ else { return $("<span>").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 "<a target='_blank' href='" + match + "'><img src='" + match + "'></a>"
- } else {
- return "<a target='_blank' href='" + match + "'>" + match + "</a>"
- }
+ var PicRegex = /\.(jpg|jpeg|png|gif|bmp)$/i;
+ var matchWithoutParams = match.replace(/\?.*$/i, "")
+ if (PicRegex.test(matchWithoutParams)){
+ LastMsgContainsImage = true
+ return "<a target='_blank' href='" + match + "'><img src='" + match + "'></a>"
+ } else {
+ return "<a target='_blank' href='" + match + "'>" + match + "</a>"
+ }
+}
+
+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 '<div class="msgDiv ' + loadingClass + '" ' + 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) {
@@ -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()
}
diff --git a/static/tests/scrolling.html b/static/tests/scrolling.html
index bef6f7e..00e7b89 100644
--- a/static/tests/scrolling.html
+++ b/static/tests/scrolling.html
@@ -86,7 +86,7 @@ function isScrolledToBottom(){
}
function scrollIfPossible(){
- if (lastScriptedScrolledPosition >= messagePane.scrollTop || isScrolledToBottom())
+ if (lastScriptedScrolledPosition <= messagePane.scrollTop || isScrolledToBottom())
scrollToEnd()
}
diff --git a/static/webcam/webcam.js b/static/webcam/webcam.js
index 9829fd7..f5a5536 100644
--- a/static/webcam/webcam.js
+++ b/static/webcam/webcam.js
@@ -1,21 +1,11 @@
/* JPEGCam v1.0.8 */
/* Webcam library for capturing JPEG images and submitting to a server */
-/* Copyright (c) 2008 - 2009 Joseph Huckaby <jhuckaby@goldcartridge.com> */
+/* Copyright (c) 2008 - 2009
+ Joseph Huckaby <jhuckaby@goldcartridge.com>
+ AND TIMB, ESQ. <http://bon.gs> */
/* Licensed under the GNU Lesser Public License */
/* http://www.gnu.org/licenses/lgpl.html */
-/* Usage:
- <script language="JavaScript">
- document.write( webcam.get_html(320, 240) );
- webcam.set_api_url( 'test.php' );
- webcam.set_hook( 'onComplete', 'my_callback_function' );
- function my_callback_function(response) {
- alert("Success! PHP returned: " + response);
- }
- </script>
- <a href="javascript:void(webcam.snap())">Take Snapshot</a>
-*/
-
// Everything is under a 'webcam' Namespace
window.webcam = {
version: '1.0.8',