Get JavaScript and DHTML Cookbook 2nd Ed Edition Danny Goodman PDF Ebook With Full Chapters Now
Get JavaScript and DHTML Cookbook 2nd Ed Edition Danny Goodman PDF Ebook With Full Chapters Now
com
https://ebookname.com/product/javascript-and-dhtml-
cookbook-2nd-ed-edition-danny-goodman/
OR CLICK HERE
DOWLOAD NOW
https://ebookname.com/product/pure-javascript-2nd-ed-edition-jason-
gilliam/
ebookname.com
https://ebookname.com/product/python-cookbook-2nd-ed-edition-beazley/
ebookname.com
https://ebookname.com/product/linux-shell-scripting-cookbook-2nd-
ed-2nd-edition-shantanu-tushar/
ebookname.com
https://ebookname.com/product/conquerors-brides-and-concubines-
interfaith-relations-and-social-power-in-medieval-iberia-1st-ed-
edition-barton/
ebookname.com
Under the Surface Fracking Fortunes and the Fate of the
Marcellus Shale 1st Edition Tom Wilber
https://ebookname.com/product/under-the-surface-fracking-fortunes-and-
the-fate-of-the-marcellus-shale-1st-edition-tom-wilber/
ebookname.com
https://ebookname.com/product/get-through-first-frcr-questions-for-
the-anatomy-module-1st-edition-grant-mair/
ebookname.com
https://ebookname.com/product/wiley-cpaexcel-exam-review-2014-study-
guide-financial-accounting-and-reporting-11th-edition-o-ray-
whittington/
ebookname.com
https://ebookname.com/product/work-engagement-a-handbook-of-essential-
theory-and-research-1st-edition-arnold-b-bakker/
ebookname.com
https://ebookname.com/product/handbook-of-birds-of-the-world-
vol-10-cuckoo-shrikes-to-thrushes-part-2-5-1-edition-j-del-hoyo/
ebookname.com
Records Management 8th ed Edition J. Read
https://ebookname.com/product/records-management-8th-ed-edition-j-
read/
ebookname.com
JavaScript & DHTML Cookbook ™
Other resources from O’Reilly
Related titles Adding Ajax HTML & XHTML: The
CSS Cookbook™ Definitive Guide
CSS: The Definitive Guide JavaScript: The Definitive
Dynamic HTML: The Defini- Guide
tive Reference Learning JavaScript
Danny Goodman
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (safari.oreilly.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or [email protected].
Printing History:
April 2003: First Edition.
August 2007: Second Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. The Cookbook series designations, JavaScript and DHTML Cookbook, the image of
a howler monkey, and related trade dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions, or for damages resulting from the use of the information
contained herein.
ISBN-10: 0-596-51408-5
ISBN-13: 978-0-596-51408-2
[M]
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
1. Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Concatenating (Joining) Strings 4
1.2 Improving String Handling Performance 6
1.3 Accessing Substrings 7
1.4 Changing String Case 8
1.5 Testing Equality of Two Strings 9
1.6 Testing String Containment Without Regular Expressions 11
1.7 Testing String Containment with Regular Expressions 13
1.8 Searching and Replacing Substrings 14
1.9 Using Special and Escaped Characters 15
1.10 Reading and Writing Strings for Cookies 17
1.11 Converting Between Unicode Values and String Characters 20
1.12 Encoding and Decoding URL Strings 21
1.13 Encoding and Decoding Base64 Strings 23
v
2.10 Calculating a Previous or Future Date 43
2.11 Calculating the Number of Days Between Two Dates 45
2.12 Validating a Date 47
vi | Table of Contents
5.9 Detecting Object Property and Method Support 124
5.10 Detecting W3C DOM Standard Support 126
5.11 Detecting the Browser Written Language 127
5.12 Detecting Cookie Availability 128
5.13 Defining Browser- or Feature-Specific Links 129
5.14 Testing on Multiple Browser Versions 130
Table of Contents | ix
13.8 Determining the Location of a Nonpositioned Element 414
13.9 Animating Straight-Line Element Paths 415
13.10 Animating Circular Element Paths 419
13.11 Creating a Draggable Element 421
13.12 Scrolling div Content 426
13.13 Creating a Custom Scrollbar 432
13.14 Creating a Slider Control 445
x | Table of Contents
15.8 Displaying the Number of Days Before Christmas 525
15.9 Displaying a Countdown Timer 527
15.10 Creating a Calendar Date Picker 534
15.11 Displaying an Animated Progress Bar 542
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
Table of Contents | xi
Preface 1
It may be difficult to imagine that a technology born as recently as 1995 would have
had enough of a life cycle to experience a rise and fall in popularity, followed now by
an amazing renaissance. Client-side scripting, begun initially with JavaScript embed-
ded in Netscape Navigator 2, has experienced such a roller coaster ride. A number of
early incompatibilities among major browsers caused many a content author’s head
to ache. But we learned to live with it, as a long period of stability in one platform—
Internet Explorer 6, in particular—meant that we could use our well-worn compati-
bility workarounds without cause for concern. Another stabilizing factor was the
W3C DOM Level 2 specification, which remained a major target for browser makers
not following Microsoft’s proprietary ways. Mozilla, Safari, and Opera used the
W3C DOM as the model to implement, even if Microsoft didn’t seem to be in a
hurry to follow suit in all cases.
Two factors have contributed to the rebirth of interest in JavaScript and Dynamic
HTML. The first is the wide proliferation of broadband connections. Implementing
large client-side applications in JavaScript can take a bunch of code, all of which
must be downloaded to the browser. At dial-up speeds, piling a 50–75 kilobyte script
onto a page could seriously degrade perceived performance; at broadband speeds,
nobody notices the difference.
But without a doubt, the major attraction these days is the now widespread availabil-
ity in all mainstream browsers of a technology first implemented by Microsoft: the
XMLHttpRequest object. It’s a mouthful (leading some to refer to it as, simply, XHR),
but it allows background communication between the browser and server so that a
script can request incremental data from the server and update only a portion of a
page. It is far more efficient than downloading a bunch of data with the page and less
visually disruptive than the old submit-and-wait-for-a-new-page process. To help put
a label on the type of applications one can build with this technology, the term Asyn-
chronous JavaScript and XML (Ajax) was coined. In truth, Ajax is simply a catchy
handle for an existing technology.
xiii
Ajax has opened the floodgates for web developers. Perhaps the most popular first
implementation was Google Maps, whereby you could drag your way around a map,
while scripts and the XMLHttpRequest object in the background downloaded adjacent
blocks of the map in anticipation of your dragging your way over there. It was
smooth, fast, and a real joy to use. And now, more powerful applications—word
processors, spreadsheets, email clients—are being built with JavaScript and
DHTML.
JavaScript in the browser was originally designed for small scripts to work on small
client-side tasks. It is still used that way quite a bit around the Web. Not every appli-
cation is a mega DHTML app. Therefore, this collection of recipes still has plenty of
small tasks in mind. At the same time, however, many recipes from the first edition
have been revised with scripting practices that will serve both the beginner and the
more advanced scripter well. Examples prepare you for the eventuality that your
scripting skills will grow, perhaps leading to a mega DHTML app in the future. Even
so, there are plenty of times when you need an answer to that age-old programming
question: “How do I...?”
About You
Client-side scripting and DHTML are such broad and deep subjects that virtually
every reader coming to this book will have different experience levels, expectations,
and perhaps, fears. No book could hope to anticipate every possible question from
someone wishing to use these technologies in his web pages. Therefore, this book
makes some assumptions about readers at various stages of their experience:
• You have at least rudimentary knowledge of client-side JavaScript concepts. You
know how to put scripts into a web page—where <script> tags go, as well as
how to link an external .js file into the current page. You also know what vari-
ables, strings, numbers, Booleans, arrays, and objects are—even if you don’t
necessarily remember the precise way they’re used with the JavaScript language.
This book is not a tutorial, but you can learn a lot from reading the introduc-
tions to each chapter and the discussions following each solution.
• You may be a casual scripter, who wants to put a bit of intelligence into a web
page for some project or other. You don’t use the language or object model every
day, so you need a refresher about even some simple things, such as the correct
syntax for creating an array or preloading images for fast image rollover effects.
• While surfing the Web, you may have encountered some scripted DHTML effect
that you’d like to implement or adapt for your own pages, but either you can’t
decipher the code you see or you want to “roll your own” version to avoid copy-
right problems with the code’s original owner. If the effect or technique you’ve
seen is fairly popular, this cookbook probably has a recipe for it. You can use these
recipes as they are or modify them to fit your designs. There are no royalties or
xiv | Preface
Another Random Document on
Scribd Without Any Related Topics
Pots, kettles and the like should be set upon the range—not
thumped and banged. A nicked cooking utensil is a disgrace to the
handler thereof.
Cracks and scaling-off are still oftener the result of sudden
overheating and of allowing an empty vessel to stand over the fire.
The teakettle boils dry, the soup seethes and simmers until bones
and meat stick to the bottom of the pot. To complete the wreck, the
ignorant or indifferent cook snatches off the misused utensil and
runs with it to the sink, turning the cold-water faucet upon the
heated metal. Yet the mistress marvels at the semi-yearly necessity
of replenishing kitchen tools!
Never put away a vessel which is not both clean and dry. Wash with
hot water, good soap, and household ammonia. Use mop and soap-
shaker, if you would spare your hands and do justice to bottoms,
seams and sides of pot and pan. Rinse off the suds, wipe and set,
upside down, upon the range for thirty seconds to make assurance
doubly sure.
Hang up everything that furnishes the semblance of a loop by which
it may be suspended. And always in its own place, so that you could
find each in the dark.
Cover the shelves of the crockery closet with strips of scalloped
oilcloth that come for the purpose, and the shelves on which you
keep metal pie-plates and pans with stout paper, pinked at the
edges.
If you use tin milk-pans, have them seamless, scald daily with boiling
water into which you have stirred a little baking soda, rinse with
pure water and stand in the sun.
Wooden ware should be scrubbed with a clean, stiff brush and soda-
and-water, rinsed well, wiped and dried near the fire or in the open
window.
Buy three qualities of dish-towels—the finest for glass, silver and
china; the second best for crockery used in kitchen work; the third
for heavy kettles, griddles, etc., and have them washed every day.
Even when no grease adheres to them they have a musty odor if
used several times without washing.
Rub gridirons and griddles with dry salt before each using, wiping it
off with a clean towel.
Never undertake to polish your stove until it is quite cold, and do not
rekindle the fire too soon when the polishing is done.
Next to the range, or stove, the sink is the most important feature of
the kitchen.
“Let me see a woman’s sink, and I will tell you what sort of a
manager she is!” was the saying of a shrewd housemother who had
seen much of life and of cooks.
The waste-pipe should be flushed every day when the water in the
boiler is hottest. During the flushing two tablespoonfuls of strong
ammonia should be poured down the grating over the waste. Once a
week in summer add a handful of crushed washing-soda. And keep
the sink, itself, clean all the time!
Grease should never accumulate upon the sides and in the corners;
tea leaves and other débris never be clotted over the vent.
A stout whisk-brush must hang above the sink and be used freely in
scrubbing it. When the whisk becomes stained and flabby, burn it up
and get another. A dirty brush, mop or dish-cloth makes—not
removes—dirt.
Follow these directions, and if the outer drain-pipes are properly
built, you will have no occasion to employ disinfectants and
deodorizers.
The old New England kitchen was the family sitting-room in winter,
and in thousands of farm-houses, this is still the custom. Since no
device can make the sink and its appurtenances ornamental, or
passably comely, have a tall folding screen that may be drawn in
front of it when the day’s work is done. The mistress who never sits
in her own kitchen, but wishes that her maids should have a
pleasant resting-place in the evenings, may offer the screen for their
use. The better class of “girls” will appreciate the kindly thought.
CHEMISTRY IN THE KITCHEN
Here again I shall be brief and practical. Nobody would read this
page were I to prate learnedly (apparently) of proteids, phosphates,
dextrine, hyposulphites and computed chemical and dietetic values.
The purpose of the honest cook-book is to help, not hinder.
A few facts relative to chemical effects and changes in every-day
cookery should be tabulated.
For example, the mission of the much-used and oft-abused
bicarbonate of soda—familiarly called “baking-soda”—is imperfectly
apprehended by those who handle it most frequently. The average
cook does this handling heavily. “Soda makes bread and biscuits
rise,” is the sum of her knowledge and the aim of her practice in this
direction.
Soda should be measured as accurately as if it were a potent drug,
and never used except in combination with an acid. Even then, lean
to the side of mercy in measuring. One even teaspoonful of soda to
two rounded teaspoonfuls of cream of tartar, one even teaspoonful
of soda to two cupfuls of buttermilk, or “bonny clabber,” one even
teaspoonful of soda to one cupful (one-half pint) of molasses, cause
what may be considered an equitable effervescence, liberating gases
that lighten dough and batter without making them unwholesome.
The “greeny-yellowy” streaks in farmhouse quick biscuits are
poisonous, but the alkali is not in fault. Soda should never be driven
in single harness.
The first stage of incipient decomposition is acidity. If, when a
slightly-suspected fowl or cut of meat is to be boiled or stewed, a
teaspoonful of soda be thrown into the pot as soon as the boil
begins, violent effervescence will attest the presence of the
disturbing acid. This subsiding will leave the meat free from
unpleasant taint.
Beefsteak and chops, which are just a trifle “touched,” may be
restored to sanity by a bath of soda and water, well rubbed in.
Butter that has suffered in quality through the neglect of the maker
in not working all the milk out may be made tolerable for kitchen use
by working it over in iced water in which a little soda has been
dissolved. After which the butter should be wrapped in a salted cloth
with a lump of charcoal in the outer fold.
Ammonia is another beneficent agent in correcting natural or
artificial deficiencies. A bottle of household ammonia should be as
invariably an adjunct to the kitchen sink and that of the waitress’s
pantry as the soap-dish. It “kills” grease by a chemical combination
with it, and lends luster to silver by the same.
Dry soda, laid upon a burn or scald, heals, but not merely by
excluding the air. Flour would do that as well. The alkali acts directly
upon the decomposing skin and vitiated juices of the flesh. The sting
of a bee, wasp or hornet is formic acid; that of a mosquito
something akin to it. Ammonia, applied instantly, neutralizes the
venom and eases the smart.
In the composition of salad dressing, stirring the oil, vinegar, salt,
pepper and dash of mustard together, long and skilfully, makes a
chemical emulsion smoother and more palatable than the hasty slap-
dash mixture too often served as “French dressing.”
Bread-dough which has begun to sour can be brought to terms by
working into the batch a little saleratus dissolved in boiling water,
which is then allowed to become lukewarm before it is kneaded
faithfully through the dough. A like solution should be beaten hard
into griddle-cake batter that has a pungent smell.
Vinegar and lemon juice are invaluable aids in the business of
“tendering” tough meats. Beefsteak, covered for some hours with
vinegar or lemon juice, and olive oil, is made eatable by the action
of the acid upon the fibers which are further “suppled” by the oil.
Vinegar put into the water in which a fowl or mutton is boiled will
serve the same purpose, and a dash of vinegar in boiling fish
removes the strong oily taste that would otherwise cling to it.
Powdered alum stirred into turbid water—an even tablespoonful to
four gallons—will cause a precipitate and a settlement. The clear
water may be drawn off cautiously and used for washing and even
for drinking, having no perceptible taste of the alum.
A bag of powdered charcoal sunk in a pork barrel will keep the brine
sweet through the winter, without blackening it or the meat.
Javelle water, invaluable for removing mildew and rust-stains, may
be made at home in the following manner:
Place four pounds of bicarbonate of soda in a large granite or
porcelain-lined can, and pour over it four quarts of hot water.
Stir with a stick until the soda has dissolved, add a pound of chloride
of lime and stir until this also has dissolved.
Allow the liquid to cool in the pan, strain the clear portion through
thin cloths into wide-mouthed bottles or jugs and cork tightly for
use.
The part that contains the sediment may also be bottled and used
for cleaning sinks, kitchen tables, etc.
An excellent detersive for cleansing and sweetening a kitchen sink is
washing soda. Dissolve a couple of handfuls in hot water and when
boiling hot pour down the drain.
To prevent oil-lamps from smoking or giving forth a disagreeable
odor, boil the wicks in vinegar, then dry in the sun.
CARVING
The present mode of serving meats after the manner of the table
d’hôte—the carving done in the kitchen, and the results placed upon
the platter to be served to the guests by butler or waiter—has in
large measure done away with the demand for hints to the master
or mistress of the home upon the art of carving. To those who
adhere to the earlier custom, directions can be merely outlines; for
the single means by which one may become an adept as a carver is
in the repeated practice which is required for skill in any work of
manipulation.
A prerequisite to carving is appropriate implements. The knife, the
edge of which has been dulled upon the bread-board, or hacked in
the offices of the kitchen, where it has been employed as the
scullion’s tool, may puncture and tear, but it will not carve. In the
hand of even the most skilful it is exasperation.
The mistress of the home owes it to the head of the table, as well as
to the ease of mind of her guests, to see that the carving set—the
knife and its companion fork—shall be in the best condition for their
work.
This will depend upon the form in which the roast is placed upon the
platter. If it include several ribs, furnishing sufficient room for a base
of bone, it may be so put before the carver that he may cut
perpendicularly in thin slices, passing the knife in a line parallel with
the ribs. If, however, the roast be laid upon the side, as is usual, the
same direction is to be observed as to the cutting in lines parallel to
the ribs.
Where a tenderloin roast is to be carved—having but the one large
bone which divides the tenderloin from the more solid portion—there
is little choice whether the knife is drawn with or transversely to the
grain: the tenderness of the meat is assured in either case. It may
be more convenient to sever entirely the tenderloin from the firmer
part of the roast before beginning to slice. This will leave the carver
at liberty to serve a portion of each quality of the meat to every
guest, as the tenderloin may not be of sufficient size to serve to all.
If the small ribs—which are generally taken off for chops—are left
with the leg, the carver is free to ask the preference of each guest
for the rib or solid slice. The chops may be detached by drawing the
point of the knife between the ribs, and—if the butcher has properly
done his part—in severing the light cartilage at the backbone, as in
parting vertebræ. The fleshy portion of the leg will be more tender if
cut in slices at a right angle with the bone, as one would carve a
ham; that is, across the grain. Some carvers, however, prefer to cut
lamb or mutton with the grain, as it enables them to serve a portion
more or less thoroughly cooked, according to the preference of
those to be helped. These directions apply equally to carving a
haunch of venison.
To carve poultry
To carve fish
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.
ebookname.com