-
Notifications
You must be signed in to change notification settings - Fork 1
/
dubstext.js
68 lines (60 loc) · 1.78 KB
/
dubstext.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
56
57
58
59
60
61
62
63
64
65
66
67
68
Noises = new Meteor.Collection("noises");
if (Meteor.is_client) {
//makes blinky things blink
function setBlinkIntervalForSpeed(speed){
return setInterval(function(){
$(".blinky-" + speed).toggle()
}, speed);
}
//'noise' events
Template.noise.events = {
"click .blinky": function(){
console.log("asdf")
Noises.remove({_id: this._id})
}
}
//'allnoise' helpers/events
intervalIds = []
setupBlinks = function (noises) {
var existingIntervals = [];
_.each(intervalIds, function(id){ clearInterval(id) })
noises.forEach(function(noise){
if(!existingIntervals[noise.speed]){
existingIntervals[noise.speed] = true
id = setBlinkIntervalForSpeed(noise.speed)
intervalIds.push(id);
}
})
}
Template.noises.allNoises = function () {
var noises = Noises.find({});
setupBlinks(noises); //janky rerender listener
return noises;
}
Template.noises.newNoise = function () {
return Session.get("newNoise")
}
Template.noises.events = {
'click #container' : function (e) {
Session.set("newNoise", {x: e.x, y: e.y})
}
};
//end of 'allnoise' helpers/events
//'newnoise' events
clickCanceler = function(e) { return false; }
Template.newNoise.events = {
'click .bordered' : clickCanceler,
'click #submit' : function(e) {
Noises.insert({text: $("#text").val(), speed: $("#speed").val(), size: $("#size").val(), color: $("#color").val(), x: this.x, y: this.y })
Session.set("newNoise", undefined);
return false;
}
}
}
if (Meteor.is_server) {
Meteor.startup(function () {
// delete everything and add a noise to start with
Noises.remove({});
Noises.insert({text: "doop", x: 300, y: 200, speed: 200, size: 20, color: "aa0"});
});
}