-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
77 lines (49 loc) · 1.65 KB
/
utils.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
function getSize() {
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
}
function sumArray(inputArray) {
var total = 0;
for (i=0; i<inputArray.length; i++) {
total = total + inputArray[i];
}
return total;
}
function addImg(id, src, x, y) {
getSize();
if (!document.getElementById(id)) {
var newLocation = document.createElement('img');
newLocation.setAttribute('id', id);
newLocation.setAttribute('src', src);
document.getElementById('display').appendChild(newLocation);
}
var currentLocation = document.getElementById(id);
currentLocation.style.top = Math.round((myHeight / 35) * x);
currentLocation.style.left = Math.round((myWidth / 50) * y);
currentLocation.style.position = 'absolute';
currentLocation.style.visibility = 'visible';
currentLocation.height = Math.round(myHeight / 34);
currentLocation.width = Math.round(myWidth / 49);
}
//Array clone prototype function
Array.prototype.clone = function() {
var newObj = this.slice(0);
for (i=0; i<this.length; i++) {
if (this[i].clone) {
newObj[i] = this[i].clone();
break;
}
}
return newObj;
}