From b952bbfbc4e4eba423d86f63331e3b69314ed705 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sat, 29 Feb 2020 13:29:03 -0500 Subject: [PATCH] Fix playlist with links in track notes --- templates.go | 17 ++++++----------- templates/parts.tmpl | 17 ++++++----------- 2 files changed, 12 insertions(+), 22 deletions(-) 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]); }