forked from server/soundboard
Fix whitespace issues (trailing, indentation, etc)
This commit is contained in:
parent
b6905e566c
commit
984ff20c19
107
static/main.js
107
static/main.js
@ -1,4 +1,3 @@
|
||||
|
||||
var localModeEnabled = false;
|
||||
|
||||
// References to howler objects
|
||||
@ -39,7 +38,6 @@ ready(function() {
|
||||
searchfield.focus();
|
||||
|
||||
searchfield.addEventListener("keyup", function() {
|
||||
|
||||
var buttons = document.querySelectorAll(".sound");
|
||||
|
||||
buttons.forEach(function(item) {
|
||||
@ -68,42 +66,42 @@ ready(function() {
|
||||
* Adds all necessary KeyListeners to document
|
||||
*/
|
||||
function addKeyListeners() {
|
||||
// keyboard listener for global key strokes/inputs
|
||||
document.onkeydown = function(evt) {
|
||||
evt = evt || window.event;
|
||||
if (evt.keyCode == 27) {
|
||||
// esc key
|
||||
resetSearch();
|
||||
} else if ((evt.keyCode == 75 || evt.keyCode == 67) && evt.ctrlKey) {
|
||||
// ctrl+k and ctrl+c key binding
|
||||
killAllAudio();
|
||||
} else if (evt.keyCode == 88 && evt.ctrlKey){
|
||||
// ctrl+x key binding
|
||||
toggleLocalMode();
|
||||
}
|
||||
};
|
||||
// keyboard listener for global key strokes/inputs
|
||||
document.onkeydown = function(evt) {
|
||||
evt = evt || window.event;
|
||||
if (evt.keyCode == 27) {
|
||||
// esc key
|
||||
resetSearch();
|
||||
} else if ((evt.keyCode == 75 || evt.keyCode == 67) && evt.ctrlKey) {
|
||||
// ctrl+k and ctrl+c key binding
|
||||
killAllAudio();
|
||||
} else if (evt.keyCode == 88 && evt.ctrlKey){
|
||||
// ctrl+x key binding
|
||||
toggleLocalMode();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// keyboard listener for playing sounds using enter key
|
||||
// keyboard listener for playing sounds using enter key
|
||||
var buttons = document.querySelectorAll(".sound");
|
||||
|
||||
buttons.forEach(function(item) {
|
||||
item.firstChild.addEventListener('keypress', async function (e) {
|
||||
var key = e.keyCode;
|
||||
var source = e.target;
|
||||
// keylistener for enter or ctrl+enter (which is k10 on chrome)
|
||||
if (key === 13 || (key === 10 && e.ctrlKey)) {
|
||||
if(e.ctrlKey){
|
||||
killAllAudio();
|
||||
await sleep(100);
|
||||
}
|
||||
source.classList.add("sound-pressed");
|
||||
source.onclick();
|
||||
await sleep(300);
|
||||
source.classList.remove("sound-pressed");
|
||||
}
|
||||
});
|
||||
});
|
||||
item.firstChild.addEventListener('keypress', async function (e) {
|
||||
var key = e.keyCode;
|
||||
var source = e.target;
|
||||
// keylistener for enter or ctrl+enter (which is k10 on chrome)
|
||||
if (key === 13 || (key === 10 && e.ctrlKey)) {
|
||||
if(e.ctrlKey){
|
||||
killAllAudio();
|
||||
await sleep(100);
|
||||
}
|
||||
source.classList.add("sound-pressed");
|
||||
source.onclick();
|
||||
await sleep(300);
|
||||
source.classList.remove("sound-pressed");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -111,11 +109,11 @@ function resetSearch() {
|
||||
var searchfield = document.querySelector("#search");
|
||||
var buttons = document.querySelectorAll(".sound");
|
||||
|
||||
buttons.forEach(function(item) {
|
||||
item.style.display = "inline-block";
|
||||
});
|
||||
buttons.forEach(function(item) {
|
||||
item.style.display = "inline-block";
|
||||
});
|
||||
|
||||
searchfield.value = "";
|
||||
searchfield.value = "";
|
||||
searchfield.focus();
|
||||
}
|
||||
|
||||
@ -136,15 +134,15 @@ function hideSections() {
|
||||
}
|
||||
|
||||
function ajaxRequest(url) {
|
||||
var ajaxRequest;
|
||||
try{
|
||||
ajaxRequest = new XMLHttpRequest();
|
||||
ajaxRequest.open("GET", url, true);
|
||||
ajaxRequest.send(null);
|
||||
}catch (e){
|
||||
alert("Unfortunately we were unable to handle your request. Please try again later and contact the server administrator if the problem persists.");
|
||||
return false;
|
||||
}
|
||||
var ajaxRequest;
|
||||
try{
|
||||
ajaxRequest = new XMLHttpRequest();
|
||||
ajaxRequest.open("GET", url, true);
|
||||
ajaxRequest.send(null);
|
||||
}catch (e){
|
||||
alert("Unfortunately we were unable to handle your request. Please try again later and contact the server administrator if the problem persists.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -161,8 +159,8 @@ function toggleLocalMode() {
|
||||
}else{
|
||||
localModeEnabled = true;
|
||||
toggleButton.classList.add("local");
|
||||
toggleButton.innerHTML = "[L]";
|
||||
toggleButton.title = "play sounds locally";
|
||||
toggleButton.innerHTML = "[L]";
|
||||
toggleButton.title = "play sounds locally";
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,7 +171,7 @@ function playSound(filename) {
|
||||
if(localModeEnabled){
|
||||
// play local audio using howler.js
|
||||
var sound = new Howl({
|
||||
src: ['/sounds/'+filename]
|
||||
src: ['/sounds/'+filename]
|
||||
});
|
||||
sound.play();
|
||||
howlerSounds.push(sound);
|
||||
@ -184,7 +182,7 @@ function playSound(filename) {
|
||||
|
||||
function killAllHowlerAudio() {
|
||||
for(i=0; i<howlerSounds.length; i++) {
|
||||
howlerSounds[i].stop();
|
||||
howlerSounds[i].stop();
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,9 +191,8 @@ function killAllHowlerAudio() {
|
||||
*/
|
||||
function killAllAudio() {
|
||||
if (localModeEnabled) {
|
||||
killAllHowlerAudio();
|
||||
} else {
|
||||
ajaxRequest("/?killvideo=yes");
|
||||
}
|
||||
killAllHowlerAudio();
|
||||
} else {
|
||||
ajaxRequest("/?killvideo=yes");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user