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
2017-11-06 11:39:14 -08:00
documentation/md Remove dist and html docs from git 2016-12-06 15:05:29 +01:00
examples Update toc nav subitem parsing 2017-10-31 18:27:26 -07:00
libs Add metatags for annotations 2017-07-06 17:53:48 -04:00
src Clean up pageList 2017-11-06 11:39:14 -08:00
test Use alice epub for section#find() tests 2017-06-16 20:51:56 -04:00
tools Updates to contents for Android, server update, jszip updated to 3.1.1 2016-08-19 10:47:28 +02:00
.babelrc Use es2015 for lib compile 2016-12-09 11:27:01 +01:00
.eslintrc.js Fix eslint errors 2016-12-08 01:08:39 +01:00
.gitignore Intial move to ES2015 2016-12-06 15:04:16 +01:00
.jshintrc Added webpack build, karma test runner, travis config 2016-10-26 17:05:27 +02:00
.nojekyll Turned of Jekyll 2013-11-16 23:48:19 -08:00
.npmignore Ignore .babelrc for npm 2016-12-09 13:19:01 +01:00
.travis.yml Clean up pageList 2017-11-06 11:39:14 -08:00
.watchmanconfig added polymer/url library 2016-11-15 15:21:56 +01:00
API.js Continuous and Paginate inherit from Rendition 2015-05-11 13:42:47 -04:00
bower.json Intial move to ES2015 2016-12-06 15:04:16 +01:00
documentation.yml Added pageList, initial documentation 2016-11-10 23:08:39 +01:00
gulpfile.js Added core Url and Path, split up book.open, added Container and Packaging 2016-11-08 02:06:10 +01:00
karma.conf.js Clean up pageList 2017-11-06 11:39:14 -08:00
license Add license file back, correct in package.json 2016-10-31 00:20:37 +01:00
package-lock.json Clean up pageList 2017-11-06 11:39:14 -08:00
package.json Clean up pageList 2017-11-06 11:39:14 -08:00
README.md updated to new JSZip api 2016-08-19 11:50:48 +02:00
webpack.config.js Include url-polyfill by default, fix linear default to yes 2017-07-03 14:16:32 -04:00
yarn.lock Allow using arrays in themes for @font-face 2017-06-15 11:08:16 -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>

If using archived .epub files include JSZip:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.1/jszip.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.