bookreader

The Internet Archive BookReader

Github星跟蹤圖

Internet Archive BookReader

Build Status codecov

The Internet Archive BookReader is used to view books from the Internet Archive online and can also be used to view other books.

See live examples:

Demos

See BookReaderDemo directory. These can be tested by building the source files (make sure Node.js is installed):

npm run build

and starting a simple web server in the root directory:

python -m SimpleHTTPServer

Or for Python 3:

python3 -m http.server

And then open http://localhost:8000/BookReaderDemo/demo-simple.html.

Usage

Here is a short example.

// Create the BookReader object
var options = {
  data: [
    [
      { width: 800, height: 1200,
        uri: '//archive.org/download/BookReader/img/page001.jpg' },
    ],
    [
      { width: 800, height: 1200,
        uri: '//archive.org/download/BookReader/img/page002.jpg' },
      { width: 800, height: 1200,
        uri: '//archive.org/download/BookReader/img/page003.jpg' },
    ],
    [
      { width: 800, height: 1200,
        uri: '//archive.org/download/BookReader/img/page004.jpg' },
      { width: 800, height: 1200,
        uri: '//archive.org/download/BookReader/img/page005.jpg' },
    ]
  ],

  bookTitle: 'Simple BookReader Presentation',

  // thumbnail is optional, but it is used in the info dialog
  thumbnail: '//archive.org/download/BookReader/img/page014.jpg',

  // Metadata is optional, but it is used in the info dialog
  metadata: [
    {label: 'Title', value: 'Open Library BookReader Presentation'},
    {label: 'Author', value: 'Internet Archive'},
    {label: 'Demo Info', value: 'This demo shows how one could use BookReader with their own content.'},
  ],

  ui: 'full', // embed, full (responsive)

};
var br = new BookReader(options);

// Let's go!
br.init();

See BookReaderDemo/demo-simple.html and BookReaderDemo/BookReaderJSSimple.js for a full example. The best way to learn how to use BookReader is to view the source of the demos.

Properties

  • TODO (for now see BookReader.js and BookReader function at approx. line 44)

Plugins

A basic plugin system is used. See the examples in the plugins directory. The general idea is that they are mixins that augment the BookReader prototype. See the plugins directory for all the included plugins, but here are some examples:

  • plugin.autoplay.js - autoplay mode. Flips pages at set intervals.
  • plugin.chapters.js - render chapter markers
  • plugin.search.js - add search ui, and callbacks
  • plugin.tts.js - add tts (read aloud) ui, sound library, and callbacks
  • plugin.url.js - automatically updates the browser url
  • plugin.resume.js - uses cookies to remember the current page
  • plugin.mobile_nav.js - adds responsive mobile nav to BookReader
  • plugin.vendor-fullscreen.js - replaces fullscreen mode with vendor native fullscreen

Embedding

BookReader can be embedded within an <iframe>. If you use the IFrame Plugin inside the <iframe>, the reader will send notifications about changes in the state of the reader via window.postMessage(). The parent window can send messages of its own (also via window.postMessage()) and the IFrame Plugin will handle updating the reader to match.

Message Events

Fragment Change

The Fragment Change message is sent to the parent window when the embedded BookReader moves between pages/modes. When the <iframe> receives this message, it moves to the specified page/mode. The “fragment” is formatted in accordance with the BookReader URL spec.

{
  "type": "bookReaderFragmentChange",
  "fragment": "page/n1/mode/2up"
}

Development

The source JavaScript is written in ES6 (located in the src/js directory) and in ES5 (located in BookReader). To build the JS run npx webpack (npx webpack --watch will auto-build when the files are saved). To build the CSS and the JS, use npm run build.

Releases

To version bump the repo and prepare a release, run npm version major, minor, patch (following semver), then (something like) git push origin HEAD --tags. It'll automatically update the version number where it appears.

Tests

Tests use QUnit. To run all tests, start up an HTTP server at the root of the project and navigate to /tests/qunit.html in a browser.

To add a new test, create a file in the tests/ directory with the format test-name-of-my-test.js and add it as a <script> tag in qunit.html.

More info

Developer documentation:
https://openlibrary.org/dev/docs/bookreader

Hosted source code:
https://github.com/internetarchive/bookreader

IIIF (http://iiif.io)
See BookReaderDemo/demo-iiif.html to see an example of how to load a IIIF manifest in BookReader.

Target Devices

Note that BookReader is a core part of Archive.org's mission of Universal Access to All Knowledge. Therefore, care must be taken to support legacy browsers. It should still work and be useable on old devices.

Areas for improvement

  • Change libraries to be NPM dependencies rather than included in the source code

See CHANGELOG.md for history of the project.

License

The source code license is AGPL v3, as described in the LICENSE file.

The mobile menu is built with mmenu, which is free for personal and non-profit use. However, for commmercial use, a license must be purchased.

To use it, include the script plugins/plugin.mobile_nav.js.

Other credits

The ability to test on multiple devices is provided courtesy of Browser Stack.

主要指標

概覽
名稱與所有者internetarchive/bookreader
主編程語言JavaScript
編程語言CSS (語言數: 4)
平台
許可證GNU Affero General Public License v3.0
所有者活动
創建於2008-11-06 04:29:36
推送於2025-05-06 17:21:26
最后一次提交2025-04-30 18:46:23
發布數199
最新版本名稱v5.0.0-96 (發布於 )
第一版名稱0.9.1 (發布於 2009-04-01 22:26:05)
用户参与
星數1k
關注者數43
派生數438
提交數3.1k
已啟用問題?
問題數327
打開的問題數129
拉請求數695
打開的拉請求數98
關閉的拉請求數277
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?