-
Notifications
You must be signed in to change notification settings - Fork 2
/
annuaire.html
147 lines (131 loc) · 4.6 KB
/
annuaire.html
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
---
layout: default
title: Annuaire
nav_menu: directory
---
<div class="hero">
<h1>Découvrez les coopératives tech</h1>
<p>
Travailler avec une coopérative c'est directement être en contact avec les co-propriétaires de l'entreprise. Cela vous garantie une équipe réactive qui s'assurera de la réussite de votre projet.
</p>
<form action="{{site.baseurl}}/annuaire" onsubmit="event.preventDefault(); onSearch()">
<div class="input">
<input type="text" name="q" placeholder="Rechercher une société, un service, un produit, etc..." id="searchbox">
</div>
<button type="submit" class="btn"><i class="bi-search"></i> Rechercher</button>
</form>
</div>
{% include tags.html %}
<div id="members-search-label">
<span></span>
<button onclick="clearSearch()">Effacer</button>
</div>
<div id="members" class="container cards">
{% for member in site.members %}
<a href="{{member.url|prepend:site.baseurl}}">
<div class="image" style="{% if member.accent_color %}background-color: {{member.accent_color}}{% endif %}">
<div style="background-image: url({% if member.thumbnail %}{{member.thumbnail}}{% else %}{{member.logo}}{% endif %})"></div>
</div>
<div class="title">{{member.title}}</div>
{% if member.description %}
<p>{{member.description}}</p>
{% endif %}
</a>
{% endfor %}
</div>
<section>
<div class="container">
<p>
Notre base de membre est aussi <a href="{{site.baseurl}}/members.json">disponible en JSON</a>.
</p>
</div>
</section>
<script src="{{site.baseurl}}/assets/js/lunr.js"></script>
<script>
const documents = [
{% for member in site.members -%}
{
"title": normalizeStr({{member.title|strip_newlines|jsonify}}),
"body": normalizeStr({{member.content|strip_html|jsonify}}),
"description": normalizeStr({{member.description|strip_html|jsonify}}),
"keywords": {% if member.keywords %}{{member.keywords|jsonify}}{% else %}[]{% endif %}.map(normalizeStr),
"keywords_str": normalizeStr({% if member.keywords %}{{member.keywords|jsonify}}{% else %}[]{% endif %}.join(", ")),
"id": {{member.url|prepend:site.baseurl|jsonify}}
},
{%- endfor %}
];
const lunrIndex = lunr(function() {
this.field('title');
this.field('body');
this.field('description');
this.field('keywords_str');
for (let doc of Object.values(documents)) {
this.add(doc);
}
});
document.addEventListener('DOMContentLoaded', () => {
const searchbox = document.getElementById('searchbox');
let match = RegExp('[?&]q=([^&]*)').exec(window.location.search);
if (match) {
const q = decodeURIComponent(match[1].replace(/\+/g, ' '));
searchbox.value = q;
onSearch();
searchbox.scrollIntoView();
}
document.querySelector(".hero form").addEventListener("submit", (e) => {
e.preventDefault();
onSearch();
searchbox.scrollIntoView();
});
for (const tag of document.querySelectorAll("#tags a")) {
tag.addEventListener("click", (e) => {
e.preventDefault();
searchbox.value = "#" + tag.innerText;
onSearch();
});
}
});
function onSearch(preventLocationChange=false) {
const q = document.getElementById('searchbox').value.trim();
const members = document.getElementById('members');
const label = document.getElementById("members-search-label");
if (!q) {
clearSearch();
return;
}
clearSearch(false);
members.classList.add('searching');
let docs;
if (q.substr(0, 1) === "#") {
const tag = normalizeStr(q.substr(1));
docs = documents.filter(doc => doc.keywords.includes(tag)).map(doc => ({ref: doc.id}));
} else {
docs = lunrIndex.search(normalizeStr(q));
}
let count = 0;
for (let doc of docs) {
const el = members.querySelector(`a[href="${doc.ref}"]`);
if (el) {
el.classList.add('result');
count++;
}
}
label.querySelector("span").innerText = count > 0 ? `Nos ${count} coopératives pour "${q}"` : `Pas de résultats pour "${q}"`;
label.style.display = "block";
}
function clearSearch(resetLocation=true) {
const members = document.getElementById('members');
const label = document.getElementById("members-search-label");
members.classList.remove('searching');
label.style.display = "none";
if (resetLocation) {
window.location.search = '';
}
for (const el of members.querySelectorAll('a.result')) {
el.classList.remove('result');
}
}
function normalizeStr(str) {
return str.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "")
}
</script>