/
index.htm
191 lines (167 loc) · 7.42 KB
/
index.htm
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>xRTML new message notifier example</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
.sidebar-nav {
padding: 9px 0;
}
</style>
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">xRTML new message notifier example</a>
<div class="nav-collapse collapse">
<ul class="nav pull-right">
<li><a href="#">Messages <span id="unread_messages"><span class="badge badge-inverse">0</span><span></a></li>
</ul>
<p class="navbar-text pull-right">
Logged in as <a href="#" class="navbar-link">Username</a>
</p>
<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Sidebar</li>
<li class="active"><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li class="nav-header">Sidebar</li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li class="nav-header">Sidebar</li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
</div><!--/.well -->
</div><!--/span-->
<div class="span9">
<div class="hero-unit">
<h1>xRTML new message notifier example</h1>
<p>This is an example of how to use <a href="http://www.realtime.co" target="_blank">Realtime's</a> <a href="http://www.xrtml.org" target="_blank">xRTML</a> to notify a user that he/she has a new message. Click the button bellow to simulate a message coming in. You should see the counter on the top right increment each time you do so. For this example, we will be using a placeholderTry opening this example in 2 different browsers to see it working in its full glory!</p><p><strong>IMPORTANT:</strong> Don't forget to use your own Realtime Application Key by replacing "YOUR_APPLICATION_KEY" inside the JavaScript code at the end of this file or this example will NOT work.</p>
<p><a class="btn btn-primary btn-large" id="btn_sendMessage">Send a message »</a></p>
</div>
<div class="row-fluid">
<div class="span4">
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
<p><a class="btn" href="#">View details »</a></p>
</div><!--/span-->
<div class="span4">
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
<p><a class="btn" href="#">View details »</a></p>
</div><!--/span-->
<div class="span4">
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
<p><a class="btn" href="#">View details »</a></p>
</div><!--/span-->
</div><!--/row-->
</div><!--/span-->
</div><!--/row-->
</div><!--/span-->
</div><!--/row-->
<hr>
<footer>
<p>© Company 2012</p>
</footer>
</div><!--/.fluid-container-->
<!-- REALTIME STUFF -->
<!-- Template for the placeholder (which holds the badge with the number of unread messages) -->
<script type="text/html" id="new_message_template">
<span class="badge badge-important" data-bind="text: count"></span>
</script>
<script src="js/xrtml-custom-3.0-min.js"></script>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script>
var counter = 0;
var appkey = 'YOUR_APPLICATION_KEY'; // Realtime Application Key. Add yours here. If you don't have one, get it for FREE at www.realtime.co
var url = 'http://ortc-developers.realtime.co/server/2.1';
xRTML.ready(function(){
xRTML.Config.debug = true; // enables debug, showing data on your browser's console
// Creates a connection to the ORTC server
xRTML.ConnectionManager.create(
{
id: 'myConn',
appkey: appkey,
authToken: 'anything',
url: url,
channels: [
{name: 'users:id_1'}
]
});
// Creates the Placeholder tag that will update the number of unread messages
xRTML.TagManager.create({
name: 'Placeholder',
id: 'phUnreadMessages',
target: '#unread_messages', // the DOM element to be affected
triggers: ['newMessage'],
template: 'new_message_template'
});
});
// Sends a xRTML message
function sendMessage(){
counter++; // increases the counter by 1. This number should come from the server. In fact the data should actually be sent from the server, not from a browser.
// Creates a xRTML message
var xrtmlMessage = xRTML.MessageManager.create({
trigger: 'newMessage',
action: 'insert',
data: {
count: counter
}
});
// Sends the message
xRTML.ConnectionManager.sendMessage({
connections: ['myConn'],
channel: 'users:id_1',
content: xrtmlMessage
});
}
$(function() {
$('#btn_sendMessage').click(function() {
sendMessage();
});
})
</script>
<!-- /REALTIME STUFF -->
</body>
</html>