4 $(".jp-jplayer").each(function() {
5 console.log('starting player')
7 var $root = $self.parent();
9 // // var $number = $('.number', $root);
11 swfPath: "/static/jplayer/",
12 solution: "html,flash",
14 cssSelectorAncestor: "#" + $self.attr("data-player"),
20 var setMedia = function(elem, time=0) {
21 console.log('setMedia', elem, time);
24 media['mp3'] = elem.attr('data-mp3');
25 media['oga'] = elem.attr('data-ogg');
26 media['id'] = elem.attr('data-media-id');
28 $(".c-player__title", $root).html($(".title", elem).html());
29 $(".c-player__info", $root).html($(".attribution", elem).html());
30 $(".c-media__caption .content", $root).html($(".project-description", elem).html());
31 $(".c-media__caption .license", $root).html($(".license", elem).html());
32 $(".c-media__caption .project-logo", $root).html($(".project-icon", elem).html());
34 player.jPlayer("setMedia", media);
35 player.jPlayer("pause", time);
39 $('.play-next', $root).click(function() {
40 var next = parseInt($number.text()) + 1;
41 var p = $('.jp-playlist .play:eq(' + (next - 1) + ')', $root);
43 setMedia(p).jPlayer("play");
47 $('.play-prev', $root).click(function() {
48 var next = parseInt($number.text()) - 1;
51 var p = $('.jp-playlist .play:eq(' + (next - 1) + ')', $root);
52 setMedia(p).jPlayer("play");
58 var initialElem = $('.jp-playlist li', $root).first();
60 if (true || Modernizr.localstorage) {
62 audiobooks = JSON.parse(localStorage["audiobook-history"]);
66 last = audiobooks[$root.attr("data-book-slug")]
67 // Fallback for book id;
69 last = audiobooks[$root.attr("data-book-id")]
73 initialElem = $('[data-media-id="' + last[1] + '"] .play', $root).first();
74 initialTime = last[2];
75 $number.text($(".jp-playlist .play", $root).index(initialElem) + 1);
78 setMedia(initialElem, initialTime);
81 timeupdate: function(event) {
82 //event.jPlayer.status.currentTime
85 if (true || (event.jPlayer.status.currentTime && Modernizr.localstorage)) {
87 audiobooks = JSON.parse(localStorage["audiobook-history"]);
91 t = event.jPlayer.status.currentTime;
92 if (t && event.jPlayer.status.duration - t > 10) {
93 audiobooks[$root.attr("data-book-slug")] = [
95 event.jPlayer.status.media.id,
96 event.jPlayer.status.currentTime
99 delete audiobooks[$root.attr("data-book-slug")];
101 // Remove old book id, if present.
102 delete audiobooks[$root.attr("data-book-id")];
103 localStorage["audiobook-history"] = JSON.stringify(audiobooks);