1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-02 14:49:16 +02:00
JS epub parser/reader
Find a file
2016-01-02 23:42:35 -05:00
books@ab9755a747 Handle misses in epubcfi 2015-12-23 15:38:01 -08:00
dist ignore working for simple highlights 2016-01-02 23:42:35 -05:00
examples ignore working for simple highlights 2016-01-02 23:42:35 -05:00
libs Updated coverUrl 2015-12-04 18:10:50 -05:00
src ignore working for simple highlights 2016-01-02 23:42:35 -05:00
test ignore working for simple highlights 2016-01-02 23:42:35 -05:00
tools tidy up serve tool, adds 'gulp serve' task 2015-02-16 14:12:33 -05:00
.gitignore inital setup/cleaning for v3 2014-07-23 13:31:34 -04: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
API.js Continuous and Paginate inherit from Rendition 2015-05-11 13:42:47 -04:00
bower.json expand views multiple times, infinite offset set to pageWidth 2014-10-30 09:45:51 -04:00
gulpfile.js ignore working for simple highlights 2016-01-02 23:42:35 -05:00
package.json ignore working for simple highlights 2016-01-02 23:42:35 -05:00
README.md Fixed single example, added example links to readme 2015-05-11 14:15:35 -04:00

Epub.js v0.3

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="../dist/epub.min.js"></script>

Setup a element to render to:

<div id="area"></div>

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

<script>
  var book = ePub("url/to/book/package.opf");
  var rendition = book.renderTo("area", {width: 600, height: 400});
  var displayed = rendition.display();
</script>

Render Methods

Single: book.renderTo("area");

View example

Continuous: book.renderTo("area", { method: "continuous", width: "100%", height: "100%" });

View example

Paginate: book.renderTo("area", { method: "paginate", width: "900", height: "600" });

View example

Documentation

Work in progress documentation at API.js

Running Locally

install node.js

install the project dependences with npm

npm install

then you can run the reader locally with the command

./tools/serve

install bower

bower install

Examples

See examples folder

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 gulp

To generate a new build run

gulp

or to continuously build run

gulp watch

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.