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 namedImageCaption.js
. To start, create a new JavaScript file and name itImageCaption.js
.Next, let us set up the "template" for our class. A plugin will have three staples. The first is
Implements
, which handles theOptions
. Because a plugin is typically flexible and customizable , it will have anoptions
option. Finally, it will have theinitialize
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. } });
We will start with the plugins options. Our plugin will have four options, as we've defined in our design sheet earlier.
wrapperClass...
MooTools 1.2 Beginner's Guide
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
Free Chapter
MooTools and Me
Writing JavaScript with MooTools
Selecting DOM Elements
The Core's Useful Utility Functions
Working with Events
Bringing Web Pages to Life with Animation
Going 2.0 with Ajax
Beefing Up MooTools: Using the MooTools More Plugins
Creating Your Own Plugin
Customer Reviews