SHOW:
|
|
- or go back to the newest paste.
| 1 | - | function Post(username, content, time) {
|
| 1 | + | <!DOCTYPE HTML> |
| 2 | - | var self = this; |
| 2 | + | <html> |
| 3 | - | self.username = ko.observable(username); |
| 3 | + | <head> |
| 4 | - | self.content = ko.observable(content); |
| 4 | + | <title>NovaPlasm's Chat Room</title> |
| 5 | - | self.time = time; |
| 5 | + | <meta charset='UTF-8' /> |
| 6 | - | self.timestamp = ko.computed(function () {
|
| 6 | + | <meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> |
| 7 | - | return moment(self.time, "YYYYMMDD").fromNow(); |
| 7 | + | <link href='http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css' rel='stylesheet' type='text/css' /> |
| 8 | - | }); |
| 8 | + | <link href='http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css' rel='stylesheet'> |
| 9 | - | } |
| 9 | + | <link href="http://fonts.googleapis.com/css?family=Carrois+Gothic+SC" rel='stylesheet' type='text/css'></link> |
| 10 | <link href="../assets/css/base.css" rel='stylesheet' type="text/css"></link> | |
| 11 | <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script> | |
| 12 | <script type="text/javascript" src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script> | |
| 13 | <script type="text/javascript" src='http://cdnjs.cloudflare.com/ajax/libs/knockout/2.2.1/knockout-min.js'></script> | |
| 14 | <script type="text/javascript" src='https://rawgithub.com/timrwood/moment/2.1.0/min/moment.min.js'></script> | |
| 15 | </head> | |
| 16 | <body> | |
| 17 | <div id="main"> | |
| 18 | <textarea id="content" placeholder="Enter Message Here"></textarea> | |
| 19 | <button onclick="SendPost($('#content').val());">Submit</button>
| |
| 20 | <ul class='posts' style="height: 100%"data-bind='foreach: posts'> | |
| 21 | <li class='post'> | |
| 22 | <p class='user userPost' style="display: inline;" data-bind='text: $data.username + " says"'></p> | |
| 23 | <p class='content' data-bind='text: $data.content'></p> | |
| 24 | <p class='user userPost' style="display: inline;" data-bind='text: $data.timestamp'></p> | |
| 25 | </li> | |
| 26 | </ul> | |
| 27 | </div> | |
| 28 | <div class="footer" id="footer"> | |
| 29 | <div class ="foottext2" id= "foottext1"> | |
| 30 | ©NovaPlasm | 2013 | All Rights Reserved | |
| 31 | </div> | |
| 32 | <div class ="foottext1" id= "foottext1"> | |
| 33 | No part of this website or any of its contents may be reproduced, copied, modified or adapted, without the prior written consent of the author, unless otherwise indicated for stand-alone materials | |
| 34 | </div> | |
| 35 | </div> | |
| 36 | <script> | |
| 37 | function Post(username, content, time) {
| |
| 38 | var self = this; | |
| 39 | self.username = username; | |
| 40 | self.content = content; | |
| 41 | self.time = time; | |
| 42 | self.timestamp = ko.computed(function () {
| |
| 43 | model.timeChanged(); | |
| 44 | return moment(self.time).fromNow(); | |
| 45 | }); | |
| 46 | self.timestamp.subscribe(function(newValue){console.log('Update')});
| |
| 47 | } | |
| 48 | var ViewModel = function () {
| |
| 49 | var self = this; | |
| 50 | self.timeChanged = ko.observable(true); | |
| 51 | self.timeChanged.extend({notify:'always'});
| |
| 52 | self.posts = ko.observableArray(); | |
| 53 | } | |
| 54 | var model = new ViewModel(); | |
| 55 | ko.applyBindings(model); | |
| 56 | function SendPost(content) {
| |
| 57 | var timestamp = moment(); | |
| 58 | $.post("app.js", {sendMessage: true, content: content});
| |
| 59 | //} | |
| 60 | //$.onBroadcast(broadcast) {
| |
| 61 | model.posts.unshift(new Post("NovaPlasm"/*broadcast.user*/, content/*broadcast.cont*/, Date.now()/*broadcast.timestamp*/));
| |
| 62 | } | |
| 63 | setInterval(function() {
| |
| 64 | model.timeChanged(true); | |
| 65 | }, 1000); | |
| 66 | </script> | |
| 67 | </body> | |
| 68 | </html> |