1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-11-05 22:36:16 +00:00

Feat: central parseCmd function

This commit is contained in:
jcorporation 2018-11-11 23:48:49 +00:00
parent 7257aa66ce
commit 83cb02c370

View File

@ -402,11 +402,8 @@ function appInit() {
addFilterLetter('BrowsePlaylistsFilterLetters'); addFilterLetter('BrowsePlaylistsFilterLetters');
document.getElementById('syscmds').addEventListener('click', function(event) { document.getElementById('syscmds').addEventListener('click', function(event) {
event.preventDefault();
if (event.target.nodeName == 'A') { if (event.target.nodeName == 'A') {
var cmd = JSON.parse(event.target.getAttribute('data-href')); parseCmd(event, event.target.getAttribute('data-href'));
if (typeof window[cmd.cmd] === 'function')
window[cmd.cmd](... cmd.options);
} }
}, false); }, false);
@ -415,17 +412,7 @@ function appInit() {
for (var i = 0; i < hrefsLen; i++) { for (var i = 0; i < hrefsLen; i++) {
hrefs[i].classList.add('clickable'); hrefs[i].classList.add('clickable');
hrefs[i].addEventListener('click', function(event) { hrefs[i].addEventListener('click', function(event) {
event.preventDefault(); parseCmd(event, this.getAttribute('data-href'));
var cmd = JSON.parse(this.getAttribute('data-href'));
if (typeof window[cmd.cmd] === 'function') {
switch(cmd.cmd) {
case 'sendAPI':
sendAPI(... cmd.options);
break;
default:
window[cmd.cmd](... cmd.options);
}
}
}, false); }, false);
} }
@ -658,12 +645,7 @@ function appInit() {
return; return;
var cmd = keymap[event.key]; var cmd = keymap[event.key];
if (cmd && typeof window[cmd.cmd] === 'function') { if (cmd && typeof window[cmd.cmd] === 'function') {
event.preventDefault(); parseCmd(event, cmd);
event.stopPropagation();
if (cmd.cmd == 'sendAPI')
sendAPI(... cmd.options);
else
window[cmd.cmd](... cmd.options);
} }
}, false); }, false);
@ -718,7 +700,10 @@ function appInit() {
function parseCmd(event, href) { function parseCmd(event, href) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
var cmd = JSON.parse(href); var cmd = href;
if (typeof(href) == 'string')
cmd = JSON.parse(href);
if (typeof window[cmd.cmd] === 'function') { if (typeof window[cmd.cmd] === 'function') {
switch(cmd.cmd) { switch(cmd.cmd) {
case 'sendAPI': case 'sendAPI':
@ -2463,15 +2448,7 @@ function showMenu(el, event) {
var dh = event.target.getAttribute('data-href'); var dh = event.target.getAttribute('data-href');
if (dh) { if (dh) {
var cmd = JSON.parse(b64DecodeUnicode(dh)); var cmd = JSON.parse(b64DecodeUnicode(dh));
if (typeof window[cmd.cmd] === 'function') { parseCmd(event, cmd);
switch(cmd.cmd) {
case 'sendAPI':
sendAPI(... cmd.options);
break;
default:
window[cmd.cmd](... cmd.options);
}
}
hideMenu(); hideMenu();
} }
} }