implementing AJAX loading for sounds as described in issue #5

This commit is contained in:
Erhard 2017-08-03 17:17:51 +02:00
parent f605cdc8be
commit 26bb3dca85
2 changed files with 14 additions and 3 deletions

View File

@ -30,8 +30,6 @@ ready(function() {
var searchfield = document.querySelector("#search");
searchfield.addEventListener("keyup", function() {
console.log("Search!");
var buttons = document.querySelectorAll(".sound");
buttons.forEach(function(item) {
@ -67,3 +65,16 @@ function hideSections() {
item.style.display = "none";
});
}
function ajaxRequest(filename){
var ajaxRequest;
try{
ajaxRequest = new XMLHttpRequest();
var url = "play/" + filename;
ajaxRequest.open("GET", url, true);
ajaxRequest.send(null);
}catch (e){
alert("Your browser broke!");
return false;
}
}

View File

@ -38,7 +38,7 @@
<section id="sounds">
<div><input type="text" id="search" autofocus/><span id="reset"></span></div>
{% for sound in sounds %}
<div class="sound"><a href="{{ '/play/' + sound | urlencode }}">{{ sound.split('.', 1)[0] }}</a></div>
<div class="sound"><a href="{{ '/play/' + sound | urlencode }}" onclick="ajaxRequest({{ sound | urlencode }});">{{ sound.split('.', 1)[0] }}</a></div>
{% endfor %}
</section>
<section id="youtube">