-
Notifications
You must be signed in to change notification settings - Fork 0
/
meteor_mobile_demo.js
44 lines (38 loc) · 1016 Bytes
/
meteor_mobile_demo.js
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
Buzz = new Mongo.Collection('buzz');
if (Meteor.isClient) {
Meteor.subscribe('buzzes');
// counter starts at 0
Session.setDefault("counter", 0);
Template.hello.helpers({
counter: function () {
return Session.get("counter");
}
});
Template.hello.events({
'click button': function () {
// increment the counter when button is clicked
Session.set("counter", Session.get("counter") + 1);
Buzz.insert({ createdAt: Date.now() });
}
});
// code to run on client startup
Meteor.startup(function() {
Buzz.find({}).observe({
added: function(doc) {
console.log('Buzz!', doc);
$('body').addClass('buzz');
setTimeout(function() {
$('body').removeClass('buzz');
}, 500);
if (Meteor.isCordova) {
navigator.notification.vibrate(500);
}
}
});
});
}
if (Meteor.isServer) {
Meteor.publish('buzzes', function() {
return Buzz.find({ createdAt: { $gte: Date.now() }});
});
}