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());
118 doesUpdateSynchro = false;
119 if (!$currentMedia || $currentMedia[0] != elem[0]) {
120 console.log('set', player.jPlayer("setMedia", media))
121 player.jPlayer("option", "playbackRate", speed);
123 doesUpdateSynchro = true;
124 player.jPlayer(cmd, time);
126 $currentMedia = elem;
127 $(".play-next", $root).prop("disabled", !elem.next().length);
129 let du = parseFloat(elem.data('duration'));
130 currentDuration = du;
131 elem.nextAll().each(function() {
132 du += parseFloat($(this).data('duration'));
134 totalDurationLeft = du;
137 elem.prevAll().each(function() {
138 pdu += parseFloat($(this).data('duration'));
140 totalDurationBefore = pdu;
141 console.log('sm 3', du, pdu);
147 var updateSynchrotext = function(position) {
148 if (!doesUpdateSynchro) return;
150 let curElemId = null;
151 for (let i=0; i<smil.length; ++i) {
153 if (smil[i][1] <= position) curElemId = smil[i][0];
156 $(".playing-highlight").removeClass("playing-highlight");
157 if (curElemId !== null) {
158 let curElem = $("#" + curElemId);
159 curElem.addClass("playing-highlight");
161 let miny = window.scrollY;
162 let maxy = miny + window.innerHeight;
163 let y = curElem.offset().top;
165 let locator = $("#locator");
166 // TODO: if snap then roll
167 locator.removeClass('up').removeClass('down');
168 if (locator.hasClass('snap')) {
169 console.log('SCROLL!');
173 locator.addClass('up');
176 locator.addClass('down');
183 swfPath: "/static/js/contrib/jplayer/",
184 solution: "html,flash",
186 cssSelectorAncestor: "#" + $self.attr("data-player"),
187 useStateClassSkin: true,
192 let selectItem = $('.c-select li');
193 selectItem.on('click', function() {
194 let speedStr = $(this).data('speed');
195 speed = parseFloat(speedStr);
196 player.jPlayer("option", "playbackRate", speed);
197 localStorage['audiobook-speed'] = speedStr;
198 _paq.push(['trackEvent', 'audiobook', 'speed', speedStr]);
201 $('.jp-play', $root).click(function() {
202 _paq.push(['trackEvent', 'audiobook', 'play']);
204 $('.jp-seek-bar', $root).click(function() {
205 _paq.push(['trackEvent', 'audiobook', 'seek']);
207 $('.jp-mute', $root).click(function() {
208 _paq.push(['trackEvent', 'audiobook', 'mute']);
210 $('.jp-volume-bar', $root).click(function() {
211 _paq.push(['trackEvent', 'audiobook', 'volume']);
214 $('.play-next', $root).click(function() {
215 let p = $currentMedia.next();
217 setMedia(p).jPlayer("play");
218 _paq.push(['trackEvent', 'audiobook', 'next']);
221 $('.play-prev', $root).click(function() {
222 let p = $currentMedia.prev();
224 setMedia(p).jPlayer("play");
225 _paq.push(['trackEvent', 'audiobook', 'prev']);
227 // If in first part, restart it.
228 setMedia($currentMedia).jPlayer("play");
229 _paq.push(['trackEvent', 'audiobook', 'rewind']);
233 $('.jp-playlist li', $root).click(function() {
234 setMedia($(this)).jPlayer("play");
235 $('.c-player__chapters').removeClass('is-active');
236 _paq.push(['trackEvent', 'audiobook', 'chapter']);
239 console.log('READY 3!');
240 var initialElem = $('.jp-playlist li', $root).first();
242 console.log('READY 4!');
243 if (true || Modernizr.localstorage) {
245 let speedStr = localStorage['audiobook-speed'];
247 speed = parseFloat(speedStr);
248 $(".speed .is-active").removeClass("is-active");
249 $(".speed [data-speed='" + speedStr + "']").addClass("is-active");
254 audiobooks = JSON.parse(localStorage["audiobook-history"]);
258 last = audiobooks[$root.attr("data-book-slug")]
259 // Fallback for book id;
261 last = audiobooks[$root.attr("data-book-id")]
265 initialElem = $('[data-media-id="' + last[1] + '"]', $root).first();
266 initialTime = last[2];
269 console.log('READY 5!', initialElem, initialTime);
270 setMedia($(initialElem), initialTime);
271 console.log('READY 6!');
274 timeupdate: function(event) {
275 t = event.jPlayer.status.currentTime;
277 updateSynchrotext(totalDurationBefore + t);
280 ttl = (totalDurationLeft - t) / speed;
281 ttl = $.jPlayer.convertTime(ttl);
282 $(".total-time-left").text('Czas do końca: ' + ttl);
284 $(".time-left").text('– ' + $.jPlayer.convertTime(
289 if (Math.abs(t - lastUpdate) > 3) {
291 audiobooks = JSON.parse(localStorage["audiobook-history"]);
295 if (t && event.jPlayer.status.duration - t > 10) {
296 audiobooks[$root.attr("data-book-slug")] = [
298 event.jPlayer.status.media.id,
299 event.jPlayer.status.currentTime
302 delete audiobooks[$root.attr("data-book-slug")];
304 // Remove old book id, if present.
305 delete audiobooks[$root.attr("data-book-id")];
306 localStorage["audiobook-history"] = JSON.stringify(audiobooks);
312 ended: function(event) {
313 let p = $currentMedia.next();
315 setMedia(p).jPlayer("play");
322 $('#locator').on('click', function() {
323 $(this).toggleClass('snap');