4 $.jPlayer.timeFormat.showHour = true;
6 $(".jp-jplayer").each(function() {
8 var $root = $self.parent();
9 var $currentMedia = null
10 var currentDuration = 0;
12 var totalDurationLeft = 0;
16 var setMedia = function(elem, time=0) {
19 media['mp3'] = elem.attr('data-mp3');
20 media['oga'] = elem.attr('data-ogg');
21 media['id'] = elem.attr('data-media-id');
23 $(".c-player__head", $root).html(
24 $(".attribution", elem).html())
26 $(".c-player__info", $root).html(
27 $(".title", elem).html()
29 $(".c-media__caption .content", $root).html($(".project-description", elem).html());
30 $(".c-media__caption .license", $root).html($(".license", elem).html());
31 $(".c-media__caption .project-logo", $root).html($(".project-icon", elem).html());
33 player.jPlayer("setMedia", media);
34 player.jPlayer("option", "playbackRate", speed);
35 player.jPlayer("pause", time);
38 $(".play-next", $root).prop("disabled", !elem.next().length);
40 let du = elem.data('duration');
42 elem.nextAll().each(function() {
43 du += $(this).data('duration');
45 totalDurationLeft = du;
52 swfPath: "/static/js/contrib/jplayer/",
53 solution: "html,flash",
55 cssSelectorAncestor: "#" + $self.attr("data-player"),
56 useStateClassSkin: true,
61 let selectItem = $('.c-select li');
62 selectItem.on('click', function() {
63 let speedStr = $(this).data('speed');
64 speed = parseFloat(speedStr);
65 player.jPlayer("option", "playbackRate", speed);
66 localStorage['audiobook-speed'] = speedStr;
67 _paq.push(['trackEvent', 'audiobook', 'speed', speedStr]);
70 $('.jp-play', $root).click(function() {
71 _paq.push(['trackEvent', 'audiobook', 'play']);
73 $('.jp-seek-bar', $root).click(function() {
74 _paq.push(['trackEvent', 'audiobook', 'seek']);
76 $('.jp-mute', $root).click(function() {
77 _paq.push(['trackEvent', 'audiobook', 'mute']);
79 $('.jp-volume-bar', $root).click(function() {
80 _paq.push(['trackEvent', 'audiobook', 'volume']);
83 $('.play-next', $root).click(function() {
84 let p = $currentMedia.next();
86 setMedia(p).jPlayer("play");
87 _paq.push(['trackEvent', 'audiobook', 'next']);
90 $('.play-prev', $root).click(function() {
91 let p = $currentMedia.prev();
93 setMedia(p).jPlayer("play");
94 _paq.push(['trackEvent', 'audiobook', 'prev']);
96 // If in first part, restart it.
97 setMedia($currentMedia).jPlayer("play");
98 _paq.push(['trackEvent', 'audiobook', 'rewind']);
102 $('.jp-playlist li', $root).click(function() {
103 setMedia($(this)).jPlayer("play");
104 $('.c-player__chapters').removeClass('is-active');
105 _paq.push(['trackEvent', 'audiobook', 'chapter']);
108 var initialElem = $('.jp-playlist li', $root).first();
110 if (true || Modernizr.localstorage) {
112 let speedStr = localStorage['audiobook-speed'];
114 speed = parseFloat(speedStr);
115 $(".speed .is-active").removeClass("is-active");
116 $(".speed [data-speed='" + speedStr + "']").addClass("is-active");
121 audiobooks = JSON.parse(localStorage["audiobook-history"]);
125 last = audiobooks[$root.attr("data-book-slug")]
126 // Fallback for book id;
128 last = audiobooks[$root.attr("data-book-id")]
132 initialElem = $('[data-media-id="' + last[1] + '"]', $root).first();
133 initialTime = last[2];
136 setMedia(initialElem, initialTime);
139 timeupdate: function(event) {
140 t = event.jPlayer.status.currentTime;
141 ttl = (totalDurationLeft - t) / speed;
142 ttl = $.jPlayer.convertTime(ttl);
143 $(".total-time-left").text('Czas do końca: ' + ttl);
145 $(".time-left").text('– ' + $.jPlayer.convertTime(
150 if (Math.abs(t - lastUpdate) > 3) {
152 audiobooks = JSON.parse(localStorage["audiobook-history"]);
156 if (t && event.jPlayer.status.duration - t > 10) {
157 audiobooks[$root.attr("data-book-slug")] = [
159 event.jPlayer.status.media.id,
160 event.jPlayer.status.currentTime
163 delete audiobooks[$root.attr("data-book-slug")];
165 // Remove old book id, if present.
166 delete audiobooks[$root.attr("data-book-id")];
167 localStorage["audiobook-history"] = JSON.stringify(audiobooks);
173 ended: function(event) {
174 let p = $currentMedia.next();
176 setMedia(p).jPlayer("play");