]> CyberLeo.Net >> Repos - CDN/metadata.git/blob - views/handler_js.erb
More screwing around
[CDN/metadata.git] / views / handler_js.erb
1 function format_track(index, title, length, bpm, notes) {
2   length = Math.round(length);
3   var minutes = Math.floor(length / 60);
4   var seconds = length % 60;
5   var length = minutes + ":" + ( "0" + seconds ).slice(-2);
6   if ( notes == null ) notes = '-';
7   entry = $('<div id="track_' + index + '" class="track" onClick="current(' + index + ');">');
8   entry.append($('<span class="index">' + index + '</span>'));
9   entry.append($('<span class="title">' + title + '</span>'));
10   entry.append($('<span class="length">' + length + '</span>'));
11   entry.append($('<span class="clear"></span>'));
12   entry.append($('<span class="bpm">' + bpm + ' BPM</span>'));
13   entry.append($('<span class="notes">' + notes + '</span>'));
14   return entry;
15 }
16
17 function init() {
18   for (var index in tracklist) {
19     track = tracklist[index];
20     entry = format_track(track['index'], track['title'], track['length'], track['bpm'], track['notes']);
21     $('#tracks').append(entry);
22   }
23 }
24
25 /* Track 0 is 'no current track' */
26 function current(index) {
27   if (index < 0 || index > maximum_index)
28     return;
29   current_index = index;
30   $("div.track").removeClass("current");
31   $("div#track_" + index).addClass("current");
32 }
33
34 function running(index) {
35   if (index < 0 || index > maximum_index)
36     return;
37   running_index = index;
38   $("div.track").removeClass("running");
39   $("div#track_" + index).addClass("running");
40 }
41
42 function next() {
43   current(current_index + 1);
44 }
45
46 function prev() {
47   current(current_index - 1);
48 }
49
50 function commit() {
51   running(current_index);
52 }
53
54 maximum_index = tracklist.length;
55 current_index = 0;
56 running_index = 0;
57
58 init();