-
Notifications
You must be signed in to change notification settings - Fork 101
Plugins
Juan Corona edited this page Mar 19, 2015
·
9 revisions
define(['readium-plugins'], function (Plugins) {
Plugins.register("pluginIdentifierHere", function (api) {
//plugin implementation here
});
});
define(['readium-plugins'], function (Plugins) {
Plugins.register("pluginIdentifierHere", function (api) {
api.plugin.warn('Something weird happened.')
api.plugin.error('Something bad happened! This will be fatal.')
});
});
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";
});
});
});
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
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);
});
});
- Add your plugin.js file inside the
readium-shared-js/plugins
folder - Open up
_loader.js
and include your plugin's require call:require(['readium-plugins/myPlugin']);
- Depending on how you are using Readium, you may need to invoke the grunt task to rebuild the aggregated Readium.js library file to include your plugin during "compile time"
You can include default and overridable configuration options in your plugins using this method:
define(['readium-plugins'], function(Plugins) {
var config = {
backgroundColor: "yellow"
};
Plugins.register("changeBackground", function(api) {
api.reader.on(ReadiumSDK.Events.CONTENT_DOCUMENT_LOADED, function($iframe, spineItem) {
var contentDoc = $iframe[0].contentDocument;
contentDoc.body.style.backgroundColor = config.backgroundColor;
});
});
});
In _loader.js
:
require(['readium-plugins/changeBackground'], function (config) {
config.backgroundColor = "red";
});
By default if the plugin is not configured in _loader.js
(require(['readium-plugins/changeBackground']);
) the background color used will be yellow
if the value is set in _loader.js
like shown above it will be red
.