Book Image

MooTools 1.2 Beginner's Guide

Book Image

MooTools 1.2 Beginner's Guide

Overview of this book

MooTools is a simple-to-use JavaScript library, ideal for people with basic JavaScript skills who want to elevate their web applications to a superior level. If you're a newcomer to MooTools looking to build dynamic, rich, and user-interactive web site applications this beginner's guide with its easy-to-follow step-by-step instructions is all you need to rapidly get to grips with MooTools.
Table of Contents (14 chapters)
MooTools 1.2 Beginner's Guide
Credits
About the Authors
About the Reviewer
Preface

Time for action—creating the ImageCaption plugin


We'll now create our plugin.

  1. A plugin should be in its own JavaScript file. The file name, for best practice, must be the same as the class name. Since our class name is ImageCaption, our JavaScript file should be named ImageCaption.js. To start, create a new JavaScript file and name it ImageCaption.js.

  2. Next, let us set up the "template" for our class. A plugin will have three staples. The first is Implements, which handles the Options. Because a plugin is typically flexible and customizable , it will have an options option. Finally, it will have the initialize option, which, if you can remember, runs the code whenever our class is instantiated.

    var ImageCaption = new Class({
    Implements: [Options],
    options: {
    // Available options
    },
    initialize: function(){
    // Code to run whenever this class is instantiated.
    }
    });
    
  3. We will start with the plugins options. Our plugin will have four options, as we've defined in our design sheet earlier. wrapperClass...