corrade-http-templates – Blame information for rev 4

Subversion Repositories:
Rev:
Rev Author Line No. Line
2 eva 1 <!doctype html>
2  
3 <html lang="en">
4 <head>
5 <meta charset="utf-8">
6  
7 <title>Corrade Group Chat</title>
8  
9 <meta name="description" content="Group Chat Relay using Corrade">
10 <meta name="author" content="Wizardry and Steamworks">
4 eva 11  
2 eva 12 <link rel="stylesheet" href="css/style.css?v=1.0">
13  
14 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
15 <script type="text/javascript">
16 $(document).ready(function () {
3 eva 17 function sendGroupMessage() {
4 eva 18 // Do not send the message if either the name or the message is empty.
19 // This check is performed in the PHP script as well.
20 if($.trim($("#name").val()) == '' || $.trim($('#message').val()) == '')
21 return;
22 // Hide the controls.
2 eva 23 $("#controls").animate({ opacity: 'hide' }, 'slow');
4 eva 24 // Make the POST request to the PHP script and pass the values of the fields.
2 eva 25 $.ajax({
26 type: 'post',
27 url: "sendGroupMessage.php",
28 data: {
29 name: $("#name").val(),
30 message: $("#message").val()
31 }
32 }).done(function(data) {
4 eva 33 // If any error occurred, display it.
34 if(data)
35 alert(data);
36 // When the data returns, clear the message box and show the controls.
2 eva 37 $('#message').val("");
38 $("#controls").animate({ opacity: 'show' }, 'slow');
39 });
3 eva 40 }
4 eva 41 // Polls the chatlog every second for changes.
3 eva 42 setInterval(function () {
43 $.get("chat.log?t=" + Math.random(), function(data) {
44 $("#chat").html(data);
45 });
46 $("#chat").animate({
47 scrollTop:$("#chat")[0].scrollHeight - $("#chat").height()
48 },1000);
49 }, 1000);
4 eva 50 // When the send button is pressed, then call the sendGroupMessage function to
51 // send the message to the PHP script, which then send the message to Corrade.
3 eva 52 $("#send").click(function(e){
53 sendGroupMessage();
2 eva 54 });
3 eva 55 // Subscribe to pressing enter with the message input box selected.
56 $("#message").keypress(function(e) {
57 if (e.which == 13) {
58 sendGroupMessage();
59 return false;
60 }
61 });
2 eva 62 });
63 </script>
64 </head>
65  
66 <body>
67 <div id="container">
68 <textarea id="chat" rows="12"></textarea><br/>
69 <div id="controls">
70 Name: <input type="text" size="8" value="Someone" id="name"></input>
71 Message: <input type="text" size="35" id="message"></input>
72 <button type="button" id="send">Send</button>
73 </div>
74 </div>
75 </body>
76 </html>