-
Notifications
You must be signed in to change notification settings - Fork 54
/
module.js
101 lines (92 loc) · 4.05 KB
/
module.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
M.block_progress = {
progressBarLast: new Array(),
locked: false,
init: function (YUIObject, instances, users) {
var instance;
var user;
for (instance = 0; instance < instances.length; instance++) {
for (user = 0; user < users.length; user++) {
this.progressBarLast[instances[instance] + '-' + users[user]] = 'info';
}
}
this.addEvent(window, 'resize', function(e) {M.block_progress.setupScrolling(YUIObject);});
},
showInfo: function (instance, user, id) {
if (this.locked) {
return;
}
var last = this.progressBarLast[instance + '-' + user];
document.getElementById('progressBarInfo' + instance + '-' + user + '-' + last).style.display = 'none';
document.getElementById('progressBarInfo' + instance + '-' + user + '-' + id).style.display = 'block';
this.progressBarLast[instance + '-' + user] = id;
},
showAll: function (instance, user) {
var infoBlocks = document.getElementsByClassName('progressEventInfo');
var i;
var searchString = 'progressBarInfo' + instance + '-' + user + '-';
var searchStringLength = searchString.length;
for (i = 0; i < infoBlocks.length; i++) {
if (infoBlocks[i].id.substring(0,searchStringLength) == searchString) {
infoBlocks[i].style.display = 'block';
}
}
document.getElementById(searchString + 'info').style.display = 'none';
this.locked = true;
},
setupScrolling: function(YUIObject) {
var barContainers = document.getElementsByClassName('barContainer');
var i;
var leftArrows;
var rightArrows;
var nowIcons;
for (i = 0; i < barContainers.length; i++) {
nowIcons = barContainers[i].getElementsByClassName('nowicon');
if(nowIcons.length > 0) {
barContainers[i].scrollLeft = nowIcons[0].offsetLeft - (barContainers[i].offsetWidth / 2);
}
leftArrows = barContainers[i].getElementsByClassName('left-arrow-svg');
rightArrows = barContainers[i].getElementsByClassName('right-arrow-svg');
if(leftArrows.length > 0) {
this.checkArrows(barContainers[i]);
this.addEvent(leftArrows[0].firstChild, 'click', function(e) {M.block_progress.scrollContainer(e.target.parentNode, -1); e.target.stopPagination();})
this.addEvent(rightArrows[0].firstChild, 'click', function(e) {M.block_progress.scrollContainer(e.target.parentNode, 1); e.target.stopPagination();})
}
}
},
checkArrows: function(container) {
var leftArrow = container.getElementsByClassName('left-arrow-svg')[0];
var rightArrow = container.getElementsByClassName('right-arrow-svg')[0];
var scrolled = container.scrollLeft;
var scrollWidth = container.scrollWidth - container.offsetWidth;
var threshold = 10;
var buffer = 5;
if (scrolled > threshold) {
leftArrow.style.display = 'block';
leftArrow.style.left = (scrolled + buffer) + 'px';
} else {
leftArrow.style.display = 'none';
}
if (scrollWidth > threshold && scrolled < scrollWidth - threshold) {
rightArrow.style.display = 'block';
rightArrow.style.right = (buffer - scrolled) + 'px';
} else {
rightArrow.style.display = 'none';
}
},
scrollContainer: function(arrow, direction) {
var container = arrow.parentNode;
var amount = direction * container.scrollWidth * 0.15;
container.scrollLeft += amount;
M.block_progress.checkArrows(container);
},
addEvent: function(target, evt, func) {
if (target.addEventListener) {
target.removeEventListener(evt, func);
target.addEventListener(evt, func);
}
else if (target.attachEvent) {
target.detachEvent('on' + evt, func);
target.attachEvent('on' + evt, func);
}
}
};