1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00

updated book / render events, polymer updates

This commit is contained in:
Fred Chasen 2013-07-17 18:12:52 -07:00
parent 3c2d0bb6bc
commit 61fa786325
19 changed files with 402 additions and 140 deletions

View file

@ -34,12 +34,11 @@ EPUBJS.Book = function(bookPath, options){
//-- All Book events for listening //-- All Book events for listening
/* /*
book:resized book:ready
book:stored book:stored
book:online book:online
book:offline book:offline
book:pageChanged book:pageChanged
book:chapterDisplayed
*/ */
//-- All hooks to add functions (with a callback) to //-- All hooks to add functions (with a callback) to
@ -69,6 +68,10 @@ EPUBJS.Book = function(bookPath, options){
}; };
this.ready.all = RSVP.all(_.values(this.ready)); this.ready.all = RSVP.all(_.values(this.ready));
this.ready.all.then(function(){
this.trigger("book:ready");
}.bind(this));
// BookUrl is optional, but if present start loading process // BookUrl is optional, but if present start loading process
if(bookPath) { if(bookPath) {
@ -465,6 +468,8 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){
//-- Set the book's spine position //-- Set the book's spine position
this.spinePos = pos; this.spinePos = pos;
//-- Create a new chapter //-- Create a new chapter
this.chapter = new EPUBJS.Chapter(this.spine[pos]); this.chapter = new EPUBJS.Chapter(this.spine[pos]);
@ -489,7 +494,7 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){
book.preloadNextChapter(); book.preloadNextChapter();
}); });
} }
return render; return render;
} }
@ -1534,6 +1539,13 @@ EPUBJS.Renderer = function(book) {
this.initialize(); this.initialize();
this.listeners(); this.listeners();
//-- Renderer events for listening
/*
renderer:resized
renderer:chapterDisplayed
renderer:chapterUnloaded
*/
} }
//-- Build up any html needed //-- Build up any html needed
@ -1546,7 +1558,7 @@ EPUBJS.Renderer.prototype.initialize = function(){
} else { } else {
this.resizeIframe(false, this.el.clientWidth, this.el.clientHeight); this.resizeIframe(false, this.el.clientWidth, this.el.clientHeight);
this.on("book:resized", this.resizeIframe, this); this.on("renderer:resized", this.resizeIframe, this);
} }
@ -1573,7 +1585,9 @@ EPUBJS.Renderer.prototype.chapter = function(chapter){
if(this.currentChapter) { if(this.currentChapter) {
this.currentChapter.unload(); this.currentChapter.unload();
this.trigger("book:chapterDestroyed");
this.trigger("renderer:chapterUnloaded");
this.book.trigger("renderer:chapterUnloaded");
} }
this.currentChapter = chapter; this.currentChapter = chapter;
@ -1615,10 +1629,13 @@ EPUBJS.Renderer.prototype.hideHashChanges = function(){
EPUBJS.Renderer.prototype.onResized = function(){ EPUBJS.Renderer.prototype.onResized = function(){
this.trigger("book:resized", { var msg = {
width: this.el.clientWidth, width: this.el.clientWidth,
height: this.el.clientHeight height: this.el.clientHeight
}); };
this.trigger("renderer:resized", msg);
this.book.trigger("book:resized", msg);
this.reformat(); this.reformat();
} }
@ -1722,7 +1739,8 @@ EPUBJS.Renderer.prototype.setIframeSrc = function(url){
renderer.currentLocationCfi = renderer.getPageCfi(); renderer.currentLocationCfi = renderer.getPageCfi();
renderer.trigger("book:chapterDisplayed"); renderer.trigger("renderer:chapterDisplayed");
renderer.book.trigger("renderer:chapterDisplayed");
renderer.visible(true); renderer.visible(true);
@ -1878,7 +1896,7 @@ EPUBJS.Renderer.prototype.nextPage = function(){
this.currentLocationCfi = this.getPageCfi(); this.currentLocationCfi = this.getPageCfi();
this.trigger("book:pageChanged", this.currentLocationCfi); this.book.trigger("book:pageChanged", this.currentLocationCfi);
return this.chapterPos; return this.chapterPos;
@ -1897,7 +1915,7 @@ EPUBJS.Renderer.prototype.prevPage = function(){
this.currentLocationCfi = this.getPageCfi(); this.currentLocationCfi = this.getPageCfi();
this.trigger("book:pageChanged", this.currentLocationCfi); this.book.trigger("book:pageChanged", this.currentLocationCfi);
return this.chapterPos; return this.chapterPos;
}else{ }else{

4
build/epub.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -196,11 +196,11 @@ EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, c
item.addEventListener('load', size, false); item.addEventListener('load', size, false);
chapter.on("book:resized", size); chapter.on("renderer:resized", size);
chapter.on("book:chapterDestroyed", function(){ chapter.on("renderer:chapterUnloaded", function(){
item.removeEventListener('load', size); item.removeEventListener('load', size);
chapter.off("book:resized", size); chapter.off("renderer:resized", size);
}); });
size(); size();

4
demo/js/epub.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.doc.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g={};EPUBJS.core.addCss("../demo/css/popup.css",!1,b.doc.head),d.forEach(function(a){function c(){var c,e=b.iframe.height,f=b.iframe.width,j=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),g[k]||(g[k]=document.createElement("div"),g[k].setAttribute("class","popup"),pop_content=document.createElement("div"),g[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),b.bodyEl.appendChild(g[k]),g[k].addEventListener("mouseover",d,!1),g[k].addEventListener("mouseout",h,!1),b.book.on("book:pageChanged",i,this),b.book.on("book:pageChanged",h,this)),c=g[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){g[k].classList.add("on")}function h(){g[k].classList.remove("on")}function i(){setTimeout(function(){g[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.doc.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",i,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.doc.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.height();d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f;e=b.height(),0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g,a.style.maxHeight=c+"px",a.style.width="auto"):(i=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto"),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("book:resized",c),b.on("book:chapterDestroyed",function(){a.removeEventListener("load",c),b.off("book:resized",c)}),c()}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.doc.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>b.colWidth&&(d=b.colWidth/j,j=b.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.book.listenUntil("book:resized","book:chapterDestroy",c),f.src=e,i.replaceChild(f,a)}),a&&a()}; EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.doc.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g={};EPUBJS.core.addCss("../demo/css/popup.css",!1,b.doc.head),d.forEach(function(a){function c(){var c,e=b.iframe.height,f=b.iframe.width,j=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),g[k]||(g[k]=document.createElement("div"),g[k].setAttribute("class","popup"),pop_content=document.createElement("div"),g[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),b.bodyEl.appendChild(g[k]),g[k].addEventListener("mouseover",d,!1),g[k].addEventListener("mouseout",h,!1),b.book.on("book:pageChanged",i,this),b.book.on("book:pageChanged",h,this)),c=g[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){g[k].classList.add("on")}function h(){g[k].classList.remove("on")}function i(){setTimeout(function(){g[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.doc.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",i,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.doc.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.height();d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f;e=b.height(),0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g,a.style.maxHeight=c+"px",a.style.width="auto"):(i=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto"),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.doc.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>b.colWidth&&(d=b.colWidth/j,j=b.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.book.listenUntil("book:resized","book:chapterDestroy",c),f.src=e,i.replaceChild(f,a)}),a&&a()};

View file

@ -36,7 +36,7 @@
box-shadow: 0px 5px 10px rgba(0,0,0,.1); box-shadow: 0px 5px 10px rgba(0,0,0,.1);
} }
epub iframe { epub-reader iframe {
border: none; border: none;
padding: 40px 40px; padding: 40px 40px;
} }

View file

@ -0,0 +1,18 @@
<polymer-element name="epub-controls" attributes="items">
<template>
<div id="controls">
<a id="network"><img id="store" src="../../demo/img/save.png" save="../../demo/img/save.png" data-saved="../../demo/img/saved.png"></a>
<a id="setting"><img id="settings" src="../../demo/img/settings.png"></a>
<a id="bookmark"><img id="bookmarks" src="../../demo/img/star.png"></a>
</div>
</template>
<script>
Polymer('epub-controls', {
ready: function() {
}
});
</script>
</polymer-element>

View file

@ -0,0 +1,84 @@
<script src="/build/epub.min.js"></script>
<script type="text/javascript">
//-- Setups
</script>
<polymer-element name="epub-js" attributes="src width height restore spreads">
<template>
<style>
@host {
* {
display: block;
}
}
#area {
width: 100%;
height: 100%;
}
iframe {
border: none;
}
</style>
<div id="area"></div>
</template>
<script>
Polymer('epub-js', {
src: '',
ready: function() {
},
prevPage: function() {
if (this.Book) this.Book.prevPage();
},
nextPage: function() {
if (this.Book) this.Book.nextPage();
},
srcChanged: function() {
var src = this.src,
width = this.width || false,
height = this.height || false,
spreads = this.spreads != null ? true : false,
restore = this.restore != null ? true : false;
if(this.Book) this.Book.destroy();
this.Book = new EPUBJS.Book(src, {
width: width,
height: height,
spreads : spreads,
restore : restore
});
this.events();
this.Book.renderTo(this.$.area);
},
events: function() {
var element = this;
var ready = new CustomEvent('book-ready', { "bubbles" : true, "cancelable" : true }),
displayed = new CustomEvent('book-displayed', { "bubbles" : true, "cancelable" : true }),
unloaded = new CustomEvent('book-unloaded', { "bubbles" : true, "cancelable" : true });
this.Book.on("book:ready", function() {
element.dispatchEvent(ready);
});
this.Book.on("renderer:chapterDisplayed", function() {
element.dispatchEvent(displayed);
});
this.Book.on("renderer:chapterUnloaded", function() {
element.dispatchEvent(unloaded);
});
},
hi: function(){
console.log("confused")
}
});
</script>
</polymer-element>

View file

@ -1,53 +1,30 @@
<polymer-element name="epub-reader" on-keyup="keyup" attributes="src"> <link rel="import" href="epub-sidebar.html">
<link rel="import" href="epub-titlebar.html">
<link rel="import" href="epub-viewer.html">
<polymer-element name="epub-reader" attributes="src">
<template> <template>
<link rel="stylesheet" href="../../demo/css/main.css"> <link rel="stylesheet" href="../../demo/css/main.css">
<link rel="stylesheet" href="../../demo/css/popup.css"> <link rel="stylesheet" href="../../demo/css/popup.css">
<style>
@host {
}
epub-viewer {
width: 80%;
height: 80%;
margin: 0 auto;
max-width: 1250px;
}
</style>
<div id="sidebar"> <epub-sidebar></epub-sidebar>
<div id="controls">
<a id="network"><img id="store" src="../../demo/img/save.png" save="../../demo/img/save.png" data-saved="../../demo/img/saved.png"></a>
<a id="setting"><img id="settings" src="../../demo/img/settings.png"></a>
<a id="bookmark"><img id="bookmarks" src="../../demo/img/star.png"></a>
</div>
<div id="toc">
<ul>
<template id="tocTemplate" repeat="{{ toc }}">
<li id="toc-{{ id }}">
<a href="{{ href }}" class="toc_link{{ type }}">{{ label }}</a>
<ul>
<template ref="tocTemplate" repeat="{{ subitems }}"></template>
</ul>
<li>
</template>
</ul>
</div>
<div id="settingsPanel">
</div>
</div>
<div id="main"> <div id="main">
<div id="opener"> <epub-titlebar></epub-titlebar>
<a id="open"><img src="../../demo/img/menu-icon.png" data-close="../../demo/img/close.png" data-open="../../demo/img/menu-icon.png"></a> <epub-viewer on-book-ready="bookReady" src="{{src}}"></epub-viewer>
</div>
<div id="titlebar">
<span id="book-title"></span>
<span id="title-seperator">&nbsp;&nbsp;&nbsp;&nbsp;</span>
<span id="chapter-title"> </span>
</div>
<div id="divider"></div>
<div id="prev" onclick="Book.prevPage();" class="arrow"></div>
<epub src="/demo/moby-dick/" width="400" height="600"></epub>
<div id="next" onclick="Book.nextPage();"class="arrow"></div>
<div id="loader"><img src="../../demo/img/loader.gif"></div>
</div> </div>
</template> </template>
@ -57,37 +34,11 @@
src: '', src: '',
ready: function() { ready: function() {
// var Book = new EPUBJS.Book("/demo/moby-dick/", { restore: true, reload: true }); },
bookReady: function(){
// Book.getMetadata().then(function(meta){ console.log("book is ready")
// document.title = meta.bookTitle+" "+meta.creator;
// });
// Book.getToc().then(function(toc){
// var $select = document.getElementById("toc");
// var $template = document.getElementById("tocTemplate");
// $template.model = { toc: toc };
// $select.onchange = function(){
// var index = $select.selectedIndex,
// url = $select.options[index].getAttribute('ref');
// Book.goto(url);
// return false;
// }
// });
// Book.ready.all.then(function(){
// document.getElementById("loader").style.display = "none";
// });
// Book.renderTo("area");
} }
}); });
</script> </script>

View file

@ -0,0 +1,16 @@
<polymer-element name="epub-settings" attributes="items">
<template>
<div id="settings">
</div>
</template>
<script>
Polymer('epub-settings', {
ready: function() {
}
});
</script>
</polymer-element>

View file

@ -0,0 +1,22 @@
<link rel="import" href="epub-controls.html">
<link rel="import" href="epub-settings.html">
<link rel="import" href="epub-toc.html">
<polymer-element name="epub-sidebar" attributes="items">
<template>
<div id="sidebar">
<epub-controls></epub-controls>
<epub-toc items="{{ toc }}"></epub-toc>
<epub-setting></epub-setting>
</div>
</template>
<script>
Polymer('epub-controls', {
ready: function() {
}
});
</script>
</polymer-element>

View file

@ -0,0 +1,22 @@
<polymer-element name="epub-titlebar" attributes="items">
<template>
<div id="opener">
<a id="open"><img src="../../demo/img/menu-icon.png" data-close="../../demo/img/close.png" data-open="../../demo/img/menu-icon.png"></a>
</div>
<div id="titlebar">
<span id="book-title"></span>
<span id="title-seperator">&nbsp;&nbsp;&nbsp;&nbsp;</span>
<span id="chapter-title"> </span>
</div>
</template>
<script>
Polymer('epub-settings', {
ready: function() {
}
});
</script>
</polymer-element>

View file

@ -0,0 +1,30 @@
<polymer-element name="epub-toc" attributes="items">
<template>
<div id="toc">
<ul>
<template id="tocTemplate" repeat="{{ toc }}">
<li id="toc-{{ id }}">
<a href="{{ href }}" class="toc_link{{ type }}">{{ label }}</a>
<ul>
<template ref="tocTemplate" repeat="{{ subitems }}"></template>
</ul>
<li>
</template>
</ul>
</div>
</div>
</template>
<script>
Polymer('epub-toc', {
src: '',
ready: function() {
}
});
</script>
</polymer-element>

View file

@ -0,0 +1,115 @@
<link rel="import" href="epub-js.html">
<polymer-element name="epub-viewer" attributes="src">
<template>
<style>
@host {
* {
display: block;
}
}
epub-js {
width: 100%;
height: 100%;
}
#prev {
left: 40px;
}
#next {
right: 40px;
}
.arrow {
position: absolute;
top: 50%;
font-size: 64px;
color: #E2E2E2;
font-family: arial, sans-serif;
font-weight: bold;
cursor: pointer;
}
.arrow:hover {
color: #777;
}
.arrow:active {
color: #000;
}
#divider {
position: absolute;
width: 1px;
border-right: 1px #000 solid;
height: 80%;
z-index: 1;
left: 50%;
top: 10%;
opacity: .15;
box-shadow: -2px 0 15px rgba(0, 0, 0, 1);
display: none;
}
#divider.show {
display: block;
}
#loader {
position: absolute;
z-index: 10;
left: 50%;
top: 50%;
margin: -33px 0 0 -33px;
}
</style>
<div id="divider"></div>
<div id="prev" on-click="prev" class="arrow"></div>
<epub-js id="book" src="{{ src }}" restore spreads
on-book-ready="bookReady"
on-book-displayed="bookDisplayed"
on-book-unloaded="bookUnloaded"
></epub-js>
<div id="next" on-click="next" class="arrow"></div>
<div id="loader"><img src="../../demo/img/loader.gif"></div>
</template>
<script>
Polymer('epub-viewer', {
src: '',
ready: function() {
// this.$.book.addEventListener("ready", this.bookReady.bind(this), false);
// this.$.book.addEventListener("bookDisplayed", this.bookDisplayed.bind(this), false);
// this.$.book.addEventListener("bookUnloaded", this.bookUnloaded.bind(this), false);
},
prev: function() {
this.$.book.prevPage();
},
next: function() {
this.$.book.nextPage();
},
bookReady: function () {
this.$.loader.style.display = "none";
},
bookDisplayed: function () {
this.$.divider.style.display = "block";
},
bookUnloaded: function () {
this.$.divider.style.display = "none";
},
srcChanged: function() {
//-- change epub src
}
});
</script>
</polymer-element>

View file

@ -1,27 +0,0 @@
<polymer-element name="epub" attributes="src">
<script>
Polymer('epub', {
src: '',
ready: function() {
var src = this.getAttribute("src"),
width = this.getAttribute("width") || false,
height = this.getAttribute("height") || false,
spreads = this.getAttribute("spreads") != null ? true : false,
restore = this.getAttribute("restore") != null ? true : false;
var Book = new EPUBJS.Book(src, {
width: width,
height: height,
spreads : spreads,
restore : restore
});
Book.renderTo(this);
}
});
</script>
</polymer-element>

View file

@ -1,18 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<!--
Copyright 2013 The Polymer Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<html> <html>
<head> <head>
<title>Polymer EpubJS</title> <title>Polymer EpubJS</title>
<meta charset="UTF-8"> <meta charset="UTF-8">
<script src="../../libs/polymer/polymer.min.js"></script> <script src="../../libs/polymer/polymer.min.js"></script>
<script src="/build/epub.min.js"></script>
<link rel="import" href="epub-reader.html"> <link rel="import" href="epub-reader.html">
<link rel="import" href="epub.html">
<link rel="stylesheet" href="../../demo/css/normalize.css"> <link rel="stylesheet" href="../../demo/css/normalize.css">
<style> <style>
@ -20,6 +15,6 @@ license that can be found in the LICENSE file.
</style> </style>
</head> </head>
<body> <body>
<epub-reader id="reader"></epub-reader> <epub-reader id="reader" src="/demo/moby-dick/"></epub-reader>
</body> </body>
</html> </html>

View file

@ -40,11 +40,11 @@ EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, c
item.addEventListener('load', size, false); item.addEventListener('load', size, false);
chapter.on("book:resized", size); chapter.on("renderer:resized", size);
chapter.on("book:chapterDestroyed", function(){ chapter.on("renderer:chapterUnloaded", function(){
item.removeEventListener('load', size); item.removeEventListener('load', size);
chapter.off("book:resized", size); chapter.off("renderer:resized", size);
}); });
size(); size();

View file

@ -26,12 +26,11 @@ EPUBJS.Book = function(bookPath, options){
//-- All Book events for listening //-- All Book events for listening
/* /*
book:resized book:ready
book:stored book:stored
book:online book:online
book:offline book:offline
book:pageChanged book:pageChanged
book:chapterDisplayed
*/ */
//-- All hooks to add functions (with a callback) to //-- All hooks to add functions (with a callback) to
@ -61,6 +60,10 @@ EPUBJS.Book = function(bookPath, options){
}; };
this.ready.all = RSVP.all(_.values(this.ready)); this.ready.all = RSVP.all(_.values(this.ready));
this.ready.all.then(function(){
this.trigger("book:ready");
}.bind(this));
// BookUrl is optional, but if present start loading process // BookUrl is optional, but if present start loading process
if(bookPath) { if(bookPath) {
@ -457,6 +460,8 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){
//-- Set the book's spine position //-- Set the book's spine position
this.spinePos = pos; this.spinePos = pos;
//-- Create a new chapter //-- Create a new chapter
this.chapter = new EPUBJS.Chapter(this.spine[pos]); this.chapter = new EPUBJS.Chapter(this.spine[pos]);
@ -481,7 +486,7 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){
book.preloadNextChapter(); book.preloadNextChapter();
}); });
} }
return render; return render;
} }

View file

@ -16,6 +16,13 @@ EPUBJS.Renderer = function(book) {
this.initialize(); this.initialize();
this.listeners(); this.listeners();
//-- Renderer events for listening
/*
renderer:resized
renderer:chapterDisplayed
renderer:chapterUnloaded
*/
} }
//-- Build up any html needed //-- Build up any html needed
@ -28,7 +35,7 @@ EPUBJS.Renderer.prototype.initialize = function(){
} else { } else {
this.resizeIframe(false, this.el.clientWidth, this.el.clientHeight); this.resizeIframe(false, this.el.clientWidth, this.el.clientHeight);
this.on("book:resized", this.resizeIframe, this); this.on("renderer:resized", this.resizeIframe, this);
} }
@ -55,7 +62,9 @@ EPUBJS.Renderer.prototype.chapter = function(chapter){
if(this.currentChapter) { if(this.currentChapter) {
this.currentChapter.unload(); this.currentChapter.unload();
this.trigger("book:chapterDestroyed");
this.trigger("renderer:chapterUnloaded");
this.book.trigger("renderer:chapterUnloaded");
} }
this.currentChapter = chapter; this.currentChapter = chapter;
@ -97,10 +106,13 @@ EPUBJS.Renderer.prototype.hideHashChanges = function(){
EPUBJS.Renderer.prototype.onResized = function(){ EPUBJS.Renderer.prototype.onResized = function(){
this.trigger("book:resized", { var msg = {
width: this.el.clientWidth, width: this.el.clientWidth,
height: this.el.clientHeight height: this.el.clientHeight
}); };
this.trigger("renderer:resized", msg);
this.book.trigger("book:resized", msg);
this.reformat(); this.reformat();
} }
@ -204,7 +216,8 @@ EPUBJS.Renderer.prototype.setIframeSrc = function(url){
renderer.currentLocationCfi = renderer.getPageCfi(); renderer.currentLocationCfi = renderer.getPageCfi();
renderer.trigger("book:chapterDisplayed"); renderer.trigger("renderer:chapterDisplayed");
renderer.book.trigger("renderer:chapterDisplayed");
renderer.visible(true); renderer.visible(true);
@ -360,7 +373,7 @@ EPUBJS.Renderer.prototype.nextPage = function(){
this.currentLocationCfi = this.getPageCfi(); this.currentLocationCfi = this.getPageCfi();
this.trigger("book:pageChanged", this.currentLocationCfi); this.book.trigger("book:pageChanged", this.currentLocationCfi);
return this.chapterPos; return this.chapterPos;
@ -379,7 +392,7 @@ EPUBJS.Renderer.prototype.prevPage = function(){
this.currentLocationCfi = this.getPageCfi(); this.currentLocationCfi = this.getPageCfi();
this.trigger("book:pageChanged", this.currentLocationCfi); this.book.trigger("book:pageChanged", this.currentLocationCfi);
return this.chapterPos; return this.chapterPos;
}else{ }else{