Commit 203c5751 authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

changed the way that messages are appended in textarea

parent f8675232
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
</head> </head>
<body> <body>
<form action="/pub" method="POST"> <form action="/pub" method="POST">
<p> <p>
<span style="display: block; float: left; width: 55px;">satus:</span> <span style="display: block; float: left; width: 55px;">satus:</span>
<span class="online" style="display:none; color:green">online</span> <span class="online" style="display:none; color:green">online</span>
<span class="offline" style="display:block; color:red">offline</span> <span class="offline" style="display:block; color:red">offline</span>
</p> </p>
...@@ -42,25 +42,27 @@ ...@@ -42,25 +42,27 @@
}; };
function _manageEvent(eventMessage) { function _manageEvent(eventMessage) {
if (eventMessage != '') { var chat = $("#chat");
var values = $.parseJSON(eventMessage); if (eventMessage != '') {
var line = values.nick + ': ' + values.text; var values = $.parseJSON(eventMessage);
if ($("#chat").val() == '') { var line = values.nick + ': ' + values.text;
$("#chat").val(line); if (chat.val() == '') {
} else { chat.val(line);
$("#chat").val(line + '\n' + $("#chat").val()); } else {
} chat.val(chat.val() + '\n' + line);
} }
}
chat.scrollTop(chat[0].scrollHeight - chat.height());
}; };
function _statuschanged() { function _statuschanged() {
if (PushStream.status == 5) { if (PushStream.status == 5) {
$(".offline").hide(); $(".offline").hide();
$(".online").show(); $(".online").show();
} else { } else {
$(".online").hide(); $(".online").hide();
$(".offline").show(); $(".offline").show();
} }
}; };
$("#room").change(function(){ $("#room").change(function(){
...@@ -68,30 +70,30 @@ ...@@ -68,30 +70,30 @@
PushStream.disconnect(); PushStream.disconnect();
} }
$("#chat").val(''); $("#chat").val('');
PushStream.joinChannel($("#room").val(), 10 ); PushStream.joinChannel($("#room").val(), 0 );
PushStream.connect(); PushStream.connect();
}); });
$("#sendButton").click(function(){ $("#sendButton").click(function(){
if (($("#nick").val() != "") && ($("#message").val() != "") && ($("#room").val() != "")) { if (($("#nick").val() != "") && ($("#message").val() != "") && ($("#room").val() != "")) {
$.post( '/pub?id=' + $("#room").val(), '{"nick":"' + $("#nick").val() + '", "text":"' + $("#message").val() + '"}', onSendText); $.post( '/pub?id=' + $("#room").val(), '{"nick":"' + $("#nick").val() + '", "text":"' + $("#message").val() + '"}', onSendText);
} else { } else {
alert("nick, room and text are required"); alert("nick, room and text are required");
} }
return false; return false;
}); });
var now = new Date(); var now = new Date();
var _hostId = (now.getTime() + "" + (Math.random() * 10000)).replace('.',''); var _hostId = (now.getTime() + "" + (Math.random() * 10000)).replace('.','');
PushStream.host = window.location.hostname; PushStream.host = window.location.hostname;
PushStream.port = window.location.port; PushStream.port = window.location.port;
PushStream.hostid = _hostId; PushStream.hostid = _hostId;
PushStream.registerEventCallback("process", _manageEvent); PushStream.registerEventCallback("process", _manageEvent);
PushStream.registerEventCallback("statuschanged", _statuschanged); PushStream.registerEventCallback("statuschanged", _statuschanged);
PushStream.joinChannel($("#room").val(), 10 ); PushStream.joinChannel($("#room").val(), 0 );
PushStream.connect(); PushStream.connect();
}); });
// ]]> // ]]>
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment