Created
November 11, 2014 18:53
-
-
Save AstraLuma/00e58c3431f64feec3ad to your computer and use it in GitHub Desktop.
Comfy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Comfy</title> | |
| </head> | |
| <body> | |
| <table id="chat"> | |
| <thead> | |
| <tr> | |
| <th>Timestamp</th> | |
| <th>Who</th> | |
| <th>Message</th> | |
| </tr> | |
| </thead> | |
| <tbody id="history"></tbody> | |
| <tfoot> | |
| <th id="name" title="Click to change name">Guy</th> | |
| <td> | |
| <input id="message"> | |
| <button id="send">Send</button> | |
| </td> | |
| </tfoot> | |
| </table> | |
| <script src="http://localhost:5984/_utils/script/jquery.js"></script> | |
| <script src="http://localhost:5984/_utils/script/jquery.couch.js"></script> | |
| <script type="text/javascript"> | |
| $.couch.urlPrefix = "http://localhost:5984"; | |
| $.couch.db("comfy").create(); // Don't care about failure | |
| $(function() { | |
| function loadName() { | |
| $('#name').text(localStorage.name || "Guy"); | |
| } | |
| loadName(); | |
| $('#send').click(function() { | |
| $.couch.db("comfy").saveDoc({ | |
| 't': Date.now(), | |
| 'u': $('#name').text(), | |
| 'm': $('#message').val() | |
| }); | |
| }); | |
| $('#name').click(function() { | |
| localStorage.name = prompt("Enter handle", localStorage.name); | |
| loadName() | |
| }); | |
| $.couch.db("comfy").changes('now', { | |
| 'include_docs': true | |
| }).onChange(function(data) { | |
| data.results.forEach(function(change) { | |
| var doc = change.doc; | |
| $('#history').append( | |
| $('<tr class=message>').append( | |
| $('<th>').text((new Date(doc.t)).toLocaleTimeString()), | |
| $('<th>').text(doc.u), | |
| $('<td>').text(doc.m) | |
| ) | |
| ); | |
| }); | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment