forked from insideoutprojectbr/mulheres-palestrantes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
92 lines (81 loc) · 2.98 KB
/
app.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
//PURE.js template init
var directive = {
'article':{
'mulher<-mulheres':{
'h3': 'mulher.name',
'.tags li':{
'tag<-mulher.interests':{
'.': 'tag'
}
},
'.location': 'mulher.location',
'img.photo@src': function(){
return this.photo || generateGravatarUrl(this.email);
},
'.fb a@href': 'https://facebook.com/#{mulher.fb}',
'.fb@class': function(){
return this.fb ? "" : "hidden";
},
'.twitter a@href': 'https://twitter.com/#{mulher.twitter}',
'.twitter @class': function(){
return this.twitter ? "" : "hidden";
},
'.github a@href': 'https://github.com/#{mulher.github}',
'.github @class': function(){
return this.github ? "" : "hidden";
}
}
}
};
$(function(){
$.get("mulheres.json", {crossDomain: true}, function(data) {
$p('main').render(data, directive);
enableSearch();
});
});
function enableSearch() {
var $search = $('.search'),
$cards = $('.card'),
filter;
$search.keyup(function(e) {
filter = this.value;
$cards.find("h3:not(:Contains(" + filter + "))").parent().hide();
$cards.find("p:not(:Contains(" + filter + "))").parent().hide();
$cards.find("li:not(:Contains(" + filter + "))").parent().parent().hide();
$cards.find("h3:Contains(" + filter + ")").parent().show();
$cards.find("p:Contains(" + filter + ")").parent().show();
$cards.find("li:Contains(" + filter + ")").parent().parent().show();
});
};
// Cria um Contains para que ele seja case-insensitive e ignore acentuação
jQuery.expr[':'].Contains = function(element, i, arrFilter) {
var textContent = removeAccents(element.textContent || ""),
innerText = removeAccents(element.innerText || ""),
filter = removeAccents(arrFilter[3] || "");
return (textContent || innerText).indexOf(filter) >= 0;
};
function removeAccents(text) {
return text
.replace(/&/g, '&')
.replace(/á/g, 'a')
.replace(/é/g, 'e')
.replace(/í/g, 'i')
.replace(/ó/g, 'o')
.replace(/ú/g, 'u')
.replace(/ç/g, 'c')
.replace(/ã/g, 'a')
.replace(/õ/g, 'o')
.replace(/ç/g, 'c')
.replace(/[áàã]/g, 'a')
.replace(/[éèê]/g, 'e')
.replace(/[íî]/g, 'i')
.replace(/[óòôõ]/g, 'o')
.replace(/[úùû]/g, 'u')
.toLowerCase();
};
function generateGravatarUrl(email){
var hash = md5(email);
var placeholderImagePath = "http://insideoutproject.xyz/mulheres-palestrantes/img/placeholder-female.jpg";
var imageURL = "https://secure.gravatar.com/avatar/" + hash + "?r=PG&d=" + placeholderImagePath;
return email ? imageURL : placeholderImagePath;
}