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>'));
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);
25 /* Track 0 is 'no current track' */
26 function current(index) {
27 if (index < 0 || index > maximum_index)
29 current_index = index;
30 $("div.track").removeClass("current");
31 $("div#track_" + index).addClass("current");
35 function running(index) {
36 if (index < 0 || index > maximum_index)
38 running_index = index;
39 $("div.track").removeClass("running");
40 $("div#track_" + index).addClass("running");
43 function scroll_to(index) {
44 // Scroll so that this tile is at the top third. If beyond page boundaries, clamp.
45 var height = $(document).height();
46 var viewport = $(window).height() / 3;
47 var target = height * (index / maximum_index) - viewport;
49 $('html,body').animate({scrollTop: target}, 250);
53 current(current_index + 1);
57 current(current_index - 1);
61 running(current_index);
64 maximum_index = tracklist.length;