1
0
mirror of https://github.com/thebaer/cdr.git synced 2024-11-15 01:31:01 +00:00

Fix playlist with links in track notes

This commit is contained in:
Matt Baer 2020-02-29 13:29:03 -05:00
parent d3782204fe
commit b952bbfbc4
2 changed files with 12 additions and 22 deletions

View File

@ -75,7 +75,7 @@ var files = map[string]string{
<ol id="playlist"> <ol id="playlist">
{{range $i, $el := .}} {{range $i, $el := .}}
<li{{if eq $i 0}} class="active"{{end}}> <li{{if eq $i 0}} class="active"{{end}}>
<a href="{{$el.Filename}}">{{$el.Artist}} - {{$el.Title}}</a> <a class="track" href="{{$el.Filename}}">{{$el.Artist}} - {{$el.Title}}</a>
{{template "track-info" $el}} {{template "track-info" $el}}
</li> </li>
{{end}} {{end}}
@ -97,14 +97,13 @@ var files = map[string]string{
var current = 0; var current = 0;
var $audio = $('#player'); var $audio = $('#player');
var $playlist = $('#playlist'); var $playlist = $('#playlist');
var $tracks = $playlist.find('li a'); var $tracks = $playlist.find('li a.track');
var len = $tracks.length; var len = $tracks.length;
$playlist.on('click', 'a', function (e) { $playlist.on('click', 'a.track', function (e) {
e.preventDefault(); e.preventDefault();
link = $(this); link = $(this);
current = link.parent().index(); current = link.parent().index();
console.log(current);
play(link, $audio[0]); play(link, $audio[0]);
}); });
$audio[0].addEventListener('ended', function (e) { $audio[0].addEventListener('ended', function (e) {
@ -122,11 +121,9 @@ var files = map[string]string{
function playPrev() { function playPrev() {
current--; current--;
if (current <= 0) { if (current <= 0) {
current = len; current = len - 1;
link = $playlist.find('a')[0];
} else {
link = $playlist.find('a')[current];
} }
link = $playlist.find('a.track')[current];
play($(link), $audio[0]); play($(link), $audio[0]);
} }
@ -134,10 +131,8 @@ var files = map[string]string{
current++; current++;
if (current == len) { if (current == len) {
current = 0; current = 0;
link = $playlist.find('a')[0];
} else {
link = $playlist.find('a')[current];
} }
link = $playlist.find('a.track')[current];
play($(link), $audio[0]); play($(link), $audio[0]);
} }

View File

@ -9,7 +9,7 @@
<ol id="playlist"> <ol id="playlist">
{{range $i, $el := .}} {{range $i, $el := .}}
<li{{if eq $i 0}} class="active"{{end}}> <li{{if eq $i 0}} class="active"{{end}}>
<a href="{{$el.Filename}}">{{$el.Artist}} - {{$el.Title}}</a> <a class="track" href="{{$el.Filename}}">{{$el.Artist}} - {{$el.Title}}</a>
{{template "track-info" $el}} {{template "track-info" $el}}
</li> </li>
{{end}} {{end}}
@ -31,14 +31,13 @@
var current = 0; var current = 0;
var $audio = $('#player'); var $audio = $('#player');
var $playlist = $('#playlist'); var $playlist = $('#playlist');
var $tracks = $playlist.find('li a'); var $tracks = $playlist.find('li a.track');
var len = $tracks.length; var len = $tracks.length;
$playlist.on('click', 'a', function (e) { $playlist.on('click', 'a.track', function (e) {
e.preventDefault(); e.preventDefault();
link = $(this); link = $(this);
current = link.parent().index(); current = link.parent().index();
console.log(current);
play(link, $audio[0]); play(link, $audio[0]);
}); });
$audio[0].addEventListener('ended', function (e) { $audio[0].addEventListener('ended', function (e) {
@ -56,11 +55,9 @@
function playPrev() { function playPrev() {
current--; current--;
if (current <= 0) { if (current <= 0) {
current = len; current = len - 1;
link = $playlist.find('a')[0];
} else {
link = $playlist.find('a')[current];
} }
link = $playlist.find('a.track')[current];
play($(link), $audio[0]); play($(link), $audio[0]);
} }
@ -68,10 +65,8 @@
current++; current++;
if (current == len) { if (current == len) {
current = 0; current = 0;
link = $playlist.find('a')[0];
} else {
link = $playlist.find('a')[current];
} }
link = $playlist.find('a.track')[current];
play($(link), $audio[0]); play($(link), $audio[0]);
} }