-
Notifications
You must be signed in to change notification settings - Fork 0
/
supercat.js
55 lines (47 loc) · 1.2 KB
/
supercat.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
45
46
47
48
49
50
51
52
53
54
55
function makeid(len) {
var
text = "",
possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
;
for( var i=0; i < len; i++ ) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
if (Meteor.isClient) {
var game_id;
// check for game id
if (Session.get('game_id') === undefined) {
var hash = window.location.hash;
// check if game_id available via hash
if (hash.match(/^#[a-zA-Z0-9]*$/)) {
game_id = hash.slice(1);
} else {
// create a new game_id
game_id = makeid(8);
}
} else {
game_id = Session.get('game_id');
}
// set the game_id everywhere
window.location.hash = '#' + game_id;
Session.set('game_id', game_id);
console.log('Current game id: ', game_id);
Session.setDefault('counter', 0);
Template.game.helpers({
counter: function () {
return Session.get('counter');
}
});
Template.game.events({
'click button': function () {
// increment the counter when button is clicked
Session.set('counter', Session.get('counter') + 1);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}