-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
101 lines (93 loc) · 2.82 KB
/
script.js
File metadata and controls
101 lines (93 loc) · 2.82 KB
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
function similarity(s1, s2) {
var longer = s1;
var shorter = s2;
if (s1.length < s2.length) {
longer = s2;
shorter = s1;
}
var longerLength = longer.length;
if (longerLength === 0) {
return 1.0;
}
return (longerLength - editDistance(longer, shorter)) / parseFloat(longerLength);
}
function editDistance(s1, s2) {
s1 = s1.toLowerCase();
s2 = s2.toLowerCase();
var costs = new Array();
for (var i = 0; i <= s1.length; i++) {
var lastValue = i;
for (var j = 0; j <= s2.length; j++) {
if (i == 0)
costs[j] = j;
else {
if (j > 0) {
var newValue = costs[j - 1];
if (s1.charAt(i - 1) != s2.charAt(j - 1))
newValue = Math.min(Math.min(newValue, lastValue),
costs[j]) + 1;
costs[j - 1] = lastValue;
lastValue = newValue;
}
}
}
if (i > 0)
costs[s2.length] = lastValue;
}
return costs[s2.length];
}
function search(value) {
var links = ['introduction', 'contact', 'help', 'about', 'Applications', 'Termes_Affixes', 'Autres_Resources']
var ratios = [];
for (var link in links) {
var ratio = similarity(value, links[link]);
ratios.push(ratio);
}
var results = [];
for (var i=0; i<10; i++) {
if (ratios[0] == undefined) break;
var max = Math.max.apply(Math, ratios);
var index = ratios.indexOf(max);
var result = links[index];
results.push(result);
ratios.splice(index, 1);
links.splice(index, 1)
}
return results;
}
function catchSearchValue() {
var value = document.getElementById('search_input_id').value;
var label = document.getElementById('search_labels_id');
if (!value.trim()) {
label.innerHTML = "";
label.style.boxShadow = 'none';
label.style.padding = '0';
}
else {
label.style.boxShadow = '0 0 0 2px rgba(135, 135, 135, 1)';
label.style.paddingLeft = '60px';
label.style.paddingTop = '5px';
label.style.paddingBottom = '5px';
label.innerHTML = "";
var results = search(value);
for (var result in results) {
result = results[result];
var mainPages = ['introduction', 'contact', 'help', 'about'];
var mainPagesFr = ['Introduction', 'Contactez-moi', 'Contribuer', 'À propos'];
for (var page in mainPages){
if (result == mainPages[page]){
name = mainPagesFr[page];
i = '';
break;
}
else{
name = result.replace('_', ' ');
i = 'articles/';
};
}
// var anchor_tag = '<a href="file:///home/mohyeddine/Documents/Web/Projects/Medicine/articles/' + result + '.html' + '">' + result + '</a><br>'
var anchor_tag = '<a style="text-transform: capitalize" href="https://mohyoo.github.io/medecinechlef/' + i + result + '.html' + '">' + name + '</a><br>'
label.innerHTML += anchor_tag;
}
}
}