Pro JavaScript with MooTools Learning Advanced JavaScript Programming 1st Edition Mark Joseph Obcena (Auth.) - Get instant access to the full ebook with detailed content
Pro JavaScript with MooTools Learning Advanced JavaScript Programming 1st Edition Mark Joseph Obcena (Auth.) - Get instant access to the full ebook with detailed content
https://ebookultra.com/download/mootools-essentials-the-official-
mootools-reference-for-javascript-and-ajax-development-1st-edition-
aaron-newton/
https://ebookultra.com/download/html5-programming-with-javascript-for-
dummies-1st-edition-john-paul-mueller/
https://ebookultra.com/download/professional-xmpp-programming-with-
javascript-and-jquery-1st-edition-jack-moffitt/
https://ebookultra.com/download/javascript-with-promises-1st-edition-
daniel-parker/
Eloquent JavaScript A Modern Introduction to Programming
1st Edition Marijn Haverbeke
https://ebookultra.com/download/eloquent-javascript-a-modern-
introduction-to-programming-1st-edition-marijn-haverbeke/
https://ebookultra.com/download/learn-javascript-and-ajax-
with-w3schools-1st-edition-w3schools/
https://ebookultra.com/download/eloquent-javascript-a-modern-
introduction-to-programming-2nd-edition-marijn-haverbeke/
https://ebookultra.com/download/learning-javascript-data-structures-
and-algorithms-2nd-edition-loiane-groner/
Pro JavaScript with MooTools Learning Advanced
JavaScript Programming 1st Edition Mark Joseph
Obcena (Auth.) Digital Instant Download
Author(s): Mark Joseph Obcena (auth.)
ISBN(s): 9781430230557, 143023055X
Edition: 1
File Details: PDF, 3.97 MB
Year: 2010
Language: english
Pro JavaScript with
MooTools
Learning Advanced
JavaScript Programming
■■■
i
Pro JavaScript with MooTools: Learning Advanced JavaScript Programming
Copyright © 2010 by Mark Joseph A. Obcena
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN 978-1-4302-3054-0
ISBN 978-1-4302-3055-7 (eBook)
Printed and bound in the United States of America (POD)
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol
with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only
in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of
the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are
not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject
to proprietary rights.
President and Publisher: Paul Manning
Lead Editors: Frank Pohlmann and Ben Renow-Clarke
Technical Reviewer: Simo Kinnunen
Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick,
Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank
Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh
Coordinating Editor: Mary Tobin
Copy Editor: Sharon Terdeman
Compositor: MacPS, LLC
Indexer: Julie Grady
Artist: April Milne
Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring
Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
[email protected], or visit www.springeronline.com.
For information on translations, please e-mail [email protected], or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use.
eBook versions and licenses are also available for most titles. For more information, reference our
Special Bulk Sales–eBook Licensing web page at www.apress.com/info/bulksales.
The information in this book is distributed on an “as is” basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have
any liability to any person or entity with respect to any loss or damage caused or alleged to be caused
directly or indirectly by the information contained in this work.
The source code for this book is available to readers at www.apress.com.
ii
To the one who owns my heart.
iii
Contents at a Glance
■Contents ................................................................................................................ v
■Foreword ............................................................................................................ xiv
■About the Author ................................................................................................. xv
■About the Technical Reviewer............................................................................ xvi
■Acknowledgments............................................................................................. xvii
■Preface ............................................................................................................. xviii
Part I: Exploring JavaScript and MooTools .............................................................. 1
■Chapter 1: JavaScript and MooTools .................................................................... 3
■Chapter 2: Functions ........................................................................................... 11
■Chapter 3: Objects ............................................................................................... 47
■Chapter 4: Classes............................................................................................... 71
■Chapter 5: Classes: The Extras ............................................................................ 99
■Chapter 6: Types ............................................................................................... 127
Part II: Conquering the Client Side ....................................................................... 171
■Chapter 7: JavaScript in a Window ................................................................... 173
■Chapter 8: Elements .......................................................................................... 187
■Chapter 9: Selector Engines .............................................................................. 245
■Chapter 10: Events ............................................................................................ 261
■Chapter 11: Request .......................................................................................... 307
■Chapter 12: Animation ...................................................................................... 339
Part III: Breaking from the Browser ..................................................................... 359
■Chapter 13: JavaScript without Limits.............................................................. 361
■Chapter 14: MooTools on Deck.......................................................................... 371
■Appendix: Resources......................................................................................... 387
■Index ................................................................................................................. 389
iv
Contents
v
■ CONTENTS
vi
■ CONTENTS
vii
■ CONTENTS
viii
■ CONTENTS
ix
■ CONTENTS
x
■ CONTENTS
xi
■ CONTENTS
xii
■ CONTENTS
xiii
■ CONTENTS
Foreword
I began working on MooTools in 2005, and, after a year of development, I released the very first version
to the public. MooTools slowly gained popularity, ascending to its current position as one of the top
JavaScript frameworks.
MooTools, however, has a rather steep learning curve and a very big codebase. It was never written
with absolute beginners in mind, so users are often intimidated about trying to learn it. This is
unfortunate; they’re missing out on the great power and customizability MooTools offers, simply
because it looks scary.
It is not all MooTools’ fault, of course. There’s a distinct lack of useful information available on the
subject, though I must admit that MooTools itself hasn’t done enough to correct the situation. People
who want to learn the framework are left to their own devices—and that can get really at times.
Fortunately, that’s where this book comes in. Pro JavaScript with MooTools will take you on a journey
from the building blocks of JavaScript, through the prototypal concepts, to the very inner workings of
MooTools. By the time you’re finished reading it, MooTools will hold no more secrets from you.
When I think about the best MooTools articles I have ever read on the Web, Mark’s blog, Keetology,
comes immediately to mind. Mark has been writing awesome JavaScript and MooTools material for
years, in articles (like his “Up the Moo herd” series) and in actual code (Raccoon!). His blog is a must-
read for anyone wanting to learn or expand his knowledge of MooTools, or JavaScript in general.
Pro JavaScript with MooTools isn’t simply a well-written technical book. This book thoroughly
explains how object-oriented programming works in JavaScript, and then gradually takes advantage of
your newly acquired knowledge to explain how MooTools operates, and how you can build awesome
stuff with it.
And awesome stuff is what we want you to build! MooTools is no longer an obscure framework that
sprang from a simple effects library. It’s now a full-fledged development tool with a great set of core
developers, an active and growing community, and a huge roll of user-developed applications and extensions.
But development doesn’t end with the recent successes. While this book is about MooTools 1.3, the
most recent release, it is also a preparation of sorts for version 2.0. MooTools 1.3 reflects the direction
we’re heading in the future—toward a better, faster, and more powerful MooTools. We’re working to
make the strong parts of the framework even stronger, and we’re going to improve the parts that need
improvement.
However, we want you to share in these exciting developments, and the first step toward that is
learning more about MooTools. You don’t need to be an expert to learn MooTools, as this book will show
you. All you need is a little patience, creativity—and a whole lot of milk.
Back in 2005, MooTools was just a small framework I created for fun and experimentation. It never
occurred to me that it would eventually become the subject of a book, a book whose range, I must say, is
as impressive as its depth. It makes me proud of what MooTools has achieved.
Things are just gonna get more awesome from here…
Valerio Proietti
MooTools Founder and Lead-Developer
xiv
About the Author
■ Mark Joseph Obcena is a freelance software developer, graphic designer, and writer
from Manila, Philippines. Popularly known as keeto online, Mark is a big fan of open
source development and regularly contributes to several open source projects,
including MooTools where he’s a member of the official Community Team. He’s
currently experimenting with new programming languages while working on several
CommonJS projects, which are available from his Github page, and he sometimes
gets bullied by the MooTools community into writing a post for his web site, Keetology
(http://keetology.com).
Mark also owns a cat named Shröddy, who may or may not exist.
xv
■ CONTENTS
■ Simo Kinnunen, originally from Helsinki, lives in Tokyo, where he combines the study of the Japanese
language with being a web expert and JavaScript hacker. He is also a Zend engineer, and he spent quite a
large part of this spare time building a rather complicated web text replacement hack called cufón.
xvi
Acknowledgments
I’ve often thought of myself as a one-man show: Mark, the Developer for Every Occasion™. This book,
however, is not mine alone. A lot of people have contributed in one way or another to make this book
possible, and I’d like to take a piece of it to thank them.
First, I want to give a big thank-you to Valerio Proietti, MooTools Founder and Lead Developer, who
has not only given his time to read early drafts of the work, but has also graced this book with a foreword.
You, sir, are truly awesome.
I’d also like to thank the MooTools team—the builders, the contributors, and the creators—who
have tirelessly given their love to the framework. This book would literally not have been possible if not
for the great work that you’ve put into MooTools. Special thanks to Christoph, Djamil, William, David,
and Thomas, who have given their input, pings, and thumbs-up for the book.
A thank-you also goes out to the members of the MooTools community, especially the regulars of
the #mootools IRC channel. Your constant need for updates about the book and unending
encouragement drove me to make this work worthy of the highlights. Thanks and []/ are also due to the
regulars of the “other” mootools IRC channel: Jabis, Michael, Graham, and Rud. You guys are all
awesome.
Of course, I won’t forget to thank Simo, my dear technical reviewer, who has given his time and
effort in reviewing the drafts of this work. Thank you for putting up with my dangling semicolons.
Chocolates and thank-yous are sent to Tokyo for you.
Another round of cheers and claps are also given to the people at Apress who believed enough in
this work to put their time into it. To Frank, thank you for giving me the chance to broadcast my ideas to
the world, and thank you for believing that I could pull off this work. To Mary and Ben, thank you for
putting up with my haphazard writing styles and weird submission schedule. And to Sharon, thank you
for adding more awesome to my writing.
Of course, I’d also like to give thanks and hugs to my family. To my mom and dad who have always
believed in me in their own quirky way, to my siblings Christine and Jan Raleigh who are now learning
the value of being connected, and to my aunt and uncle who have stood by me like a second set of
parents, thank you.
Finally, I’d like to give the biggest thanks to three people by dedicating parts of the book to them.
Part I is dedicated to my friend Garrick Cheung. Without you, this book would have never been
started. Thank you for the input, the critiques and the ideas. You are a great man, an awesome person,
and a very good friend. To Happiness.
Part II is dedicated to my very good friend Tim Wienk. Without you, this book would never have
been completed. Thank you for listening to my rants, thank you for keeping me company, thank you for
keeping me sane, and thank you for being a good friend. To Friendship.
And Part III is dedicated to P.E.M. Without you, I would have never gotten the courage to find
happiness. Thank you for showing me what’s wrong, what’s changing, and what’s possible. I’ll always be
your Marquito. To Love.
xvii
■ CONTENTS
Preface
The universe, perhaps, is just a crazy runtime environment with sparse documentation and seemingly
random side effects, and life is nothing more than a program written in a language called “Universcript.”
I conclude that this might be the case because, when I decided to invoke my audition method in the fall
of 2008 to try out for the role of Moritz Stiefel in a local production of Spring Awakening, I never
expected that it would return a Book object.
Fortunately, not all things are that quirky. The universe might think that it’s a great idea to take my
botched audition and turn it into a writing opportunity—an API decision I fully approve, by the way—but
most programming languages behave more predictably. Some languages behave predictably well, some
languages behave predictably well with some exceptions, and some languages behave predictably weird.
The fascinating thing, though, is that a language’s predictability often has less to do with the
language itself and more to do with its users. The more we learn about a programming language, the
more predictable it becomes. The key, then, isn’t coding blindly and whining (quite loudly for some)
about a language’s apparent shortcomings, but learning, experimenting, and applying. The quirks will
stay quirky, but at least now we can appreciate their quirkiness.
This book is about JavaScript as it relates to the MooTools framework. Like any other language,
JavaScript’s predictability has a lot to do with the people who code with it. While it is pretty predictable,
JavaScript does have some quirks and unique features that might not be apparent at base level.
Unfortunately, a lot of us who proudly proclaim to be JavaScript developers don’t take time to learn the
language enough to appreciate these quirks and features.
A big part of this problem, surprisingly, comes from the popularity of frameworks. JavaScript’s
almost prodigal-son-like comeback into the limelight of web development has brought forth a slew of
libraries and frameworks that promise an easier experience when working with the language. While
most of them do deliver on the promise, it comes with the cost of dependency: developers get so
comfortable with a framework that they forget there’s a powerful language underneath the abstraction.
This book tries to address this particular issue for the MooTools framework. MooTools is in the
unique position of being one of the more popular frameworks that extend and improve JavaScript rather
than bury it in the guise of an API. MooTools works with native JavaScript, uses native JavaScript, and
feels like native JavaScript. MooTools users, therefore, are exposed to the power of JavaScript at every
level—all they have to do is look at it.
If you’re looking for a recipe book, a how-to book, or a book of source code that you can copy and
paste into your next application, I’m afraid this is not that book. This book is all about exploring
JavaScript and looking at how JavaScript is used for the internals of the MooTools framework. This book
will show you how the features of JavaScript are used inside the framework, and how they come together
to create the very powerful set of APIs we know as MooTools.
In essence, this book is an extension and expansion of the Up the MooTools Herd series I previously
wrote for my blog. As with that series, this book is not aimed at beginners, but at intermediate and
advanced users. So, if you’re new to MooTools or JavaScript, I suggest you put this book on your to-read
list and grab a beginner’s book first.
This book is divided into three parts. The first part is all about JavaScript as ECMAScript, and
focuses on the native features of the language—functions, objects, and types—and the subsystems
xviii
■ PREFACE
inside MooTools that work with these parts. The second part of the book focuses on JavaScript in the
browser and explores subjects such as elements, events, and animation. Finally, the last part of this book
is a short exploration of JavaScript outside the browser and gives an introduction to CommonJS and
MooTools using Deck.
As you’ll learn in the next chapter, MooTools is divided into two main projects: MooTools Core and
MooTools More. In writing this book, I’ve decided to focus solely on MooTools Core, so there’s no
mention of any of the features or extensions found in MooTools More. Also, I’ve limited myself to
MooTools version 1.3 for this book, so any features from or incompatibilities with previous versions are
not mentioned.
And with those words out of the way, it’s time for us to start our exploration. It’s best that we begin
with the opening credits and get to know our dramatis personae. So if you’re ready, let’s meet the cast:
JavaScript and MooTools.
xix
PART I
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com