X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/87e084d47c335cd6f0b3e91d614999f55d148044..623676b97cc93293eff63398c7deb45cdec76af9:/src/catalogue/static/player/player.js diff --git a/src/catalogue/static/player/player.js b/src/catalogue/static/player/player.js old mode 100755 new mode 100644 index a41d2c0ae..d80446318 --- a/src/catalogue/static/player/player.js +++ b/src/catalogue/static/player/player.js @@ -13,7 +13,7 @@ ready: function() { var player = $(this); - var setMedia = function(elem) { + var setMedia = function(elem, time=0) { var li = $(elem).parent(); var media = {} @@ -21,7 +21,9 @@ media['oga'] = li.attr('data-ogg'); $(".title", $root).html(li.html()); - return player.jPlayer("setMedia", media); + $root.attr('data-media-id', li.attr('data-media-id')); + player.jPlayer("setMedia", media); + player.jPlayer("pause", time); }; $('.play-next', $root).click(function() { @@ -41,8 +43,29 @@ $number.text(next) }); - setMedia($('.play', $root).first()); + var initialElem = $('.play', $root).first(); + var initialTime = 0; + if (Modernizr.localstorage) { + audiobooks = JSON.parse(localStorage["audiobook-history"]); + last = audiobooks[$root.attr("data-book-id")] + if (last) { + initialElem = $('[data-media-id="' + last[1] + '"] .play', $root).first(); + initialTime = last[2]; + } + } + setMedia(initialElem, initialTime); + }, + timeupdate: function(event) { + if (Modernizr.localstorage) { + try { + audiobooks = JSON.parse(localStorage["audiobook-history"]); + } catch { + audiobooks = {}; + } + audiobooks[$root.attr("data-book-id")] = [Date.now(), $root.attr("data-media-id"), event.jPlayer.status.currentTime]; + localStorage["audiobook-history"] = JSON.stringify(audiobooks); + } } }); });