Adds the left and right keys to get previous / next song

Removes the previous code in main-controller.js
This commit is contained in:
Hyzual 2015-02-08 22:31:02 +01:00
parent a85865371c
commit 5a7a06d1a2
4 changed files with 41 additions and 74 deletions

View file

@ -178,66 +178,37 @@ angular.module('JamStash')
// $document.keydown(function (e) { // $document.keydown(function (e) {
// $scope.scrollToIndex(e); // $scope.scrollToIndex(e);
// }); // });
// $scope.scrollToIndex = function (e) { $scope.scrollToIndex = function (e) {
// var source = e.target.id; var source = e.target.id;
// if (e.target.tagName.toUpperCase() != 'INPUT') { if (e.target.tagName.toUpperCase() != 'INPUT') {
// var unicode = e.charCode ? e.charCode : e.keyCode; var unicode = e.charCode ? e.charCode : e.keyCode;
// if (globals.settings.Debug) { console.log('Keycode Triggered: ' + unicode); } if (globals.settings.Debug) { console.log('Keycode Triggered: ' + unicode); }
// if (unicode == 49) { // 1 if (unicode == 49) { // 1
// $('#action_Queue').click(); $('#action_Queue').click();
// } else if (unicode == 50) { } else if (unicode == 50) {
// $('#action_Library').click(); $('#action_Library').click();
// } else if (unicode == 51) { } else if (unicode == 51) {
// $('#action_Archive').click(); $('#action_Archive').click();
// } else if (unicode == 52) { } else if (unicode == 52) {
// $('#action_Settings').click(); $('#action_Settings').click();
// } else if (unicode == 53) { } else if (unicode == 53) {
// } else if (unicode == 54) { // 6 } else if (unicode == 54) { // 6
// } }
// if (unicode >= 65 && unicode <= 90 && $('#tabLibrary').is(':visible')) { // a-z if (unicode >= 65 && unicode <= 90 && $('#tabLibrary').is(':visible')) { // a-z
// var key = utils.findKeyForCode(unicode); var key = utils.findKeyForCode(unicode);
// if (key == 'x' || key == 'y' || key == 'z') { if (key == 'x' || key == 'y' || key == 'z') {
// key = 'x-z'; key = 'x-z';
// } }
// var el = '#' + key.toUpperCase(); var el = '#' + key.toUpperCase();
// if ($(el).length > 0) { if ($(el).length > 0) {
// $('#left-component').stop().scrollTo(el, 400); $('#left-component').stop().scrollTo(el, 400);
// } }
// } else if (unicode == 39 || unicode == 176) { // right arrow } else if (unicode == 36 && $('#tabLibrary').is(':visible')) { // home
// player.nextTrack(); $('#left-component').stop().scrollTo('#MusicFolders', 400);
// } else if (unicode == 37 || unicode == 177) { // back arrow }
// player.previousTrack(); }
// // } else if (unicode == 32 || unicode == 179 || unicode.toString() == '0179') { // spacebar return true;
// // player.togglePause(); };
// // return false;
// } else if (unicode == 36 && $('#tabLibrary').is(':visible')) { // home
// $('#left-component').stop().scrollTo('#MusicFolders', 400);
// }
// if (unicode == 189) { // dash - volume down
// var volume = utils.getValue('Volume') ? parseFloat(utils.getValue('Volume')) : 1;
// if (volume <= 1 && volume > 0 && source === '') {
// volume += -0.1;
// $(globals.Player1).jPlayer({
// volume: volume
// });
// utils.setValue('Volume', volume, true);
// if (globals.settings.Debug) { console.log('Volume: ' + Math.round(volume * 100) + '%'); }
// }
// }
// if (unicode == 187) { // equals - volume up
// var volume = utils.getValue('Volume') ? parseFloat(utils.getValue('Volume')) : 1;
// if (volume < 1 && volume >= 0 && source ==- '') {
// volume += 0.1;
// $(globals.Player1).jPlayer({
// volume: volume
// });
// utils.setValue('Volume', volume, true);
// if (globals.settings.Debug) { console.log('Volume: ' + Math.round(volume * 100) + '%'); }
// }
// }
// }
// return true;
// };
$scope.scrollToIndexName = function (index) { $scope.scrollToIndexName = function (index) {
var el = '#' + index; var el = '#' + index;
if ($(el).length > 0) { if ($(el).length > 0) {
@ -342,7 +313,7 @@ angular.module('JamStash')
in order to bind keypresses to <body> and have global shortcuts */ in order to bind keypresses to <body> and have global shortcuts */
$scope.togglePause = function () { $scope.togglePause = function () {
if(globals.settings.Jukebox) { if(globals.settings.Jukebox) {
$scope.sendToJukebox('pause'); $scope.sendToJukebox('stop');
} else { } else {
player.togglePause(); player.togglePause();
} }
@ -368,6 +339,9 @@ angular.module('JamStash')
persistence.saveVolume(volume); persistence.saveVolume(volume);
}; };
$scope.nextTrack = player.nextTrack;
$scope.previousTrack = player.previousTrack;
$rootScope.addToJukebox = function (id) { $rootScope.addToJukebox = function (id) {
if (globals.settings.Debug) { console.log("LOAD JUKEBOX"); } if (globals.settings.Debug) { console.log("LOAD JUKEBOX"); }
$.ajax({ $.ajax({

View file

@ -93,12 +93,12 @@ describe("Main controller", function() {
}); });
describe("When I toggle pause,", function() { describe("When I toggle pause,", function() {
it("given that we're using the Jukebox mode, it sends a 'pause' command to the jukebox", function() { it("given that we're using the Jukebox mode, it sends a 'stop' command to the jukebox", function() {
mockGlobals.settings.Jukebox = true; mockGlobals.settings.Jukebox = true;
spyOn(scope, "sendToJukebox"); spyOn(scope, "sendToJukebox");
scope.togglePause(); scope.togglePause();
expect(scope.sendToJukebox).toHaveBeenCalledWith('pause'); expect(scope.sendToJukebox).toHaveBeenCalledWith('stop');
}); });
it("it toggles pause using the player service", function() { it("it toggles pause using the player service", function() {

View file

@ -20,7 +20,7 @@
<link href="styles/Mobile.css" rel="stylesheet" type="text/css" data-name="main" /> <link href="styles/Mobile.css" rel="stylesheet" type="text/css" data-name="main" />
<link href="" rel="stylesheet" type="text/css" data-name="theme" /> <link href="" rel="stylesheet" type="text/css" data-name="theme" />
</head> </head>
<body ui-keypress="{'32 179': 'togglePause()', '187 61 43': 'turnVolumeUp()', '189 95 45': 'turnVolumeDown()'}"> <body ui-keypress="{'32 179': 'togglePause()', '43 61 187': 'turnVolumeUp()', '45 95 189': 'turnVolumeDown()'}" ui-keydown="{'right 176': 'nextTrack()', 'left 177': 'previousTrack()'}">
<div id="container"> <div id="container">
<div id="header"> <div id="header">
<div id="messages"> <div id="messages">

View file

@ -11,9 +11,7 @@ angular.module('jamstash.player.controller', ['jamstash.player.service', 'jamsta
function($scope, player, globals){ function($scope, player, globals){
'use strict'; 'use strict';
$scope.getPlayingSong = function () { $scope.getPlayingSong = player.getPlayingSong;
return player.getPlayingSong();
};
$scope.play = function () { $scope.play = function () {
if (globals.settings.Jukebox) { if (globals.settings.Jukebox) {
@ -31,13 +29,8 @@ angular.module('jamstash.player.controller', ['jamstash.player.service', 'jamsta
} }
}; };
$scope.previousTrack = function () { $scope.previousTrack = player.previousTrack;
player.previousTrack(); $scope.nextTrack = player.nextTrack;
};
$scope.nextTrack = function () {
player.nextTrack();
};
//TODO: Hyz: updateFavorite - leave in rootScope ? //TODO: Hyz: updateFavorite - leave in rootScope ?
}]); }]);