forked from devops001/samsara
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
60 lines (48 loc) · 1.46 KB
/
helpers.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
var Helpers = {
getUniqueID: function(prefix) {
if (!this._nextID) this._nextID = 1;
return prefix +'_'+ this._nextID++;
},
randInt: function(min, max) {
return Math.floor(Math.random()*(max-min+1)+min);
},
randBool: function() {
return Math.round(Math.random())===1;
},
randElement: function(array) {
return array[this.randInt(0, array.length-1)];
},
shuffle: function(array) {
var currentIndex = array.length, temporaryValue, randomIndex ;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
},
showPopup: function(html) {
var posX = App.mouse.clientX + 100;
var posY = App.mouse.clientY;
var div = document.getElementById('popup');
div.innerHTML = html;
div.style.display = 'block';
var popupHeight = div.offsetHeight;
var screenHeight = document.body.clientHeight;
var bottom = posY + popupHeight;
var diff = bottom - screenHeight;
if (diff > 0) {
var margin = 30;
posY = App.mouse.pageY - (diff+margin);
} else {
posY = App.mouse.pageY;
}
div.style.left = posX +"px";
div.style.top = posY +"px";
},
hidePopup: function() {
document.getElementById('popup').style.display = 'none';
}
};