diff --git a/templates.go b/templates.go
index c25966d..08025c1 100644
--- a/templates.go
+++ b/templates.go
@@ -75,7 +75,7 @@ var files = map[string]string{
{{range $i, $el := .}}
-
- {{$el.Artist}} - {{$el.Title}}
+ {{$el.Artist}} - {{$el.Title}}
{{template "track-info" $el}}
{{end}}
@@ -97,14 +97,13 @@ var files = map[string]string{
var current = 0;
var $audio = $('#player');
var $playlist = $('#playlist');
- var $tracks = $playlist.find('li a');
+ var $tracks = $playlist.find('li a.track');
var len = $tracks.length;
- $playlist.on('click', 'a', function (e) {
+ $playlist.on('click', 'a.track', function (e) {
e.preventDefault();
link = $(this);
current = link.parent().index();
- console.log(current);
play(link, $audio[0]);
});
$audio[0].addEventListener('ended', function (e) {
@@ -122,11 +121,9 @@ var files = map[string]string{
function playPrev() {
current--;
if (current <= 0) {
- current = len;
- link = $playlist.find('a')[0];
- } else {
- link = $playlist.find('a')[current];
+ current = len - 1;
}
+ link = $playlist.find('a.track')[current];
play($(link), $audio[0]);
}
@@ -134,10 +131,8 @@ var files = map[string]string{
current++;
if (current == len) {
current = 0;
- link = $playlist.find('a')[0];
- } else {
- link = $playlist.find('a')[current];
}
+ link = $playlist.find('a.track')[current];
play($(link), $audio[0]);
}
diff --git a/templates/parts.tmpl b/templates/parts.tmpl
index 408fc5a..a873151 100644
--- a/templates/parts.tmpl
+++ b/templates/parts.tmpl
@@ -9,7 +9,7 @@
{{range $i, $el := .}}
-
- {{$el.Artist}} - {{$el.Title}}
+ {{$el.Artist}} - {{$el.Title}}
{{template "track-info" $el}}
{{end}}
@@ -31,14 +31,13 @@
var current = 0;
var $audio = $('#player');
var $playlist = $('#playlist');
- var $tracks = $playlist.find('li a');
+ var $tracks = $playlist.find('li a.track');
var len = $tracks.length;
- $playlist.on('click', 'a', function (e) {
+ $playlist.on('click', 'a.track', function (e) {
e.preventDefault();
link = $(this);
current = link.parent().index();
- console.log(current);
play(link, $audio[0]);
});
$audio[0].addEventListener('ended', function (e) {
@@ -56,11 +55,9 @@
function playPrev() {
current--;
if (current <= 0) {
- current = len;
- link = $playlist.find('a')[0];
- } else {
- link = $playlist.find('a')[current];
+ current = len - 1;
}
+ link = $playlist.find('a.track')[current];
play($(link), $audio[0]);
}
@@ -68,10 +65,8 @@
current++;
if (current == len) {
current = 0;
- link = $playlist.find('a')[0];
- } else {
- link = $playlist.find('a')[current];
}
+ link = $playlist.find('a.track')[current];
play($(link), $audio[0]);
}