Static site generator for making web mixtapes in 2020.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

parts.tmpl 2.5 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. {{define "player"}}
  2. {{with $x := index . 0}}
  3. <audio id="player" preload="auto" tabindex="0" controls>
  4. <source src="{{$x.Filename}}">
  5. </audio>
  6. {{end}}
  7. {{end}}
  8. {{define "playlist"}}
  9. <ol id="playlist">
  10. {{range $i, $el := .}}
  11. <li{{if eq $i 0}} class="active"{{end}}>
  12. <a class="track" href="{{$el.Filename}}">{{$el.Artist}} - {{$el.Title}}</a>
  13. {{template "track-info" $el}}
  14. </li>
  15. {{end}}
  16. </ol>
  17. {{end}}
  18. {{define "track-info"}}{{end}}
  19. {{define "full-player"}}
  20. {{template "player" .}}
  21. {{template "playlist" .}}
  22. {{template "playlist-js"}}
  23. {{end}}
  24. {{define "playlist-js"}}
  25. <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  26. <script type="text/javascript">
  27. $(document).ready(function() {
  28. var current = 0;
  29. var $audio = $('#player');
  30. var $playlist = $('#playlist');
  31. var $tracks = $playlist.find('li a.track');
  32. var len = $tracks.length;
  33. $playlist.on('click', 'a.track', function (e) {
  34. e.preventDefault();
  35. link = $(this);
  36. current = link.parent().index();
  37. play(link, $audio[0]);
  38. });
  39. $audio[0].addEventListener('ended', function (e) {
  40. playNext();
  41. });
  42. $('a#next').on('click', function (e) {
  43. e.preventDefault();
  44. playNext();
  45. });
  46. $('a#prev').on('click', function (e) {
  47. e.preventDefault();
  48. playPrev();
  49. });
  50. function playPrev() {
  51. current--;
  52. if (current <= 0) {
  53. current = len - 1;
  54. }
  55. link = $playlist.find('a.track')[current];
  56. play($(link), $audio[0]);
  57. }
  58. function playNext() {
  59. current++;
  60. if (current == len) {
  61. current = 0;
  62. }
  63. link = $playlist.find('a.track')[current];
  64. play($(link), $audio[0]);
  65. }
  66. function play($link, $player) {
  67. $player.src = $link.attr('href');
  68. par = $link.parent();
  69. par.addClass('active').siblings().removeClass('active');
  70. $player.load();
  71. $player.play();
  72. }
  73. });
  74. </script>
  75. {{end}}