]> git.wh0rd.org - chrome-ext/music-player-client.git/blobdiff - main.js
playlist: fix display, and let people delete items
[chrome-ext/music-player-client.git] / main.js
diff --git a/main.js b/main.js
index 9155650966c2f3a40c2f14befc72a61a33437080..9902b935d01e7042570268c13be9d07b82f337c1 100644 (file)
--- a/main.js
+++ b/main.js
@@ -56,6 +56,23 @@ window.onload = function() {
        });
 };
 
+window.onkeypress = function(e) {
+       switch (e.keyCode) {
+       case 49: // 1
+               show_page('controls');
+               break;
+       case 50: // 1
+               show_page('metadata');
+               break;
+       case 51: // 1
+               show_page('playlist');
+               break;
+       case 52: // 1
+               show_page('options');
+               break;
+       }
+};
+
 function mpc_refresh() {
        mpc.status();
 }
@@ -93,6 +110,7 @@ function tramp_mpc_consume() {
        mpc.consume(val);
        setToggleButton(this, val);
 }
+function tramp_mpc_deleteid() { mpc.deleteid(this.title); }
 function tramp_mpc_next() { mpc.next(); }
 function tramp_mpc_pause() { mpc.pause(); }
 function tramp_mpc_play() { mpc.play(); }
@@ -191,11 +209,17 @@ function update_sync_settings() {
 }
 
 function init_ui(local_keys, sync_keys, options) {
+       var ele, i;
+
        /* Setup footer */
+       i = 1;
        [
-               'controls', 'metadata', 'options', 'playlist',
+               'controls', 'metadata', 'playlist', 'options',
        ].forEach(function(id) {
-               document.getElementById('tab.' + id).onclick = show_page;
+               var ele = document.getElementById('tab.' + id);
+               ele.onclick = show_page;
+               ele.title = id + ' [' + i + ']';
+               ++i;
        });
 
        /* Setup control tab */
@@ -207,6 +231,8 @@ function init_ui(local_keys, sync_keys, options) {
                var ele = window['ui_mpc_' + id] = document.getElementById(id);
                ele.onchange = ele.onclick = window['tramp_mpc_' + id];
                ele.title = id;
+               if (ele.accessKey)
+                       ele.title += ' [' + ele.accessKey + ']'
        });
        window['ui_mpc_currtime'] = document.getElementById('currtime');
 
@@ -247,6 +273,11 @@ function pretty_time(time) {
        return ret + ("00" + sec).substr(-2);
 }
 
+function playlist_del() {
+       mpc.deleteid(this.title);
+       this.parentNode.remove();
+}
+
 function update_ui(state, cmd) {
        if (typeof(state) == 'string') {
                ui_mpc_status.innerText = ({
@@ -289,6 +320,12 @@ function update_ui(state, cmd) {
                if (song.Pos == currentsong.Pos)
                        row.style.fontWeight = 'bold';
 
+               cell = row.insertCell(-1);
+               cell.id = 'playlist_del';
+               cell.innerHTML = '¤';
+               cell.title = song.Id;
+               cell.onclick = playlist_del;
+
                cell = row.insertCell(-1);
                cell.innerText = song.Pos;
                cell.style.textAlign = 'right';