Browse Source

Fix playlist with links in track notes

Matt Baer 3 months ago
parent
commit
b952bbfbc4
2 changed files with 12 additions and 22 deletions
  1. 6
    11
      templates.go
  2. 6
    11
      templates/parts.tmpl

+ 6
- 11
templates.go View File

@@ -75,7 +75,7 @@ var files = map[string]string{
75 75
     <ol id="playlist">
76 76
         {{range $i, $el := .}}
77 77
         <li{{if eq $i 0}} class="active"{{end}}>
78
-            <a href="{{$el.Filename}}">{{$el.Artist}} - {{$el.Title}}</a>
78
+            <a class="track" href="{{$el.Filename}}">{{$el.Artist}} - {{$el.Title}}</a>
79 79
             {{template "track-info" $el}}
80 80
         </li>
81 81
         {{end}}
@@ -97,14 +97,13 @@ var files = map[string]string{
97 97
             var current = 0;
98 98
             var $audio = $('#player');
99 99
             var $playlist = $('#playlist');
100
-            var $tracks = $playlist.find('li a');
100
+            var $tracks = $playlist.find('li a.track');
101 101
             var len = $tracks.length;
102 102
 
103
-            $playlist.on('click', 'a', function (e) {
103
+            $playlist.on('click', 'a.track', function (e) {
104 104
                 e.preventDefault();
105 105
                 link = $(this);
106 106
                 current = link.parent().index();
107
-                console.log(current);
108 107
                 play(link, $audio[0]);
109 108
             });
110 109
             $audio[0].addEventListener('ended', function (e) {
@@ -122,11 +121,9 @@ var files = map[string]string{
122 121
             function playPrev() {
123 122
                 current--;
124 123
                 if (current <= 0) {
125
-                    current = len;
126
-                    link = $playlist.find('a')[0];
127
-                } else {
128
-                    link = $playlist.find('a')[current];
124
+                    current = len - 1;
129 125
                 }
126
+                link = $playlist.find('a.track')[current];
130 127
                 play($(link), $audio[0]);
131 128
             }
132 129
 
@@ -134,10 +131,8 @@ var files = map[string]string{
134 131
                 current++;
135 132
                 if (current == len) {
136 133
                     current = 0;
137
-                    link = $playlist.find('a')[0];
138
-                } else {
139
-                    link = $playlist.find('a')[current];
140 134
                 }
135
+                link = $playlist.find('a.track')[current];
141 136
                 play($(link), $audio[0]);
142 137
             }
143 138
 

+ 6
- 11
templates/parts.tmpl View File

@@ -9,7 +9,7 @@
9 9
     <ol id="playlist">
10 10
         {{range $i, $el := .}}
11 11
         <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>
13 13
             {{template "track-info" $el}}
14 14
         </li>
15 15
         {{end}}
@@ -31,14 +31,13 @@
31 31
             var current = 0;
32 32
             var $audio = $('#player');
33 33
             var $playlist = $('#playlist');
34
-            var $tracks = $playlist.find('li a');
34
+            var $tracks = $playlist.find('li a.track');
35 35
             var len = $tracks.length;
36 36
 
37
-            $playlist.on('click', 'a', function (e) {
37
+            $playlist.on('click', 'a.track', function (e) {
38 38
                 e.preventDefault();
39 39
                 link = $(this);
40 40
                 current = link.parent().index();
41
-                console.log(current);
42 41
                 play(link, $audio[0]);
43 42
             });
44 43
             $audio[0].addEventListener('ended', function (e) {
@@ -56,11 +55,9 @@
56 55
             function playPrev() {
57 56
                 current--;
58 57
                 if (current <= 0) {
59
-                    current = len;
60
-                    link = $playlist.find('a')[0];
61
-                } else {
62
-                    link = $playlist.find('a')[current];
58
+                    current = len - 1;
63 59
                 }
60
+                link = $playlist.find('a.track')[current];
64 61
                 play($(link), $audio[0]);
65 62
             }
66 63
 
@@ -68,10 +65,8 @@
68 65
                 current++;
69 66
                 if (current == len) {
70 67
                     current = 0;
71
-                    link = $playlist.find('a')[0];
72
-                } else {
73
-                    link = $playlist.find('a')[current];
74 68
                 }
69
+                link = $playlist.find('a.track')[current];
75 70
                 play($(link), $audio[0]);
76 71
             }
77 72