Books & Videos

Table of Contents

  1. Chapter 1 Working with JavaScript Strings

    1. Introduction

    2. Concatenating Two or More Strings

    3. Concatenating a String and Another Data Type

    4. Conditionally Comparing Strings

    5. Finding a Substring in a String

    6. Extracting a Substring from a String

    7. Checking for an Existing, Nonempty String

    8. Breaking a Keyword String into Separate Keywords

    9. Inserting Special Characters

    10. Processing Individual Lines of a textarea

    11. Trimming Whitespace from the Ends of a String

    12. Left- or Right-Pad a String

  2. Chapter 2 Using Regular Expressions

    1. Introduction

    2. Testing Whether a Substring Exists

    3. Testing for Case-Insensitive Substring Matches

    4. Validating a Social Security Number

    5. Finding and Highlighting All Instances of a Pattern

    6. Replacing Patterns with New Strings

    7. Swap Words in a String Using Capturing Parentheses

    8. Using Regular Expressions to Trim Whitespace

    9. Replace HTML Tags with Named Entities

    10. Searching for Special Characters

  3. Chapter 3 Dates, Time, and Timers

    1. Introduction

    2. Printing Out Today’s Date

    3. Printing Out the UTC Date and Time

    4. Printing Out an ISO 8601 Formatted Date

    5. Converting an ISO 8601 Formatted Date to a Format Acceptable to the Date Object

    6. Creating a Specific Date

    7. Scheduling a Future Date

    8. Tracking Elapsed Time

    9. Creating a Timeout

    10. Creating Recurring Timers

    11. Using Function Closures with Timers

  4. Chapter 4 Working with Numbers and Math

    1. Introduction

    2. Keeping an Incremental Counter

    3. Converting a Decimal to a Hexadecimal Value

    4. Creating a Random Number Generator

    5. Randomly Generating Colors

    6. Converting Strings in a Table to Numbers

    7. Summing All Numbers in a Table Column

    8. Converting Between Degrees and Radians

    9. Find the Radius and Center of a Circle to Fit Within a Page Element

    10. Calculating the Length of a Circular Arc

  5. Chapter 5 Working with Arrays and Loops

    1. Introduction

    2. Looping Through an Array

    3. Creating a Multidimensional Array

    4. Creating a String from an Array

    5. Sorting an Array

    6. Store and Access Values in Order

    7. Store and Access Values in Reverse Order

    8. Create a New Array as a Subset of an Existing Array

    9. Searching Through an Array

    10. Flatten a Multidimensional Array

    11. Search and Remove or Replace Array Elements

    12. Applying a Function Against Each Array Element

    13. Applying a Function to Every Element in an Array and Returning a New Array

    14. Creating a Filtered Array

    15. Validating Array Contents

    16. Using an Associative Array to Store Form Element Names and Values

  6. Chapter 6 Building Reusability with JavaScript Functions

    1. Introduction

    2. Creating a Block of Reusable Code

    3. Passing Single Data Values to and from a Function

    4. Passing Complex Data Objects to a Function

    5. Creating a Dynamic Runtime Function

    6. Passing a Function As an Argument to Another Function

    7. Implementing a Recursive Algorithm

    8. Create a Function That Remembers Its State

    9. Improving Application Performance with a Generalized Currying Function

    10. Improve Application Performance with Memoization (Caching Calculations)

    11. Using an Anonymous Function to Wrap Global Variables

  7. Chapter 7 Handling Events

    1. Introduction

    2. Detecting When the Page Has Finished Loading

    3. Capturing the Location of a Mouse Click Event Using the Event Object

    4. Creating a Generic, Reusable Event Handler Function

    5. Canceling an Event Based on Changed Circumstance

    6. Preventing an Event from Propagating Through a Set of Nested Elements

    7. Capturing Keyboard Activity

    8. Using the New HTML5 Drag-and-Drop

    9. Using Safari Orientation Events and Other Mobile Development Environments

  8. Chapter 8 Browser Pieces

    1. Introduction

    2. Ask the Web Page Reader to Confirm an Action

    3. Creating a New, Stripped-Down Browser Window

    4. Finding Out About the Browser Accessing the Page

    5. Warning the Web Page Reader About Leaving a Page

    6. Changing Stylesheets Depending on Color Support

    7. Modifying Image Dimensions Depending on Page Size

    8. Creating Breadcrumbs in a CMS Template Page

    9. Bookmarking a Dynamic Page

    10. Preserving State for Back Button, Page Refresh

  9. Chapter 9 Form Elements and Validation

    1. Introduction

    2. Accessing Form Text Input Values

    3. Dynamically Disabling and Enabling Form Elements

    4. Getting Information from a Form Element Based on an Event

    5. Performing an Action When a Radio Button Is Clicked

    6. Checking for a Valid Phone Number

    7. Canceling a Form Submission

    8. Preventing Duplicate Form Submissions

    9. Hiding and Displaying Form Elements

    10. Modifying a Selection List Based on Other Form Decisions

  10. Chapter 10 Debugging and Error Handling

    1. Introduction

    2. Gracefully Handling No JavaScript Support

    3. Checking for Errors in Functions

    4. Using an Alert for Simple Debugging

    5. Catching an Error and Providing Graceful Error Handling

    6. Initiating Manageable Errors

    7. Using Firebug with Firefox

    8. Setting a Breakpoint and Examining Data with Firebug

    9. Firefox and the Console

    10. Using IE’s Built-in Debugger

    11. Setting a Breakpoint with IE Developer Tools

    12. Opera’s Dragonfly

    13. Setting a Breakpoint with Dragonfly

    14. Turning on Safari’s Development Tools

    15. Setting a Breakpoint with Safari’s Debugger

    16. Debugging in Chrome

  11. Chapter 11 Accessing Page Elements

    1. Introduction

    2. Access a Given Element and Find Its Parent and Child Elements

    3. Accessing All Images in the Web Page

    4. Discover All Images Within an Article

    5. Discover all Images in Articles Using the Selectors API

    6. Finding the Parent Element for a Group of Elements

    7. Highlighting the First Paragraph in Every Element

    8. Apply a Striping Theme to an Unordered List

    9. Creating an Array of All Elements of a Given Class

    10. Finding All Elements That Share an Attribute

    11. Finding All Checked Options

    12. Summing All the Values in a Table Row

    13. Get Element Attributes

    14. Get Style Information for an Element

  12. Chapter 12 Creating and Removing Elements and Attributes

    1. Introduction

    2. Using innerHTML: A Quick and Easy Approach to Adding Content

    3. Inserting Elements Before Existing Page Elements

    4. Appending a New Element to the End of a Page

    5. Triggering Older Versions of IE to Style New Elements

    6. Inserting a New Paragraph

    7. Adding Text to a New Paragraph

    8. Adding Attributes to an Existing Element

    9. Testing for a Boolean Attribute

    10. Removing an Attribute

    11. Moving a Paragraph

    12. Replacing Links with Footnote Bullets

    13. Adding Rows to an Existing Table

    14. Removing a Paragraph from a div Element

    15. Deleting Rows from an HTML Table

    16. Changing the Element’s CSS Style Properties

  13. Chapter 13 Working with Web Page Spaces

    1. Introduction

    2. Determining the Area of the Web Page

    3. Measuring Elements

    4. Locating Elements in the Page

    5. Hiding Page Sections

    6. Creating Collapsible Form Sections

    7. Adding a Page Overlay

    8. Creating Tab Pages

    9. Creating Hover-Based Pop-up Info Windows

    10. Collapsing or Resizing the Sidebar

  14. Chapter 14 Creating Interactive and Accessible Effects with JavaScript, CSS, and ARIA

    1. Introduction

    2. Displaying a Hidden Page Section

    3. Creating an Alert Message

    4. Highlighting Form Field with Missing or Incorrect Data

    5. Adding Keyboard Accessibility to a Page Overlay

    6. Creating Collapsible Form Sections

    7. Displaying a Flash of Color to Signal an Action

    8. Adding ARIA Attributes to a Tabbed Page Application

    9. Live Region

  15. Chapter 15 Creating Media Rich and Interactive Applications

    1. Introduction

    2. Creating Basic Shapes in Canvas (Using the canvas Element)

    3. Implementing Canvas Applications in IE

    4. Creating a Dynamic Line Chart in Canvas

    5. Adding JavaScript to an SVG File

    6. Accessing SVG from Web Page Script

    7. Emulating SVG in Internet Explorer

    8. Enable Interactive SVG Embedded in HTML

    9. Using the Math Functions to Create a Realistic, Ticking Analog Clock in SVG

    10. Integrating SVG and the Canvas Element in HTML

    11. Turning on WebGL Support in Firefox and WebKit/Safari

    12. Running a Routine When an Audio File Begins Playing

    13. Controlling Video from JavaScript with the video Element

  16. Chapter 16 JavaScript Objects

    1. Introduction

    2. Defining a Basic JavaScript Object

    3. Keeping Object Members Private

    4. Expanding Objects with prototype

    5. Adding Getter/Setter to Objects

    6. Inheriting an Object’s Functionality

    7. Extending an Object by Defining a New Property

    8. Enumerating an Object’s Properties

    9. Preventing Object Extensibility

    10. Preventing Object Additions and Changes to Property Descriptors

    11. Preventing Any Changes to an Object

    12. One-Off Objects and Namespacing Your JavaScript

    13. Rediscovering “this” with Prototype.bind

    14. Chaining Your Object’s Methods

  17. Chapter 17 JavaScript Libraries

    1. Introduction

    2. Packaging Your Code

    3. Testing Your Code with JsUnit

    4. Minify Your Library

    5. Hosting Your Library

    6. Using an External Library: Building on the jQuery Framework

    7. Using Existing jQuery Plug-ins

    8. Convert Your Library to a jQuery Plug-in

    9. Safely Combining Several Libraries in Your Applications

  18. Chapter 18 Communication

    1. Introduction

    2. Accessing the XMLHttpRequest Object

    3. Preparing the Data for Transmission

    4. Determining the Type of Query Call

    5. Adding a Callback Function to an Ajax Request

    6. Checking for an Error Condition

    7. Processing a Text Result

    8. Making an Ajax Request to Another Domain (Using JSONP)

    9. Populating a Selection List from the Server

    10. Using a Timer to Automatically Update the Page with Fresh Data

    11. Communicating Across Windows with PostMessage

  19. Chapter 19 Working with Structured Data

    1. Introduction

    2. Process an XML Document Returned from an Ajax Call

    3. Extracting Pertinent Information from an XML Tree

    4. Generate a JavaScript Object with JSON, Old-School Style

    5. Parse a JSON Formatted String

    6. Convert an Object to a Filtered/Transformed String with JSON

    7. Convert hCalendar Microformat Annotations into a Canvas Timeline

    8. Glean Page RDFa and Convert It into JSON Using rdfQuery and the jQuery RDF Plug-in

  20. Chapter 20 Persistence

    1. Introduction

    2. Attaching Persistent Information to URLs

    3. Creating a Cookie to Persist Information Across Pages

    4. Persisting Information Using the History.pushState Method and window.onpopevent

    5. Using sessionStorage for Client-Side Storage

    6. Creating a localStorage Client-Side Data Storage Item

    7. Persisting Data Using a Relational Data Store

  21. Chapter 21 JavaScript Outside the Box

    1. Introduction

    2. Creating a Browser Add-0n, Plug-in, or Extension

    3. Creating Desktop and Mobile Widgets

    4. Creating JavaScript Applications for the iPhone, Android, and BlackBerry with PhoneGap

    5. Enhancing Tools with JavaScript

    6. Creating Efficient Desktop Applications with Web Workers and the File API

  1. Colophon