From 7e356f38a84980bbce3fe2dcf1e3098dd89c6e8f Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Mon, 24 Jun 2013 22:45:44 -0400 Subject: [PATCH] Reduce freezes on large playlists --- www/assets/js/data.js | 1 + www/assets/js/util.js | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/www/assets/js/data.js b/www/assets/js/data.js index 2a15c721..6d313eea 100644 --- a/www/assets/js/data.js +++ b/www/assets/js/data.js @@ -40,6 +40,7 @@ if($("#ytapiplayer").length > 0) { var VHEIGHT = ""+parseInt(parseInt(VWIDTH) * 9 / 16); } var POSITION = -1; +var REBUILDING = false; var socket = { emit: function() { console.log("socket not initialized"); diff --git a/www/assets/js/util.js b/www/assets/js/util.js index b3ce06ea..827e2cd0 100644 --- a/www/assets/js/util.js +++ b/www/assets/js/util.js @@ -291,9 +291,23 @@ function addQueueButtons(li) { } function rebuildPlaylist() { - $("#queue li").each(function() { - $(this).find(".btn-group").remove(); - addQueueButtons($(this)); + if(REBUILDING) + return; + + REBUILDING = true; + var i = 0; + var qli = $("#queue li"); + qli.each(function() { + var li = $(this); + setTimeout(function() { + addQueueButtons(li); + }, 10*i); + if(i == qli.length - 1) { + setTimeout(function() { + REBUILDING = false; + }, 10*i); + } + i++; }); }