From c27230ceab690b9e2bc13ad16922494a4078f9cb Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 7 Apr 2016 12:17:35 +0200 Subject: [PATCH] add playlist player to index --- app/festival/static/js/player.js | 41 +++++++++ .../templates/festival/audio_playlist.html | 87 ++++--------------- app/festival/templatetags/festival_tags.py | 4 + app/templates/index.html | 3 + 4 files changed, 66 insertions(+), 69 deletions(-) create mode 100644 app/festival/static/js/player.js diff --git a/app/festival/static/js/player.js b/app/festival/static/js/player.js new file mode 100644 index 00000000..5eae7bf8 --- /dev/null +++ b/app/festival/static/js/player.js @@ -0,0 +1,41 @@ + +function init_player(){ + var audio; + var playlist; + var tracks; + var current; + + current = 0; + audio = $('#audio'); + playlist = $('#playlist'); + tracks = playlist.find('li a'); + len = tracks.length - 1; + audio[0].volume = .90; +// audio[0].play(); + playlist.find('a').click(function(e){ + e.preventDefault(); + link = $(this); + current = link.parent().index(); + run_player(link, audio[0]); + }); + audio[0].addEventListener('ended',function(e){ + current++; + if(current == len){ + current = 0; + link = playlist.find('a')[0]; + }else{ + link = playlist.find('a')[current]; + } + run_player($(link),audio[0]); + }); +} +function run_player(link, player){ + $(player).find('#primarysrc').attr('src', link.attr('href')); + $(player).find('#secondarysrc').attr('src', link.attr('data-altsrc')); + par = link.parent(); + par.addClass('active').siblings().removeClass('active'); + player.load(); + player.play(); +} + +init_player(); diff --git a/app/festival/templates/festival/audio_playlist.html b/app/festival/templates/festival/audio_playlist.html index 073ffdaf..306a619e 100644 --- a/app/festival/templates/festival/audio_playlist.html +++ b/app/festival/templates/festival/audio_playlist.html @@ -1,74 +1,23 @@ - - - - - - +{% load staticfiles %} +{% for audio in playlist.audios.all %} +{% if forloop.first %} - - - - - + + diff --git a/app/festival/templatetags/festival_tags.py b/app/festival/templatetags/festival_tags.py index a3c398cd..980d7c0c 100644 --- a/app/festival/templatetags/festival_tags.py +++ b/app/festival/templatetags/festival_tags.py @@ -37,3 +37,7 @@ def featured_artist(*args): @register.as_tag def featured_video(*args): return Video.objects.filter(featured=True).order_by('?').first() + +@register.as_tag +def featured_playlist(*args): + return Playlist.objects.filter(event=None)[0] diff --git a/app/templates/index.html b/app/templates/index.html index 806657ae..ffde84c5 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -15,4 +15,7 @@ {% featured_video as video %} {% include 'festival/inc/video_card.html' %} +{% featured_playlist as playlist %} +{% include 'festival/audio_playlist.html' %} + {% endblock %} -- 2.39.5