← Back to team overview

zeya team mailing list archive

PATCH: Shuffling feature

 

Hey all:

Just added a small feature to Zeya JS client for shuffling. Pls. find the patch attached.

For the lack of a better icon, I have used a "cheap" substitute. I hope I can find a better icon. I have attached the image file for testing.

I hope this can make it to the Zeya project!


Best Regards,
Amit
--
Journal: http://amitksaha.wordpress.com
µ-blog: http://twitter.com/amitsaha
IRC: cornucopic on #scheme, #lisp, #math, #linux
diff --git a/resources/library.html b/resources/library.html
index cb9b110..1994cb5 100644
--- a/resources/library.html
+++ b/resources/library.html
@@ -27,6 +27,9 @@
       <span id="next_button" class="control">
 	<img id="next_img" src="next.png" alt="Next" onclick="next()" title="Next">
       </span>
+      <span id="shuffle" class="control">
+	<img id="shuffle_img" src="multimedia-player.png" onclick="shuffle()" title="Shuffle">
+	</span>
       <span id="spinner">
 	<img id="spinner_icon" src="spinner.gif" style="visibility: hidden;">
       </span>
diff --git a/resources/zeya.js b/resources/zeya.js
index 6dbe9c4..9438942 100644
--- a/resources/zeya.js
+++ b/resources/zeya.js
@@ -243,6 +243,26 @@ function focus_search_box() {
   search_box.select();
 }
 
+// Peform the library shuffle via Durstenfeld's shuffle
+function shuffle_collection()
+{
+
+    for (var temp, j, i = library.length; i;) { 
+        j = parseInt (Math.random () * i);
+        temp = library [--i];
+        library [i] = library [j];
+        library [j] = temp;
+    }
+}
+
+// Shuffle the play list
+function shuffle() {
+    clear_collection();
+    //shuffle
+    shuffle_collection();
+    window.setTimeout("render_collection()", 1);
+}
+
 // Pause the currently playing song.
 function pause() {
   if (current_index !== null) {

PNG image


Follow ups