1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-06-25 22:23:16 +00:00

Feat: added keyboard shurtcuts help

Fix: use event.code instead of deprecated event.which
Feat: blur inputs on Esc
Feat: / focuses search fields
This commit is contained in:
jcorporation 2018-11-08 22:42:45 +00:00
parent a70ab4e48c
commit 9ca519c69a
5 changed files with 92 additions and 50 deletions

View File

@ -836,7 +836,6 @@
//end patch
set[i].tagName === 'A' && newSet[push](set[i]);
}
console.log(newSet);
return newSet;
})(),
@ -891,6 +890,8 @@
idx = isSameElement ? 0
: key === 38 ? (idx>1?idx-1:0)
: key === 40 ? (idx<menuItems[length]-1?idx+1:idx) : idx;
if ( idx == 0 || idx == menuItems[length]-1)
break;
} while ( !menuItems[idx].offsetHeight )
//end patch
menuItems[idx] && setFocus(menuItems[idx]);

View File

@ -311,4 +311,13 @@ caption {
#menu-dbupdate {
padding-left:1rem;
}
div.key {
border: 1px solid #bbb;
background-color: #eee;
border-radius: 2px;
width: 20px;
heigth: 20px;
text-align: center;
}

View File

@ -941,6 +941,31 @@
</div>
</div>
</div>
<div class="modal fade" id="modalHelp" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><span class="material-icons title-icon">keyboard</span> Keyboard Shortcuts</h5>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
<div class="table-responsive-md">
<table class="table table-sm">
<thead>
<tr><th>Key</th><th>Action</th></tr>
</thead>
<tbody id="tbodyShortcuts">
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script src="/js/keymap.min.js"></script>
<script src="/js/bootstrap-native-v4.min.js"></script>

View File

@ -1,30 +1,28 @@
var keymap = {
"shiftKey": {
"83": {"cmd": "MPD_API_QUEUE_SHUFFLE", "options": []}, // S
"67": {"cmd": "MPD_API_QUEUE_CROP", "options": []} // C
},
"key": {
"37": {"cmd": "clickPrev", "options": []}, // cursor left
"39": {"cmd": "clickNext", "options": []}, // cursor right
"32": {"cmd": "clickPlay", "options": []}, // space
"83": {"cmd": "clickStop", "options": []}, // s
"173": {"cmd": "chVolume", "options": [-5]}, // +
"171": {"cmd": "chVolume", "options": [5]}, // -
"67": {"cmd": "MPD_API_QUEUE_CLEAR", "options": []}, // c
"85": {"cmd": "updateDB", "options": []}, // u
"82": {"cmd": "rescanDB", "options": []}, // r
"76": {"cmd": "openLocalPlayer", "options": []}, // l
"80": {"cmd": "updateSmartPlaylists", "options": []}, // p
"65": {"cmd": "showAddToPlaylist", "options": ["stream"]}, // a
"84": {"cmd": "openModal", "options": ["modalSettings"]}, // t
"89": {"cmd": "openModal", "options": ["modalAbout"]}, // y
"49": {"cmd": "appGoto", "options": ["Playback"]}, // 1
"50": {"cmd": "appGoto", "options": ["Queue"]}, // 2
"51": {"cmd": "appGoto", "options": ["Browse","Database"]}, // 3
"52": {"cmd": "appGoto", "options": ["Browse","Playlists"]}, // 4
"53": {"cmd": "appGoto", "options": ["Browse","Filesystem"]}, // 5
"54": {"cmd": "appGoto", "options": ["Search"]}, // 6
"77": {"cmd": "openDropdown", "options": ["dropdownMainMenu"]}, // m
"86": {"cmd": "openDropdown", "options": ["dropdownVolumeMenu"]}, // v
}
"ArrowLeft": {"cmd": "clickPrev", "options": [], "action": "Previous Song", "key": "keyboard_arrow_left"},
"ArrowRight": {"cmd": "clickNext", "options": [], "action": "Next Song", "key": "keyboard_arrow_right"},
" ": {"cmd": "clickPlay", "options": [], "action": "Toggle Play / Pause", "key": "space_bar"},
"s": {"cmd": "clickStop", "options": [], "action": "Stop Playing"},
"-": {"cmd": "chVolume", "options": [-5], "action": "Volume Down"},
"+": {"cmd": "chVolume", "options": [5], "action": "Volume Up"},
"c": {"cmd": "MPD_API_QUEUE_CLEAR", "options": [], "action": "Clear Queue"},
"u": {"cmd": "updateDB", "options": [], "action": "Update Database"},
"r": {"cmd": "rescanDB", "options": [], "action": "Rescan Database"},
"l": {"cmd": "openLocalPlayer", "options": [], "action": "Open Local Player"},
"p": {"cmd": "updateSmartPlaylists", "options": [], "action": "Update Smart Playlists"},
"a": {"cmd": "showAddToPlaylist", "options": ["stream"], "action": "Add Stream"},
"t": {"cmd": "openModal", "options": ["modalSettings"], "action": "Open Settings"},
"y": {"cmd": "openModal", "options": ["modalAbout"], "action": "Open About"},
"1": {"cmd": "appGoto", "options": ["Playback"], "action": "Goto Playback"},
"2": {"cmd": "appGoto", "options": ["Queue"], "action": "Goto Queue"},
"3": {"cmd": "appGoto", "options": ["Browse","Database"], "action": "Goto Browse Database"},
"4": {"cmd": "appGoto", "options": ["Browse","Playlists"], "action": "Goto Browse Playlists"},
"5": {"cmd": "appGoto", "options": ["Browse","Filesystem"], "action": "Goto Browse Filesystem"},
"6": {"cmd": "appGoto", "options": ["Search"], "action": "Goto Search"},
"m": {"cmd": "openDropdown", "options": ["dropdownMainMenu"], "action": "Open Main Menu"},
"v": {"cmd": "openDropdown", "options": ["dropdownVolumeMenu"], "action": "Open Volume Menu"},
"S": {"cmd": "MPD_API_QUEUE_SHUFFLE", "options": [], "action": "Shuffle Queue"},
"C": {"cmd": "MPD_API_QUEUE_CROP", "options": [], "action": "Crop Queue"},
"?": {"cmd": "openModal", "options": ["modalHelp"], "action": "Open Help"},
"/": {"cmd": "focusSearch", "options": [], "action": "Focus Search"}
}

View File

@ -93,6 +93,7 @@ var modalRenamePlaylist = new Modal(document.getElementById('modalRenamePlaylist
var modalUpdateDB = new Modal(document.getElementById('modalUpdateDB'));
var modalSaveSmartPlaylist = new Modal(document.getElementById('modalSaveSmartPlaylist'));
var modalDeletePlaylist = new Modal(document.getElementById('modalDeletePlaylist'));
var modalHelp = new Modal(document.getElementById('modalHelp'));
var dropdownMainMenu;// = new Dropdown(document.getElementById('mainMenu'));
var dropdownVolumeMenu = new Dropdown(document.getElementById('volumeMenu'));
@ -329,16 +330,6 @@ function appInit() {
icon.innerText = 'keyboard_arrow_right';
}, false);
/* document.addEventListener('keyup', function(event) {
if (event.which != 13)
return;
if (event.target.nodeName == 'A') {
event.stopPropagation();
event.preventDefault();
event.target.click();
}
}, false);
*/
document.getElementById('volumeMenu').parentNode.addEventListener('show.bs.dropdown', function () {
sendAPI({"cmd": "MPD_API_PLAYER_OUTPUT_LIST"}, parseOutputs);
});
@ -354,6 +345,15 @@ function appInit() {
document.getElementById('addToPlaylistPlaylist').focus();
});
document.getElementById('modalHelp').addEventListener('show.bs.modal', function () {
var trs = '';
for (var key in keymap) {
trs += '<tr><td><div class="key' + (keymap[key].key && keymap[key].key.length > 1 ? ' material-icons material-icons-small' : '') +
'">' + (keymap[key].key != undefined ? keymap[key].key : key ) + '</div></td><td>' + keymap[key].action + '</td></tr>';
}
document.getElementById('tbodyShortcuts').innerHTML = trs;
});
document.getElementById('modalUpdateDB').addEventListener('hidden.bs.modal', function () {
document.getElementById('updateDBprogress').classList.remove('updateDBprogressAnimate');
});
@ -552,7 +552,10 @@ function appInit() {
}, false);
document.getElementById('searchqueuestr').addEventListener('keyup', function(event) {
appGoto(app.current.app, app.current.tab, app.current.view, '0/' + app.current.filter + '/' + this.value);
if (event.key == 'Escape')
this.blur();
else
appGoto(app.current.app, app.current.tab, app.current.view, '0/' + app.current.filter + '/' + this.value);
}, false);
document.getElementById('searchqueuetags').addEventListener('click', function(event) {
@ -605,7 +608,10 @@ function appInit() {
}, false);
document.getElementById('searchstr').addEventListener('keyup', function(event) {
appGoto('Search', undefined, undefined, '0/' + app.current.filter + '/' + this.value);
if (event.key == 'Escape')
this.blur();
else
appGoto('Search', undefined, undefined, '0/' + app.current.filter + '/' + this.value);
}, false);
document.getElementById('BrowseDatabaseByTagDropdown').addEventListener('click', function(event) {
@ -632,16 +638,10 @@ function appInit() {
document.addEventListener('keydown', function(event) {
if (event.target.tagName == 'INPUT' || event.target.tagName == 'SELECT')
if (event.target.tagName == 'INPUT' || event.target.tagName == 'SELECT' ||
event.ctrlKey || event.altKey)
return;
if (event.ctrlKey || event.altKey)
return;
var cmd;
if (event.shiftKey)
cmd = keymap.shiftKey[event.which];
else
cmd = keymap.key[event.which];
var cmd = keymap[event.key];
if (cmd && typeof window[cmd.cmd] === 'function') {
event.preventDefault();
event.stopPropagation();
@ -2852,6 +2852,15 @@ function openDropdown(dropdown) {
window[dropdown].toggle();
}
function focusSearch() {
if (app.current.app == 'Queue')
document.getElementById('searchqueuestr').focus();
else if (app.current.app == 'Search')
document.getElementById('searchstr').focus();
else
appGoto('Search');
}
function chVolume(increment) {
var newValue = parseInt(domCache.volumeBar.value) + increment;
if (newValue < 0)