-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathfunctions.js
77 lines (59 loc) · 1.95 KB
/
functions.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
69
70
71
72
73
74
75
76
77
seperate_number_with_commas = function(x) {
var parts = x.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
}
round_number = function(num) {
return seperate_number_with_commas(Math.floor(num))
}
round_number_1 = function(num) {
return seperate_number_with_commas(Math.floor(num * 10) / 10)
}
round_number_2 = function(num) {
return seperate_number_with_commas(Math.floor(num * 100) / 100)
}
hex_link = function(text) {
/* regex: looks for coordinates like 43,-55. includes optional minus sign.
allows coordinates with 3 digits and optional spaces in between.*/
var regex = /(-?\d{1,3})\s?,\s?(-?\d{1,3})/g;
text = text.replace(regex, function(match, p1, p2) {
var hexLink = document.createElement('a');
hexLink.setAttribute('class', 'hex-link');
hexLink.setAttribute('href', '');
hexLink.dataset.x = p1;
hexLink.dataset.y = p2;
hexLink.innerHTML = match;
var tmp = document.createElement("div");
tmp.appendChild(hexLink);
return tmp.innerHTML;
});
return text;
};
/////////////////////////////////////////////////////////////////////////////////
// User Properties
/////////////////////////////////////////////////////////////////////////////////
/*
* Sometimes, Meteor.userId() is not available, such as in publish functions.
* If this is the case, pass the userId in to the function manually.
*/
get_user_property = function (property, userId) {
var fields = {}
fields[property] = 1
var userId = userId || Meteor.userId()
var user = Meteor.users.findOne(userId, {fields: fields})
if (user) {
return user[property]
}
}
// clone object before returning so that it doesn't return a reference
cloneObject = function(obj){
if(obj == null || typeof(obj) != 'object')
return obj;
var temp = obj.constructor(); // changed
for(var key in obj)
temp[key] = this.cloneObject(obj[key]);
return temp;
}
cloneArray = function(arr) {
return arr.slice(0)
}