document.getElementById("player-total-time").textContent = getTimeString(audio.duration);
}
+// Shown song details when the "..." button is clicked in a song list
+function showSongDetails(event) {
+ var songElement = event.target.closest(".song");
+ var songDetails = songElement.querySelector(".song-details");
+ var detailsToggle = songElement.querySelector(".details-toggle img");
+ if (songDetails.hidden) {
+ // Show details
+ songDetails.hidden = false;
+ detailsToggle.alt = "Hide Details";
+ detailsToggle.className = "lsp_btn_hide02";
+ detailsToggle.src = customImage(document.getElementById("lsp_btn_hide02"), detailsToggle);
+ }
+ else {
+ // Hide details
+ songDetails.hidden = true;
+ detailsToggle.alt = "Show Details";
+ detailsToggle.className = "lsp_btn_show02";
+ detailsToggle.src = customImage(document.getElementById("lsp_btn_show02"), detailsToggle);
+ }
+ return false;
+}
+
+// Shuffle the songs in a song list
+function shuffleSongList(event) {
+ var songList = event.target.closest(".song-list");
+ var songs = songList.querySelector(".song-list-songs");
+ if (event.target.checked) {
+ // Store original list so it can be restored later
+ songList.dataset.original = songs.innerHTML;
+
+ // Shuffle
+ var songElements = [];
+ while (songs.firstElementChild) {
+ songElements.push(songs.lastElementChild);
+ songs.removeChild(songs.lastElementChild);
+ }
+ for (let i = songElements.length - 1; i >= 0; i --) {
+ const j = Math.floor(Math.random() * (i + 1));
+ [songElements[i], songElements[j]] = [songElements[j], songElements[i]];
+ }
+ for (const child of songElements) {
+ songs.appendChild(child);
+ }
+ }
+ else {
+ // Unshuffle
+ if (songList.dataset.original) {
+ songs.innerHTML = songList.dataset.original;
+ }
+ }
+}
+
// Add event listeners
var m_firstLoadPlayer = true;
document.addEventListener("DOMContentLoaded", (event) => {
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="/static/styles.css?v=5"/>
<link rel="icon" type="image/x-icon" href="/static/lsp_notes.png?v=1"/>
- <script src="/static/player.js?v=4"></script>
+ <script src="/static/player.js?v=5"></script>
<script src="/static/nav.js?v=4"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</div>
<h2>hot new tunes</h2>
-{% include "song-list.html" %}
+{%- from "song-macros.html" import song_list %}
+{{ song_list(songs, current_user_playlists) }}
{% endblock %}
<br/>
<br/>
{% if songs %}<p><small>This event has received {{ songs|length }} {% if songs|length > 1 %}entries{% else %}entry{% endif %}</small></p>{% endif %}
- {% include "song-list.html" %}
+
+ {%- from "song-macros.html" import song_list %}
+ {{ song_list(songs, current_user_playlists) | indent(4) }}
{%- endif %}
<h2>Comments</h2>
{%- endif %}
-{% include "song-list.html" %}
+{%- from "song-macros.html" import song_list -%}
+{{ song_list(songs, current_user_playlists) }}
{% if session["userid"] == userid -%}
<!-- Drag-and-drop playlist editor -->
{% endif %}
<!-- Song List -->
- {% include "song-list.html" %}
+ {%- from "song-macros.html" import song_list -%}
+ {{ song_list(songs, current_user_playlists) | indent(4) }}
</div>
{% endif %}
+++ /dev/null
-{% from "song-macros.html" import song_info, song_details %}
-
-<div class="song-list">
- {% if songs|length > 1 %}
- <div class="song-list-controls">
- <label><input type="checkbox" name="shuffle" onchange="shuffleSongList(event)">Shuffle</label>
- </div>
- {% endif %}
-
- <div class="song-list-songs">
- {% for song in songs %}
- {%- if not (song.hidden and session['userid'] != song.userid) -%}
- <div class="song" data-song="{{ song.json() }}">
- <div class="song-main">
- <div class="song-list-pfp-container">
- {%- if song.user_has_pfp %}
- <!-- Profile Picture -->
- <img class="small-pfp" src="/pfp/{{ song.userid }}" onerror="this.style.display = 'none'" width="32" height="32" />
- {%- endif %}
- </div>
-
- {{ song_info(song) | indent(12) }}
-
- <div class="song-buttons">
- <!-- Details Button -->
- <button onclick="return showDetails(event)" class="song-list-button details-toggle" title="Toggle Details">
- <img class="lsp_btn_show02" alt="Show Details">
- </button>
-
- <!-- Play Button -->
- <button onclick="return play(event)" class="song-list-button" title="Play">
- <img class="lsp_btn_play02" alt="Play">
- </button>
- </div>
- </div>
- {{ song_details(song, current_user_playlists) | indent(8) }}
- </div>
- {%- endif -%}
- {% endfor %}
- </div>
-</div>
-
-<script>
-function showDetails(event) {
- var songElement = event.target.closest(".song");
- var songDetails = songElement.querySelector(".song-details");
- var detailsToggle = songElement.querySelector(".details-toggle img");
- if (songDetails.hidden) {
- // Show details
- songDetails.hidden = false;
- detailsToggle.alt = "Hide Details";
- detailsToggle.className = "lsp_btn_hide02";
- detailsToggle.src = customImage(document.getElementById("lsp_btn_hide02"), detailsToggle);
- }
- else {
- // Hide details
- songDetails.hidden = true;
- detailsToggle.alt = "Show Details";
- detailsToggle.className = "lsp_btn_show02";
- detailsToggle.src = customImage(document.getElementById("lsp_btn_show02"), detailsToggle);
- }
- return false;
-}
-
-function shuffleSongList(event) {
- var songList = event.target.closest(".song-list");
- var songs = songList.querySelector(".song-list-songs");
- if (event.target.checked) {
- // Store original list so it can be restored later
- songList.dataset.original = songs.innerHTML;
-
- // Shuffle
- var songElements = [];
- while (songs.firstElementChild) {
- songElements.push(songs.lastElementChild);
- songs.removeChild(songs.lastElementChild);
- }
- for (let i = songElements.length - 1; i >= 0; i --) {
- const j = Math.floor(Math.random() * (i + 1));
- [songElements[i], songElements[j]] = [songElements[j], songElements[i]];
- }
- for (const child of songElements) {
- songs.appendChild(child);
- }
- }
- else {
- // Unshuffle
- if (songList.dataset.original) {
- songs.innerHTML = songList.dataset.original;
- }
- }
-}
-</script>
{{ comment_thread(song.threadid, session["userid"], song.userid, song.get_comments()) }}
</div>
{% endmacro %}
+
+{% macro song_list_entry(song, current_user_playlists) -%}
+{%- if not (song.hidden and session['userid'] != song.userid) -%}
+<div class="song" data-song="{{ song.json() }}">
+ <div class="song-main">
+ <div class="song-list-pfp-container">
+ {%- if song.user_has_pfp %}
+ <!-- Profile Picture -->
+ <img class="small-pfp" src="/pfp/{{ song.userid }}" onerror="this.style.display = 'none'" width="32" height="32" />
+ {%- endif %}
+ </div>
+ {{ song_info(song) | indent(8) }}
+ <div class="song-buttons">
+ <!-- Details Button -->
+ <button onclick="return showSongDetails(event)" class="song-list-button details-toggle" title="Toggle Details">
+ <img class="lsp_btn_show02" alt="Show Details">
+ </button>
+
+ <!-- Play Button -->
+ <button onclick="return play(event)" class="song-list-button" title="Play">
+ <img class="lsp_btn_play02" alt="Play">
+ </button>
+ </div>
+ </div>
+ {{ song_details(song, current_user_playlists) | indent(4) }}
+</div>
+{%- endif -%}
+{%- endmacro %}
+
+{% macro song_list(songs, current_user_playlists) -%}
+<div class="song-list">
+ {% if songs|length > 1 %}
+ <div class="song-list-controls">
+ <label><input type="checkbox" name="shuffle" onchange="shuffleSongList(event)">Shuffle</label>
+ </div>
+ {% endif %}
+
+ <div class="song-list-songs">
+ {% for song in songs -%}
+ {{ song_list_entry(song, current_user_playlists) | indent(8) }}
+ {%- endfor %}
+ </div>
+</div>
+{%- endmacro %}
+
</div>
{% endif %}
-{% include "song-list.html" %}
+{% from "song-macros.html" import song_list %}
+{{ song_list(songs, current_user_playlists) }}
{% endblock %}