mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 18:17:38 +00:00
parent
08251ca069
commit
e472baf74f
2 changed files with 101 additions and 73 deletions
|
|
@ -3,61 +3,44 @@ Hotkeys = {
|
|||
keylog = [];
|
||||
trigger = [78,85,76,27,76,27,83,79,70,84];
|
||||
document.onkeyup = function(e){
|
||||
var key = e.keyCode;
|
||||
// Keys that correspond to node clicks
|
||||
var keyboardAction = {
|
||||
66: winamp.nodes.next, // B
|
||||
67: winamp.nodes.pause, // C
|
||||
76: winamp.nodes.eject, // L
|
||||
86: winamp.nodes.stop, // V
|
||||
82: winamp.nodes.repeat, // R
|
||||
83: winamp.nodes.shuffle, // S
|
||||
88: winamp.nodes.play, // X
|
||||
90: winamp.nodes.previous, // Z
|
||||
100: winamp.nodes.previous, // numpad 4
|
||||
101: winamp.nodes.play, // numpad 5
|
||||
102: winamp.nodes.next, // numpad 6
|
||||
96: winamp.nodes.eject // numpad 0
|
||||
};
|
||||
if(keyboardAction[key]){
|
||||
keyboardAction[key].click();
|
||||
}else if(e.keyCode == 76 && e.ctrlKey){ //CTRL+L
|
||||
winamp.nodes.option.click();
|
||||
}else if(e.keyCode == 68 && e.ctrlKey){ //CTRL+D
|
||||
winamp.nodes.buttonD.click();
|
||||
}else if(e.keyCode == 84 && e.ctrlKey){ //CTRL+T
|
||||
winamp.nodes.time.click();
|
||||
}else{
|
||||
switch (key){
|
||||
// *1 is used to cast these values to integers. Could be improved.
|
||||
// up arrow
|
||||
case 38: winamp.setVolume((winamp.nodes.volume.value*1)+1); break;
|
||||
// numpad 8
|
||||
case 104: winamp.setVolume((winamp.nodes.volume.value*1)+1); break;
|
||||
// down arrow
|
||||
case 40: winamp.setVolume((winamp.nodes.volume.value*1)-1); break;
|
||||
// numpad 2
|
||||
case 98: winamp.setVolume((winamp.nodes.volume.value*1)-1); break;
|
||||
// left arrow
|
||||
case 37: winamp.media.seekToTime(winamp.media.timeElapsed() - 5); winamp.updateTime(); break;
|
||||
// numpad 7
|
||||
case 103: winamp.media.seekToTime(winamp.media.timeElapsed() - 5); winamp.updateTime(); break;
|
||||
// right arrow
|
||||
case 39: winamp.media.seekToTime(winamp.media.timeElapsed() + 5); winamp.updateTime(); break;
|
||||
// numpad 9
|
||||
case 105: winamp.media.seekToTime(winamp.media.timeElapsed() + 5); winamp.updateTime(); break;
|
||||
// numpad 1
|
||||
case 97: /* Placeholder for jump backwards 10 songs in playlist or to start of */ break;
|
||||
// numpad 3
|
||||
case 99: /* Placeholder for jump forwards 10 songs in playlist or to start of */ break;
|
||||
if(e.ctrlKey) { // Is CTRL depressed?
|
||||
switch(e.keyCode) {
|
||||
case 68: winamp.toggleDoubledMode(); break; // CTRL+D
|
||||
case 76: winamp.openOptionMenu(); break; // CTRL+L
|
||||
case 84: winamp.toggleTimeMode(); break; // CTRL+T
|
||||
}
|
||||
} else {
|
||||
switch(e.keyCode) {
|
||||
case 37: winamp.seekForwardBy(-5); break; // left arrow
|
||||
case 38: winamp.incrementVolumeBy(1); break; // up arrow
|
||||
case 39: winamp.seekForwardBy(5); break; // right arrow
|
||||
case 40: winamp.incrementVolumeBy(-1); break; // down arrow
|
||||
case 66: winamp.next(); break; // B
|
||||
case 67: winamp.pause(); break; // C
|
||||
case 76: winamp.openFileDialog(); break; // L
|
||||
case 82: winamp.toggleRepeat(); break; // R
|
||||
case 83: winamp.toggleShuffle(); break; // S
|
||||
case 86: winamp.stop(); break; // V
|
||||
case 88: winamp.play(); break; // X
|
||||
case 90: winamp.previous(); break; // Z
|
||||
case 96: winamp.openFileDialog(); break; // numpad 0
|
||||
case 97: winamp.previous(10); break; // numpad 1
|
||||
case 98: winamp.incrementVolumeBy(-1); break; // numpad 2
|
||||
case 99: winamp.next(10) break; // numpad 3
|
||||
case 100: winamp.previous(); break; // numpad 4
|
||||
case 101: winamp.play(); break; // numpad 5
|
||||
case 102: winamp.next(); break; // numpad 6
|
||||
case 103: winamp.seekForwardBy(-5); break; // numpad 7
|
||||
case 104: winamp.incrementVolumeBy(1); break; // numpad 8
|
||||
case 105: winamp.seekForwardBy(5); break; // numpad 9
|
||||
}
|
||||
}
|
||||
|
||||
// Easter Egg
|
||||
keylog.push(key);
|
||||
keylog.push(e.keyCode);
|
||||
keylog = keylog.slice(-10);
|
||||
if(keylog.toString() == trigger.toString()) {
|
||||
document.getElementById('winamp').classList.toggle('llama');
|
||||
winamp.toggleLlama();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
93
js/winamp.js
93
js/winamp.js
|
|
@ -64,8 +64,8 @@ Winamp = {
|
|||
this.windowManager.registerWindow(this.nodes.winamp, this.nodes.titleBar);
|
||||
|
||||
this.nodes.option.onclick = function(event) {
|
||||
self.toggleOptionMenu();
|
||||
event.stopPropagation();
|
||||
this.classList.toggle('selected');
|
||||
}
|
||||
|
||||
this.nodes.close.onclick = function() {
|
||||
|
|
@ -85,8 +85,7 @@ Winamp = {
|
|||
}
|
||||
|
||||
this.nodes.buttonD.onclick = function() {
|
||||
this.classList.toggle('selected');
|
||||
self.nodes.winamp.classList.toggle('doubled');
|
||||
self.toggleDoubledMode();
|
||||
}
|
||||
|
||||
this.media.addEventListener('timeupdate', function() {
|
||||
|
|
@ -119,13 +118,11 @@ Winamp = {
|
|||
}
|
||||
|
||||
this.nodes.time.onclick = function() {
|
||||
self.nodes.time.classList.toggle('countdown');
|
||||
self.updateTime();
|
||||
self.toggleTimeMode();
|
||||
}
|
||||
|
||||
this.nodes.shadeTime.onclick = function() {
|
||||
self.nodes.time.classList.toggle('countdown');
|
||||
self.updateTime();
|
||||
self.toggleTimeMode();
|
||||
}
|
||||
|
||||
this.nodes.visualizer.onclick = function() {
|
||||
|
|
@ -150,35 +147,23 @@ Winamp = {
|
|||
}
|
||||
|
||||
this.nodes.previous.onclick = function() {
|
||||
// Implement this when we support playlists
|
||||
self.previous();
|
||||
}
|
||||
|
||||
this.nodes.play.onclick = function() {
|
||||
if(self.nodes.winamp.classList.contains('play')){
|
||||
self.media.stop();
|
||||
}
|
||||
self.media.play();
|
||||
self.setStatus('play');
|
||||
self.play();
|
||||
}
|
||||
|
||||
this.nodes.pause.onclick = function() {
|
||||
if(self.nodes.winamp.classList.contains('pause')){
|
||||
self.media.play();
|
||||
}
|
||||
else if(self.nodes.winamp.classList.contains('play'))
|
||||
{
|
||||
self.media.pause();
|
||||
self.setStatus('pause');
|
||||
}
|
||||
self.pause();
|
||||
}
|
||||
|
||||
this.nodes.stop.onclick = function() {
|
||||
self.media.stop();
|
||||
self.setStatus('stop');
|
||||
self.stop();
|
||||
}
|
||||
|
||||
this.nodes.next.onclick = function() {
|
||||
// Implement this when we support playlists
|
||||
self.next();
|
||||
}
|
||||
|
||||
this.nodes.eject.onclick = function() {
|
||||
|
|
@ -269,6 +254,53 @@ Winamp = {
|
|||
this.nodes.option.classList.remove('selected');
|
||||
},
|
||||
|
||||
toggleOptionMenu: function() {
|
||||
this.nodes.option.classList.toggle('selected');
|
||||
},
|
||||
|
||||
toggleDoubledMode: function() {
|
||||
this.nodes.buttonD.classList.toggle('selected');
|
||||
this.nodes.winamp.classList.toggle('doubled');
|
||||
},
|
||||
|
||||
toggleTimeMode: function() {
|
||||
self.nodes.time.classList.toggle('countdown');
|
||||
self.updateTime();
|
||||
},
|
||||
|
||||
previous: function(num) {
|
||||
// Jump back num tracks
|
||||
// Not yet supported
|
||||
},
|
||||
|
||||
play: function() {
|
||||
if(this.nodes.winamp.classList.contains('play')){
|
||||
this.media.stop();
|
||||
}
|
||||
this.media.play();
|
||||
this.setStatus('play');
|
||||
},
|
||||
|
||||
pause: function() {
|
||||
if(this.nodes.winamp.classList.contains('pause')){
|
||||
this.media.play();
|
||||
}
|
||||
else if(this.nodes.winamp.classList.contains('play'))
|
||||
{
|
||||
this.media.pause();
|
||||
this.setStatus('pause');
|
||||
}
|
||||
},
|
||||
stop: function() {
|
||||
this.media.stop();
|
||||
this.setStatus('stop');
|
||||
},
|
||||
|
||||
next: function(num) {
|
||||
// Jump back num tracks
|
||||
// Not yet supported
|
||||
},
|
||||
|
||||
// From 0-100
|
||||
setVolume: function(volume) {
|
||||
// Ensure volume does not go out of bounds
|
||||
|
|
@ -290,6 +322,10 @@ Winamp = {
|
|||
this.nodes.volume.value = volume;
|
||||
},
|
||||
|
||||
incrementVolumeBy: function(ammount) {
|
||||
this.setVolume((winamp.nodes.volume.value*1) + ammount);
|
||||
},
|
||||
|
||||
// From -100 to 100
|
||||
setBalance: function(balance) {
|
||||
var string = '';
|
||||
|
|
@ -309,6 +345,11 @@ Winamp = {
|
|||
this.nodes.balance.style.backgroundPosition = '-9px -' + offset + 'px';
|
||||
},
|
||||
|
||||
seekForwardBy: function(seconds) {
|
||||
this.media.seekToTime(this.media.timeElapsed() + seconds);
|
||||
winamp.updateTime()
|
||||
},
|
||||
|
||||
toggleRepeat: function() {
|
||||
this.media.toggleRepeat();
|
||||
this.nodes.repeat.classList.toggle('selected');
|
||||
|
|
@ -319,6 +360,10 @@ Winamp = {
|
|||
this.nodes.shuffle.classList.toggle('selected');
|
||||
},
|
||||
|
||||
toggleLlama: function() {
|
||||
document.getElementById('winamp').classList.toggle('llama');
|
||||
},
|
||||
|
||||
// TODO: Refactor this function
|
||||
updateTime: function() {
|
||||
this.updateShadePositionClass();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue