The JavaScript Anthology: 101 Essential Tips, Tricks & Hacks (Paperback)

Cameron Adams, James Edwards

  • 出版商: Sitepoint
  • 出版日期: 2006-03-28
  • 售價: $1,540
  • 貴賓價: 9.5$1,463
  • 語言: 英文
  • 頁數: 592
  • 裝訂: Paperback
  • ISBN: 0975240269
  • ISBN-13: 9780975240267
  • 相關分類: JavaScript
  • 無法訂購

買這商品的人也買了...

商品描述

Description  

“Take control with the ultimate JavaScript toolkit”

Among the 101 Tips, Tricks & Hacks you'll learn how-to:
  • Create a slick yet accessible drop-down menu system
  • Take control of your web pages with the DOM
  • Validate forms in real time using regular expressions
  • Optimize your code so that it runs faster
  • Manage style sheets and modify styles on-the-fly
  • Produce sophisticated drag-and-drop interaction
  • Enhance your site with slick, animated transitions
  • Create AJAX applications with the XMLHttpRequest object

…and much more.  Far too many things to mention here!

Table of Contents
  1. Preface
    • Who Should Read this Book?
    • What’s in this Book?
    • The Book’s Web Site
      • The Code Archive
      • Updates and Errata
    • The SitePoint Forums
    • The SitePoint Newsletters
    • Your Feedback
    • Acknowledgements
  2. Getting Started with JavaScript
    • JavaScript Defined
    • JavaScript’s Limitations
      • Security Restrictions
    • JavaScript Best Practices
    • Providing for Users who Don’t Have JavaScript (Progressive Enhancement)
    • Separating Content from Behavior (Unobtrusive Scripting)
    • Using Braces and Semicolons (Consistent Coding Practice)
    • Adding a Script to a Page
      • Putting HTML Comments Around Code
      • The language Attribute
    • Getting Multiple Scripts to Work on the Same Page
    • Hiding JavaScript Source Code
    • Debugging a Script
      • Understanding a Browser’s Built-in Error Reporting
      • Using alert
      • Using try-catch
      • Writing to the Page or Window
      • Using an External Debugger
    • Strict Warnings
    • Summary
  3. Working with Numbers
    • Doing Math with JavaScript
    • Rounding a Number to x Decimal Places
    • Creating and Constraining Random Numbers
    • Converting a Number to a String
    • Formatting Currency Values
    • Converting a String to a Number
    • Converting Numbers to Ordinals (-st, -nd, -rd, -th)
    • Summary
  4. Working with Strings
    • Including a Special Character in a String
    • Transforming the Character Case of a String
    • Encoding a URL
    • Comparing Two Strings
    • Finding a Substring within a String
    • Splitting a String into Substrings
    • Creating a Regular Expression
    • Testing whether a String Matches a Regular Expression
    • Testing whether a String Contains Only Numeric Data
    • Testing whether a String is a Valid Phone Number
    • Testing whether a String is a Valid Email Address
    • Searching and Replacing Text using a Regular Expression
    • Summary
  5. Working with Arrays
    • Using Array-literals
    • Creating an Array of Arrays
    • Indexing an Array with Strings Instead of Numbers
    • Turning an Array into a String
    • Adding or Removing Members from an Array
    • Sorting an Array into Alphabetical or Numeric Order
    • Sorting a Multi-dimensional Array
    • Sorting an Array Randomly
    • Summary
  6. Navigating the Document Object Model
    • Accessing Elements
    • Creating Elements and Text Nodes
    • Changing the Type of an Element
    • Removing an Element or Text Node
    • Reading and Writing the Attributes of an Element
    • Getting all Elements with a Particular Attribute Value
    • Adding and Removing Multiple Classes to/from an Element
    • Summary
  7. Processing and Validating Forms
    • Reading and Writing the Data in a Text Field
    • Reading and Setting the State of a Checkbox
    • Reading and Setting the State of a Radio Button
    • Reading and Setting the Value of a Select Box
    • Validating a Mandatory Text Field
    • Validating a Numeric Field
    • Validating an Email Address Field
    • Checking for Unselected Radio Buttons
    • Stopping a Form Being Submitted Unless all its Fields are Valid
    • Validating a Form with an Unknown Number of Fields
    • Printing Inline Error Messages when Validating a Form
    • Making Form Fields Appear or Disappear, Based on the Value of other Fields
    • Summary
  8. Working with Windows and Frames
    • Using Popup Windows
      • What’s Wrong with Popups?
      • How Do I Minimize the Problems?
    • Opening Off-site Links in a New Window
    • Communicating Between Frames
    • Getting the Scrolling Position
    • Making the Page Scroll to a Particular Position
    • Getting the Viewport Size (the Available Space inside the Window)
    • Summary
  9. Working with Cookies
    • Writing Cookies
    • Reading a Cookie
    • Setting a Cookie to Expire at a Specific Date and Time
    • Making a Cookie Accessible Only from a Specific Domain or Path
    • Circumventing Browser Restrictions on the Number of Cookies you can Use
    • Summary
  10. Working with Dates and Times
    • Getting the Date and Time
    • Formatting a Date into a Sentence
    • Formatting the Time into a 12- or 24-hour Clock
    • Comparing Two Dates
    • Formatting the Difference Between Dates
    • Summary
  11. Working with Images
    • Preloading Images
    • Swapping One Image for Another
    • Displaying an Image at Random
    • Making a Slideshow of Several Images
    • Making an Image Fade in or out
    • Making an Image-based Clock that Updates in Real Time
    • Making a Progress Indicator
    • Summary
  12. Detecting Browser Differences
    • Identifying Support for a Particular Feature
    • Identifying a Particular Browser
    • Detecting Quirks Mode and Standards Mode
    • Summary
  13. Using JavaScript with CSS
    • Changing the Style of a Single Element
    • Changing the Style of a Group of Elements
    • Retrieving the Computed Style of an Element
    • Making a Style Sheet Switcher
      • Maintaining Alternate Style Sheet States
    • Making a Style Sheet Switcher that Handles Multiple Media Types
    • Reading and Modifying an Existing Style Sheet
    • Adding New Style Sheet Rules
    • Deleting a Rule from a Style Sheet
    • Creating a New Style Sheet
    • Summary
  14. Basic Dynamic HTML
    • Handling Events
      • The Short Way: Using Event Handlers
      • The W3C Way (Event Listeners)
        • Referencing the Target Element
        • What is Event Bubbling, and How do I Control it?
    • Finding the Size of an Element
    • Finding the Position of an Element
    • Detecting the Position of the Mouse Cursor
    • Displaying a Tooltip when you Mouse Over an Element
    • Sorting Tables by Column
    • Summary
  15. Time and Motion
    • Using setTimeout and setInterval
    • Making an Object Move Along a Set Path
    • Making Animation Less Jerky
      • Animation Frame Times
      • Changing Between Frames
      • Complexity of the Animation
      • The Speed of the Computer
      • The Speed of the Browser
    • Implementing Drag-and-drop Behavior
    • Reordering a List Using Drag-and-drop Functionality
    • Making a Scrolling News Ticker
    • Creating Clip-based Transition Effects
    • Making a Slider Control
    • Summary
  16. DHTML Menus and Navigation
    • Making a Drop-down or Fly-out Menu
    • Adding Arrows to Indicate the Presence of a Submenu
    • Adding Timers so the Menus Don’t Open and Close so Abruptly
    • Making Sure the Menus Stay Inside the Window
    • Making the Menus Display Over select Elements
    • Making a Folder Tree or Expanding Menu
      • Discussion
    • Indicating Expanded Branches in a Menu
    • Allowing Only One Menu Branch to Be Open at Any Time
    • Opening the Current Sub-branch Automatically
    • Summary
  17. JavaScript and Accessibility
    • Is JavaScript Inaccessible?
      • What is Accessibility?
      • Who are the Affected Users?
    • Making Scripts Accessible to the Keyboard
    • Using Device-independent Event Handlers
    • Making Scripts Accessible to the Keyboard as well as the Mouse
      • Rollovers and Revealing Content
      • Form Validation
      • Drag-and-drop Functionality
      • AJAX and other Remote Scripting Techniques
    • Making title Attribute Tooltips Display on Focus
    • Making a DHTML Menu Accessible to the Keyboard
    • Making a DHTML Menu Usable via the Keyboard
    • Making a DHTML Slider Control Accessible to the Keyboard
    • Making Scripts Accessible to Screen Readers
      • JavaScript Behaviors
        • Rollovers and Revealing Content
        • Form Validation
        • Non-user-initiated Scripts
        • AJAX and other Remote Scripting Techniques
      • Tricks and Hacks
      • Towards Best Practice
        • The Mission
        • The Joy of Mode
        • Reaching toward a Best Practice Approach
        • Into the Future
    • Summary
  18. Using JavaScript with Flash
    • Detecting whether Flash is Installed in a Browser
    • Communicating Between JavaScript and Flash
      • FSCommand
      • Flash/JavaScript Integration Kit
    • Summary
  19. Building Web Applications with JavaScript
    • Retrieving Data Using XMLHttpRequest
      • Requesting Data from a Server
      • Parsing the Data
      • Caching
      • AJAX Frameworks
    • Retrieving Data without Using XMLHttpRequest
    • Creating Custom Dialogs (Such as Popup Forms)
    • Creating Editable Elements
    • Controlling Text Selections
    • Creating an Auto-complete Text Field
    • Summary
  20. Object Orientation in JavaScript
    • What’s so Good about Object Orientation?
      • Abstraction
      • Encapsulation
      • Class Inheritance
      • Polymorphism
    • Object Based Code vs Object Oriented Code
    • Writing an Object Oriented Script
    • Creating Methods for an Object
      • Prototype-based Method Creation
    • Modelling Inheritance
    • Understanding Scope
    • Implementing Namespaces
    • Summary
  21. Keeping up the Pace
    • Making Scripts Run Faster
      • Saving References to Objects you Use Frequently
      • Using Ternary Operators and Switch Statements
      • Optimizing Loops
      • Avoiding eval
      • Avoiding Strict Warnings
      • Optimizing for a Particular Browser
    • Writing Scripts Using Less Code
      • Dividing Tasks into Functions (or Using OO)
      • Using Arrays and Iteration to Avoid Code Repetition
      • Compacting Conditions and Return Statements
    • Optimizing Scripts for the Web
      • Removing Comments and Unnecessary Whitespace
      • Compacting the Names of Variables and Properties
    • Avoiding Memory Leaks
      • Avoiding Circular References
      • Cleaning Up After the Fact
    • Making Scripts Run Before the Load Event
    • Summary
  22. Index