-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisotest.js
More file actions
88 lines (77 loc) · 2.23 KB
/
isotest.js
File metadata and controls
88 lines (77 loc) · 2.23 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
81
82
83
84
85
86
87
88
Blocks = new Meteor.Collection("blocks");
if (Meteor.isClient) {
var container = {};
Template.container.rendered = function () {
container = $(this.find("#container"));
}
Template.block.rendered = function () {
var items = container.find(".item");
// console.log("Running rendered for container with " + items.length + " blocks");
if ((!container.hasClass("isotope")) && (items.length == Blocks.find().count())) {
// This seems to run once per block. Wasteful.
// console.log("Initialize isotope");
// Initialize isotope
container.isotope({
itemSelector : '.item',
layoutMode : 'fitRows',
getSortData : {
number : function( $elem ) {
return parseInt( $elem.text(), 10 );
}
}
});
container.isotope({sortBy: "number"});
} else if (container.hasClass("isotope")) {
console.log("Updating isotope");
container.isotope('addItems', $(this.find(".item:not(.isotope-item)")), function() {
container.isotope({sortBy: "number"});
});
}
}
Template.container.blocks = function () {
return Blocks.find();
};
Template.block.destroyed = function () {
console.log("Running destroy for block " + this.data.num);
container.isotope({sortBy: "number"});
}
}
if (Meteor.isServer) {
function getRandomInt (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function rejigger() {
var count = Blocks.find().count();
var i = getRandomInt(0, count-1);
var num = getRandomInt(0,100);
var item = Blocks.find().fetch()[i];
var c = getRandomInt(0,2);
if (count > 30) c++;
if (c==0) {
// Add
console.log("Add");
Blocks.insert({num: num});
} else if (c==1) {
// Remove
console.log("Remove");
if (item) {
Blocks.remove(item._id);
}
} else if (c>=2) {
// Fiddle
console.log("Fiddle");
if (item) {
Blocks.update(item._id, {num: num});
}
}
}
Meteor.startup(function () {
// code to run on server at startup
while (Blocks.find().count() < 10) {
Blocks.insert({
num: Blocks.find().count() + 1
});
}
Meteor.setInterval(rejigger, 1000);
});
}