peepcode_unobtrusive_js.pdf

(302 KB) Pobierz
588751990 UNPDF
thanks for buying this pre-release draft. may contain errors or odd formatting. final version will be available at soon.
$9
Unobtrusive
Robust, Organized Javascripting
by Jarkko Laine
thanks for buying this pre-release draft. may contain errors or odd formatting. final version will be available at soon.
Prototype.js
588751990.001.png
thanks for buying this pre-release draft. may contain errors or odd formatting. final version will be available at soon.
PeepCode: Unobtrusive Prototype.js
©2008 Jarkko Laine
Every effort was made to provide accurate infor-
mation in this document. However, neither Cody
Fauser nor Topfunky Corporation shall have any
liability for any errors in the code or descriptions
presented in this book.
“Rails” and “Ruby on Rails” are trademarks of
David Heinemeier Hansson.
This document is available for single users for
US$9 at PeepCode.com ( http://peepcode.com ).
Group discounts and site licenses can also be
purchased by sending email to peepcode@
topfunky.com.
thanks for buying this pre-release draft. may contain errors or odd formatting. final version will be available at soon.
2
thanks for buying this pre-release draft. may contain errors or odd formatting. final version will be available at soon.
contents
5
Introduction. Towards accessible Javascript
9
Brief history of Javascript on Rails
11
Introducing Low Pro
11 Event.addBehaviour
13 Behaviour classes
15 DOM builder
17 Refactoring an existing Rails application
26 Going DRY with multiple elements
34 Bubbling performance with event delegation
38 Caveats
40 More on Behaviour Classes
41 Writing your own behaviours
thanks for buying this pre-release draft. may contain errors or odd formatting. final version will be available at soon.
thanks for buying this pre-release draft. may contain errors or odd formatting. final version will be available at soon.
thanks for buying this pre-release draft. may contain errors or odd formatting. final version will be available at soon.
4
588751990.002.png
thanks for buying this pre-release draft. may contain errors or odd formatting. final version will be available at soon.
Introduction. Towards accessible Javascript
chapter 1
Let’s start by making a few terms straight. The three most important
terms in the scope of this book are accessibility, progressive enhance-
ment and unobtrusiveness. And while interconnected, they don’t
mean the same thing (at all).
The thing that’s been touted a lot lately in Javascript is unobtrusive-
ness. Many people talk about unobtrusive Javascript being all the
rage even though they actually mean accessible or using progressive
enhancement.
Accessibility in Javascript (and in web in general) means that as
many people as possible will have access to the content or function-
ality of the page even if the Javascript implementation in their brows-
ing device is lacking or nonexistent. Attaining some level of acces-
sibility is not only the right thing to do from the viewpoint of both the
bottom line and the readers/customers, but also required by law in
many countries. So writing accessible web applications even when
using the latest and greatest Javascript and Ajax whizbangs is the
learning target of this book.
Progressive enhancement , on the other hand, is a methodology for
building web pages and applications. Its roots are in the term grace-
ful degradation , which was dubbed to mean that web content using
Javascript and/or CSS would, well, degrade gracefully for users whose
browsers were incapable of taking advantage of these technologies.
The problem with graceful degradation is in its wording. It hints that
something is done afterwards to help these poor kids that can’t have
the cool toys to play with. This idea of making something afterwards
implicitly assumes that it will also cost extra. So when the function-
ality of your typical web app was ready and it was time to make it
degrade gracefully, time and money was short so the project lead
thanks for buying this pre-release draft. may contain errors or odd formatting. final version will be available at soon.
5
588751990.003.png
Zgłoś jeśli naruszono regulamin