mirror of
https://github.com/fergalmoran/dss-realtime.git
synced 2025-12-22 09:38:06 +00:00
48 lines
1.0 KiB
JavaScript
48 lines
1.0 KiB
JavaScript
// connect to our socket server
|
|
var socket = io.connect('http://127.0.0.1:8001/');
|
|
|
|
var app = app || {};
|
|
|
|
|
|
// shortcut for document.ready
|
|
$(function(){
|
|
//setup some common vars
|
|
var $blastField = $('#blast'),
|
|
$allPostsTextArea = $('#allPosts'),
|
|
$clearAllPosts = $('#clearAllPosts'),
|
|
$sendBlastButton = $('#send');
|
|
|
|
|
|
//SOCKET STUFF
|
|
socket.on("blast", function(data){
|
|
var copy = $allPostsTextArea.html();
|
|
$allPostsTextArea.html('<p>' + copy + data.msg + "</p>");
|
|
$allPostsTextArea.scrollTop($allPostsTextArea[0].scrollHeight - $allPostsTextArea.height());
|
|
//.css('scrollTop', $allPostsTextArea.css('scrollHeight'));
|
|
|
|
});
|
|
|
|
$clearAllPosts.click(function(e){
|
|
$allPostsTextArea.text('');
|
|
});
|
|
|
|
$sendBlastButton.click(function(e){
|
|
|
|
var blast = $blastField.val();
|
|
if(blast.length){
|
|
socket.emit("blast", {msg:blast},
|
|
function(data){
|
|
$blastField.val('');
|
|
});
|
|
}
|
|
|
|
|
|
});
|
|
|
|
$blastField.keydown(function (e){
|
|
if(e.keyCode == 13){
|
|
$sendBlastButton.trigger('click');//lazy, but works
|
|
}
|
|
})
|
|
|
|
}); |