-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmodule.js
73 lines (69 loc) · 2.52 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
M.block_heatmap = {
config: 0,
min: 0,
max: 0,
diff: 0,
numColours: 5,
toggleState: true,
viewsicon: '',
usersicon: '',
initHeatmap: function (YUIObject, config, min, max, toggledon, viewsicon, usersicon, whattoshow) {
this.config = JSON.parse(config);
this.min = min;
this.max = max;
this.diff = max - min + 1;
this.toggleState = toggledon == 1;
this.viewsicon = viewsicon;
this.usersicon = usersicon;
this.whattoshow = whattoshow;
if (this.toggleState) {
this.showHeatmap();
}
},
showHeatmap: function () {
var module;
var weight;
var info;
for (var i = 0; i < this.config.length; i++) {
module = document.getElementById('module-' + this.config[i].cmid);
weight = parseInt((this.config[i].numviews - this.min) / this.diff * this.numColours);
if (module) {
if (this.whattoshow != 'showicons') {
module.className += ' block_heatmap_heat_' + weight;
}
if (this.whattoshow != 'showbackground') {
info = '<div class="block_heatmap_view_count">';
info += this.viewsicon;
info += ' <span class="block_heatmap_views block_heatmap_icon_' + weight + '">';
info += this.config[i].numviews;
info += '</span> ';
info += this.usersicon;
info += ' <span class="block_heatmap_users block_heatmap_icon_' + weight + '"">';
info += this.config[i].distinctusers;
info += '</span></div>';
module.innerHTML = module.innerHTML + info;
}
}
}
},
hideHeatmap: function () {
var module;
for (var i = 0; i < this.config.length; i++) {
module = document.getElementById('module-' + this.config[i].cmid);
if (module) {
module.className = module.className.replace(/ block_heatmap_heat_(\d)/, '');
module.removeChild(module.getElementsByClassName('block_heatmap_view_count')[0]);
}
}
},
toggleHeatmap: function () {
this.toggleState = !this.toggleState;
if(this.toggleState) {
this.showHeatmap();
}
else {
this.hideHeatmap();
}
M.util.set_user_preference('heatmaptogglestate', this.toggleState);
}
};