diff options
author | makefu <github@syntax-fehler.de> | 2013-12-30 17:38:02 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2013-12-30 17:38:02 +0100 |
commit | ee33c348658a12a4e54281dc34eaca8639e247f8 (patch) | |
tree | 142ea8052af9e75886b6c71979eed302885ab22a /webchat/public/functions.js | |
parent | efef353ef2bf65ef6123fc699bce6c69fc37cfcc (diff) | |
parent | 11de3d6d4c62f7059cdb45992d7d0fec05dde0e4 (diff) |
Merge branch 'master' of ssh://github.com/krebscode/painload
Diffstat (limited to 'webchat/public/functions.js')
-rw-r--r-- | webchat/public/functions.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/webchat/public/functions.js b/webchat/public/functions.js new file mode 100644 index 00000000..781fafce --- /dev/null +++ b/webchat/public/functions.js @@ -0,0 +1,54 @@ +function inputParser (str) { + var match = /^\/([a-z]+)(?:\s+(.*\S))?\s*$/.exec(str) + if (match) { + return { method: match[1], params: match[2] } + } else { + return { method: 'msg', params: str } + } +} + +function replaceURLWithHTMLLinks (text) { + var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; + return text.replace(exp,"<a class=chat_link href='$1'>$1</a>"); +} + +function getNicklistElement(name, type) { + var el; + $('.'+type+'_name').each(function (i,e) { + if (e.innerHTML === name) { + if (typeof el !== 'undefined') { + throw new Error('duplicate name: ' + name); + }; + el = e; + }; + }); + return el; +} + +function chatboxAppend (chat_from, chat_msg, type) { + type = type||'msg' + $('<tr><td class="date '+type+'_date">'+getCurTime()+'</td><td class="from '+type+'_from">'+chat_from+'</td><td class="msg '+type+'_msg">'+chat_msg+'</td></tr>').insertBefore('#foot'); + + var elem = document.getElementById('chatter'); + elem.scrollTop = elem.scrollHeight; +}; + +function getCurTime () { + date = new Date; + h = date.getHours(); + if(h<10) + { + h = "0"+h; + } + m = date.getMinutes(); + if(m<10) + { + m = "0"+m; + } + s = date.getSeconds(); + if(s<10) + { + s = "0"+s; + } + return ''+h+':'+m+':'+s; +}; |