Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: D-Ne0/Chatroom
base: 9a1cafc104
...
head fork: D-Ne0/Chatroom
compare: b98bbb1a12
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 45 additions and 18 deletions.
  1. +43 −17 chat/chat.js
  2. +2 −1  chat/chat.php
View
60 chat/chat.js
@@ -5,7 +5,10 @@ var username;
var enroll;
var chatRefreshTimer;
var newmsg="yes";
-var tabTitle = "Chatroom";
+var browserTitle = "Chatroom";
+var soundHandle;
+var soundFile = "../sound/notify.mp3";
+var soundFile1 = "../sound/notify.ogg";
$(document).ready(function(){
$(window).load(showOnline(),popUpChat());
@@ -14,7 +17,7 @@ $(document).ready(function(){
$("div#online_search_box input").val("");
});
$(window).focus(function(){
- $("title").text(tabTitle);
+ $("title").text(browserTitle);
});
});
@@ -98,8 +101,8 @@ function chatWith(username,enroll) {
startChatSession(enroll);
clearInterval(chatRefreshTimer);
newmsg="yes";
- getChat(enroll);
- chatRefreshTimer = setInterval("getChat("+enroll+")",1500);
+ getChat(enroll,username);
+ chatRefreshTimer = setInterval("getChat("+enroll+","+username+")",1500);
}
else {
restructChatbox(enroll,username);
@@ -156,8 +159,8 @@ function restructChatbox(roll,name) {
$("div#chatbox_"+roll+" div.chatbox_text input").focus();
clearInterval(chatRefreshTimer);
newmsg="yes";
- getChat(roll);
- chatRefershTimer = setInterval("getChat("+roll+")",1500);
+ getChat(roll,name);
+ chatRefershTimer = setInterval("getChat("+roll+","+name+")",1500);
}
function startChatSession(roll) {
@@ -181,7 +184,7 @@ function sendChat(roll,name) {
}
else{
newmsg="yes";
- getChat(roll);
+ getChat(roll,name);
}
}
});
@@ -191,7 +194,7 @@ function sendChat(roll,name) {
return false;
}
-function getChat(roll) {
+function getChat(roll,name) {
var str = "action=getChat&roll="+roll;
var user;
@@ -216,10 +219,15 @@ function getChat(roll) {
$("div#chatbox_"+roll+" div.chatbox_msg").prepend("<div class='msg_container'><div id='sender'><b>"+user+"</b>: "+msg+"</div><br>");
});
- //alert(newmsg);
+
if(newmsg=="yes") {
- $("div#chatbox_"+roll+" div.chatbox_msg").scrollTop($("div#chatbox_"+roll+" div.chatbox_msg")[0].scrollHeight);
- $("div#chatbox_"+roll+" div.chatbox_text input").focus();
+ $("div#chatbox_"+roll+" div.chatbox_msg").scrollTop($("div#chatbox_"+roll+" div.chatbox_msg")[0].scrollHeight);
+ if($("div#chatbox_"+roll+" div.chatbox_text input").is(":focus")==false) {
+ setBrowserTitle(name);
+ playSound();
+ $("div#chatbox_"+roll+" div.chatbox_text input").focus();
+ }
+ newmsg="no"; //set to no for repetition of chat sound
}
}
@@ -244,12 +252,16 @@ function refreshPopUpChat() {
$(result).find("users").each(function(){
var name = $(this).find("name").text();
var roll = $(this).find("roll").text();
- //newmsg="yes";
- if($("div#chatbox_"+roll).length==0)
+
+ if($("div#chatbox_"+roll).length==0) {
+ setBrowserTitle(name);
+ playSound();
chatWith(name,roll);
+ }
else
if($("div#chatbox_"+roll).css("top")=="205px"){
-
+ setBrowserTitle(name);
+ playSound();
$("div#chatbox_"+roll).show();
$("div#chatbox_"+roll+" div.chatbox_title").css("background-color","#99C");
$("div#chatbox_"+roll+" div.chatbox_title").text(name+" says...");
@@ -257,10 +269,10 @@ function refreshPopUpChat() {
else{
$("div#chatbox_"+roll).show();
newmsg="yes";
- getChat(roll);
- chatRefreshTimer = setInterval("getChat("+roll+")",1500);
+ getChat(roll,name);
+ chatRefreshTimer = setInterval("getChat("+roll+","+name+")",1500);
}
- //newmsg="no";
+
});
}
else
@@ -280,6 +292,20 @@ function setWritingStatus(roll,name) {
}
}
+function playSound() {
+
+ soundHandle = document.getElementById('soundHandle');
+ soundHandle.src = soundFile; // for google chrome mp3
+ soundHandle.play();
+ soundHandle.src = soundFile1; // for firefox and opera ogg
+ soundHandle.play();
+
+}
+
+function setBrowserTitle(name) {
+ document.title=name+" says...";
+}
+
function hello() {
alert("helo");
}
View
3  chat/chat.php
@@ -15,6 +15,7 @@
echo "Welcome ".$username.", <a href='../logout.php'>Logout</a>";
}
?>
+<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="chat.css" />
@@ -24,7 +25,7 @@
</head>
<body>
<div id="online_box" class="online">
-
+ <audio controls="controls" style="display:none;" id="soundHandle"></audio>
<div id="online_title_box" class="online" >
<div id="online_title" onClick="goOnline()">Who's Online</div>
<div id="min" class="opt" onClick="goOffline()" title="Go offline">-</div>

No commit comments for this range

Something went wrong with that request. Please try again.