Mootools Essentials Apress’S Firstpress Series Is Your Source for Understanding Cutting-Edge Technology
Total Page:16
File Type:pdf, Size:1020Kb
BOOKS FOR PROFESSIONALS BY PROFESSIONALS® Available as a PDF Electronic Book MooTools Essentials MooTools Apress’s firstPress series is your source for understanding cutting-edge technology. Short, highly or Print On Demand focused, and written by experts, Apress’s firstPress books save you time and effort. They contain the information you could get based on intensive research yourself or if you were to attend a conference every other week—if only you had the time. They cover the concepts and techniques that will keep you ahead of the technology curve. Apress’s firstPress books are real books, in your choice of electronic or print-on-demand format, with no rough edges even when the technology itself is still rough. You can’t afford to be without them. MooTools Essentials: The Official MooTools Reference for JavaScript™ and Ajax Development MooTools Dear Reader, Whether you are visiting or building a web site these days, you can’t deny that JavaScript has become an important part of the experience. Visitors to web sites expect them to be interactive and responsive, and that means that those of us who build them must spend the time to make that experience come alive. In the past, JavaScript was often a tedious business, with browsers each offer- ing their own mercurial blend of standard and nonstandard functionality. Modern JavaScript has taken off with the advent of JavaScript frameworks: libraries that Essentials enhance the JavaScript language itself and help you avoid all the pesky browser bugs. MooTools is a JavaScript framework that enables you to write clean, concise, reus- able code to animate and dynamically change the content on your site using Ajax and The Official MooTools Reference for other technologies, taking care of all the grunt work for you. This book aims to make the process of getting started with MooTools an easy one, covering everything from ™ downloading the code and adding it to your pages to explaining what each class and JavaScript and Ajax Development method does (and, perhaps more importantly, when you’ll use each one). I’ve combined real-world examples with nuanced explanations of everything you need to know to make your site fun and engaging. You’ll be adding effects and Ajax in no time. Have fun, Aaron Newton 276 PAGES Newton Aaron Newton SOURCE CODE ONLINE www.apress.com User level: Beginner–Intermediate About firstPress Apress's firstPress series is your source for understanding cutting-edge technology. Short, highly focused, and written by experts, Apress's firstPress books save you time and effort. They contain the information you could get based on intensive research yourself or if you were to attend a conference every other week—if only you had the time. They cover the concepts and techniques that will keep you ahead of the technology curve. Apress's firstPress books are real books, in your choice of electronic or print-on-demand format, with no rough edges even when the technology itself is still rough. You can't afford to be without them. MooTools Essentials: The Official MooTools Reference for JavaScript™ and Ajax Development Dear Reader, Whether you are visiting or building a web site these days, you can’t deny that JavaScript has become an important part of the experience. Visitors to web sites expect them to be interactive and responsive, and that means that those of us who build them must spend the time to make that experience come alive. In the past, JavaScript was often a tedious business, with browsers each offering their own mercurial blend of standard and nonstandard functionality. Modern JavaScript has taken off with the advent of JavaScript frameworks: libraries that enhance the JavaScript language itself and help you avoid all the pesky browser bugs. MooTools is a JavaScript framework that enables you to write clean, concise, reusable code to animate and dynamically change the content on your site using Ajax and other technologies, taking care of all the grunt work for you. This book aims to make the process of getting started with MooTools an easy one, covering everything from downloading the code and adding it to your pages to explaining what each class and method does (and, perhaps more importantly, when you’ll use each one). I’ve combined real-world examples with nuanced explanations of everything you need to know to make your site fun and engaging. You’ll be adding effects and Ajax in no time. Have fun, Aaron Newton Contents Preface ..................................................................................... xi Acknowledgments...................................................................................xi A Note on the Code Formatting in This Book......................................xi Introduction ............................................................................ xiii JavaScript Frameworks ....................................................................... xiv Why You Should Use a JavaScript Framework ................................. xiv About MooTools.................................................................................... xv MooTools vs. Other Frameworks.........................................................xvii About the Author..................................................................................xix About This Book....................................................................................xx Who This Book Is For................................................................................ xxi What You Need to Know ..........................................................................xxii Summary..............................................................................................xxii Chapter 1: Getting Started with MooTools.....................................1 Downloading MooTools..........................................................................1 Downloading MooTools Official Plug-Ins ................................................... 2 Core Builder .................................................................................................. 4 Making Use of MooTools’ Modular Design................................................. 4 Compatibility................................................................................................. 5 Compression Options .................................................................................... 5 MooTools Essentials i Adding MooTools to Your Page(s).........................................................6 Coding for Reuse.....................................................................................6 Compression ............................................................................................7 Using the YUI Compressor ........................................................................... 7 Chapter 2: Reviewing MooTools ...................................................9 MooTools File Structure.........................................................................9 Manifest of MooTools Scripts ..............................................................10 The MooTools Core .................................................................................... 10 The MooTools Plug-Ins: “More” ................................................................ 17 Chapter 3: Shortcuts and Helpful Functions.................................23 Determining the Type of an Object: $type ...........................................23 $type :: Core/Core.js.................................................................................... 23 Checking Whether Values Are Defined: $defined, $chk, and $pick .................................................................25 $defined :: Core/Core.js............................................................................... 25 $chk :: Core/Core.js..................................................................................... 26 $pick :: Core/Core.js.................................................................................... 26 Working with Objects: $extend, $merge, and $unlink .........................................................................28 $extend :: Core/Core.js................................................................................ 29 $merge :: Core/Core.js ................................................................................ 31 $unlink :: Core/Core.js ................................................................................ 33 Iterable Helpers and Shortcuts: $arguments, $each, $splat, $A, and $H.................................................................34 $arguments :: Core/Core.js ......................................................................... 34 $each :: Core/Core.js................................................................................... 35 $splat :: Core/Core.js................................................................................... 36 ii MooTools Essentials $A :: Core/Core.js........................................................................................ 37 $H :: Core/Core.js........................................................................................ 38 Other Shortcuts: $clear, $empty, $lambda, $random, $time, $try .........................................................................39 $clear :: Core/Core.js .................................................................................. 39 $empty :: Core/Core.js................................................................................. 39 $lambda :: Core/Core.js .............................................................................