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

Creating custom events


Besides the standard HTML events that you saw earlier in this chapter, you can also create custom events of your own. For example, you may want to create a custom event for a user pressing the Caps Lock key; you can do this by adding (extending) properties to the Element.Events object in MooTools. Here is the format for adding event properties to the Element.Events MooTools object:

Element.Events.eventname = {
'base' : 'click', // A base event such as click, keypress, keydown, onload, etc.
'condition' : function() {
// conditions that need to be met to trigger event
},
'onAdd' : function() {
// Functions to trigger when you bind/add the event to elements
},
'onRemove' : function() {
// Functions to execute when you unbind/remove elements
}
};

There are five things to take a note off in the above code sample.

  • eventname: This is the name of your custom event.

  • base: This is an optional string value which gives our custom event a standard event to listen to. If you have...