Skip to content
Juan Corona edited this page Mar 19, 2015 · 9 revisions

Creating a plugin

Minimal template

define(['readium-plugins'], function (Plugins) {
  
    Plugins.register("pluginIdentifierHere", function (api) {
        //plugin implementation here
    });
});

Talking back to the plugin loader

define(['readium-plugins'], function (Plugins) {
  
    Plugins.register("pluginIdentifierHere", function (api) {
        api.plugin.warn('Something weird happened.')
        api.plugin.error('Something bad happened. Cancel initialization!')
    });
});

Hook on to Reader events

define(['readium-plugins'], function (Plugins) {
  
    Plugins.register("pluginIdentifierHere", function (api) {

        api.reader.on(ReadiumSDK.Events.CONTENT_DOCUMENT_LOADED, function ($iframe, spineItem) {
            var contentDoc = $iframe[0].contentDocument;
            contentDoc.body.style.backgroundColor = "red";
        });
    });
});

Provide your own API

define(['readium-plugins'], function(Plugins) {

    Plugins.register("pluginIdentifierHere", function(api) {
        this.sayHello = function() {
            alert('Hello world!');
        };

        api.extendReader(this);
    });
});

Your plugin interface can be accessed using reader.plugins.pluginIdentifierHere

Emit your own events

define(['readium-plugins'], function(Plugins) {

    Plugins.register("pluginIdentifierHere", function(api) {
        this.sayHello = function() {
            this.emit('hello', 'Hello world!');
        };

        // This is required to set up your event emitter on the reader,
        // even if you do not provide an API.
        api.extendReader(this);
    });
});

Including your plugin in Readium

  1. Add your plugin.js file inside the /plugins folder
  2. Open up
Clone this wiki locally