[vlc-commits] WebUI: Update Playlist improvement

Mark Hassman git at videolan.org
Sun Aug 5 22:48:43 CEST 2012


vlc | branch: master | Mark Hassman <mark at hassman.org> | Sat Aug  4 19:32:30 2012 -0400| [60758c0313ef5553515bbc545dc5aa4b9299ca3c] | committer: Jean-Baptiste Kempf

WebUI: Update Playlist improvement

Close #5583

Playlist is cached/updated locally within browser instead of
refreshing after each function call.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=60758c0313ef5553515bbc545dc5aa4b9299ca3c
---

 share/lua/http/index.html       |    5 ++++-
 share/lua/http/js/controlers.js |   38 +++++++++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/share/lua/http/index.html b/share/lua/http/index.html
index 60ff532..258ed2b 100644
--- a/share/lua/http/index.html
+++ b/share/lua/http/index.html
@@ -122,7 +122,10 @@
 					sendCommand({'command':'pl_random'});
 					return false;
 				})
-				$('#buttonRefresh').click(updatePlayList);
+				$('#buttonRefresh').click(function(){
+				    updatePlayList(true);
+				    return false;
+				});
 				$('#buttonPlPlay').click(function(){
 					sendCommand({
 						'command': 'pl_play',
diff --git a/share/lua/http/js/controlers.js b/share/lua/http/js/controlers.js
index ab59bcf..9233683 100644
--- a/share/lua/http/js/controlers.js
+++ b/share/lua/http/js/controlers.js
@@ -1,6 +1,8 @@
 var current_id = 1;
 var currentArt = null;
 var current_que = 'main';
+var previous_title = null;
+var current_title = null;
 
 function updateArt(url) {
     $('#albumArt').fadeOut(500, function () {
@@ -72,6 +74,13 @@ function updateStatus() {
                     currentArt = 'images/vlc-48.png';
                     updateArt(currentArt);
                 }
+
+                current_title = $('[name="filename"]', data).text();
+                if (previous_title != current_title) {
+                    updatePlayList();
+                }
+                previous_title = current_title;
+
                 if (pollStatus) {
                     setTimeout(updateStatus, 1000);
                 }
@@ -119,8 +128,30 @@ function updateStatus() {
     });
 }
 
-function updatePlayList() {
-    $('#libraryTree').jstree('refresh', -1);
+function updatePlayList(force_refresh) {
+    if (force_refresh) {
+        //refresh playlist..
+        $('#libraryTree').jstree('refresh', -1);
+    } else {
+        //iterate through playlist..
+        $('.jstree-leaf').each(function(){
+            var id = $(this).attr('id');
+            if (id != null && id.substr(0,5) == 'plid_') {
+                var name = $(this).attr('name');
+                if (name != null && name == current_title) {
+                    $(this).addClass('ui-state-highlight');
+                    $(this).attr('current', 'current');
+                    this.scrollIntoView(true);
+                } else {
+                    $(this).removeClass('ui-state-highlight');
+                    $(this).removeAttr('current');
+                }
+                if ($(this).children('a').size() > 0) {
+                    $($(this).children('a')[0]).removeClass('ui-state-active');
+                }
+            }
+    	});
+    }
 }
 
 function sendCommand(params, append) {
@@ -133,7 +164,6 @@ function sendCommand(params, append) {
                     eval(append);
                 }
                 updateStatus();
-                updatePlayList();
             }
         });
     } else {
@@ -155,7 +185,6 @@ function sendCommand(params, append) {
                     if (append != undefined) {
                         eval(append);
                     }
-                    updatePlayList();
                 }
             });
         }
@@ -490,7 +519,6 @@ $(function () {
         event.preventDefault();
         current_id = $(this).parent().attr('id').substr(5);
         sendCommand('command=pl_play&id=' + current_id);
-        updatePlayList();
     });
     updateStatus();
     updateStreams();



More information about the vlc-commits mailing list