-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathsearch.html
68 lines (65 loc) · 2.76 KB
/
search.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
---
layout: default
---
<div class="hero lazyloaded">
<div class="hero__wrap">
<h1 class="hero__title">اشتراکگذاری تجربهی کاری با همه!</h1>
<br/>
<h2 class="hero-search"><input class="input" id="search" type="search" name="search" autocomplete="off" placeholder="جستجوی نام شرکت مورد نظر..."></h2>
</div>
</div>
<main class="site__content">
<section class="blog">
<div class="container">
<div class="row"></div>
<div id="list">
</div>
<div style="clear: both"></div>
</div>
</section>
</main>
<script type="text/javascript" src="{{ "/assets/fetch.js" | relative_url }}"></script>
<script type="text/javascript">
const endpoint = '{{ "/assets/search.json" | relative_url }}';
const pages = [];
fetch(endpoint)
.then(blob => blob.json())
.then(data => pages.push(...data))
function findResults(termToMatch, pages) {
return pages.filter(item => {
const regex = new RegExp(termToMatch, 'gi');
return item.title.match(regex) || item.title_en.match(regex);
});
}
function displayResults() {
const resultsArray = findResults(this.value, pages);
const html = resultsArray.map(item => {
return `
<div class="col-md-4 col-lg-4 col-xl-4">
<a class="black-link" href="${item.url}"><div class="place-card place-card--small">
<div class="place-card__img">
<img src="/assets/company-logo.png" class="place-card__img-thumbnail" alt="Thumbnail">
</div>
<div class="place-card__content">
<h3 class="place-card__content_header">${item.title}</h3>
<p class="mb-0"><i class="fa fa-map-marker"></i> <span class="text-muted">${item.city}</span></p>
</div>
</div></a>
</div>`;
}).join('');
if ((resultsArray.length == 0) || (this.value == '')) {
const company = document.querySelector('#search').value;
resultsList.innerHTML = `<br/><p class="center">شرکت «${company}» یافت نشد، میخواهید «${company}» را به <a href="{{ site.github }}issues/new?assignees=tajrobe&labels=%D8%AB%D8%A8%D8%AA+%D8%B4%D8%B1%DA%A9%D8%AA+%D8%AC%D8%AF%DB%8C%D8%AF&template=ADD_MISSING_COMPANY_TEMPLATE.md" target="_blank">به لیست شرکتها اضافه کنید؟</a></p><br/><br/><br/>`;
} else {
resultsList.innerHTML = html;
}
}
const field = document.querySelector('#search');
const resultsList = document.querySelector('#list');
field.addEventListener('keyup', displayResults);
field.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
event.preventDefault();
}
});
</script>