Minor code style improvements (mostly whitespace)

This commit is contained in:
Martin Müller 2017-09-14 18:33:01 +02:00
parent 984ff20c19
commit d0dc1a7fbd

View File

@ -81,7 +81,6 @@ function addKeyListeners() {
} }
}; };
// keyboard listener for playing sounds using enter key // keyboard listener for playing sounds using enter key
var buttons = document.querySelectorAll(".sound"); var buttons = document.querySelectorAll(".sound");
@ -91,7 +90,7 @@ function addKeyListeners() {
var source = e.target; var source = e.target;
// keylistener for enter or ctrl+enter (which is k10 on chrome) // keylistener for enter or ctrl+enter (which is k10 on chrome)
if (key === 13 || (key === 10 && e.ctrlKey)) { if (key === 13 || (key === 10 && e.ctrlKey)) {
if(e.ctrlKey){ if (e.ctrlKey){
killAllAudio(); killAllAudio();
await sleep(100); await sleep(100);
} }
@ -135,11 +134,11 @@ function hideSections() {
function ajaxRequest(url) { function ajaxRequest(url) {
var ajaxRequest; var ajaxRequest;
try{ try {
ajaxRequest = new XMLHttpRequest(); ajaxRequest = new XMLHttpRequest();
ajaxRequest.open("GET", url, true); ajaxRequest.open("GET", url, true);
ajaxRequest.send(null); ajaxRequest.send(null);
}catch (e){ } catch (e) {
alert("Unfortunately we were unable to handle your request. Please try again later and contact the server administrator if the problem persists."); alert("Unfortunately we were unable to handle your request. Please try again later and contact the server administrator if the problem persists.");
return false; return false;
} }
@ -151,12 +150,12 @@ function ajaxRequest(url) {
*/ */
function toggleLocalMode() { function toggleLocalMode() {
toggleButton = document.getElementById("local-mode-button").children[0]; toggleButton = document.getElementById("local-mode-button").children[0];
if(localModeEnabled){ if (localModeEnabled) {
localModeEnabled = false; localModeEnabled = false;
toggleButton.classList.remove("local"); toggleButton.classList.remove("local");
toggleButton.innerHTML = "[S]"; toggleButton.innerHTML = "[S]";
toggleButton.title = "play sounds on server"; toggleButton.title = "play sounds on server";
}else{ } else {
localModeEnabled = true; localModeEnabled = true;
toggleButton.classList.add("local"); toggleButton.classList.add("local");
toggleButton.innerHTML = "[L]"; toggleButton.innerHTML = "[L]";
@ -168,20 +167,20 @@ function toggleLocalMode() {
* Either plays the given sound file locally by using howler.js or forwards the request to the remote server using AJAX. * Either plays the given sound file locally by using howler.js or forwards the request to the remote server using AJAX.
*/ */
function playSound(filename) { function playSound(filename) {
if(localModeEnabled){ if (localModeEnabled){
// play local audio using howler.js // play local audio using howler.js
var sound = new Howl({ var sound = new Howl({
src: ['/sounds/'+filename] src: ['/sounds/' + filename]
}); });
sound.play(); sound.play();
howlerSounds.push(sound); howlerSounds.push(sound);
}else{ } else {
ajaxRequest("/play/"+filename); ajaxRequest("/play/" + filename);
} }
} }
function killAllHowlerAudio() { function killAllHowlerAudio() {
for(i=0; i<howlerSounds.length; i++) { for (var i = 0; i < howlerSounds.length; i++) {
howlerSounds[i].stop(); howlerSounds[i].stop();
} }
} }