Java Reference
In-Depth Information
The handleResponse() function also saw a few changes. Thanks to MooTools' built‐in support for
JSON, the function has been simplified:
function handleResponse(data, json) {
if (data.available) {
alert(data.searchTerm + " is available!");
} else {
alert("We're sorry, but " + data.searchTerm + " is not available.");
}
}
The data passed to the first parameter, data , is already parsed into a JavaScript object. So you
simply use it to check if the username or e‐mail is available and display the correct information to
the user.
Finally, you wire up the events:
$("usernameAvailability").addEvent("click", checkUsername);
$("emailAvailability").addEvent("click", checkEmail);
You find the <a/> elements in the document and register their click event listeners with MooTools'
addEvent() method.
MooTools is a popular framework because it offers you utility similar to jQuery while maintaining
aspects of traditional DOM programming. MooTools also has an animation/effects component,
making it a well‐rounded framework. This section can hardly do the framework justice, so make
sure to visit the API documentation at http://mootools.net/core/docs/ .
summarY
This chapter introduced you into the rather large world of JavaScript frameworks and libraries.
You learned that two types of libraries and frameworks exist: general and specific. You
were also given a short list of the popular solutions available today.
You learned where to obtain the files needed to use Modernizr, Prototype, and
MooTools.
You learned how Modernizr helps you write feature‐specific code, and how to load external
resources, like polyfills, for browsers that don't support certain features.
You learned the basics of the Prototype framework—how to retrieve, create, and
manipulate elements. You also learned how to register event listeners and send Ajax
requests.
You learned how to use MooTools to create, select, and modify elements, as well as wire up
event listeners and make Ajax requests.
 
Search WWH ::




Custom Search