forked from roryscarson/dndnext_spell_server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspell_server.js
More file actions
49 lines (42 loc) · 1.33 KB
/
Copy pathspell_server.js
File metadata and controls
49 lines (42 loc) · 1.33 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
function getSpellUrl(spellName)
{
// Replace any "/"s with the url code equivalent "%2F"
return spellName.replace("/", "%2F");
}
function go_to_spell() {
spellUrl = getSpellUrl($("#spell_name_txt").val());
location.href = window.location.origin + '/' + spellUrl + '/';
}
$("#get_spell_btn").click(function() {
go_to_spell();
});
$("#spell_name_txt").keypress(function(event) {
if (event.which == 13) {
event.preventDefault();
go_to_spell();
}
});
spellNames = document.getElementById("names").innerHTML.split("!");
function populateMatches() {
// Clear the contents
matchesContainer = document.getElementById("matches");
matchesContainer.innerHTML = "";
searchTerm = $("#spell_name_txt").val();
// Bail out if we have an empty or null string
if (!searchTerm || searchTerm.length == 0) {
return;
}
lowerSearchTerm = searchTerm.toLowerCase();
for (i = 0; i < spellNames.length; i++) {
lowerName = spellNames[i].toLowerCase();
if (lowerName.indexOf(lowerSearchTerm) != -1) {
spellUrl = getSpellUrl(spellNames[i]);
linkLocation = window.location.origin + "/" + spellUrl + "/"
spellLink = '<a href="' + linkLocation + '">' + spellNames[i] + '</a>'
matchesContainer.innerHTML += spellLink + "<br>";
}
}
}
$("#spell_name_txt").keyup(function(event) {
populateMatches();
});