JavaScript

From MegaZine3
Jump to: navigation, search
Plugin: JavaScript
Name JavaScript
Files
  • javascript.swf
Related plugins

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

Contents

Plugin interactions

The JavaScript plugin registers a protocol with the Links plugin, if loaded. The registered protocol is javascript: and can be used to run JavaScript code if the book is displayed using a browser. Example usage:
<element url="javascript:alert('test');"/>

Settings

jsenabled

This setting can be used to globally enable or disable JavaScript interaction of the book. As all plugins should use this plugin for registering and enabling JavaScript functionality, this will control the use of any JavaScript use at all, meaning if set to false it can be guaranteed (when using "nice" plugins) that there will indeed be no JavaScript interaction used.

Attributes

This plugin handles no attributes.

Examples

<book plugins="javascript,swfaddress,links">
    <chapter>
        <page>
            <img src="test.jpg" url="javascript:alert('Hello World!');"/>
        </page>
        <!-- ... -->
    </chapter>
</book>

Example showing the use of the Javascript API (functions defined in megazine.js):

<script>
  jQuery(function($){
    $('#megazine').before('<div id="header" style="display:inline; height:50px; width:100%">');
    $('#header').prepend('<p style="color:#ffffff;" id="pgnum"></p>');
    $('#pgnum').text('jQuery initialzied');
    MegaZine.onJSInit = function() {
      MegaZine.onPageChange = function(newPageNumber){$('#pgnum').text('page number: ' + newPageNumber.toString(10))};
    };
    $('div#megazine').mz3js();
  });
</script>

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.

MegaZine3 Plugin-related articles
Plugins Anchors · Background Sounds · Batchpages · Bookmarks · Console · ElementIDs · Gallery · Google Analytics · Help · JavaScript · Keyboard Navigation · Links · NavigationBar · Options · Overlays · Password · PDFLinks · Print · PrintPDF · SWFAddress· Search · Sidebar · Slideshow · Titles
Plugin Articles Writing a plugin · Writing a plugin II · Plugin development
Personal tools
Namespaces
Variants
Actions
Navigation
documentation
miscellaneous
Toolbox