corrade-http-templates – Blame information for rev 33
?pathlinks?
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> |
||
33 | office | 22 | <!-- Group chat container. --> |
28 | office | 23 | <div class="container"> |
30 | office | 24 | <form role="form" data-toggle="validator"> |
28 | office | 25 | <div class="form-group"> |
26 | <textarea class="form-control" id="chat" readonly="readonly" rows="12"></textarea> |
||
27 | </div> |
||
33 | office | 28 | <div class="form-group row"> |
28 | office | 29 | <div id="controls"> |
33 | office | 30 | <div class="col-xs-3"> |
31 | <div class="input-group"> |
||
32 | <span class="input-group-addon"> |
||
33 | <label for="name">Name</label> |
||
34 | </span> |
||
35 | <input class="form-control" id="name" maxlength="8" type="text" value="Someone" required> |
||
36 | </div> |
||
37 | </div> |
||
38 | <div class="col-xs-8"> |
||
39 | <div class="input-group"> |
||
40 | <span class="input-group-addon"> |
||
41 | <label for="message">Message</label> |
||
42 | </span> |
||
43 | <div class="input-group col-xs-12"> |
||
44 | <input class="form-control" id="message" type="text" required> |
||
45 | <span class="input-group-btn"> |
||
46 | <button class="btn btn-default" id="send" type="submit">Send</button> |
||
47 | </span> |
||
48 | </div> |
||
49 | </div> |
||
50 | </div> |
||
28 | office | 51 | </div> |
52 | </div> |
||
53 | </form> |
||
54 | </div> |
||
2 | eva | 55 | |
30 | office | 56 | <!-- Include jQuery --> |
32 | office | 57 | <script src="bower_components/jquery/dist/jquery.min.js"></script> |
30 | office | 58 | <!-- Include Bootstrap Validator --> |
59 | <script src="bower_components/bootstrap-validator/js/validator.js"></script> |
||
32 | office | 60 | <!-- Include Velocity --> |
61 | <script src="bower_components/velocity/velocity.min.js"></script> |
||
30 | office | 62 | <script> |
2 | eva | 63 | $(document).ready(function () { |
3 | eva | 64 | function sendGroupMessage() { |
4 | eva | 65 | // Hide the controls. |
32 | office | 66 | $("#controls").animate( |
67 | { |
||
68 | opacity: 0 |
||
69 | }, |
||
70 | { |
||
71 | duration: 1000, |
||
72 | easing: "linear" |
||
73 | } |
||
74 | ); |
||
4 | eva | 75 | // Make the POST request to the PHP script and pass the values of the fields. |
2 | eva | 76 | $.ajax({ |
77 | type: 'post', |
||
78 | url: "sendGroupMessage.php", |
||
79 | data: { |
||
80 | name: $("#name").val(), |
||
81 | message: $("#message").val() |
||
82 | } |
||
83 | }).done(function(data) { |
||
4 | eva | 84 | // If any error occurred, display it. |
85 | if(data) |
||
86 | alert(data); |
||
87 | // When the data returns, clear the message box and show the controls. |
||
2 | eva | 88 | $('#message').val(""); |
32 | office | 89 | $("#controls").animate( |
90 | { |
||
91 | opacity: 1 |
||
92 | }, |
||
93 | { |
||
94 | duration: 1000, |
||
95 | easing: "linear" |
||
96 | } |
||
97 | ); |
||
2 | eva | 98 | }); |
3 | eva | 99 | } |
4 | eva | 100 | // Polls the chatlog every second for changes. |
5 | zed | 101 | (function retrieveMessages() { |
3 | eva | 102 | $.get("chat.log?t=" + Math.random(), function(data) { |
103 | $("#chat").html(data); |
||
22 | office | 104 | $("#chat").scrollTop($("#chat")[0].scrollHeight); |
5 | zed | 105 | setTimeout(retrieveMessages, 1000); |
3 | eva | 106 | }); |
5 | zed | 107 | }()); |
4 | eva | 108 | // When the send button is pressed, then call the sendGroupMessage function to |
109 | // send the message to the PHP script, which then send the message to Corrade. |
||
3 | eva | 110 | $("#send").click(function(e){ |
111 | sendGroupMessage(); |
||
2 | eva | 112 | }); |
3 | eva | 113 | // Subscribe to pressing enter with the message input box selected. |
114 | $("#message").keypress(function(e) { |
||
115 | if (e.which == 13) { |
||
116 | sendGroupMessage(); |
||
117 | return false; |
||
118 | } |
||
119 | }); |
||
2 | eva | 120 | }); |
121 | </script> |
||
122 | </body> |
||
123 | </html> |