4 $(".jp-jplayer").each(function() {
6 var $root = $self.parent();
7 var $number = $('.number', $root);
9 swfPath: "/static/jplayer/",
10 solution: "html,flash",
11 supplied: $self.attr('data-supplied'),
12 cssSelectorAncestor: "#" + $self.attr("data-player"),
16 var setMedia = function(elem, time=0) {
17 var li = $(elem).parent();
20 media['mp3'] = li.attr('data-mp3');
21 media['oga'] = li.attr('data-ogg');
23 $(".title", $root).html(li.html());
24 $root.attr('data-media-id', li.attr('data-media-id'));
25 player.jPlayer("setMedia", media);
26 player.jPlayer("pause", time);
29 $('.play-next', $root).click(function() {
30 var next = parseInt($number.text()) + 1;
31 var p = $('.play:eq(' + next + ')', $root);
33 setMedia(p).jPlayer("play");
37 $('.play-prev', $root).click(function() {
38 var next = parseInt($number.text()) - 1;
41 var p = $('.play:eq(' + next + ')', $root);
42 setMedia(p).jPlayer("play");
46 var initialElem = $('.play', $root).first();
48 if (Modernizr.localstorage) {
49 audiobooks = JSON.parse(localStorage["audiobook-history"]);
50 last = audiobooks[$root.attr("data-book-id")]
52 initialElem = $('[data-media-id="' + last[1] + '"] .play', $root).first();
53 initialTime = last[2];
56 setMedia(initialElem, initialTime);
59 timeupdate: function(event) {
60 if (Modernizr.localstorage) {
62 audiobooks = JSON.parse(localStorage["audiobook-history"]);
66 audiobooks[$root.attr("data-book-id")] = [Date.now(), $root.attr("data-media-id"), event.jPlayer.status.currentTime];
67 localStorage["audiobook-history"] = JSON.stringify(audiobooks);