Coder Social home page Coder Social logo

hilltopmediadesign / bookreader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from internetarchive/bookreader

0.0 1.0 0.0 11.43 MB

The Internet Archive BookReader

Home Page: https://openlibrary.org/dev/docs/bookreader

License: GNU Affero General Public License v3.0

JavaScript 85.03% CSS 11.68% HTML 3.29%

bookreader's Introduction

Internet Archive BookReader

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 starting a simple web server in the root directory. For example:

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:

  • plugins.chapters.js - render chapter markers
  • plugins.search.js - add search ui, and callbacks
  • plugins.tts.js - add tts (read aloud) ui, sound library, and callbacks
  • plugins.url.js - automatically updates the browser url
  • plugins.resume.js - uses cookies to remember the current page
  • plugins.mobile_nav.js - adds responsive mobile nav to BookReader

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

At the time of writing, all of BookReader's JS codebase does not use any compilation. The source files are edited directly. However, the CSS is built with SCSS. Use npm run build to build the scss file.

The sass compiler will need to be installed.

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.

Contributing

Some notes for contributing:

  • Please try to follow the code style within the file (spacing/comments/etc).
  • Please only submit merge requests for features that would be useful for the general use
  • Please try to avoid adding new libraries
  • If the PR is a bug fix, include a link to a jsbin/codepen if possible
  • Please test the changes in desktop, mobile, and embed modes, and also on many different devices/browsers.

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.

bookreader's People

Contributors

mangtronix avatar rchrd2 avatar rajbot avatar anandology avatar nikolas avatar bfalling avatar stweil avatar ato avatar evanminto avatar jammycakes-ukpds avatar jbpressac avatar lmonson avatar appdev312 avatar hilltopmediadesign avatar shenzhuxi avatar yankl avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.