From 5bec1f28f6403a4d1ff3cd32a3dbd9c04f205777 Mon Sep 17 00:00:00 2001 From: jcorporation Date: Wed, 12 Sep 2018 23:03:24 +0100 Subject: [PATCH] Fix: don't build json strings manually, use JSON.stringify - should fix bug #50 --- htdocs/index.html | 139 +++++++++++++++++++++++---------------------- htdocs/js/mympd.js | 72 ++++++++++------------- 2 files changed, 101 insertions(+), 110 deletions(-) diff --git a/htdocs/index.html b/htdocs/index.html index 0b261e0..13b5b51 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -23,9 +23,9 @@ myMPD
- - - -
@@ -54,11 +54,11 @@
- +
- +
@@ -76,23 +76,23 @@
Playback
- - + +
-

+

Artist -

+

Album -

+

-
- +
@@ -139,13 +140,13 @@
- +
- +
@@ -173,18 +174,18 @@
-
- +
- +
@@ -194,13 +195,13 @@
@@ -208,10 +209,10 @@
- +
-
@@ -221,13 +222,13 @@
- +
- +
@@ -271,18 +272,18 @@
-
- +
- +
@@ -295,7 +296,7 @@
- +
@@ -304,7 +305,7 @@
- +
- +
- +
@@ -345,18 +346,18 @@
-
- +
- +
@@ -371,7 +372,7 @@
- +
- +
- +
@@ -417,18 +418,18 @@
-
- +
- +
@@ -456,7 +457,7 @@
- +
- +
- +
@@ -498,18 +499,18 @@
-
- +
- +
@@ -519,10 +520,10 @@ @@ -581,7 +582,7 @@
- +
@@ -602,11 +603,11 @@ @@ -634,7 +635,7 @@ @@ -651,24 +652,24 @@
-
-
-
-
@@ -711,12 +712,12 @@
-
-
@@ -725,7 +726,7 @@
@@ -786,7 +787,7 @@ diff --git a/htdocs/js/mympd.js b/htdocs/js/mympd.js index 22bf15e..0eb42f3 100644 --- a/htdocs/js/mympd.js +++ b/htdocs/js/mympd.js @@ -359,7 +359,7 @@ function appInit() { hrefs[i].addEventListener('click', function(event) { event.preventDefault(); //event.stopPropagation(); - var cmd = JSON.parse(this.getAttribute('data-href').replace(/\'/g, '"')); + var cmd = JSON.parse(this.getAttribute('data-href')); if (typeof window[cmd.cmd] === 'function') { switch(cmd.cmd) { case 'sendAPI': @@ -1676,6 +1676,10 @@ function dirname(uri) { return uri.replace(/\/[^\/]*$/, ''); } +function addMenuItem(href, text) { + return '' + text +''; +} + function showMenu(el, event) { event.preventDefault(); event.stopPropagation(); @@ -1697,59 +1701,45 @@ function showMenu(el, event) { var menu = ''; if ((app.current.app == 'Browse' && app.current.tab == 'Filesystem') || app.current.app == 'Search' || - (app.current.app == 'Browse' && app.current.tab == 'Database' && app.current.view == 'Album')) { - menu += 'Append to queue' + - ( type == 'song' ? 'Add after current playing song' : '') + - 'Replace queue' + - ( type != 'plist' ? 'Add to playlist' : '') + - ( type == 'song' ? 'Songdetails' : '') + - ( type == 'plist' ? 'Show playlist' : ''); + (app.current.app == 'Browse' && app.current.tab == 'Database')) { + menu += addMenuItem({"cmd": "appendQueue", "options": [type, uri, name]}, 'Append to queue') + + (type == 'song' ? addMenuItem({"cmd": "appendAfterQueue", "options": [type, uri, nextsongpos, name]}, 'Add after current playing song') : '') + + addMenuItem({"cmd": "replaceQueue", "options": [type, uri, name]}, 'Replace queue') + + (type != 'plist' ? addMenuItem({"cmd": "showAddToPlaylist", "options": [uri]}, 'Add to playlist') : '') + + (type == 'song' ? addMenuItem({"cmd": "songDetails", "options": [uri]}, 'Songdetails') : '') + + (type == 'plist' ? addMenuItem({"cmd": "playlistDetails", "options": [uri]}, 'Show playlist') : ''); if (app.current.app == 'Search') { var baseuri = dirname(uri); menu += '' + 'keyboard_arrow_rightAlbum actions' + '
' + - 'Append to queue' + - 'Add after current playing song' + - 'Replace queue' + - 'Add to playlist' + + addMenuItem({"cmd": "appendQueue", "options": [type, baseuri, name]}, 'Append to queue') + + addMenuItem({"cmd": "appendAfterQueue", "options": [type, baseuri, nextsongpos, name]}, 'Add after current playing song') + + addMenuItem({"cmd": "replaceQueue", "options": [type, baseuri, name]}, 'Replace queue') + + addMenuItem({"cmd": "showAddToPlaylist", "options": [baseuri]}, 'Add to playlist') + '
'; } } else if (app.current.app == 'Browse' && app.current.tab == 'Playlists' && app.current.view == 'All') { - menu += 'Append to queue' + - 'Replace queue' + - 'Edit playlist' + - 'Rename playlist' + - 'Delete playlist'; + menu += addMenuItem({"cmd": "appendQueue", "options": [type, uri, name]}, 'Append to queue') + + addMenuItem({"cmd": "replaceQueue", "options": [type, uri, name]},'Replace queue') + + addMenuItem({"cmd": "playlistDetails", "options": [uri]}, 'Edit playlist') + + addMenuItem({"cmd": "showRenamePlaylist", "options": [uri]}, 'Rename playlist') + + addMenuItem({"cmd": "delPlaylist", "options": [uri]}, 'Delete playlist'); } else if (app.current.app == 'Browse' && app.current.tab == 'Playlists' && app.current.view == 'Detail') { - menu += 'Append to queue' + - 'Replace queue' + - ( document.getElementById('BrowsePlaylistsDetailList').getAttribute('data-ro') == 'false' ? - 'Remove' : '') + - ( type != 'plist' ? 'Add to playlist' : ''); + var x = document.getElementById('BrowsePlaylistsDetailList'); + menu += addMenuItem({"cmd": "appendQueue", "options": [type, uri, name]}, 'Append to queue') + + addMenuItem({"cmd": "replaceQueue", "options": [type, uri, name]}, 'Replace queue') + + (x.getAttribute('data-ro') == 'false' ? addMenuItem({"cmd": "removeFromPlaylist", "options": [x.getAttribute('data-uri'), + el.parentNode.parentNode.getAttribute('data-songpos')]}, 'Remove') : '') + + (type != 'plist' ? addMenuItem({"cmd": "showAddToPlaylist", "options": [uri]}, 'Add to playlist') : ''); } else if (app.current.app == 'Queue') { - menu += 'Remove' + - 'Remove all upwards' + - 'Remove all downwards' + - ( uri.indexOf('http') == -1 ? 'Songdetails' : ''); + menu += addMenuItem({"cmd": "delQueueSong", "options": ["single", el.parentNode.parentNode.getAttribute('data-trackid')]}, 'Remove') + + addMenuItem({"cmd": "delQueueSong", "options": ["range", 0, el.parentNode.parentNode.getAttribute('data-songpos')]}, 'Remove all upwards') + + addMenuItem({"cmd": "delQueueSong", "options": ["range", (parseInt(el.parentNode.parentNode.getAttribute('data-songpos'))-1), -1]}, 'Remove all downwards') + + (uri.indexOf('http') == -1 ? addMenuItem({"cmd": "songDetails", "options": [uri]}, 'Songdetails') : ''); } new Popover(el, { trigger: 'click', delay: 0, dismissible: true, template: '