Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
80 lines (68 loc) · 1.79 KB
/
Copy pathindex.html
File metadata and controls
80 lines (68 loc) · 1.79 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
<style>
body {
padding: 0;
margin: 0;
}
#counter, h1 {
padding: 20px;
margin: 50px;
font-size: 100px;
font-weight: 100;
font-family: "Helvetica Neue";
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
h1 {
padding: 10px;
margin: 10px;
font-size: 50px;
font-weight: 200;
}
#log, .log {
padding: 0 20px;
margin: 0 50px;
font-family: Monaco;
}
.log {
padding: 0 20px;
margin: 0 50px;
}
</style>
<h1>Message Counter</h1>
<div id=counter>0 msgs</div>
<div class=log><strong>Log</strong></div>
<div id=log></div>
<div id=pubnub></div>
<script src=../../web/pubnub.min.js></script>
<script>(function(){
var counter = +PUBNUB.db.get('message-counter') || 0
, cnt = PUBNUB.$('counter')
, log = PUBNUB.$('log')
, channel = 'my_channel'
, p = PUBNUB.init({
publish_key : 'demo',
subscribe_key : 'demo'
});
// Initial
log.innerHTML = PUBNUB.db.get('message-log') || '';
cnt.innerHTML = counter + ' msgs';
function increment() {
var datelog = '' + new Date();
log.innerHTML += "<div>" + datelog + " received.</div>";
counter++;
cnt.innerHTML = counter + ' msgs';
PUBNUB.db.set( 'message-counter', ''+counter );
PUBNUB.db.set( 'message-log', log.innerHTML );
p.css( cnt, { background : '#ff0' } );
setTimeout( function() {
p.css( cnt, { background : '#fff' } );
}, 700 );
}
p.subscribe({
channel : channel,
callback : increment
});
})();</script>