JavaScript

The JavaScript plugin introduces a common interface for the engine and other plugins to communicate with JavaScript, should the engine run in a browser. It provides two interfaces, one for itself, so that other plugins can access it, and one other plugins can implement so they can add themselves to the list of JavaScript aware plugins. All registered plugins will be notified when the JavaScript plugin's setting "jsenabled" is set to true.

All plugins should use this way when offering JavaScript functionality, to allow a common behavior and centralized way of controlling the use of JavaScript.

The Javascript interface defined and made availalble with js/megazine.js only works if


 * the javascript plugin is activated (listed in the 'plugins' attribute), and
 * MegaZine3 runs on a server (a 'real' or a local one like XAMP). If you call a local file directly in a browser, the book might show up, but the Javascript API will not work!

= Plugin interactions =

The JavaScript plugin registers a protocol with the Links plugin, if loaded. The registered protocol is  and can be used to run JavaScript code if the book is displayed using a browser. Example usage:

= Settings =

= Attributes =

This plugin handles no attributes.

= Examples =

Example showing the use of the Javascript API (functions defined in megazine.js): First an HTML 'div' block with id 'header is inserted above the book, with one paragraph (id #pgnum) which will be updated when a page is turned. The JS API is availbale after the book is initialized. When everything is ready, the API is available and the function defined as handler for onJSInit will be called. Here the handler for onPageChange is defined, which will be called during a page turn. That function provides the new and old page number as their 2 parameters. The first parameter (new page) is used to update the text in the #pgnum paragraph. All available functions can be found in the js/megazine.js class.