Refactor media keys and fix play/pause
- Using space to play/pause was broken due to an issue with data binding. Running `$scope.$apply()` after updating the `player.pauseSong` property using `player.togglePause()` seems to have fixed this. - All of the key event processing has been moved into the JS. This means that all the key event logic is all in one spot (easier to understand IMO). Additionally, this removes the need to redefine functions for each shortcut. - Removed the now-unused `angular-ui-utils/keypress.js` package. - Fixed key events being active when editing dropdown/checkbox controls in the settings menu - Removed the custom `[Home]` shortcut since this is done natively by the browser already. - Removed the 1-6 shortcuts for the tabs. Logic being that it seems pretty rare that you would want to rapidly switch between them (you would have to use the mouse to do anything on all tabs except the subsonic one anyway), and they were already broken without anyone complaining. - Fixed tests
This commit is contained in:
parent
dbf5010745
commit
8c279093df
8 changed files with 69 additions and 115 deletions
|
@ -154,9 +154,9 @@ angular.module('JamStash')
|
|||
});
|
||||
};
|
||||
|
||||
$(document).on("click", ".message", function(){
|
||||
$(this).remove();
|
||||
});
|
||||
$(document).on("click", ".message", function(){
|
||||
$(this).remove();
|
||||
});
|
||||
|
||||
// Global Functions
|
||||
window.onbeforeunload = function () {
|
||||
|
@ -171,39 +171,51 @@ angular.module('JamStash')
|
|||
$(this).fadeOut(function () { $(this).remove(); });
|
||||
return false;
|
||||
})
|
||||
$document.keydown(function (e) {
|
||||
$scope.scrollToIndex(e);
|
||||
|
||||
// Shortcut processing
|
||||
$(document).keydown(function (e) {
|
||||
$scope.processKeyEvent(e);
|
||||
});
|
||||
$scope.scrollToIndex = function (e) {
|
||||
var source = e.target.id;
|
||||
if (e.target.tagName.toUpperCase() != 'INPUT') {
|
||||
var unicode = e.charCode ? e.charCode : e.keyCode;
|
||||
if (globals.settings.Debug) { console.log('Keycode Triggered: ' + unicode); }
|
||||
if (unicode == 49) { // 1
|
||||
$('#action_Queue').click();
|
||||
} else if (unicode == 50) {
|
||||
$('#action_Library').click();
|
||||
} else if (unicode == 51) {
|
||||
$('#action_Archive').click();
|
||||
} else if (unicode == 52) {
|
||||
$('#action_Settings').click();
|
||||
} else if (unicode == 53) {
|
||||
} else if (unicode == 54) { // 6
|
||||
$scope.processKeyEvent(e);
|
||||
return true;
|
||||
};
|
||||
$scope.processKeyEvent = function (e) {
|
||||
if (e.isDefaultPrevented() ||
|
||||
e.repeat ||
|
||||
e.altKey || e.metaKey || e.ctrlKey ||
|
||||
(e.target && _.contains(['input', 'textarea', 'select'], e.target.tagName.toLowerCase()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
var key = e.key;
|
||||
if (globals.settings.Debug) { console.log('Key pressed: ' + key); }
|
||||
if (key == "Esc" || key == "Escape") {
|
||||
$rootScope.hideQueue();
|
||||
} else if (key == " " || key == "Space") {
|
||||
player.togglePause();
|
||||
} else if (key == "ArrowLeft" || key == "Left") {
|
||||
player.previousTrack();
|
||||
} else if (key == "ArrowRight" || key == "Right") {
|
||||
player.nextTrack();
|
||||
} else if (key == "-" || key == "_") {
|
||||
persistence.saveVolume(player.turnVolumeDown());
|
||||
} else if (key == "=" || key == "+") {
|
||||
persistence.saveVolume(player.turnVolumeUp());
|
||||
} else if (/^[a-z]$/i.test(key) && $('#tabLibrary').is(':visible')) {
|
||||
if (/^[x-z]$/i.test(key)) {
|
||||
key = 'x-z';
|
||||
}
|
||||
if (unicode >= 65 && unicode <= 90 && $('#tabLibrary').is(':visible')) { // a-z
|
||||
var key = utils.findKeyForCode(unicode);
|
||||
if (key == 'x' || key == 'y' || key == 'z') {
|
||||
key = 'x-z';
|
||||
}
|
||||
var el = '#' + key.toUpperCase();
|
||||
if ($(el).length > 0) {
|
||||
$('#left-component').stop().scrollTo(el, 400);
|
||||
}
|
||||
} else if (unicode == 36 && $('#tabLibrary').is(':visible')) { // home
|
||||
$('#left-component').stop().scrollTo('#MusicFolders', 400);
|
||||
var el = '#' + key.toUpperCase();
|
||||
if ($(el).length > 0) {
|
||||
$('#left-component').stop().scrollTo(el, 400);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
else{
|
||||
return;
|
||||
}
|
||||
$scope.$apply();
|
||||
e.preventDefault();
|
||||
};
|
||||
$scope.scrollToIndexName = function (index) {
|
||||
var el = '#' + index;
|
||||
|
@ -246,53 +258,6 @@ angular.module('JamStash')
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the target of this event is an input
|
||||
* @param {jQuery event} event
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function isTargetInput (event) {
|
||||
return (event && event.target.tagName === "INPUT");
|
||||
}
|
||||
|
||||
/* We define player-related methods here instead of in player controller
|
||||
in order to bind keypresses to <body> and have global shortcuts.
|
||||
We also check the event so we don't do anything if it's on an input */
|
||||
$scope.togglePause = function (event) {
|
||||
if(!isTargetInput(event)) {
|
||||
if(globals.settings.Jukebox) {
|
||||
$scope.sendToJukebox('stop');
|
||||
} else {
|
||||
player.togglePause();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.turnVolumeUp = function (event) {
|
||||
if(!isTargetInput(event)) {
|
||||
var volume = player.turnVolumeUp();
|
||||
persistence.saveVolume(volume);
|
||||
}
|
||||
};
|
||||
|
||||
$scope.turnVolumeDown = function (event) {
|
||||
if(!isTargetInput(event)) {
|
||||
var volume = player.turnVolumeDown();
|
||||
persistence.saveVolume(volume);
|
||||
}
|
||||
};
|
||||
|
||||
$scope.nextTrack = function (event) {
|
||||
if(!isTargetInput(event)) {
|
||||
player.nextTrack();
|
||||
}
|
||||
};
|
||||
$scope.previousTrack = function (event) {
|
||||
if(!isTargetInput(event)) {
|
||||
player.previousTrack();
|
||||
}
|
||||
};
|
||||
|
||||
$rootScope.addToJukebox = function (id) {
|
||||
if (globals.settings.Debug) { console.log("LOAD JUKEBOX"); }
|
||||
$.ajax({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue