+
+ var initialElem = $('.jp-playlist .play', $root).first();
+ var initialTime = 0;
+ if (Modernizr.localstorage) {
+ try {
+ audiobooks = JSON.parse(localStorage["audiobook-history"]);
+ } catch {
+ audiobooks = {};
+ }
+ last = audiobooks[$root.attr("data-book-slug")]
+ // Fallback for book id;
+ if (!last) {
+ last = audiobooks[$root.attr("data-book-id")]
+ }
+
+ if (last) {
+ initialElem = $('[data-media-id="' + last[1] + '"] .play', $root).first();
+ initialTime = last[2];
+ $number.text($(".jp-playlist .play", $root).index(initialElem) + 1);
+ }
+ }
+ setMedia(initialElem, initialTime);
+ },
+
+ timeupdate: function(event) {
+ if (event.jPlayer.status.currentTime && Modernizr.localstorage) {
+ try {
+ audiobooks = JSON.parse(localStorage["audiobook-history"]);
+ } catch {
+ audiobooks = {};
+ }
+ t = event.jPlayer.status.currentTime;
+ if (t && event.jPlayer.status.duration - t > 10) {
+ audiobooks[$root.attr("data-book-slug")] = [
+ Date.now(),
+ event.jPlayer.status.media.id,
+ event.jPlayer.status.currentTime
+ ];
+ } else {
+ delete audiobooks[$root.attr("data-book-slug")];
+ }
+ // Remove old book id, if present.
+ delete audiobooks[$root.attr("data-book-id")];
+ localStorage["audiobook-history"] = JSON.stringify(audiobooks);
+ }