forked from leocavalcante/phull
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
90 lines (84 loc) · 2.7 KB
/
example.php
File metadata and controls
90 lines (84 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Phull</title>
<link href="//netdna.bootstrapcdn.com/bootswatch/2.3.1/cosmo/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="span12">
<h1>Phull example</h1>
<hr>
</div>
</div>
<div class="row">
<div class="span12">
<form class="form-inline well" id="emit-form">
<input type="text" id="your-name" placeholder="your name">
<input type="text" id="your-text" placeholder="your text">
<button type="submit" class="btn btn-primary">Send</button>
<button type="reset" class="btn" id="disconnect-btn">Disconnect</button>
</form>
</div>
</div>
<div class="row">
<div class="span12">
<ul class="unstyled" id="messages">
<script id="message-template" type="text/x-handlebars">
<li>
<p>
<strong><i class="icon icon-user"></i>{{user}} says: </strong>
{{text}}<br>
<small>
<time data-moment datetime="{{at}}"></time>
</small>
</p>
</li>
<hr>
</script>
</ul>
</div>
</div>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.0.0/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.4/handlebars.min.js"></script>
<script src="phull/client.js"></script>
<script>
phull.connect('phull/', function()
{
phull.emit({user: 'user' + Math.round(Math.random() * 100), text: 'hello world', at: new Date});
},
function (message)
{
var source = $("#message-template").html(),
template = Handlebars.compile(source),
html = template(message);
$('#messages').prepend(html);
});
$('#emit-form').on('submit', function (event)
{
phull.emit({
user: $('#your-name').val(),
text: $('#your-text').val(),
at: new Date
});
$('#your-text').val('');
event.preventDefault();
});
$('#disconnect-btn').on('click', function (event)
{
phull.disconnect();
});
setInterval(function()
{
$('[data-moment]').each(function()
{
$(this).text(moment($(this).attr('datetime')).fromNow());
});
}, 1000);
</script>
</body>
</html>