Skip to content

Commit b952bbf

Browse files
committed
Fix playlist with links in track notes
1 parent d378220 commit b952bbf

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

templates.go

+6-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/parts.tmpl

+6-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ol id="playlist">
1010
{{range $i, $el := .}}
1111
<li{{if eq $i 0}} class="active"{{end}}>
12-
<a href="{{$el.Filename}}">{{$el.Artist}} - {{$el.Title}}</a>
12+
<a class="track" href="{{$el.Filename}}">{{$el.Artist}} - {{$el.Title}}</a>
1313
{{template "track-info" $el}}
1414
</li>
1515
{{end}}
@@ -31,14 +31,13 @@
3131
var current = 0;
3232
var $audio = $('#player');
3333
var $playlist = $('#playlist');
34-
var $tracks = $playlist.find('li a');
34+
var $tracks = $playlist.find('li a.track');
3535
var len = $tracks.length;
3636

37-
$playlist.on('click', 'a', function (e) {
37+
$playlist.on('click', 'a.track', function (e) {
3838
e.preventDefault();
3939
link = $(this);
4040
current = link.parent().index();
41-
console.log(current);
4241
play(link, $audio[0]);
4342
});
4443
$audio[0].addEventListener('ended', function (e) {
@@ -56,22 +55,18 @@
5655
function playPrev() {
5756
current--;
5857
if (current <= 0) {
59-
current = len;
60-
link = $playlist.find('a')[0];
61-
} else {
62-
link = $playlist.find('a')[current];
58+
current = len - 1;
6359
}
60+
link = $playlist.find('a.track')[current];
6461
play($(link), $audio[0]);
6562
}
6663

6764
function playNext() {
6865
current++;
6966
if (current == len) {
7067
current = 0;
71-
link = $playlist.find('a')[0];
72-
} else {
73-
link = $playlist.find('a')[current];
7468
}
69+
link = $playlist.find('a.track')[current];
7570
play($(link), $audio[0]);
7671
}
7772

0 commit comments

Comments
 (0)