diff options
| -rw-r--r-- | static/js/pichat.js | 78 | ||||
| -rw-r--r-- | template/messagepane.st | 2 |
2 files changed, 53 insertions, 27 deletions
diff --git a/static/js/pichat.js b/static/js/pichat.js index 09c7dd6..e32ec3b 100644 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -1,10 +1,9 @@ -/*function deleteCookie(name) { - // Only deletes non-wildcard cookies - document.cookie = name + "=;expires=Thu, 01-Jan-1970 00:00:01 GMT"; -} -deleteCookie('compojure-session'); -deleteCookie('login-token'); -*/ +// http://plugins.jquery.com/files/jquery.cookie.js.txt +jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;} +var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;} +expires='; expires='+date.toUTCString();} +var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}} +return cookieValue;}}; var cache = {} var PendingMessages = {} @@ -34,14 +33,6 @@ Anim = { // Utils -/*Object.size = function(obj) { - var size = 0, key; - for (key in obj) { - if (obj.hasOwnProperty(key)) size++; - } - return size; -};*/ - isEmptyObject = function(obj) { for (key in obj) { if (obj.hasOwnProperty(key)) return false; @@ -51,9 +42,25 @@ isEmptyObject = function(obj) { String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,'') } - function isCSSPropertySupported(prop){ return prop in document.body.style } +var Preferences = { + "Domain": '.dump.fm', + + "getProperty": function(prop, defaultValue) { + var value = $.cookie(prop); + return (value !== null) ? value : defaultValue; + }, + + "setProperty": function(prop, val) { + $.cookie(prop, val, { domain: Preferences.Domain, path: '/' }); + }, + + "delProperty": function(prop) { + $.cookie(prop, null, { domain: Preferences.Domain, path: '/' }); + } +}; + function escapeHtml(txt) { if (!txt) { return ""; } // txt = annoyingCaps(txt) @@ -251,25 +258,44 @@ function removeOldMessages(){ } } +var TextEnabled = Preferences.getProperty("chat.textEnabled", "true") == "true"; + +function setTextEnable() { + if ($(this).attr('checked')) { + TextEnabled = true; + Preferences.setProperty("chat.textEnabled", "true"); + $('.dump').not('.contains-image').show(); + } else { + TextEnabled = false; + Preferences.setProperty("chat.textEnabled", "false"); + $('.dump').not('.contains-image').hide() + } +}; + function buildMsgContent(content) { - if (content.substr(0,6) == "<safe>") return content.substr(6,content.length - 13) - else return linkify(escapeHtml(content)); + if (content.substr(0,6) == "<safe>") + return content.substr(6,content.length - 13) + else return linkify(escapeHtml(content)); } // todo: // isLoading doesn't get passed the right thing by $.map in addMessages function buildMessageDiv(msg, isLoading) { var nick = escapeHtml(msg.nick); -// if (nick == '' && Nick != '') return; - removeOldMessages() + removeOldMessages(); + + var builtContent = buildMsgContent(msg.content); + var msgId = ('msg_id' in msg) ? 'id="message-' + msg.msg_id + '"' : ''; var loadingClass = isLoading ? ' loading' : ''; var containsImageClass = LastMsgContainsImage ? ' contains-image' : ''; - return '<div class="msgDiv dump ' + loadingClass + containsImageClass + '" ' + msgId + '>' + var displayStyle = (TextEnabled || LastMsgContainsImage) ? '' : ' style="display: none"'; + + return '<div class="msgDiv dump ' + loadingClass + containsImageClass + '" ' + msgId + displayStyle + '>' + '<span class="nick"><b><a href="http://dump.fm/' + nick + ' ">' + nick + '</a></b>' + ' <img src="'+Imgs.chatThumbDot+'" class="chat-thumb" onclick="Tag.favorite(this)"> ' + '</span>' - + '<span class="content">' + buildMsgContent(msg.content) + '</span>' + + '<span class="content">' + builtContent + '</span>' + '</div>'; } @@ -521,8 +547,6 @@ function sendClicked(){ typeof Nick !== 'undefined' ? Nick : 'anon'); } submitMessage() - - } function paletteClicked(){ @@ -531,8 +555,6 @@ function paletteClicked(){ typeof Nick !== 'undefined' ? Nick : 'anon'); } paletteToggle() - - } @@ -544,6 +566,10 @@ function initChat() { var content = dump.find(".content") MessageContentCache[dump.attr("id").substr(8)] = content.text() content.html(buildMsgContent(content.text())); + if (!TextEnabled && !dump.hasClass('contains-image')) + dump.hide(); + else + dump.show(); }); $('#msgInput').keyup(ifEnter(submitMessage)); diff --git a/template/messagepane.st b/template/messagepane.st index cb41edd..d6d171a 100644 --- a/template/messagepane.st +++ b/template/messagepane.st @@ -35,7 +35,7 @@ <div id="favbox" style="display: hidden"></div>
<div id="messageList">
$messages: { m |
- <div class="msgDiv oldmsg dump $if(m.favorited)$favorite$endif$ $if(m.is_image)$contains-image$endif$" id="message-$m.message_id$" nick="$m.nick$" style="display: none">
+ <div class="msgDiv oldmsg dump $if(m.favorited)$favorite$endif$ $if(m.is_image)$contains-image$endif$" id="message-$m.message_id$" nick="$m.nick$">
<span class="nick">
<b><a href="$domain$/$m.nick$" target="_blank">$m.nick$</a></b>
$if(m.favorited)$
|
