forked from insideoutprojectbr/mulheres-palestrantes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
138 lines (125 loc) · 4.5 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
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
//PURE.js template init
var directive = {
'article':{
'mulher<-mulheres':{
'h3': 'mulher.name',
'.tags li':{
'tag<-mulher.interests':{
'.': 'tag'
}
},
'.location': 'mulher.location',
'img.photo@alt': 'mulher.name',
'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";
},
'.linkedin a@href': 'https://www.linkedin.com/in/#{mulher.linkedin}',
'.linkedin @class': function(){
return this.linkedin ? "" : "hidden";
},
'.behance a@href': 'https://www.behance.net/#{mulher.behance}',
'.behance @class': function(){
return this.behance ? "" : "hidden";
},
'.site a@href': '#{mulher.site}',
'.site @class': function(){
return this.site ? "" : "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;
filterCards($cards, filter);
});
};
var filterCards = debounce(function($cards, filter) {
$cards.find("h3:not(:Contains(" + filter + "))").parents('.card').hide();
$cards.find("p:not(:Contains(" + filter + "))").parents('.card').hide();
$cards.find("li:not(:Contains(" + filter + "))").parents('.card').hide();
$cards.find("h3:Contains(" + filter + ")").parents('.card').show();
$cards.find("p:Contains(" + filter + ")").parents('.card').show();
$cards.find("li:Contains(" + filter + ")").parents('.card').show();
}, 200);
// 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 debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
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;
};
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};