MooTools 1.2 Beginner's Guide: Learn how to create dynamic, interactive, and responsive cross-browser web applications using this popular JavaScript framework
By Gube Jacob and Cheung Garrick
()
About this ebook
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.
Related to MooTools 1.2 Beginner's Guide
Related ebooks
MooTools 1.2 Beginner's Guide Rating: 0 out of 5 stars0 ratingsOracle ADF 11gR2 Development Beginner's Guide Rating: 0 out of 5 stars0 ratingsApache Roller 4.0 – Beginner's Guide Rating: 0 out of 5 stars0 ratingsWordPress Plugin Development: Beginner's Guide: Build powerful, interactive plug-ins for your blog and to share online Rating: 0 out of 5 stars0 ratingsOpenSceneGraph 3.0 Beginner's Guide Rating: 0 out of 5 stars0 ratingsC# 2008 and 2005 Threaded Programming: Beginner's Guide Rating: 0 out of 5 stars0 ratingsVaadin 7 UI Design By Example: Beginners Guide Rating: 0 out of 5 stars0 ratingsMootools 1.2 Beginners Guide LITE: Getting started Rating: 0 out of 5 stars0 ratingsPHP and MongoDB Web Development Beginner's Guide: Combine the power of PHP and MongoDB to build dynamic web 2.0 applications Rating: 0 out of 5 stars0 ratingsjQuery 1.4 Plugin Development Beginner's Guide Rating: 0 out of 5 stars0 ratingsHTML5 Web Application Development By Example Beginner's guide Rating: 0 out of 5 stars0 ratingsSelenium 1.0 Testing Tools Beginner's Guide Rating: 0 out of 5 stars0 ratingsconcrete5 Beginner's Guide Rating: 0 out of 5 stars0 ratingsCryENGINE 3 Game Development Beginner's Guide Rating: 0 out of 5 stars0 ratingsMac Application Development by Example: Beginner's Guide Rating: 0 out of 5 stars0 ratingsCouchDB and PHP Web Development Beginner’s Guide Rating: 0 out of 5 stars0 ratingsPanda3D 1.6 Game Engine Beginner's Guide Rating: 0 out of 5 stars0 ratingshaXe 2 Beginner's Guide Rating: 0 out of 5 stars0 ratingsGame Programming Using Qt: Beginner's Guide Rating: 0 out of 5 stars0 ratingsSphinx Search Beginner's Guide Rating: 4 out of 5 stars4/5LiveCode Mobile Development: Beginner's Guide - Second Edition Rating: 4 out of 5 stars4/5Appcelerator Titanium Application Development by Example Beginner's Guide Rating: 0 out of 5 stars0 ratingsUnreal Development Kit Game Programming with UnrealScript Beginner's Guide Rating: 3 out of 5 stars3/5Learning C# by Developing Games with Unity 3D Beginner's Guide: The beauty of this book is that it assumes absolutely no knowledge of coding at all. Starting from very first principles it will end up giving you an excellent grounding in the writing of C# code and scripts. Rating: 0 out of 5 stars0 ratingsKentico CMS 5 Website Development: Beginner's Guide Rating: 0 out of 5 stars0 ratingsjQuery 2.0 Animation Techniques: Beginner's Guide: Bring your websites to life with animations using jQuery Rating: 0 out of 5 stars0 ratingsInkscape Beginner’s Guide Rating: 5 out of 5 stars5/5qooxdoo Beginner's Guide: Develop Rich Internet Applications (RIA) with Qooxdoo1.4 Rating: 0 out of 5 stars0 ratings
Information Technology For You
An Ultimate Guide to Kali Linux for Beginners Rating: 3 out of 5 stars3/5CompTIA A+ CertMike: Prepare. Practice. Pass the Test! Get Certified!: Core 1 Exam 220-1101 Rating: 0 out of 5 stars0 ratingsCybersecurity for Beginners : Learn the Fundamentals of Cybersecurity in an Easy, Step-by-Step Guide: 1 Rating: 0 out of 5 stars0 ratingsCreating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5Summary of Super-Intelligence From Nick Bostrom Rating: 4 out of 5 stars4/5CompTia Security 701: Fundamentals of Security Rating: 0 out of 5 stars0 ratingsCOMPUTER SCIENCE FOR ROOKIES Rating: 0 out of 5 stars0 ratingsData Analytics for Beginners: Introduction to Data Analytics Rating: 4 out of 5 stars4/5Supercommunicator: Explaining the Complicated So Anyone Can Understand Rating: 3 out of 5 stars3/5Understanding TCP/IP Rating: 4 out of 5 stars4/5How to Find a Wolf in Siberia (or, How to Troubleshoot Almost Anything) Rating: 0 out of 5 stars0 ratingsWordPress Plugin Development: Beginner's Guide Rating: 0 out of 5 stars0 ratingsLinux Command Line and Shell Scripting Bible Rating: 3 out of 5 stars3/5Practical Ethical Hacking from Scratch Rating: 5 out of 5 stars5/5Google Trends Instant Cash Rating: 0 out of 5 stars0 ratingsLearning Microsoft Endpoint Manager: Unified Endpoint Management with Intune and the Enterprise Mobility + Security Suite Rating: 0 out of 5 stars0 ratingsMicrosoft Access for Beginners and Intermediates Rating: 0 out of 5 stars0 ratings20 Windows Tools Every SysAdmin Should Know Rating: 5 out of 5 stars5/5How to Write Effective Emails at Work Rating: 4 out of 5 stars4/5Who Says Elephants Can't Dance?: Leading a Great Enterprise Through Dramatic Change Rating: 4 out of 5 stars4/5The Design Inference Rating: 5 out of 5 stars5/5The iPadOS 17: The Complete User Manual to Quick Set Up and Mastering the iPadOS 17 with New Features, Pictures, Tips, and Tricks Rating: 0 out of 5 stars0 ratingsA Practical Guide Wireshark Forensics Rating: 5 out of 5 stars5/5Inkscape Beginner’s Guide Rating: 5 out of 5 stars5/5CompTIA ITF+ CertMike: Prepare. Practice. Pass the Test! Get Certified!: Exam FC0-U61 Rating: 5 out of 5 stars5/5ChatGPT: The Future of Intelligent Conversation Rating: 4 out of 5 stars4/5Arch Linux: Fast and Light! Rating: 3 out of 5 stars3/5
Reviews for MooTools 1.2 Beginner's Guide
0 ratings0 reviews
Book preview
MooTools 1.2 Beginner's Guide - Gube Jacob
Table of Contents
MooTools 1.2 Beginner's Guide
Credits
About the Authors
About the Reviewer
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. MooTools and Me
What is MooTools?
Why use MooTools?
The advantages of using MooTools
Writing terse and elegant code
Extending native JavaScript
Cross-browser compatibility
Working with the Document Object Model
The advantage of using open-source projects
Downloading and installing MooTools
Time for action—downloading and installing the MooTools Core
What just happened?
Different MooTools downloads
The domready event listener
Rolling your own MooTools
MooTools Core
Time for action—exploring the MooTools Core Builder
What just happened?
Have a go hero — — explore the MooTools Core Builder output
MooTools More
Time for action—exploring the MooTools More Builder
What just happened?
The API concept
MooTools resources
MooTools Docs
MooTools Users Google groups
mooforum
The MooTorial
Summary
2. Writing JavaScript with MooTools
Writing unobtrusive JavaScript with MooTools
An obtrusive
JavaScript example
What's so bad about it?
Don't repeat it if you don't have to
It'll be hard to maintain
It's a bad practice to have functionality in your content structure
Time for action—rewriting our script unobtrusively
What just happened?
Removing our inline event handlers
Using the DOM to handle events
Pop quiz — — rewriting our script unobstrusively
Creating MooTools classes
What the heck is a class?
Real-world analogy
Creating a MooTools class
The Implements property
The options property
The initialize method
Our own Dog class methods: .bark() and .sit()
Time for action—creating an instance of Dog
What just happened?
Have a go hero — — use the .sit() class method
Time for action—giving our class instance some custom options
Time for action—determining the value of our options
Extending classes
Time for action—extending the ShowDog class with the Dog class
What just happened?
Class inheritance
Have a go hero — doing more with the thing
Using MooTools classes
The concept of chainability
The Chain class
A Chain example
A look ahead: Chaining Fx .Tween
Time for action—create a chain of Fx.Tween methods
What just happened?
Isn't MooTools classy?
Chainability
Have a go hero — doing more with chaining Fx.Tween methods
Summary
3. Selecting DOM Elements
MooTools and CSS selectors
Working with the $() and $$() functions
The $() dollar function
The $$() dollars function
When to use which
Time for action—selecting an element with the dollar function
Time for action—selecting elements with the dollars function
Time for action—selecting multiple sets of elements with the dollars function
What just happened?
$() versus document.getElementById()
Selecting multiple sets of elements
Have a go hero — tween the list item element
Common errors with the dollar and dollars functions
The dollar function doesn't work with CSS selectors!
Drop the pound # sign when using the $() function
Pop quiz — find the bad apple in the bunch
Selection using pseudo-classes
Pseudo-class example: Zebra striping a table
Time for action—using pseudo-classes to zebra stripe a table
What just happened?
Other pseudo-class selectors
Working with attribute selectors
Attribute selector operators
Attribute selector example: Styling different types of links
Time for action—using = attribute selector
Time for action—using != attribute selector
Time for action—using ^= attribute selector
Time for action—using $= attribute selector
What just happened?
Attribute selector case sensitivity
DOM selection makes unobtrusive JavaScript do-able
Summary
4. The Core's Useful Utility Functions
What is the Core?
Browser: Getting information about the client
Determining if the client has a specific feature
Browser.Features.xpath
Browser.Features.xhr
Getting information about the client's rendering engine
Determining the client's rendering engine and version
Time for action—determining the client's rendering engine and version
Checking if the client is using a particular web browser
Have a go hero — checking to see if your browser uses Gecko
Determining if the client has Adobe Flash installed
Finding out information about the client's operating system
Potential uses of this property
Example scenario: Offering the correct download based on the client's platform
SuperSoftware HTML
SuperSoftware CSS
Time for action—using Browser.Platform to customize SuperSoftware's download page
What just happened?
Pop quiz — finding out information about the client's operating system
Exploring the Core utility functions
Checking to see if objects are defined
Seeing if an object has a value with $chk
Checking if an object is defined with $defined
Selecting the first defined object using $pick
Getting the return of first working function with $try
Dealing with time and intervals
The $time() function
Time for action—the $time() function
What just happened?
The $clear() function
Time for action—exploring the $clear() function with periodical()
What just happened?
Utility functions for working with objects
Extending objects with $extend()
Merging objects with $merge()
Iterating through objects using $each
Time for action—exploring the $each function
What just happened?
Other utility functions in the Core
Generating a random number with $random
Converting objects to arrays with $splat
Determining the data type using $type
Limited use functions
Creating a function placeholder with $empty
Returning arguments using $lambda
Creating a function that returns the specified value using $arguments
Summary
5. Working with Events
What are events exactly?
Window events
Form events
Keyboard events
Mouse events
MooTools custom mouse events
Adding event listeners
Adding a single event listener
Time for action—highlighting focused fields of web forms
What just happened?
Adding multiple event listeners
Time for action—adding tooltips to the web form
What just happened?
Creating custom events
Time for action—creating a custom event for showing help tips
What just happened?
Have a go hero — create your own custom event
Removing, cloning, and firing off events
Removing events from elements
Removing a single event from elements
Time for action—removing an event
Removing a type of event, or all events, from elements
Cloning events from another element
Firing off events
Time for action—firing off a click event
The MooTools event object
Using event object methods
Preventing the default behavior
Time for action—preventing the default behavior of a hyperlink
Preventing event bubbling
Time for action—preventing event bubbling
What just happened?
Stopping default behavior and event propagation
Using event properties
Summary
6. Bringing Web Pages to Life with Animation
MooTools' Fx class
Basic syntax
Fx options
Animating a CSS property with Fx.Tween
Time for action — creating a hide/show FAQ page
What just happened?
Have a go hero — modifying the hide/show transition effect
Tweening a single CSS property using the tween() method
Time for action—toggling the visibility of a div
What just happened?
Fading elements
Time for action - fading an image in and out
What just happened?
Highlighting elements
Time for action - indicating blank form fields that are required
What just happened?
Animating multiple CSS properties with Fx.Morph
Time for action - enlarging an image
What just happened?
Have a go hero — modify the transition type
Using the morph() shortcut method
Time for action - experimenting with morph
What just happened?
Other Fx methods
Starting an effect
Setting properties immediately
Cancelling a transition
Pausing effect
Resuming a paused effect
Summary
7. Going 2.0 with Ajax
What you'll need
Creating a Request object
Request object options
Request events options
Running a function immediately when a request is made
Running a function when the request is completed
Running a function when the request is cancelled
Other Request events
Requesting data
Time for action—requesting remote data
What just happened?
Requesting HTML and JSON data
Working with HTML data
Time for action—updating a web page with HTML
What just happened?
Loading HTML documents remotely
Time for action—loading HTML data
Working with JSON data
Time for action—working with Ajax and JSON
What just happened?
Cancelling a Request
Sending data
Time for action—sending data to PHP
What just happened?
Setting and getting HTTP headers
Setting an HTTP header for an Ajax Request object
Getting an HTTP header
Time for action—getting the Last-Modified HTTP header
What just happened?
Have a go hero — get the content length of the requested page
Summary
8. Beefing Up MooTools: Using the MooTools More Plugins
Downloading MooTools More plugins
Time for action—downloading the Fx.Accordion plugin
What just happened?
Installing MooTools plugins
Time for action—installing Fx.Accordion
What just happened?
Discovering a handful of MooTools More plugins
Creating engaging content using Fx.Accordion
Time for action—creating an accordion
What just happened?
Fx.Accordion options
Downloading all the MooTools More plugins we need
Time for action—downloading more Mootools More plugins
Extending JavaScript's native Date object
Time for action—building a Date calculator tool
What just happened?
Making web forms more user-friendly with the OverText plugin
Time for action—creating a web form that uses OverText
What just happened?
Drag-and-drop with Drag and Drag.Move
Time for action—creating a simple drag-and-drop game
What just happened?
Summary
9. Creating Your Own Plugin
Why create a plugin?
Designing the plugin
Time for action—creating a design sheet for our plugin
What just happened?
Creating the ImageCaption script
Time for action—writing the ImageCaption script
What just happened?
Noting down pitfalls and places of improvement to the script
Converting the script to a flexible plugin
Time for action—creating the ImageCaption plugin
What just happened?
Instantiating the plugin
Time for action—basic instantiation of the ImageCaption plugin
What just happened?
Creating a more complex instance of the plugin
Time for action—creating new instances of the plugin
Creating multiple instances of the plugin
Time for action—multiple instances of the ImageCaption plugin
What just happened?
Preparing your plugin for the public
Documenting your plugin with comments
Time for action—documenting the ImageCaption plugin
What just happened?
External documentation
Time for action—creating a basic download page for the ImageCaption plugin
What just happened?
Summary
Index
MooTools 1.2 Beginner's Guide
Jacob Gube
Garrick Cheung
MooTools 1.2 Beginner's Guide
Copyright © 2009 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: December 2009
Production Reference: 1111209
Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK.
ISBN 978-1-847194-58-9
www.packtpub.com
Cover Image by Vinayak Chittar (<[email protected]>)
Credits
Authors
Jacob Gube
Garrick Cheung
Reviewer
Chirstoph Pojer
Acquisition Editor
Douglas Paterson
Development Editor
Steven Wilding
Technical Editor
Bhupali Khule
Indexer
Hemangini Bari
Editorial Team Leader
Akshara Aware
Project Team Leader
Lata Basantani
Project Coordinators
Rajashree Hamine
Srimoyee Ghoshal
Proofreaders
Cathy Cumberlidge
Andy Scothern
Production Coordinator
Adline Swetha Jesuthas
Cover Work
Adline Swetha Jesuthas
About the Authors
Jacob Gube is a massive MooTools developer. He is the founder and Chief Editor of Six Revisions, a website dedicated to web developers and web designers. He's also written for other popular web publications such as Read Write Web and Smashing Magazine, discussing web technologies and development. A web professional for 8 years, Jacob is an in-house web developer specializing in distance-learning education and web accessibility, using PHP, MooTools, and jQuery (alongside other web technology acronyms like VB.NET and AS3/Flash) to get the job done.
Garrick Cheung is a designer-developer and a member of the official Mootools Community team. He's currently a Senior Technical Producer for CBS Interactive developing for sites such as GameSpot.com, TV.com and MP3.com. He's passionate about code optimization and loves to teach and develop in MooTools. Garrick also writes about code and development at his site, http://www.garrickcheung.com.
About the Reviewer
Christoph currently studies Software Engineering and Business Management at the Graz University of Technology. He is an experienced web developer and has worked on numerous web applications for the past 7 years. He focuses on JavaScript and is a core developer of the MooTools JavaScript framework, as he enjoys pushing the limits of the Web. You can find a lot of his open source work on cpojer.net. In his free time he enjoys watching TV series and hanging out with friends.
Preface
This book is geared towards web developers who have a basic understanding of JavaScript and the related technologies that are involved with it, namely HTML and CSS. If you're familiar with a programming or server-side scripting language, code authoring in MooTools will be very familiar.
The goal of this book is to give you a functional and pragmatic understanding of MooTools and is not intended for learning JavaScript, HTML, CSS, and concepts such as the DOM and unobtrusive JavaScript.
This is the first book specifically designed for absolute newcomers to MooTools. It is a Packt Beginner's Guide, which means it is packed with clear step-by-step instructions for performing the most useful tasks.
MooTools is an open source, lightweight, modular object-oriented programming JavaScript web application framework. The goal of the software is to provide a means for intermediate to advanced web developers to write cross-browser JavaScript in an elegant, flexible, and efficient fashion. The MooTools JavaScript framework includes built-in functions for manipulation of CSS, DOM elements, native JavaScript objects, AJAX requests, and more.
You will start learning by 'doing' immediately. As each chapter in the book progresses, the topics get more complex. First you get to grips with the fundamentals of MooTools including downloading, installation, and basic syntax. Once you've grasped the basics you learn to make the most of MooTools' powerful framework. You will learn to bring web pages to life with animation and create exciting web pages with AJAX. You will also learn to customize MooTools to suit your own needs by creating your own plug-ins. You will soon be well on the way to creating web applications and web pages worthy of the Web 2.0 world
What this book covers
Chapter 1, MooTools and Me shows how to download and install Mootools. It demonstrates how to troubleshoot the most common installation problems. Writing a simple MooTools code block to test that the installation has worked is also explained.
Chapter 2, Writing JavaScript with MooTools demonstrates the difference between normal JavaScript against MooTools code. It explains how MooTools code can be far simpler and more efficient than ordinary JavaScript to achieve the same task.
Chapter 3, Selecting DOM Elements gives an overview of the Document Object Model tree and an in-depth discussion of the $() function in the Element class. It showcases basic DOM relationships such as parents, children, and siblings. It also demonstrates how to select page links and then give them a certain color or style
Chapter 4, The Core's Useful Utility Functions introduces native JavaScript variable definitions. It goes through each function and demonstrates how it works.
Chapter 5, Working with Events explains different browser events such as mouse click, mouse hover, mouse moving and key press. It demonstrates how to build a super-charged web form in MooTools. Events are covered showing how to add event listeners to web page elements.
Chapter 6, Bringing Web Pages to Life Using Animation introduces the different animation options available in MooTools. It demonstrates how to create a featured area slider. It demonstrates the MooTools Fx class and its useful methods for working with MooTools effects.
Chapter 7, Going 2.0 with Ajax shows the basics of Ajax. It demonstrates how MooTools makes working with Ajax easy. It will explain how XML files can be used to simulate a relational database.
Chapter 8, Beefing up MooTools Using the MooTools More Plugins demonstrates how to install and use the plug in system. It will explain how the Accordion area can be used to display content in