Fix whitespace issues (trailing, indentation, etc)

This commit is contained in:
Martin Müller 2017-09-14 18:27:36 +02:00
parent b6905e566c
commit 984ff20c19

View File

@ -1,4 +1,3 @@
var localModeEnabled = false; var localModeEnabled = false;
// References to howler objects // References to howler objects
@ -39,7 +38,6 @@ ready(function() {
searchfield.focus(); searchfield.focus();
searchfield.addEventListener("keyup", function() { searchfield.addEventListener("keyup", function() {
var buttons = document.querySelectorAll(".sound"); var buttons = document.querySelectorAll(".sound");
buttons.forEach(function(item) { buttons.forEach(function(item) {
@ -68,42 +66,42 @@ ready(function() {
* Adds all necessary KeyListeners to document * Adds all necessary KeyListeners to document
*/ */
function addKeyListeners() { function addKeyListeners() {
// keyboard listener for global key strokes/inputs // keyboard listener for global key strokes/inputs
document.onkeydown = function(evt) { document.onkeydown = function(evt) {
evt = evt || window.event; evt = evt || window.event;
if (evt.keyCode == 27) { if (evt.keyCode == 27) {
// esc key // esc key
resetSearch(); resetSearch();
} else if ((evt.keyCode == 75 || evt.keyCode == 67) && evt.ctrlKey) { } else if ((evt.keyCode == 75 || evt.keyCode == 67) && evt.ctrlKey) {
// ctrl+k and ctrl+c key binding // ctrl+k and ctrl+c key binding
killAllAudio(); killAllAudio();
} else if (evt.keyCode == 88 && evt.ctrlKey){ } else if (evt.keyCode == 88 && evt.ctrlKey){
// ctrl+x key binding // ctrl+x key binding
toggleLocalMode(); toggleLocalMode();
} }
}; };
// 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");
buttons.forEach(function(item) { buttons.forEach(function(item) {
item.firstChild.addEventListener('keypress', async function (e) { item.firstChild.addEventListener('keypress', async function (e) {
var key = e.keyCode; var key = e.keyCode;
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);
} }
source.classList.add("sound-pressed"); source.classList.add("sound-pressed");
source.onclick(); source.onclick();
await sleep(300); await sleep(300);
source.classList.remove("sound-pressed"); source.classList.remove("sound-pressed");
} }
}); });
}); });
} }
@ -111,11 +109,11 @@ function resetSearch() {
var searchfield = document.querySelector("#search"); var searchfield = document.querySelector("#search");
var buttons = document.querySelectorAll(".sound"); var buttons = document.querySelectorAll(".sound");
buttons.forEach(function(item) { buttons.forEach(function(item) {
item.style.display = "inline-block"; item.style.display = "inline-block";
}); });
searchfield.value = ""; searchfield.value = "";
searchfield.focus(); searchfield.focus();
} }
@ -136,15 +134,15 @@ 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;
} }
} }
/* /*
@ -161,8 +159,8 @@ function toggleLocalMode() {
}else{ }else{
localModeEnabled = true; localModeEnabled = true;
toggleButton.classList.add("local"); toggleButton.classList.add("local");
toggleButton.innerHTML = "[L]"; toggleButton.innerHTML = "[L]";
toggleButton.title = "play sounds locally"; toggleButton.title = "play sounds locally";
} }
} }
@ -173,7 +171,7 @@ 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);
@ -184,7 +182,7 @@ function playSound(filename) {
function killAllHowlerAudio() { function killAllHowlerAudio() {
for(i=0; i<howlerSounds.length; i++) { for(i=0; i<howlerSounds.length; i++) {
howlerSounds[i].stop(); howlerSounds[i].stop();
} }
} }
@ -193,9 +191,8 @@ function killAllHowlerAudio() {
*/ */
function killAllAudio() { function killAllAudio() {
if (localModeEnabled) { if (localModeEnabled) {
killAllHowlerAudio(); killAllHowlerAudio();
} else { } else {
ajaxRequest("/?killvideo=yes"); ajaxRequest("/?killvideo=yes");
} }
} }