-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcv.js
156 lines (141 loc) · 5.46 KB
/
cv.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
(function(){
NodeList.prototype.toArray = function(){
return Array.prototype.slice.call(this);
};
HTMLCollection.prototype.toArray = function(){
return Array.prototype.slice.call(this);
};
Element.prototype.addClass = function(c){
return this.classList.add(c);
};
Element.prototype.removeClass = function(c){
return this.classList.remove(c);
};
Element.prototype.toggleClass = function(c){
return this.classList.toggle(c);
};
Element.prototype.containsClass = function(c){
return this.classList.contains(c);
};
if (!document.getElementsByClassName('mission')[0].classList)
{
var ie9Support = Object.defineProperties({}, {
addClass : {
value : function(classname, element ) {
var cn = element.className;
var rxp = new RegExp( "\\s?\\b"+classname+"\\b", "g" );
if( !cn.match(rxp) ) {
classname = ' ' + classname;
element.className = cn + classname;
}
}
},
removeClass : {
value : function( classname, element ) {
var cn = element.className;
var rxp = new RegExp( "\\s?\\b"+classname+"\\b", "g" );
element.className = cn.replace( rxp, '' );
}
},
toggleClass : {
value : function(classname, element){
var rxp = new RegExp( "\\s+\\b"+classname+"\\b", "g" );
if (element.className.match(rxp)){
element.className = element.className.replace( rxp, '' );
} else {
element.className = element.className + ' ' + classname;
}
}
}
});
Element.prototype.addClass = function(c){
return ie9Support.addClass(c, this);
};
Element.prototype.removeClass = function(c){
return ie9Support.removeClass(c,this);
};
Element.prototype.toggleClass = function(c){
return ie9Support.toggleClass(c,this);
}
}
var missionFilter = Object.defineProperties({}, {
filterMissionWithTags : {
enumerable : false,
value : function (filters){
var missions = document.getElementsByClassName('mission').toArray();
missions.forEach(function(m){
var tag = m.dataset ? m.dataset.tag : m.getAttribute('data-tag');
missionFilter.matchFilter(tag, filters) ? m.removeClass('hidden') : m.addClass('hidden');
});
}
},
onChechboxFilterClick : {
enumerable: false,
value : function onChechboxFilterClick(e){
if (e.target.nodeName != 'INPUT'){
return true;
}
var checkboxes = document.querySelectorAll('input[type=checkbox]:checked');
checkboxes = checkboxes.length > 0 ? checkboxes : document.querySelectorAll('input[type=checkbox]');
missionFilter.filterMissionWithTags(checkboxes.toArray().map(function(c){
return (c.dataset ? c.dataset.filter : c.getAttribute('data-filter'));
}));
ga('send', 'event', 'button', 'click', 'filter' + e.target.id);
}
},
matchFilter : {
enumerable: false,
value : function matchFilter(tags, filters){
for (var i in filters){
if (tags.indexOf(filters[i]) > -1){
return true;
}
}
return false;
}
}
});
function registerEvents(){
var displayOld = document.getElementById('displayOld'),
oldies = document.getElementsByClassName('old mission').toArray(),
sideFilter = document.querySelector('section.side'),
descriptionPlus = document.getElementById('plus'),
descriptionMore = document.getElementById('more'),
showRegexp = new RegExp("Afficher"),
plusRegexp = new RegExp("Plus");
displayOld.onclick = function(){
oldies.forEach(function (o){
o.toggleClass("hiddenOld");
});
if (displayOld.innerHTML.match(showRegexp)){
displayOld.innerHTML = "Masquer les missions plus anciennes";
ga('send', 'event', 'button', 'click', 'old missions', 1);
} else {
displayOld.innerHTML = "Afficher les missions plus anciennes";
ga('send', 'event', 'button', 'click', 'old missions', 0);
}
};
descriptionPlus.onclick = function(){
if (plus.innerHTML.match(plusRegexp)){
descriptionPlus.innerHTML = "Réduire";
ga('send', 'event', 'button', 'click', 'more description', 1);
} else {
descriptionPlus.innerHTML = "Plus...";
ga('send', 'event', 'button', 'click', 'more description', 0);
}
descriptionMore.toggleClass("hidden");
};
sideFilter.onclick = missionFilter.onChechboxFilterClick;
window.onscroll = function(){
var header = document.getElementById("header");
if (window.pageYOffset > 0 && !header.containsClass("animationOff")) {
header.removeClass("animationOn");
header.addClass("animationOff");
} else if (window.pageYOffset === 0 && !header.containsClass("animationOn")) {
header.removeClass("animationOff");
header.addClass("animationOn");
}
};
}
window.onload = registerEvents;
})();