corrade-http-templates – Blame information for rev 28

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  
27 office 7 <title>Corrade Group Chat Template</title>
8  
9 <meta charset="utf-8">
10 <meta http-equiv="X-UA-Compatible" content="IE=edge">
11 <meta name="viewport" content="width=device-width, initial-scale=1">
2 eva 12 <meta name="description" content="Group Chat Relay using Corrade">
13 <meta name="author" content="Wizardry and Steamworks">
27 office 14 <link rel="icon" href="../../favicon.ico">
4 eva 15  
27 office 16 <!-- Bootstrap core CSS -->
17 <link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
28 office 18 <!-- <link rel="stylesheet" href="css/style.css?v=1.1"> -->
19 </head>
20  
21 <body>
22 <div class="container">
23 <form role="form">
24 <div class="form-group">
25 <textarea class="form-control" id="chat" readonly="readonly" rows="12"></textarea>
26 </div>
27 <div class="form-group">
28 <div id="controls">
29 <div class="input-group">
30 <input class="form-control" id="name" maxlength="8" type="text" value="Someone">
31 <span class="input-group-addon">@</span>
32 <input class="form-control" id="message" type="text">
33 <span class="input-group-btn">
34 <button class="btn btn-default" id="send" type="button">Send</button>
35 </span>
36 </div>
37 </div>
38 </div>
39 </form>
40 </div>
2 eva 41  
28 office 42 <script type="text/javascript" src="bower_components//jquery/dist/jquery.min.js"></script>
2 eva 43 <script type="text/javascript">
44 $(document).ready(function () {
3 eva 45 function sendGroupMessage() {
4 eva 46 // Do not send the message if either the name or the message is empty.
47 // This check is performed in the PHP script as well.
48 if($.trim($("#name").val()) == '' || $.trim($('#message').val()) == '')
49 return;
50 // Hide the controls.
2 eva 51 $("#controls").animate({ opacity: 'hide' }, 'slow');
4 eva 52 // Make the POST request to the PHP script and pass the values of the fields.
2 eva 53 $.ajax({
54 type: 'post',
55 url: "sendGroupMessage.php",
56 data: {
57 name: $("#name").val(),
58 message: $("#message").val()
59 }
60 }).done(function(data) {
4 eva 61 // If any error occurred, display it.
62 if(data)
63 alert(data);
64 // When the data returns, clear the message box and show the controls.
2 eva 65 $('#message').val("");
66 $("#controls").animate({ opacity: 'show' }, 'slow');
67 });
3 eva 68 }
4 eva 69 // Polls the chatlog every second for changes.
5 zed 70 (function retrieveMessages() {
3 eva 71 $.get("chat.log?t=" + Math.random(), function(data) {
72 $("#chat").html(data);
22 office 73 $("#chat").scrollTop($("#chat")[0].scrollHeight);
5 zed 74 setTimeout(retrieveMessages, 1000);
3 eva 75 });
5 zed 76 }());
4 eva 77 // When the send button is pressed, then call the sendGroupMessage function to
78 // send the message to the PHP script, which then send the message to Corrade.
3 eva 79 $("#send").click(function(e){
80 sendGroupMessage();
2 eva 81 });
3 eva 82 // Subscribe to pressing enter with the message input box selected.
83 $("#message").keypress(function(e) {
84 if (e.which == 13) {
85 sendGroupMessage();
86 return false;
87 }
88 });
2 eva 89 });
90 </script>
91 </body>
92 </html>