Book Image

Moodle JavaScript Cookbook

Book Image

Moodle JavaScript Cookbook

Overview of this book

Moodle is the best e-learning solution on the block and is revolutionizing courses on the Web. Using JavaScript in Moodle is very useful to administrators and dynamic developers as it uses built-in libraries to provide the modern and dynamic experience that is expected by web users today.The Moodle JavaScript Cookbook will take you through the basics of combining Moodle with JavaScript and its various libraries and explain how JavaScript can be used along with Moodle. It will explain how to integrate Yahoo! User Interface Library (YUI) with Moodle. YUI will be the main focus of the book, and is the key to implementing modern, dynamic feature-rich interfaces to help your users get a more satisfying and productive Moodle experience. It will enable you to add effects, make forms more responsive, use AJAX and animation, all to create a richer user experience. You will be able to work through a range of YUI features, such as pulling in and displaying information from other websites, enhancing existing UI elements to make users' lives easier, and even how to add animation to your pages for a nice finishing touch.
Table of Contents (15 chapters)
Moodle JavaScript Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Implementing event delegation


So far we have looked at a range of methods for registering single events to single elements. These techniques are very useful but it becomes inefficient and laborious when we wish to register events for multiple elements.

If we take the example of a navigation control in the form of a list of links, we could implement a click event for each link by manually registering the event against the ID of the element. While this may be fine for a handful of links, as soon as the list starts to get larger it becomes very cumbersome to manage these events. The more links there are, the more it becomes prone to mistakes and bugs. Would you want to write (and manage) code to register click events to 50 links by hand if you didn't have to?

Fortunately, it so happens that the YUI has a solution for just this type of problem, namely Event Delegation.

Event delegation is a technique whereby we can designate a parent element to hand down events to its child elements. Picking up...