100% found this document useful (1 vote)
14 views

Professional jQuery 1st Edition Cesar Otero - Own the complete ebook set now in PDF and DOCX formats

The document provides information on downloading the book 'Professional jQuery' by Cesar Otero and other related ebooks from ebookultra.com. It includes links to various recommended products and details about the book's content, authors, and publication information. The book covers jQuery fundamentals and applied jQuery techniques, making it suitable for web developers.

Uploaded by

ribartsnacks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
14 views

Professional jQuery 1st Edition Cesar Otero - Own the complete ebook set now in PDF and DOCX formats

The document provides information on downloading the book 'Professional jQuery' by Cesar Otero and other related ebooks from ebookultra.com. It includes links to various recommended products and details about the book's content, authors, and publication information. The book covers jQuery fundamentals and applied jQuery techniques, making it suitable for web developers.

Uploaded by

ribartsnacks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Visit https://ebookultra.

com to download the full version and


explore more ebooks or textbooks

Professional jQuery 1st Edition Cesar Otero

_____ Click the link below to download _____


https://ebookultra.com/download/professional-jquery-1st-
edition-cesar-otero/

Explore and download more ebooks or textbooks at ebookultra.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Professional XMPP Programming with JavaScript and jQuery


1st Edition Jack Moffitt

https://ebookultra.com/download/professional-xmpp-programming-with-
javascript-and-jquery-1st-edition-jack-moffitt/

Representing Cultural Diplomacy First Edition Cesar


Villanueva

https://ebookultra.com/download/representing-cultural-diplomacy-first-
edition-cesar-villanueva/

Smashing JQuery 1st Edition Jake Rutter

https://ebookultra.com/download/smashing-jquery-1st-edition-jake-
rutter/

Mastering jQuery Mobile 1st Edition Lambert

https://ebookultra.com/download/mastering-jquery-mobile-1st-edition-
lambert/
Learning jQuery Third Edition Jonathan Chaffer

https://ebookultra.com/download/learning-jquery-third-edition-
jonathan-chaffer/

jQuery and JavaScript Phrasebook 1st Edition Brad Dayley

https://ebookultra.com/download/jquery-and-javascript-phrasebook-1st-
edition-brad-dayley/

Murach s jQuery 2nd Edition Zak Ruvalcaba

https://ebookultra.com/download/murach-s-jquery-2nd-edition-zak-
ruvalcaba/

Drupal 6 JavaScript and jQuery 1st Edition Matt Butcher

https://ebookultra.com/download/drupal-6-javascript-and-jquery-1st-
edition-matt-butcher/

jQuery Mobile Up and Running 1st Edition Maximiliano


Firtman

https://ebookultra.com/download/jquery-mobile-up-and-running-1st-
edition-maximiliano-firtman/
Professional jQuery 1st Edition Cesar Otero Digital
Instant Download
Author(s): Cesar Otero
ISBN(s): 9781118260791, 1118260791
Edition: 1
File Details: PDF, 21.99 MB
Year: 2012
Language: english
ffirs.indd ii 22/03/12 9:13 AM
PROFESSIONAL JQUERY™

INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

 PART I JQUERY FUNDAMENTALS


CHAPTER 1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
CHAPTER 2 JavaScript Primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19
CHAPTER 3 The jQuery Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41
CHAPTER 4 DOM Element Selection and Manipulation . . . . . . . . . . . . . . . . . . . . . . . . 63
CHAPTER 5 Event Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
CHAPTER 6 HTML Forms, Data, and Ajax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
CHAPTER 7 Animations and Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

 PART II APPLIED JQUERY


CHAPTER 8 jQuery UI Part I—Making Things Look Slick . . . . . . . . . . . . . . . . . . . . . . 155
CHAPTER 9 jQuery UI Part II—Mouse Interactions . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
CHAPTER 10 Writing Effective jQuery Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
CHAPTER 11 jQuery Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
CHAPTER 12 Writing jQuery Plugins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
CHAPTER 13 Advanced Asynchronous Programming with jQuery Deferred . . . . . . 263
CHAPTER 14 Unit Testing with QUnit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
APPENDIX Plugins Used In this Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303

INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305

ffirs.indd i 22/03/12 9:13 AM


ffirs.indd ii 22/03/12 9:13 AM
PROFESSIONAL

jQuery™

Cesar Otero
Rob Larsen

John Wiley & Sons, Inc.

ffirs.indd iii 22/03/12 9:13 AM


Professional jQuery™
Published by
John Wiley & Sons, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2012 by John Wiley & Sons, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 978-1-118-02668-7
ISBN: 978-1-118-22211-9 (ebk)
ISBN: 978-1-118-23592-8 (ebk)
ISBN: 978-1-118-26079-1 (ebk)

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108
of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive,
Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed
to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011,
fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with
respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including
without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or
promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work
is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional
services. If professional assistance is required, the services of a competent professional person should be sought. Neither
the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is
referred to in this work as a citation and/or a potential source of further information does not mean that the author or the
publisher endorses the information the organization or Web site may provide or recommendations it may make. Further,
readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this
work was written and when it is read.

For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with
standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media
such as a CD or DVD that is not included in the version you purchased, you may download this material at
http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 2012932975

Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress
are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affi liates, in the United States and other
countries, and may not be used without written permission. jQuery is a trademark of Software Freedom Conservancy
Corporation. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated
with any product or vendor mentioned in this book.

ffirs.indd iv 22/03/12 9:13 AM


To Kala.
—Cesar Otero

This book is dedicated to my wife, Jude, for her


support throughout this project.
—Rob Larsen

ffirs.indd v 22/03/12 9:13 AM


CREDITS

EXECUTIVE EDITOR PRODUCTION MANAGER


Carol Long Tim Tate

PROJECT EDITOR VICE PRESIDENT AND EXECUTIVE GROUP


Ed Connor PUBLISHER
Richard Swadley
TECHNICAL EDITOR
Andrew Montalenti VICE PRESIDENT AND EXECUTIVE
PUBLISHER
PRODUCTION EDITOR Neil Edde
Kathleen Wisor
ASSOCIATE PUBLISHER
COPY EDITOR Jim Minatel
Kim Cofer
PROJECT COORDINATOR, COVER
EDITORIAL MANAGER Katie Crocker
Mary Beth Wakefield
PROOFREADERS
FREELANCER EDITORIAL MANAGER Paul Sagan, Word One
Rosemarie Graham Scott Klemp, Word One

ASSOCIATE DIRECTOR OF MARKETING INDEXER


David Mayhew Johnna VanHoose Dinse

MARKETING MANAGER COVER DESIGNER


Ashley Zurcher LeAndra Young

BUSINESS MANAGER COVER IMAGE


Amy Knies © iStock / Andrew Rich

ffirs.indd vi 22/03/12 9:13 AM


ABOUT THE AUTHORS

CESAR OTERO is a freelance web developer currently living in Mountain View,


California. His technical interests include Python, Django, JavaScript, and
jQuery. Cesar occasionally contributes articles to IBM’s developer works.
He holds a degree in electrical engineering from the Inter American University of
Puerto Rico.

ROB LARSEN has more than 12 years’ experience as a front-end engineer and team
leader, building websites and applications for some of the world’s biggest brands.
He is currently a Senior Specialist, Platform at Sapient Global Markets.
Prior to his time at Sapient, Rob spent time at Isobar, The Brand Experience,
Cramer, and as an independent consultant. Over the course of his career, Rob has
solved unique problems for clients like Adidas, Motorola, Philips, Reebok, Gillette,
Boston’s Museum of Science, State Street Corporation, and Harvard Kennedy School.
Rob is an active writer and speaker on web technology with a special focus on emerging standards
like HTML5, CSS3, and the ongoing evolution of the JavaScript programming language. He’s also
active in the open-source community, helping to bridge the gap between the front lines of web
development and the people actively working on the tools that drive the web.

ABOUT THE TECHNICAL EDITOR

ANDREW MONTALENTI is a technologist with over a decade of experience in software


engineering, and over eight years of experience in web application development. He is
cofounder and CTO at Parse.ly, a tech startup that provides insights to the web’s best
publishers. He is also the founder and CEO of Aleph Point, a boutique consulting
fi rm that specializes in large-scale text analysis, information retrieval, and UI design,
with a focus on Python, Grails, and JavaScript web programming. He specializes in
the rapid development of prototypes. Prior to becoming an entrepreneur, he was a
technical lead and project manager for a small, super-bright team within a top-tier investment bank.

ffirs.indd vii 22/03/12 9:13 AM


ACKNOWLEDGMENTS

MANY THANKS to Andrew Montalenti for taking on the technical editing, and, of course, the
editors at Wiley, Carol Long and Edward Connor. A special thanks to Lynn Haller: without her,
this project wouldn’t have come together. Also, PJ Cabrera for both helping me kickstart my writing
career and introducing me to jQuery.
Thanks to the Hacker Dojo for providing such an amazing coworking space, and to the dojo
members who contributed input.
I’m also grateful to my friends and family for their support and input, most notably Paul Wayland,
Alejandro Valsega, and Valerie Voigt.

—Cesar Otero

I’D LIKE TO THANK the folks at Wiley for giving me this opportunity and especially Carol Long and
Edward Connor for helping me hit the ground running. I’d be crazy not to mention our copy editor,
Kim Cofer, and Andrew Montalenti, our technical editor. Without them, we’d be working without
a spotter. Knowing they’re there to catch us when we stumble makes this a lot easier. I’d also like to
thank Renée Midrack and Lynn Haller from Studio B for steering me towards the opportunity in
the fi rst place.
I defi nitely want to thank the jQuery team and community for being generally phenomenal. Here’s a
big high five to all the great front-end engineers I’ve worked with at Cramer, Isobar, and Sapient —
thanks for pushing me to be a better programmer, manager, and colleague. From Sapient, I need to
specifically thank Jarlath Forde, Joe Morgan, and Alvin Crespo for direct support on the book.

—Rob Larsen

ffirs.indd viii 22/03/12 9:13 AM


CONTENTS

INTRODUCTION xv

PART I: JQUERY FUNDAMENTALS

CHAPTER 1: GETTING STARTED 3

What jQuery Is Good At 3


Hardware and Browser Requirements 4
Obtaining jQuery and jQuery UI 4
“Hello World” Example 5
JavaScript Conventions Used in This Book 6
Development Tools 9
Debugging JavaScript and jQuery 15
Using the FireQuery Plugin 16
Summary 17
CHAPTER 2: JAVASCRIPT PRIMER 19

Understanding Numbers 20
Working with Strings 21
Understanding Booleans 21
Comparison Types 22
A Brief Note About Dates 23
Reviewing Miscellaneous Types 23
Revisiting Variables 24
Understanding Objects 25
Using Functions 29
Understanding Execution Context 32
Working with Scope and Closures 32
Understanding Access Levels 34
Applying Modules 34
Using JavaScript Arrays 35
Augmenting Types 37
Applying JS Best Practices 38
Putting It All Together 38
Summary 39
Note 39

ftoc.indd ix 22/03/12 9:13 AM


CONTENTS

CHAPTER 3: THE JQUERY CORE 41

Understanding the Structure of a jQuery Script 41


Utility Functions 43
Using JavaScript Unobtrusively 52
The jQuery Framework Structure 58
Understanding the DOM and Events 60
Using jQuery with Other JavaScript Libraries 60
Summary 61
Notes 62
CHAPTER 4: DOM ELEMENT SELECTION AND MANIPULATION 63

The Power of jQuery Selectors 64


Selecting Elements 64
Selecting by CSS Styles 66
Selecting by Attributes 68
Selecting by Position 72
Using Filter Selectors 72
Custom User Selectors 81
Doing DOM Traversal 82
Accessing and Modifying Elements,
Attributes, and Content 88
Working with Content 88
Generating HTML 92
Summary 93
CHAPTER 5: EVENT HANDLING 95

Understanding the Browser Event Model 96


Event Capturing and Bubbling 99
Understanding How jQuery Handles Events 101
Applying jQuery Event Handlers 103
Working with Events 108
jQuery’s New Event API 114
Summary 116
Notes 117
CHAPTER 6: HTML FORMS, DATA, AND AJAX 119

jQuery Data Appreciation 119


Using Form Validations 121
Feature Detection with Modernizr 122

ftoc.indd x 22/03/12 9:13 AM


CONTENTS

Working with HTML Form Elements 124


Revisiting Ajax Basics 127
Applying Ajax with jQuery 129
Summary 138
Notes 138
CHAPTER 7: ANIMATIONS AND EFFECTS 141

Animating Elements 141


Animating CSS Properties 143
Resizing Elements 146
Designing Custom Animations 146
Animations with HTML5 Canvas 150
Summary 152
Notes 152

PART II: APPLIED JQUERY


CHAPTER 8: JQUERY UI PART I—MAKING THINGS
LOOK SLICK 155

Theming and Styling 155


Using ThemeRoller 156
Using jQuery UI Widgets 157
Button 158
Tabs 159
Accordion 163
Autocomplete 164
Datepicker 167
Dialog 173
Progressbar 175
Slider 176
Summary 178
Notes 178
CHAPTER 9: JQUERY UI PART II—MOUSE INTERACTIONS 179

Dragging and Dropping 179


Sorting 184
Resizing Elements 188
Making Elements Selectable 192
Summary 194

xi

ftoc.indd xi 22/03/12 9:13 AM


CONTENTS

CHAPTER 10: WRITING EFFECTIVE JQUERY CODE 195

Optimization Techniques 195


Minimize DOM Updates 196
More Effective Looping 198
Caching Objects 200
Use Efficient Selectors 200
Consider Skipping jQuery Methods Entirely 204
DRY 205
Use JavaScript Patterns 206
Creating an Application Namespace with a Singleton 207
The Module Pattern 210
The Garber-Irish Implementation 213
Using $.data() 216
The Basics of the .data() API 216
Fully Leveraging the Data API 217
Summary 219

CHAPTER 11: JQUERY TEMPLATES 221

Taming a Tangle of Strings 221


Separation of Content and Behavior 223
Code Reuse 223
Aesthetics and Clarity 223
The Past, Present, and Future of jQuery Templates 223
Creating Templates 224
Applying Templates with $.tmpl() 226
Applying Templates Using Remote Data 228
Template Tags 230
Summary 240

CHAPTER 12: WRITING JQUERY PLUGINS 241

The Plugin Basics 241


Applying jQuery Plugin Naming Conventions 242
How to Extend jQuery 242
General Plugin Guidelines 244
Applying Plugin Best Practices 249
Utilize and Learn from Existing Plugin Patterns 256
A Closer Look at the Widget Factory 258
An Example Plugin Implementation 259
Summary 262

xii

ftoc.indd xii 22/03/12 9:13 AM


CONTENTS

CHAPTER 13: ADVANCED ASYNCHRONOUS PROGRAMMING WITH


JQUERY DEFERRED 263

Building Blocks 263


Promises 264
The Promises/A Proposal 264
The jQuery Deferred Object 265
Summary 279
CHAPTER 14: UNIT TESTING WITH QUNIT 281

An Introduction to Unit Testing 281


What Is Unit Testing? 282
Benefits of Unit Testing 282
Test-Driven Development 283
Understanding What Makes a Good Unit Test 283
Getting Started with QUnit 284
The QUnit Hello World Using equal 284
A Failing QUnit Test 286
Testing for Truthiness with ok 287
Setting Expectations 287
Additional Assertions 288
Testing DOM Elements 289
Using noglobals and notrycatch 290
Organizing Tests into Modules 292
Asynchronous Testing 294
Using asyncTest 295
Mocking Ajax Requests 296
Putting it All Together in a Test Suite 298
Summary 301
APPENDIX: PLUGINS USED IN THIS BOOK 303

INDEX 305

xiii

ftoc.indd xiii 22/03/12 9:13 AM


flast.indd xiv 22/03/12 9:12 AM
INTRODUCTION

OVER THE PAST SEVERAL YEARS JAVASCRIPT has undergone a remarkable transformation. Where
once it was a “toy” language relegated to secondary status it’s now one of the most important
programming languages in the world. With the ongoing importance of Ajax-based development and
the rise of full-featured JavaScript libraries, the stigma surrounding JavaScript has all but vanished.
As easily the most popular and beginner-friendly library, jQuery is responsible for the lion’s share of
that progress.
jQuery is more than just a beginner’s choice; however, it’s in use at some of the largest organizations
in the world, adding interactivity to billions of page views every month. Amazon, IBM, Twitter,
NBC, Best Buy and Dell are just a few of the companies using jQuery in production.
With a web-scale footprint it should come as no surprise that jQuery is evolving at web speed. 2011
saw no less than three major releases and the community surrounding jQuery continues to blossom
as developers the world over contribute bug fi xes, plugins and work on related projects like jQuery
UI and QUnit. This flurry of activity ensures that jQuery presents a full-featured option for any
developer looking to do world-class JavaScript development.
This is true no matter what programming philosophy or technique is followed: jQuery is
prominently featured in the front end of Java/Spring, PHP, .NET, Ruby on Rails, and Python/
Django stacks all over the Web.
If you have experience with HTML, CSS, and JavaScript, then this book is for you. This book
will expand your jQuery knowledge by focusing on the core library with the benefit of strong
core JavaScript expertise coloring the lessons. The fi rst few chapters will help you to set up a
development environment, and reviews important JavaScript concepts. Chapters 3 to 7 examine the
jQuery core concepts. The second half of the book focuses on applying jQuery in the real world,
detailing jQuery UI, plugin development, templates, unit testing, best practices, and JavaScript
design patterns applied with jQuery.
Hopefully, this book will give you the hardcore jQuery chops you’ll need to solve whatever
problems the Web throws at you.

WHO THIS BOOK IS FOR


This book is aimed at three groups of readers:
➤ Experienced server-side web application developers looking to move more heavily into the
client side using the world’s most popular front-end library
➤ Experienced JavaScript programmers looking to ramp up quickly on jQuery
➤ Novice to intermediate jQuery developers looking to expand their jQuery knowledge into
more advanced topics

flast.indd xv 22/03/12 9:12 AM


INTRODUCTION

This book is not aimed at beginners. For beginners looking to start from the basics of HMTL, CSS,
and JavaScript/jQuery development, Beginning JavaScript and CSS Development with jQuery
(Wrox Programmer to Programmer) by Richard York is a more appropriate choice.

WHAT THIS BOOK COVERS


Professional jQuery provides a developer-level introduction to jQuery as well as providing an in-
depth look at more advanced features.
Starting with the fi rst part, the book offers an in-depth introduction to jQuery fundamentals,
selecting elements, manipulating to the DOM, and binding and reacting to browser events.
Building on that solid foundation the book will outline more advanced topics, including plugin
development, unit testing with JavaScript and other advanced features of the library.
The book focuses on features available as of jQuery 1.7.1, but tries to make note of feature support
in older versions of the library wherever relevant.

HOW THIS BOOK IS STRUCTURED


This book is divided into two parts, jQuery Fundamentals and Applied jQuery. jQuery Fundamentals
introduces the core concepts and Applied jQuery focuses on more advanced subjects.
Part I — jQuery Fundamentals consists of the following chapters:
1. Getting Started — This chapter sets up an environment for developing and debugging
jQuery and JavaScript code and defi nes the code standards that will be used throughout the
book. It also talks about ways to package JavaScript for production and sets up code.
2. JavaScript Primer — This chapter goes through the basics of the JavaScript programming
language to fi rm up the foundation upon which the rest of the book is built. jQuery is a
JavaScript library after all, and many of the best features spring from clever application of
core JavaScript techniques.
3. The jQuery Core — Introduces the basic functions that make up the library. It illuminates
usages of the core jQuery functions and then introduces many of the utility functions that
you’ll use to perform a variety of tasks.
4. DOM Element Selection and Manipulation — This chapter dives into one of the core
features of jQuery, the ability to select and manipulate HTML elements.
5. Event Handling — Introduces another key feature of jQuery, the cross-browser ability to
bind and manage browser events.
6. HTML Forms, Data, and Ajax — Explores one of the biggest revolutions in web development
of the past 10 years — Ajax.
7. Animations and Effects — Explores some of the shortcuts that jQuery offers for animating
components in your web applications such as moving, fading, toggling, and resizing
elements.

xvi

flast.indd xvi 22/03/12 9:12 AM


INTRODUCTION

Part II — Applied jQuery covers the following topics:


8. jQuery UI Part I: Making Things Look Slick — Introduces jQuery UI. jQuery UI is an
associated user interface library for jQuery that contains widgets, effects, animations, and
interactions.
9. jQuery UI Part II: Mouse Interactions — Explores additional jQuery UI features including
moving, sorting, resizing, and selecting elements with the mouse.
10. Writing Effective jQuery Code — Teaches a variety of techniques, best practices,
and patterns that you can apply to your code immediately to make it more efficient,
maintainable, and clear.
11. jQuery Templates — Focuses on the jQuery Template plugin. jQuery templates are a
standard way of marrying data and markup snippets.
12. Writing jQuery Plugins — Focuses on authoring jQuery plugins. Being able to extend the
power of jQuery with custom methods is a fundamental skill for a top jQuery developer.
13. Advanced Asynchronous Programming with jQuery Deferred — Introduces the jQuery
Deferred object. $.Deferred, introduced in version 1.5, is a chainable utility object that
provides fi ne-tuned control over the way callback functions are handled.
14. Unit Testing with QUnit — Introduces the general concept of unit testing and goes into
detail with the specific unit testing framework created and used by the jQuery project itself,
QUnit.

WHAT YOU NEED TO USE THIS BOOK


jQuery supports the following web browsers. You’ll need one of them to run the samples provided
with the book:
➤ Firefox 3.6, Current – 1 version
➤ Internet Explorer 6+
➤ Safari 5.0.x
➤ Opera Current – 1 version
➤ Chrome Current – 1 version

CONVENTIONS
To help you get the most from the text and keep track of what’s happening, we’ve used a number of
conventions throughout the book.

xvii

flast.indd xvii 22/03/12 9:12 AM


INTRODUCTION

Boxes with a warning icon like this one hold important, not-to-be-forgotten
information that is directly relevant to the surrounding text.

The pencil icon indicates notes, tips, hints, tricks, and asides to the current
discussion.

As for styles in the text:


➤ We highlight new terms and important words when we introduce them.
➤ We show keyboard strokes like this: Ctrl+A.
➤ We show fi le names, URLs, and code within the text like so: persistence.properties.
➤ We present code in two different ways:

We use a monofont type with no highlighting for most code examples.

We use bold to emphasize code that is particularly important in the present context
or to show changes from a previous code snippet.

SOURCE CODE
As you work through the examples in this book, you may choose either to type in all the code
manually, or to use the source code fi les that accompany the book. All the source code used in this
book is available for download at www.wrox.com. When at the site, simply locate the book’s title
(use the Search box or one of the title lists) and click the Download Code link on the book’s detail
page to obtain all the source code for the book. Code that is included on the website is highlighted
by the following icon:

Available for
download on
Wrox.com

Listings include the fi lename in the title. If it is just a code snippet, you’ll fi nd the fi lename in a code
note such as this:
Code snippet filename

Because many books have similar titles, you may fi nd it easiest to search by
ISBN; this book’s ISBN is 978-1-118-02668-7.

xviii

flast.indd xviii 22/03/12 9:12 AM


Other documents randomly have
different content
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookultra.com

You might also like