1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-05 15:32:55 +02:00

fix book path url to handle more options, add music hook

This commit is contained in:
Fred Chasen 2013-03-25 13:07:19 -07:00
parent 2e2f801384
commit c99fb584db
9 changed files with 2896 additions and 18 deletions

68
fpjs/hooks/music.js Normal file
View file

@ -0,0 +1,68 @@
FP.Hooks.register("beforeChapterDisplay").music = function(callback, chapter){
var trans = chapter.doc.querySelectorAll('audio'),
items = Array.prototype.slice.call(trans),
playing = false;
items.forEach(function(item){
var onSpread = 0;
function getPage() {
left = item.getBoundingClientRect().left;
onSpread = Math.floor(left / chapter.spreadWidth) + 1; //-- pages start at 1
//console.log("left", left, onPage)
// width = orginal_width;
// height = orginal_height;
//
// if(width > chapter.colWidth){
// ratio = chapter.colWidth / width;
//
// width = chapter.colWidth;
// height = height * ratio;
// }
//
// iframe.width = width;
// iframe.height = height;
}
function shouldPlay(e) {
page = 1;
if(e) page = e.msg;
if(page != onSpread) return;
if(playing) playing.pause();
item.play();
playing = item;
console.log("start", item.src)
}
//-- resize event
chapter.book.listenUntil("book:resized", "book:chapterDestroy", getPage);
chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", shouldPlay);
item.removeAttribute("controls");
getPage();
shouldPlay();
});
if(callback) callback();
}