4 $(".book-right-column").remove();
6 if ($("#player-bar").length) {
7 $("#book-text-buttons").append(
8 $("<a class='enable-player-bar'><i class='icon icon-play'></i> zacznij słuchać</a>")
12 $(".enable-player-bar").click(function() {
14 $('body').addClass('with-player-bar');
15 $('.jp-play').click();
20 var smil = $("#smil").text();
22 smil = $.parseJSON(smil);
24 $.each(smil, function(i, e) {
25 $('#' + e).addClass('syncable');
31 /*$(window).on('scroll', function() {
33 $("#locator").removeClass('snap');
39 scrollTo = function() {
40 if (!scrolling && $('.playing-highlight').length && $('.playing-highlight')[0] != lastscroll) {
41 lastscroll = $('.playing-highlight')[0];
44 scrollTop: $('.playing-highlight').offset().top,
56 $.jPlayer.timeFormat.showHour = true;
58 $(".jp-jplayer").each(function() {
61 var $root = $self.parent();
62 var $currentMedia = null
63 var currentDuration = 0;
65 var totalDurationLeft = 0;
66 var totalDurationBefore = 0;
69 var doesUpdateSynchro = true;
71 // TODO: will need class for attach
72 // may be added from sync data
75 $(".zakladka-tool_sluchaj").click(function() {
76 $('body').addClass('with-player-bar');
77 let id = $(this).data('sync');
79 for (let i=0; i<smil.length; ++i) {
80 if (smil[i][0] == id) {
81 setMediaFromTime(smil[i][1], 'play');
82 //player.jPlayer('play');
88 var setMediaFromTime = function(time, cmd='pause') {
89 $('.jp-playlist li', $root).each((i, e) => {
90 d = parseFloat($(e).data('duration'));
92 setMedia($(e), time, cmd);
100 var setMedia = function(elem, time=0, cmd='pause') {
103 media['mp3'] = elem.attr('data-mp3');
104 media['oga'] = elem.attr('data-ogg');
105 media['id'] = elem.attr('data-media-id');
107 $(".c-player__head", $root).html(
108 $(".attribution", elem).html())
110 $(".c-player__info", $root).html(
111 $(".title", elem).html()
113 $(".c-media__caption .content", $root).html($(".project-description", elem).html());
114 $(".c-media__caption .license", $root).html($(".license", elem).html());
115 $(".c-media__caption .project-logo", $root).html($(".project-icon", elem).html());
117 doesUpdateSynchro = false;
118 if (!$currentMedia || $currentMedia[0] != elem[0]) {
119 player.jPlayer("setMedia", media);
120 player.jPlayer("option", "playbackRate", speed);
122 doesUpdateSynchro = true;
123 player.jPlayer(cmd, time);
125 $currentMedia = elem;
126 $(".play-next", $root).prop("disabled", !elem.nextAll('li').length);
128 let du = parseFloat(elem.data('duration'));
129 currentDuration = du;
130 elem.nextAll('li').each(function() {
131 du += parseFloat($(this).data('duration'));
133 totalDurationLeft = du;
136 elem.prevAll('li').each(function() {
137 pdu += parseFloat($(this).data('duration'));
139 totalDurationBefore = pdu;
145 var updateSynchrotext = function(position) {
146 if (!doesUpdateSynchro) return;
148 let curElemId = null;
149 for (let i=0; i<smil.length; ++i) {
151 if (smil[i][1] <= position) curElemId = smil[i][0];
154 $(".playing-highlight").removeClass("playing-highlight");
155 if (curElemId !== null) {
156 let curElem = $("#" + curElemId);
157 curElem.addClass("playing-highlight");
159 let miny = window.scrollY;
160 let maxy = miny + window.innerHeight;
161 let y = curElem.offset().top;
163 let locator = $("#locator");
164 // TODO: if snap then roll
165 locator.removeClass('up').removeClass('down');
166 if (locator.hasClass('snap')) {
170 locator.addClass('up');
173 locator.addClass('down');
180 swfPath: "/static/js/contrib/jplayer/",
181 solution: "html,flash",
183 cssSelectorAncestor: "#" + $self.attr("data-player"),
184 useStateClassSkin: true,
189 let selectItem = $('.c-select li');
190 selectItem.on('click', function() {
191 let speedStr = $(this).data('speed');
192 speed = parseFloat(speedStr);
193 player.jPlayer("option", "playbackRate", speed);
194 localStorage['audiobook-speed'] = speedStr;
195 _paq.push(['trackEvent', 'audiobook', 'speed', speedStr]);
198 $('.jp-play', $root).click(function() {
199 _paq.push(['trackEvent', 'audiobook', 'play']);
201 $('.jp-seek-bar', $root).click(function() {
202 _paq.push(['trackEvent', 'audiobook', 'seek']);
204 $('.jp-mute', $root).click(function() {
205 _paq.push(['trackEvent', 'audiobook', 'mute']);
207 $('.jp-volume-bar', $root).click(function() {
208 _paq.push(['trackEvent', 'audiobook', 'volume']);
211 $('.play-next', $root).click(function() {
212 let p = $currentMedia.nextAll('li').first();
214 setMedia(p).jPlayer("play");
215 _paq.push(['trackEvent', 'audiobook', 'next']);
218 $('.play-prev', $root).click(function() {
219 let p = $currentMedia.prevAll('li').first();
221 setMedia(p).jPlayer("play");
222 _paq.push(['trackEvent', 'audiobook', 'prev']);
224 // If in first part, restart it.
225 setMedia($currentMedia).jPlayer("play");
226 _paq.push(['trackEvent', 'audiobook', 'rewind']);
230 $('.jp-playlist li', $root).click(function() {
231 setMedia($(this)).jPlayer("play");
232 $('.c-player__chapters').removeClass('is-active');
233 _paq.push(['trackEvent', 'audiobook', 'chapter']);
236 var initialElem = $('.jp-playlist li', $root).first();
238 if (true || Modernizr.localstorage) {
240 let speedStr = localStorage['audiobook-speed'];
242 speed = parseFloat(speedStr);
243 $(".speed .is-active").removeClass("is-active");
244 $(".speed [data-speed='" + speedStr + "']").addClass("is-active");
249 audiobooks = JSON.parse(localStorage["audiobook-history"]);
253 last = audiobooks[$root.attr("data-book-slug")]
254 // Fallback for book id;
256 last = audiobooks[$root.attr("data-book-id")]
260 initialElem = $('[data-media-id="' + last[1] + '"]', $root).first();
261 initialTime = last[2];
264 setMedia($(initialElem), initialTime);
267 timeupdate: function(event) {
268 t = event.jPlayer.status.currentTime;
270 updateSynchrotext(totalDurationBefore + t);
273 ttl = (totalDurationLeft - t) / speed;
274 ttl = $.jPlayer.convertTime(ttl);
275 $(".total-time-left").text('Czas do końca: ' + ttl);
277 $(".time-left").text('– ' + $.jPlayer.convertTime(
282 if (Math.abs(t - lastUpdate) > 3) {
284 audiobooks = JSON.parse(localStorage["audiobook-history"]);
288 if (t && event.jPlayer.status.duration - t > 10) {
289 audiobooks[$root.attr("data-book-slug")] = [
291 event.jPlayer.status.media.id,
292 event.jPlayer.status.currentTime
295 delete audiobooks[$root.attr("data-book-slug")];
297 // Remove old book id, if present.
298 delete audiobooks[$root.attr("data-book-id")];
299 localStorage["audiobook-history"] = JSON.stringify(audiobooks);
305 ended: function(event) {
306 let p = $currentMedia.nextAll('li');
308 setMedia(p).jPlayer("play");
315 $('#locator').on('click', function() {
316 $(this).toggleClass('snap');