The JavaScript ecosystem can be tough to hack through, even for experienced programmers. There are so many extensive JavaScript reference books and competing libraries to choose from-Prototype, jQuery, MooTools, YUI, Dojo, ExtJS, and so on. Christophe Porteneuve is here to help: he gives you fundamentals, the most handy techniques, and the insider's best practices. If you're reasonably comfortable programming in any widely known language, you'll be able to jump into JavaScript in no time. Divided into six Parts, the book starts with JavaScript code patterns that are too often ignored by JavaScript coders. Part 2 presents several essential JavaScript tasks-DOM and CSS manipulations, plus event handling and timers-in a framework-agnostic way, using syntax from all the major flavors. Parts 3 and 4, respectively, hit JavaScript's best features for user interface functionality-tooltips, lightboxes, image processing, infinite scrolling, and more-and forms for receiving and validating input. Part 5 explores the client/server relationship, touching on cookies, JSON, and Ajax (same- and cross-domain). Part 6 uses JavaScript in mashups with Twitter, Flickr, and geo-related APIs. The appendices feature Christophe's two-page JavaScript cheat sheet, followed by hard-won tips on debugging even the most maddening JavaScript errors. Next is an even-handed assessment of the major frameworks used in the book and in most JavaScript shops today. Last, Christophe presents an extensive group of resources for using and learning JavaScript and the major frameworks. This Pragmatic Guide is strictly focused on the techniques that will get you started in JavaScript. It's where you come to get the full scope of JavaScript in your head--fast! You'll quickly understand its core syntax, capabilities, and related frameworks. Start here first.
Contents......Page 5
Dedication......Page 9
Acknowledgments......Page 10
What's This Book About, and Who Is It For?......Page 12
This Book and JavaScript Libraries......Page 13
This Book at a Glance......Page 14
How to Read This Book......Page 15
Bread and Butter: Pure JavaScript......Page 16
Task 1. Dynamically Selecting a Method/Property......Page 18
Task 2. Achieving Code Privacy with the Module Pattern......Page 20
Task 3. Using Optional, Variable, and Named Arguments......Page 22
The DOM, Events, and Timers......Page 24
Task 4. Obtaining References to DOM Elements......Page 26
Task 5. Dynamically Styling Content......Page 28
Task 6. Changing an Element's Contents......Page 30
Task 7. Running Code When the DOM Is Loaded......Page 32
Task 8. Listening for Events (and Stopping)......Page 34
Task 9. Leveraging Event Delegation......Page 36
Task 10. Decoupling Behaviors with Custom Events......Page 38
Task 11. Simulating Background Processing......Page 40
UI Tricks......Page 42
Task 12. Pulling Off Classy Tooltips......Page 44
Task 13. Making Unobtrusive Pop-Ups......Page 46
Task 14. Preloading Images......Page 48
Task 15. Creating a Lightbox Effect......Page 50
Task 16. Implementing an ``Infinite Scroll''......Page 52
Task 17. Maintaining Viewport When Loading Content......Page 54
Form-fu......Page 56
Task 18. Temporarily Disabling a Submit Button......Page 58
Task 19. Providing Input Length Feedback......Page 60
Task 20. (Un)checking a Whole Set of Checkboxes at Once......Page 62
Task 21. Validating Forms: The Basics......Page 64
Task 22. Validating Forms: Going Further......Page 66
Task 23. Validating Forms: The Whole Nine Yards......Page 68
Task 24. Providing On-the-Fly Help Tooltips on Forms......Page 70
Task 25. Autocompleting Input As It's Typed......Page 72
Task 26. Using Dynamic Multiple File Uploads......Page 74
Talking with the Server Side......Page 76
Task 27. Reading/Writing Cookies......Page 78
Task 28. Loading Stuff Through Ajax (Same Domain)......Page 80
Task 29. Using JSON......Page 82
Task 30. Using JSON-P......Page 84
Task 31. Cross-Domain ``Ajax'' (Take 1)......Page 86
Task 32. Cross-Domain ``Ajax'' (Take 2)......Page 88
Making Mashups......Page 90
Task 33. Syndicating Your Twitter Updates......Page 92
Task 34. Syndicating Your Flickr Updates......Page 94
Task 35. Geocoding a Location and Getting Photos For It......Page 96
Appendices......Page 98
JavaScript Cheat Sheet......Page 99
Here Be Dragons......Page 102
Firefox and Firebug......Page 103
Safari and Web Inspector......Page 107
IE6, IE7, the IE Toolbar, and Web Developer Express......Page 109
IE8 and Developer Tools......Page 112
Opera and Dragonfly......Page 113
Virtual Machines Are Your Friends......Page 114
The Network May Be Your Enemy......Page 115
JavaScript Frameworks......Page 116
Prototype, script.aculo.us, and Scripty2......Page 117
jQuery and jQuery UI......Page 118
YUI......Page 120
ExtJS......Page 122
Dojo......Page 123
Help on JavaScript in General......Page 125
Help on Frameworks......Page 127
Bibliography......Page 130
D......Page 132
F......Page 133
L......Page 134
S......Page 135
Z......Page 136