2016-06-28 18:10:33 +00:00
|
|
|
<!DOCTYPE html>
|
2017-03-10 20:31:57 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
2017-03-11 15:23:55 +00:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
2017-03-10 20:31:57 +00:00
|
|
|
<title>Chat</title>
|
|
|
|
<script src="/js/jquery-1.12.1.min"></script>
|
|
|
|
<script src="/js/jquery-ui.js"></script>
|
|
|
|
<script src="/socket.io/socket.io.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var iosocket;
|
|
|
|
|
|
|
|
function initSocketIO() {
|
|
|
|
iosocket = io.connect();
|
|
|
|
|
|
|
|
iosocket.on('connect', function() {
|
|
|
|
createSystemMessage('[Connected]');
|
|
|
|
console.log("connect");
|
|
|
|
|
|
|
|
iosocket.on('debugMessage', function(message) {
|
|
|
|
alert(message);
|
|
|
|
});
|
|
|
|
iosocket.on('disconnect', function() {
|
|
|
|
createSystemMessage('[Disconnected]');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
window.onload = function() {
|
|
|
|
initSocketIO();
|
2016-06-28 18:10:33 +00:00
|
|
|
};
|
|
|
|
|
2017-03-10 20:31:57 +00:00
|
|
|
function createSystemMessage(message) {
|
|
|
|
var message = document.createTextNode(message);
|
2016-06-28 18:10:33 +00:00
|
|
|
|
2017-03-10 20:31:57 +00:00
|
|
|
var messageBox = document.createElement('p');
|
|
|
|
messageBox.className = 'system';
|
2016-06-28 18:10:33 +00:00
|
|
|
|
2017-03-10 20:31:57 +00:00
|
|
|
messageBox.appendChild(message);
|
2016-06-28 18:10:33 +00:00
|
|
|
|
2017-03-10 20:31:57 +00:00
|
|
|
var chat = document.getElementById('chat_box');
|
|
|
|
chat.appendChild(messageBox);
|
|
|
|
}
|
2016-06-28 18:10:33 +00:00
|
|
|
|
2017-03-10 20:31:57 +00:00
|
|
|
function createUserMessage(user, message) {
|
|
|
|
var user = document.createTextNode(user + ': ');
|
2016-06-28 18:10:33 +00:00
|
|
|
|
2017-03-10 20:31:57 +00:00
|
|
|
var userBox = document.createElement('span');
|
|
|
|
userBox.className = 'username';
|
|
|
|
userBox.appendChild(user);
|
2016-06-28 18:10:33 +00:00
|
|
|
|
2017-03-10 20:31:57 +00:00
|
|
|
var message = document.createTextNode(message);
|
2016-06-28 18:10:33 +00:00
|
|
|
|
2017-03-10 20:31:57 +00:00
|
|
|
var messageBox = document.createElement('p');
|
|
|
|
messageBox.appendChild(userBox);
|
|
|
|
messageBox.appendChild(message);
|
2016-06-28 18:10:33 +00:00
|
|
|
|
2017-03-10 20:31:57 +00:00
|
|
|
var chat = document.getElementById('chat_box');
|
|
|
|
chat.appendChild(messageBox);
|
|
|
|
}
|
2016-06-28 18:10:33 +00:00
|
|
|
|
2017-03-10 20:31:57 +00:00
|
|
|
function sendMessage() {
|
|
|
|
var user = document.getElementById('user');
|
|
|
|
var message = document.getElementById('message');
|
|
|
|
var number = document.getElementById('number');
|
|
|
|
var currentDate = new Date();
|
|
|
|
var time = currentDate.toLocaleTimeString();
|
|
|
|
var date = currentDate.getDate()+"/"+currentDate.getMonth()+"/"+currentDate.getFullYear();
|
2016-06-28 18:10:33 +00:00
|
|
|
|
2017-03-10 20:31:57 +00:00
|
|
|
iosocket.emit('demoMessage',number.value.toString(),date,time,message.value);
|
|
|
|
createUserMessage(time,message.value);
|
|
|
|
message.value = "";
|
|
|
|
};
|
2016-06-28 18:10:33 +00:00
|
|
|
|
2017-03-10 20:31:57 +00:00
|
|
|
// added a little wrapper for enter submit
|
|
|
|
function submitEnter(e){
|
|
|
|
if (( e.keyCode == 13 )&&(e.shiftKey === false)) {
|
|
|
|
sendMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style type="text/css">
|
2017-03-16 19:36:28 +00:00
|
|
|
@import url('https://fonts.googleapis.com/css?family=Noto+Sans');
|
2017-03-10 20:31:57 +00:00
|
|
|
* {
|
2017-03-16 19:36:28 +00:00
|
|
|
font-family: "Noto Sans", sans-serif;
|
2017-03-10 20:31:57 +00:00
|
|
|
font-size: 24px;
|
|
|
|
}
|
|
|
|
|
|
|
|
html, body, #wrapper {
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
#wrapper {
|
|
|
|
background-color: #ecf0f1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#chat_box {
|
|
|
|
box-sizing: border-box;
|
2017-03-11 15:23:55 +00:00
|
|
|
height: calc(100% - 50px);
|
2017-03-10 20:31:57 +00:00
|
|
|
overflow: auto;
|
|
|
|
padding-bottom: 50px;
|
|
|
|
}
|
|
|
|
|
|
|
|
#footer {
|
|
|
|
box-sizing: border-box;
|
|
|
|
position: fixed;
|
|
|
|
bottom: 0;
|
|
|
|
height: 50px;
|
|
|
|
width: 100%;
|
|
|
|
background-color: #2980b9;
|
|
|
|
}
|
|
|
|
|
|
|
|
#footer .content {
|
|
|
|
padding-top: 4px;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
2017-03-11 15:23:55 +00:00
|
|
|
#number {
|
|
|
|
width: 20%;
|
|
|
|
max-width: 240px;
|
|
|
|
}
|
|
|
|
#message {
|
|
|
|
width: calc(90% - 360px);
|
|
|
|
}
|
|
|
|
|
2017-03-10 20:31:57 +00:00
|
|
|
#send_btn {
|
2017-03-11 15:23:55 +00:00
|
|
|
width: 120px;
|
|
|
|
position: relative;
|
|
|
|
margin: 2px;
|
2017-03-10 20:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.content {
|
|
|
|
width: 70%;
|
|
|
|
margin: 0 auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
input[type="text"],
|
|
|
|
input[type="button"] {
|
|
|
|
border: 0;
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
|
|
|
|
input[type="text"] {
|
|
|
|
background-color: #146EA8;
|
|
|
|
padding: 3px 10px;
|
2017-03-11 15:23:55 +00:00
|
|
|
margin: 2px;
|
|
|
|
max-width: 92%;
|
2017-03-10 20:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
input[type="button"] {
|
|
|
|
background-color: #f39c12;
|
2017-03-11 15:23:55 +00:00
|
|
|
border-right: 1px solid #e67e22;
|
|
|
|
border-bottom: 1px solid #e67e22;
|
2017-03-10 20:31:57 +00:00
|
|
|
min-width: 70px;
|
|
|
|
display: inline-block;
|
2017-03-11 15:23:55 +00:00
|
|
|
position: relative;
|
2017-03-10 20:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
input[type="button"]:hover {
|
|
|
|
background-color: #e67e22;
|
2017-03-11 15:23:55 +00:00
|
|
|
border-right: 1px solid #f39c12;
|
|
|
|
border-bottom: 1px solid #f39c12;
|
2017-03-10 20:31:57 +00:00
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.system,
|
|
|
|
.username {
|
|
|
|
color: #aaa;
|
|
|
|
font-style: italic;
|
|
|
|
font-family: monospace;
|
|
|
|
font-size: 16px;
|
|
|
|
}
|
|
|
|
|
2017-03-11 15:23:55 +00:00
|
|
|
@media screen and (max-width: 1000px) {
|
2017-03-10 20:31:57 +00:00
|
|
|
.content { width: 90%; }
|
2017-03-11 15:23:55 +00:00
|
|
|
#send_btn {
|
|
|
|
position: relative;
|
|
|
|
}
|
2017-03-10 20:31:57 +00:00
|
|
|
}
|
|
|
|
|
2017-03-11 15:23:55 +00:00
|
|
|
@media screen and (max-width: 780px) {
|
|
|
|
#footer {
|
|
|
|
height: 91px;
|
|
|
|
}
|
|
|
|
#chat_box {
|
|
|
|
padding-bottom: 91px;
|
|
|
|
height: calc(100% - 91px);
|
|
|
|
}
|
2017-03-10 20:31:57 +00:00
|
|
|
|
2017-03-11 15:23:55 +00:00
|
|
|
#number {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
#message {
|
|
|
|
min-width: 60%;
|
|
|
|
}
|
|
|
|
#send_btn {
|
|
|
|
position: absolute;
|
|
|
|
right: 0;
|
|
|
|
bottom: 3px;
|
|
|
|
margin: 0;
|
|
|
|
width: 10%;
|
|
|
|
}
|
2017-03-10 20:31:57 +00:00
|
|
|
}
|
|
|
|
|
2017-03-11 15:23:55 +00:00
|
|
|
@media screen and (max-width: 400px) {
|
|
|
|
#footer {
|
|
|
|
height: 135px;
|
|
|
|
}
|
|
|
|
#chat_box {
|
|
|
|
padding-bottom: 135px;
|
|
|
|
height: calc(100% - 135px);
|
|
|
|
|
|
|
|
}
|
2017-03-10 20:31:57 +00:00
|
|
|
|
2017-03-11 15:23:55 +00:00
|
|
|
#number {
|
|
|
|
max-width: none;
|
|
|
|
width: 93%;
|
|
|
|
}
|
|
|
|
#message {
|
|
|
|
width: 93%;
|
|
|
|
}
|
2017-03-10 20:31:57 +00:00
|
|
|
#send_btn {
|
|
|
|
position: relative;
|
|
|
|
margin-top: 3px;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="wrapper">
|
|
|
|
<div id="chat_box" class="content"></div>
|
|
|
|
|
|
|
|
<div id="footer">
|
|
|
|
<div class="content">
|
|
|
|
<input type="text" id="number" value="+4301234567890" />
|
2017-03-11 15:23:55 +00:00
|
|
|
<input type="text" id="message" onkeypress="return submitEnter(event)" placeholder="Enter a Message" />
|
2017-03-10 20:31:57 +00:00
|
|
|
<input type="button" id="send_btn" value="Send" onclick="sendMessage()">
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-06-28 18:10:33 +00:00
|
|
|
</div>
|
2017-03-10 20:31:57 +00:00
|
|
|
</body>
|
|
|
|
</html>
|