Enhanced eBooks in the browser.
HTML JavaScript CSS
Latest commit 3515978 Mar 21, 2017 @fchasen fchasen committed on GitHub Merge pull request #577 from futurepress/fix_prepaginated_regex
Fix isFixedLayout check
Permalink
Failed to load latest commit information.
books @ 8d6c46e update umd, remove sourcemap for min file Feb 16, 2016
build Updated pre-paginated regex check to only return true if width and he… Mar 21, 2017
documentation Added some stuff to documentation (#501) Dec 12, 2016
examples Remove underscore in pagination example Nov 30, 2016
hooks Fix smartimages in ie Dec 11, 2015
libs Generic ncx mimetype so that it will be parse as xml, fixes #345 Dec 3, 2015
reader Updated pre-paginated regex check to only return true if width and he… Mar 21, 2017
reader_src Generic ncx mimetype so that it will be parse as xml, fixes #345 Dec 3, 2015
src Updated pre-paginated regex check to only return true if width and he… Mar 21, 2017
tests replaced zip.js with JSZip Dec 5, 2014
tools Update epubcfi use xpath when available and generation fixes Apr 9, 2014
.gitignore Added back build folder for now, updated readme with Gitter Sep 1, 2015
.gitmodules updated submodules url for books Nov 17, 2013
.jshintrc jshint fixes Nov 18, 2013
.nojekyll Turned of Jekyll Nov 17, 2013
Gruntfile.js update umd, remove sourcemap for min file Feb 16, 2016
README.md Added back build folder for now, updated readme with Gitter Sep 1, 2015
bower.json Cleared out libs folder, use npm install or bower install instead. Cl… Sep 16, 2015
index.html fix index.html internal style sheet Oct 29, 2015
license Create license Apr 12, 2013
package.json Updated pre-paginated regex check to only return true if width and he… Mar 21, 2017
server.js [server] Ædd shebang and execution permission Jul 26, 2014

README.md

Epub.js

FuturePress Views

Epub.js is a JavaScript library for rendering ePub documents in the browser, across many devices.

Epub.js provides an interface for common ebook functions (such as rendering, persistence and pagination) without the need to develop a dedicated application or plugin. Importantly, it has an incredibly permissive Free BSD license.

Try it while reading Moby Dick

Why EPUB

Why EPUB

The EPUB standard is a widely used and easily convertible format. Many books are currently in this format, and it is convertible to many other formats (such as PDF, Mobi and iBooks).

An unzipped ePUB3 is a collection of HTML5 files, CSS, images and other media – just like any other website. However, it enforces a schema of book components, which allows us to render a book and its parts based on a controlled vocabulary.

More specifically, the ePUB schema standardizes the table of contents, provides a manifest that enables the caching of the entire book, and separates the storage of the content from how it’s displayed.

Getting Started

Get the minified code from the build folder:

<script src="../build/epub.min.js"></script>

If you plan on using compressed (zipped) epubs (any .epub file) include the minified version of JSZip.js which can be found in build/libs

<!-- Zip JS -->
<script src="/build/libs/zip.min.js"></script>

Setup a element to render to:

<div onclick="Book.prevPage();">‹</div>
<div id="area"></div>
<div onclick="Book.nextPage();">›</div>

Create the new ePub, and then render it to that element:

<script>
	var Book = ePub("url/to/book/");
	Book.renderTo("area");
</script>

See the Documentation to view events and methods for getting the books contents.

The Examples are likely the best place to learn how to use the library.

Internet Explorer

Compatibility with IE is best with wicked-good-xpath, a Google-authored pure JavaScript implementation of the DOM Level 3 XPath specification (but not required). More info at https://code.google.com/p/wicked-good-xpath/

You can download the latest wgxpath here or from the examples folder.

<script src="/examples/wgxpath.install.js"></script>

Then install wgxpath via a hook like the one below:

EPUBJS.Hooks.register("beforeChapterDisplay").wgxpath = function(callback, renderer){

  wgxpath.install(renderer.render.window);

  if(callback) callback();
};

wgxpath.install(window);

There are currently a number of open issues for Internet Explorer any help addressing them would be greatly appreciated.

Recent Updates

  • v2 splits the render method from the layout and renderer. Currently only iframe rendering is supported, but this change will allow for new render methods in the future. See the breaking changes to the renderer here.

  • Work-in-progress pagination support using EPUB page-lists. See a usage example. renderer:pageChanged has changed to renderer:locationChanged and a book:pageChanged event was added to pass pagination events.

  • Moved Demo Reader to /reader/ and the source to /reader_src/.

  • Updated CFI handling to support text offsets. CFIs return wrapped like: "epubcfi(/6/12[xepigraph_001]!4/2/28/2/1:0)". Ranges to be added soon.

  • Added support for EPUB properties. This can be overridden in the settings and default to {spread: 'reflowable', layout: 'auto', orientation: 'auto'}

  • Updated Documentation

  • Many more Tests

Running Locally

Install node.js

Then install the project dependences with npm

npm install

You can run the reader locally with the command

node server.js

Builds are concatenated and minified using gruntjs

To generate a new build run

grunt

Or, to generate builds as you make changes run

grunt watch

Examples

View All Examples

Testing

Once you start a server you can run the QUnit tests at http://localhost:8080/tests/

You can download the test books from https://github.com/futurepress/books by running:

git submodule update --init --recursive

Then you can pull the latest with:

git submodule foreach git pull origin master

Hooks

Similar to a plugins, Epub.js implements events that can be "hooked" into. Thus you can interact with and manipulate the contents of the book.

Examples of this functionality is loading videos from YouTube links before displaying a chapters contents or implementing annotation.

Hooks require a event to latch onto and a callback for when they are finished.

Example hook:

EPUBJS.Hooks.register("beforeChapterDisplay").example = function(callback, renderer){

    var elements = render.doc.querySelectorAll('[video]'),
        items = Array.prototype.slice.call(elements);

    items.forEach(function(item){
      //-- do something with the video item
    }

    if(callback) callback();

}

Additional Resources

Gitter Chat

Epub.js Developer Mailing List

IRC Server: freenode.net Channel: #epub.js

Follow us on twitter: @Epubjs

Other

EPUB is a registered trademark of the IDPF.