1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00
JS epub parser/reader
Find a file
2014-05-05 09:11:46 -07:00
books@950c742b3d updated pagination to give pageRange and anchorPage 2014-04-23 22:30:15 -07:00
build Added cfi to toc 2014-05-05 09:11:46 -07:00
documentation Updated readmes, added replace.js, added built libs 2013-07-23 09:23:55 -07:00
examples Removed use of finding element by position, added pageMaps to find locations by word 2014-04-29 21:55:35 -07:00
hooks fixed page rounding error, built 2014-04-03 22:40:50 -07:00
libs Updated CFI to use caretPositionFromPoint 2014-04-09 23:17:13 -07:00
reader Added cfi to toc 2014-05-05 09:11:46 -07:00
reader_src Update epubcfi use xpath when available and generation fixes 2014-04-09 10:54:01 -07:00
src Added cfi to toc 2014-05-05 09:11:46 -07:00
tests Update epubcfi use xpath when available and generation fixes 2014-04-09 10:54:01 -07:00
tools Update epubcfi use xpath when available and generation fixes 2014-04-09 10:54:01 -07:00
.gitignore Added books submod 2013-11-05 12:42:08 -08:00
.gitmodules updated submodules url for books 2013-11-17 00:05:24 -08:00
.jshintrc jshint fixes 2013-11-17 20:28:50 -08:00
.nojekyll Turned of Jekyll 2013-11-16 23:48:19 -08:00
Gruntfile.js Generated source maps, moved demo -> reader, reader_src 2014-04-01 12:50:55 -07:00
index.html updated readme 2014-04-01 14:07:12 -07:00
license Create license 2013-04-12 11:51:31 -07:00
package.json updated pagination to give pageRange and anchorPage 2014-04-23 22:30:15 -07:00
README.md Merged v2 with Master 2014-04-01 14:51:15 -07:00
server.js white space cleanup 2013-10-25 19:59:02 -07:00

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 its 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 zip.js

Also make sure to set EPUBJS.filePath to the directory containing inflate.js

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

<script>
    EPUBJS.filePath = "../build/libs/";
</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.

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

install the project dependences with npm

npm install

then you can run the reader locally with the command

node server.js
  • dev.html will pull from the source files and should be used during development.
  • index.html will use the minified production libraries in the build/ folder.

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

Building for Distribution

Builds are concatenated and minified using gruntjs

To generate a new build run

grunt

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

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.