Instant Download Building iPhone Apps with HTML CSS and JavaScript Making App Store Apps Without Objective C or Cocoa 1st Edition Jonathan Stark PDF All Chapters
Instant Download Building iPhone Apps with HTML CSS and JavaScript Making App Store Apps Without Objective C or Cocoa 1st Edition Jonathan Stark PDF All Chapters
com
https://ebookname.com/product/building-iphone-apps-with-
html-css-and-javascript-making-app-store-apps-without-
objective-c-or-cocoa-1st-edition-jonathan-stark/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookname.com/product/building-android-apps-with-html-css-and-
javascript-2nd-edition-jonathan-stark/
ebookname.com
https://ebookname.com/product/essential-app-engine-building-high-
performance-java-apps-with-google-app-engine-1st-edition-adriaan-de-
jonge/
ebookname.com
https://ebookname.com/product/beginning-iphone-and-ipad-web-apps-
scripting-with-html5-css3-and-javascript-1st-edition-chris-apers/
ebookname.com
https://ebookname.com/product/get-it-set-it-move-it-prove-it-60-ways-
to-get-real-results-in-your-organization-1st-edition-mark-graham-
brown/
ebookname.com
Schaum s Outline of Electric Circuts 4th Edition
Edminister
https://ebookname.com/product/schaum-s-outline-of-electric-
circuts-4th-edition-edminister/
ebookname.com
https://ebookname.com/product/the-heston-model-and-its-extensions-in-
vba-1st-edition-fabrice-d-rouah/
ebookname.com
https://ebookname.com/product/advances-in-applied-microbiology-60-1st-
edition-allen-i-laskin/
ebookname.com
https://ebookname.com/product/advances-in-decision-analysis-from-
foundations-to-applications-1st-edition-ward-edwards/
ebookname.com
https://ebookname.com/product/hell-of-a-vision-regionalism-and-the-
modern-american-west-1st-edition-robert-l-dorman/
ebookname.com
Drug Courts In Theory and in Practice 1st Edition James L.
Nolan Jr. (Ed.)
https://ebookname.com/product/drug-courts-in-theory-and-in-
practice-1st-edition-james-l-nolan-jr-ed/
ebookname.com
Building iPhone Apps with HTML, CSS, and
JavaScript
Building iPhone Apps with HTML,
CSS, and JavaScript
Jonathan Stark
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 (http://my.safaribooksonline.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.
Printing History:
January 2010: First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Building iPhone Apps with HTML, CSS, and JavaScript, the image of a bluebird, 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 con-
tained herein.
This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0
United States License.
TM
ISBN: 978-0-596-80578-4
[M]
1262957633
To Erica—and that little jumping bean in her
tummy.
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
1. Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Web Apps Versus Native Apps 1
What Is a Web App? 1
What Is a Native App? 1
Pros and Cons 2
Which Approach Is Right for You? 2
Web Programming Crash Course 3
Intro to HTML 3
Intro to CSS 6
Intro to JavaScript 9
vii
What You’ve Learned 50
4. Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
With a Little Help from Our Friend 51
Sliding Home 51
Adding the Dates Panel 55
Adding the Date Panel 56
Adding the New Entry Panel 58
Adding the Settings Panel 60
Putting It All Together 62
Customizing jQTouch 64
What You’ve Learned 67
6. Going Offline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
The Basics of the Offline Application Cache 91
Online Whitelist and Fallback Options 94
Creating a Dynamic Manifest File 98
Debugging 102
The JavaScript Console 103
The Application Cache Database 107
What You’ve Learned 113
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Table of Contents | ix
Preface
Like millions of people, I fell in love with my iPhone immediately. Initially, web apps
were the only way to get a custom app on the device, which was fine by me because
I’m a web developer. Months later when the App Store was announced, I was jacked.
I ran out and bought every Objective-C book on the market. Some of my web apps
were already somewhat popular, and I figured I’d just rewrite them as native apps, put
them in the App Store, and ride off into the sunset on a big, galloping pile of money.
Disillusionment followed. I found it difficult to learn Objective-C, and I was turned off
by the fact that the language was of little use outside of Mac programming. Xcode and
Interface Builder were pretty slick, but they weren’t my normal authoring environment
and I found them hard to get accustomed to. I was infuriated by the hoops I had to
jump through just to set up my app and iPhone for testing. The process of getting the
app into the App Store was even more byzantine. After a week or two of struggling with
these variables, I found myself wondering why I was going to all the trouble. After all,
my web apps were already available worldwide—why did I care about being in the App
Store?
On top of all this, Apple can—and does—reject apps. This is certainly their prerogative,
and maybe they have good reasons. However, from the outside, it seems capricious and
arbitrary. Put yourself in these shoes (based on a true story, BTW): you spend about
100 hours learning Objective-C. You spend another 100 hours or so writing a native
iPhone app. Eventually, your app is ready for prime time and you successfully navigate
the gauntlet that is the App Store submission process. What happens next?
You wait. And wait. And wait some more. We are talking weeks, and sometimes
months. Finally you hear back! And...your app is rejected. Now what? You have noth-
ing to show for your effort. The bubble.
But wait, it can get worse. Let’s say you do get your app approved. Hundreds or maybe
thousands of people download your app. You haven’t received any money yet, but you
are on cloud nine. Then, the bug reports start coming in. You locate and fix the bug in
minutes, resubmit your app to iTunes, and wait for Apple to approve the revision. And
wait. And wait some more. Angry customers are giving you horrible reviews in the App
Store. Your sales are tanking. And still you wait. You consider offering a refund to the
xi
angry customers, but there’s no way to do that through the App Store. So you are
basically forced to sit there watching your ratings crash even though the bug was fixed
days or weeks ago.
Sure, this story is based on the experience of one developer. Maybe it’s an edge case
and the actual data doesn’t bear out my thesis. But the problem remains: we developers
have no access to Apple’s data, or the real details of the App Store approval process.
Until that changes, building a native app with Objective-C is a risky proposition.
Fortunately, there is an alternative. You can build a web app using open source,
standards-based web technologies, release it as a web app, and debug and test it under
load with real users. Once you are ready to rock, you can use PhoneGap to convert
your web app to a native iPhone app and submit it to the App Store. If it’s ultimately
rejected, you aren’t dead in your tracks because you can still offer the web app. If it’s
approved, great! You can then start adding features that enhance your web app by
taking advantage of the unique hardware features available on the device. Sounds like
the best of both worlds, right?
xii | Preface
Constant width bold
Shows commands or other text that should be typed literally by the user and for
emphasis within code listings.
Constant width italic
Shows text that should be replaced with user-supplied values or by values deter-
mined by context.
Preface | xiii
feedback for the authors. Copy and paste code samples, organize your favorites, down-
load chapters, bookmark key sections, create notes, print out pages, and benefit from
tons of other time-saving features.
O’Reilly Media has uploaded this book to the Safari Books Online service. To have full
digital access to this book and others on similar topics from O’Reilly and other pub-
lishers, sign up for free at http://my.safaribooksonline.com.
How to Contact Us
Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any additional
information. You can access this page at:
http://www.oreilly.com/catalog/9780596805784/
To comment or ask technical questions about this book, send email to:
bookquestions@oreilly.com
For more information about our books, conferences, Resource Centers, and the
O’Reilly Network, see our website at:
http://www.oreilly.com
Acknowledgments
Writing a book is a team effort. My heartfelt thanks go out to the following people for
their generous contributions.
Tim O’Reilly, Brian Jepson, and the rest of the gang at ORM for making the experience
of writing this book so rewarding and educational.
Jack Templin, Providence Geeks, and RI Nexus for introducing me to the thriving tech
scene in my own hometown. This book wouldn’t exist if it weren’t for Providence
Geeks.
David Kandeda for his wonderfully obsessive pursuit of beauty. Whether it’s a bit of
code, or a user interface animation, he can’t sleep until it’s perfect, and I love that.
Brian LeRoux, Brock Whitten, Rob Ellis, and the rest of the gang at Nitobi for creating
and continuing to support PhoneGap.
xiv | Preface
Brian Fling for broadening my view of mobile beyond just the latest and greatest hard-
ware. Brian knows mobile from back in the day; he’s a wonderful writer, and on top
of that, a very generous guy.
PPK, John Gruber, John Allsopp, and John Resig for their contributions to and support
of the underlying technologies that made this book possible.
Garrett Murray, Brian LeRoux, and the swarm of folks who generously posted com-
ments and questions on the OFPS site for this book. Your feedback was very helpful
and much appreciated.
Kazu, Chuckie, Janice, Chris, and the rest of the gang at Haruki for being so accom-
modating while I endlessly typed away at the high top by the door.
My wonderful family, friends, and clients for being understanding and supportive while
I was chained to the keyboard.
And finally, Erica. You make everything possible. I love you!
Preface | xv
CHAPTER 1
Getting Started
Before we dive in and start building applications for the iPhone, I’d like to quickly
establish the playing field. In this chapter, I’ll define key terms, compare the pros and
cons of the two most common development approaches, and present a crash course in
the three core web technologies that are used in this book.
1
Pros and Cons
Different applications have different requirements. Some apps are a better fit with web
technologies than others. Knowing the pros and cons of each approach will help you
make the right decision about which path is appropriate for your situation.
Here are the pros of native app development:
• Millions of registered credit card owners are one click away.
• Xcode, Interface Builder, and the Cocoa Touch framework constitute a pretty
sweet development environment.
• You can access all the cool hardware features of the device.
Here are the cons of native app development:
• You have to pay to become an Apple developer.
• You are at the mercy of the Apple approval process.
• You have to develop using Objective-C.
• You have to develop on a Mac.
• You can’t release bug fixes in a timely fashion.
• The development cycle is slow, and the testing cycle is constrained by the App
Store’s limitations.
Here are the pros of web app development:
• Web developers can use their current authoring tools.
• You can use your current web design and development skills.
• You are not limited to developing on the Mac OS.
• Your app will run on any device that has a web browser.
• You can fix bugs in real time.
• The development cycle is fast.
Here are the cons of web app development:
• You cannot access the all cool hardware features of the phone.
• You have to roll your own payment system if you want to charge for the app.
• It can be difficult to achieve sophisticated UI effects.
Intro to HTML
When you’re browsing the Web, the pages that you are viewing are just text documents
sitting on someone else’s computer. The text in a typical web page is wrapped in HTML
tags, which tell your browser about the structure of the document. With this informa-
tion, the browser can decide how to display the information in a way that makes sense.
Consider the web page snippet shown in Example 1-1. On the first line, the string Hi
there! is wrapped in a pair of h1 tags. (Notice that the open tag and the close tag are
slightly different: the close tag has a slash as the second character, while the open tag
does not.)
Wrapping some text in h1 tags tells the browser that the words enclosed are a heading,
which will cause it to be displayed in large bold text on its own line. There are also
h2, h3, h4, h5, and h6 heading tags. The lower the number, the more important the
header, so text wrapped in an h6 tag will be smaller (i.e., less important-looking) than
text wrapped in an h3 tag.
After the h1 tag in Example 1-1 are two lines wrapped in p tags. These are called para-
graph tags. Browsers will display each paragraph on its own line. If the paragraph is
long enough to exceed the width of the browser window, the text will bump down and
continue on the next line. In either case, a blank line will be inserted after the paragraph
to separate it from the next item on the page.
Example 1-1. HTML snippet
<h1>Hi there!</h1>
<p>Thanks for visiting my web page.</p>
<p>I hope you like it.</p>
The tags I’ve covered so far are all block tags. The defining characteristic of a block tag
is that it is displayed on a line of its own, with no elements to its left or right. That is
why headings, paragraphs, and list items progress down the page instead of across it.
The opposite of a block tag is an inline tag, which, as the name implies, can appear in
a line. The emphasis tag (em) is an example of an inline tag, and it looks like this:
<p>I <em>really</em> hope you like it.</p>
The granddaddy of the inline tags—and arguably the coolest feature of HTML—is the
a tag. The a stands for anchor, but I’ll also refer to the tag as a link or hyperlink. Text
wrapped in an anchor tag becomes clickable, such that clicking on it causes your
browser to load a new HTML page.
In order to tell the browser what new page to load, we have to add what’s called an
attribute to the tag. Attributes are named values that are inserted into an open tag. In
an anchor tag, you use the href attribute to specify the location of the target page. Here’s
a link to Google’s home page:
<a href="http://www.google.com/">Google</a>
That might look like a bit of a jumble if you are not used to reading HTML, but you
should be able to pick out the URL for the Google home page. You’ll be seeing a lot of
a tags and hrefs throughout the book, so take a minute to get your head around this if
it doesn’t make sense at first glance.
Normally, when you are using your web browser you are viewing pages that are hosted
on the Internet. However, browsers are perfectly good at displaying HTML documents
that are on your local machine as well. To see what I mean, crack open a text editor
and type up Example 1-3. When you are done, save it to your desktop as test.html and
then open it with Safari by either dragging the file onto the Safari application icon or
opening Safari and selecting File→Open File. Double-clicking test.html might work as
well, but it could open in your text editor or another browser depending on your
settings.
Even if you aren’t running Mac OS X, you should use Safari when testing
your iPhone web apps on a desktop web browser, because Safari is the
closest desktop browser to the iPhone’s Mobile Safari. Safari for Win-
dows is available from http://www.apple.com/safari/.
Intro to CSS
As you’ve seen, browsers render certain HTML elements with distinct styles (headings
are large and bold, paragraphs are followed by a blank line, etc.). These styles are very
basic and are primarily intended to help the reader understand the structure and mean-
ing of the document.
To go beyond this simple structure-based rendering, you can use Cascading Style Sheets
(CSS). CSS is a stylesheet language that is used to define the visual presentation of an
HTML document. You can use CSS to define simple things like the text color, size, and
style (bold, italic, etc.), or complex things like page layout, gradients, opacity, and much
more.
Example 1-4 shows a CSS rule that instructs the browser to display any text in the body
element using the color red. In this example, body is the selector (what is affected by the
rule) and the curly braces enclose the declaration (the rule itself). The declaration in-
cludes a set of properties and their values. In this example, color is the property, and
red is the value of the property.
Property names are predefined in the CSS specification, which means that you can’t
just make them up. Each property expects an appropriate value, and there can be lots
of appropriate values and value formats for a given property.
For example, you can specify colors with predefined keywords like red, or by using
HTML color code notation. This uses a hexadecimal notation: three pairs of hexadec-
imal digits (0–F) representing (from left to right) Red, Green, and Blue values. Proper-
ties that expect measurements can accept values like 10px, 75%, and 1em. Example 1-5
shows some common declarations. (The color code shown for background-color cor-
responds to the CSS “gray”.)
Example 1-5. Some common CSS declarations
body {
color: red;
background-color: #808080;
Selectors come in a variety of flavors. If you wanted all of your hyperlinks (the a element)
to display in italics, you would add the following to your stylesheet:
a { font-style: italic; }
If you wanted to be more specific and only italicize the hyperlinks that were contained
somewhere within an h1 tag, you would add the following to your stylesheet:
h1 a { font-style: italic; }
You can also define your own custom selectors by adding id and/or class attributes to
your HTML tags. Consider the following HTML snippet:
<h1 class="loud">Hi there!</h1>
<p id="highlight">Thanks for visiting my web page.</p>
<p>I hope you like it.</p>
<ul>
<li class="loud">Pizza</li>
<li>Beer</li>
<li>Dogs</li>
</ul>
If I added .loud { font-style: italic; } to the CSS for this HTML, Hi there! and
Pizza would show up italicized because they both have the loud class. The dot in front
of the .loud selector is important. It’s how the CSS knows to look for HTML tags with
a class of loud. If you omit the dot, the CSS would look for a loud tag, which doesn’t
exist in this snippet (or in HTML at all, for that matter).
Applying CSS by id is similar. To add a yellow background fill to the highlight para-
graph tag, you’d use this rule:
#highlight { background-color: yellow; }
Here, the # symbol tells the CSS to look for an HTML tag with the id highlight.
To recap, you can opt to select elements by tag name (e.g., body, h1, p), by class name
(e.g., .loud, .subtle, .error), or by id (e.g., #highlight, #login, #promo). And you can
get more specific by chaining selectors together (e.g., h1 a, body ul .loud).
There are differences between class and id. class attributes should be
used when you have more than one item on the page with the same
class value. Conversely, id values have to be unique to a page.
When I first learned this, I figured I’d just always use class attributes
so I wouldn’t have to worry about whether I was duping an id value.
However, selecting elements by id is much faster than selecting them
by class, so you can hurt your performance by overusing class selectors.
The light that falls from the windows of the Neighborhood Guild, in
Delancey Street, makes a white path across the asphalt pavement.
Within, there is mirth and laughter. The Tenth Ward Social Reform
Club is having its Christmas festival. Its members, poor mothers,
scrub-women,—the president is the janitress of a tenement near by,
—have brought their little ones, a few their husbands, to share in
the fun. One little girl has to be dragged up to the grab-bag. She
cries at the sight of Santa Claus. The baby has drawn a woolly
horse. He kisses the toy with a look of ecstatic bliss, and toddles
away. At the far end of the hall a game of blindman's-buff is starting
up. The aged grandmother, who has watched it with growing
excitement, bids one of the settlement workers hold her grandchild,
that she may join in; and she does join in, with all the pent-up
hunger of fifty joyless years. The worker, looking on, smiles; one has
been reached. Thus is the battle against the slum waged and won
with the child's play.
Tramp! tramp! comes the to-morrow upon the stage. Two hundred
and fifty pairs of little feet, keeping step, are marching to dinner in
the Newsboys' Lodging-house. Five hundred pairs more are
restlessly awaiting their turn upstairs. In prison, hospital, and
almshouse to-night the city is host, and gives of her plenty. Here an
unknown friend has spread a generous repast for the waifs who all
the rest of the days shift for themselves as best they can. Turkey,
coffee, and pie, with "vegetubles" to fill in. As the file of eagle-eyed
youngsters passes down the long tables, there are swift movements
of grimy hands, and shirt-waists bulge, ragged coats sag at the
pockets. Hardly is the file seated when the plaint rises: "I ain't got
no pie! It got swiped on me." Seven despoiled ones hold up their
hands.
The superintendent laughs—it is Christmas eve. He taps one
tentatively on the bulging shirt. "What have you here, my lad?"
"Me pie," responds he, with an innocent look; "I wuz scart it would
get stole."
A little fellow who has been eying one of the visitors attentively
takes his knife out of his mouth, and points it at him with conviction.
"I know you," he pipes. "You're a p'lice commissioner. I seen yer
picter in the papers. You're Teddy Roosevelt!"
The clatter of knives and forks ceases suddenly. Seven pies creep
stealthily over the edge of the table, and are replaced on as many
plates. The visitors laugh. It was a case of mistaken identity.
Farthest down town, where the island narrows toward the Battery,
and warehouses crowd the few remaining tenements, the sombre-
hued colony of Syrians is astir with preparation for the holiday. How
comes it that in the only settlement of the real Christmas people in
New York the corner saloon appropriates to itself all the outward
signs of it? Even the floral cross that is nailed over the door of the
Orthodox church is long withered and dead; it has been there since
Easter, and it is yet twelve days to Christmas by the belated
reckoning of the Greek Church. But if the houses show no sign of
the holiday, within there is nothing lacking. The whole colony is gone
a-visiting. There are enough of the unorthodox to set the fashion,
and the rest follow the custom of the country. The men go from
house to house, shake hands, and kiss one another on both cheeks,
with the salutation, "Kol am va antom Salimoon." "Every year and
you are safe," the Syrian guide renders it into English; and a non-
professional interpreter amends it: "May you grow happier year by
year." Arrack made from grapes and flavored with aniseseed, and
candy baked in little white balls like marbles, are served with the
indispensable cigarette; for long callers, the pipe.
In a top-floor room of one of the darkest of the dilapidated
tenements, the dusty window panes of which the last glow in the
winter sky is tinging faintly with red, a dance is in progress. The
guests, most of them fresh from the hillsides of Mount Lebanon,
squat about the room. A reed-pipe and a tambourine furnish the
music. One has the centre of the floor. With a beer jug filled to the
brim on his head, he skips and sways, bending, twisting, kneeling,
gesturing, and keeping time, while the men clap their hands. He lies
down and turns over, but not a drop is spilled. Another succeeds
him, stepping proudly, gracefully, furling and unfurling a
handkerchief like a banner. As he sits down, and the beer goes
around, one in the corner, who looks like a shepherd fresh from his
pasture, strikes up a song—a far-off, lonesome, plaintive lay. "'Far as
the hills,'" says the guide; "a song of the old days and the old
people, now seldom heard." All together croon the refrain. The host
delivers himself of an epic about his love across the seas, with the
most agonizing expression, and in a shockingly bad voice. He is the
worst singer I ever heard; but his companions greet his effort with
approving shouts of "Yi! yi!" They look so fierce, and yet are so
childishly happy, that at the thought of their exile and of the dark
tenement the question arises, "Why all this joy?" The guide answers
it with a look of surprise. "They sing," he says, "because they are
glad they are free. Did you not know?"
The bells in old Trinity chime the midnight hour. From dark hallways
men and women pour forth and hasten to the Maronite church. In
the loft of the dingy old warehouse wax candles burn before an altar
of brass. The priest, in a white robe with a huge gold cross worked
on the back, chants the ritual. The people respond. The women
kneel in the aisles, shrouding their heads in their shawls; a surpliced
acolyte swings his censer; the heavy perfume of burning incense fills
the hall.
The band at the anarchists' ball is tuning up for the last dance.
Young and old float to the happy strains, forgetting injustice,
oppression, hatred. Children slide upon the waxed floor, weaving
fearlessly in and out between the couples—between fierce, bearded
men and short-haired women with crimson-bordered kerchiefs. A
Punch-and-Judy show in the corner evokes shouts of laughter.
Outside the snow is falling. It sifts silently into each nook and corner,
softens all the hard and ugly lines, and throws the spotless mantle of
charity over the blemishes, the shortcomings. Christmas morning will
dawn pure and white.
WHAT THE CHRISTMAS SUN SAW
IN THE TENEMENTS
The December sun shone clear and cold upon the city. It shone upon
rich and poor alike. It shone into the homes of the wealthy on the
avenues and in the up-town streets, and into courts and alleys
hedged in by towering tenements down town. It shone upon throngs
of busy holiday shoppers that went out and in at the big stores,
carrying bundles big and small, all alike filled with Christmas cheer
and kindly messages from Santa Claus.
It shone down so gayly and altogether cheerily there, that wraps
and overcoats were unbuttoned for the north wind to toy with. "My,
isn't it a nice day?" said one young lady in a fur shoulder cape to a
friend, pausing to kiss and compare lists of Christmas gifts.
"Most too hot," was the reply, and the friends passed on. There was
warmth within and without. Life was very pleasant under the
Christmas sun up on the avenue.
Down in Cherry Street the rays of the sun climbed over a row of tall
tenements with an effort that seemed to exhaust all the life that was
in them, and fell into a dirty block, half choked with trucks, with ash
barrels and rubbish of all sorts, among which the dust was whirled in
clouds upon fitful, shivering blasts that searched every nook and
cranny of the big barracks. They fell upon a little girl, barefooted and
in rags, who struggled out of an alley with a broken pitcher in her
grimy fist, against the wind that set down the narrow slit like the
draught through a big factory chimney. Just at the mouth of the
alley it took her with a sudden whirl, a cyclone of dust and drifting
ashes, tossed her fairly off her feet, tore from her grip the
threadbare shawl she clutched at her throat, and set her down at
the saloon door breathless and half smothered. She had just time to
dodge through the storm-doors before another whirlwind swept
whistling down the street.
"My, but isn't it cold?" she said, as she shook the dust out of her
shawl and set the pitcher down on the bar. "Gimme a pint," laying
down a few pennies that had been wrapped in a corner of the shawl,
"and mamma says make it good and full."
"All'us the way with youse kids—want a barrel when yees pays fer a
pint," growled the bartender. "There, run along, and don't ye hang
around that stove no more. We ain't a steam-heatin' the block fer
nothin'."
The little girl clutched her shawl and the pitcher, and slipped out into
the street where the wind lay in ambush and promptly bore down on
her in pillars of whirling dust as soon as she appeared. But the sun
that pitied her bare feet and little frozen hands played a trick on old
Boreas—it showed her a way between the pillars, and only just her
skirt was caught by one and whirled over her head as she dodged
into her alley. It peeped after her halfway down its dark depths,
where it seemed colder even than in the bleak street, but there it
had to leave her.
It did not see her dive through the doorless opening into a hall
where no sun-ray had ever entered. It could not have found its way
in there had it tried. But up the narrow, squeaking stairs the girl with
the pitcher was climbing. Up one flight of stairs, over a knot of
children, half babies, pitching pennies on the landing, over wash-
tubs and bedsteads that encumbered the next—house-cleaning
going on in that "flat"; that is to say, the surplus of bugs was being
turned out with petroleum and a feather—up still another, past a
half-open door through which came the noise of brawling and
curses. She dodged and quickened her step a little until she stood
panting before a door on the fourth landing that opened readily as
she pushed it with her bare foot.
A room almost devoid of stick or rag one might dignify with the
name of furniture. Two chairs, one with a broken back, the other on
three legs, beside a rickety table that stood upright only by leaning
against the wall. On the unwashed floor a heap of straw covered
with dirty bedtick for a bed; a foul-smelling slop-pail in the middle of
the room; a crazy stove, and back of it a door or gap opening upon
darkness. There was something in there, but what it was could only
be surmised from a heavy snore that rose and fell regularly. It was
the bedroom of the apartment, windowless, airless, and sunless, but
rented at a price a millionaire would denounce as robbery.
"That you, Liza?" said a voice that discovered a woman bending over
the stove. "Run 'n' get the childer. Dinner's ready."
The winter sun glancing down the wall of the opposite tenement,
with a hopeless effort to cheer the back yard, might have peeped
through the one window of the room in Mrs. McGroarty's "flat," had
that window not been coated with the dust of ages, and discovered
that dinner party in action. It might have found a score like it in the
alley. Four unkempt children, copies each in his or her way of Liza
and their mother, Mrs. McGroarty, who "did washing" for a living. A
meat bone, a "cut" from the butcher's at four cents a pound, green
pickles, stale bread and beer. Beer for the four, a sup all round, the
baby included. Why not? It was the one relish the searching ray
would have found there. Potatoes were there, too—potatoes and
meat! Say not the poor in the tenements are starving. In New York
only those starve who cannot get work and have not the courage to
beg. Fifty thousand always out of a job, say those who pretend to
know. A round half-million asking and getting charity in eight years,
say the statisticians of the Charity Organization. Any one can go
round and see for himself that no one need starve in New York.
From across the yard the sunbeam, as it crept up the wall, fell
slantingly through the attic window whence issued the sound of
hammer-blows. A man with a hard face stood in its light, driving
nails into the lid of a soap box that was partly filled with straw.
Something else was there; as he shifted the lid that didn't fit, the
glimpse of sunshine fell across it; it was a dead child, a little baby in
a white slip, bedded in straw in a soap box for a coffin. The man was
hammering down the lid to take it to the Potter's Field. At the bed
knelt the mother, dry-eyed, delirious from starvation that had killed
her child. Five hungry, frightened children cowered in the corner,
hardly daring to whisper as they looked from the father to the
mother in terror.
There was a knock on the door that was drowned once, twice, in the
noise of the hammer on the little coffin. Then it was opened gently,
and a young woman came in with a basket. A little silver cross shone
upon her breast. She went to the poor mother, and, putting her
hand soothingly on her head, knelt by her with gentle and loving
words. The half-crazed woman listened with averted face, then
suddenly burst into tears and hid her throbbing head in the other's
lap.
The man stopped hammering and stared fixedly upon the two; the
children gathered around with devouring looks as the visitor took
from her basket bread, meat, and tea. Just then, with a parting
wistful look into the bare attic room, the sun-ray slipped away,
lingered for a moment about the coping outside, and fled over the
housetops.
As it sped on its winter-day journey, did it shine into any cabin in an
Irish bog more desolate than these Cherry Street "homes"? An army
of thousands, whose one bright and wholesome memory, only
tradition of home, is that poverty-stricken cabin in the desolate bog,
are herded in such barracks to-day in New York. Potatoes they have;
yes, and meat at four cents—even seven. Beer for a relish—never
without beer. But home? The home that was home, even in a bog,
with the love of it that has made Ireland immortal and a tower of
strength in the midst of her suffering—what of that? There are no
homes in New York's poor tenements.
Down the crooked path of the Mulberry Street Bend the sunlight
slanted into the heart of New York's Italy. It shone upon bandannas
and yellow neckerchiefs; upon swarthy faces and corduroy breeches;
upon black-haired girls—mothers at thirteen; upon hosts of bow-
legged children rolling in the dirt; upon pedlers' carts and rag-pickers
staggering under burdens that threatened to crush them at every
step. Shone upon unnumbered Pasquales dwelling, working, idling,
and gambling there. Shone upon the filthiest and foulest of New
York's tenements, upon Bandits' Roost, upon Bottle Alley, upon the
hidden byways that lead to the tramps' burrows. Shone upon the
scene of annual infant slaughter. Shone into the foul core of New
York's slums that was at last to go to the realm of bad memories
because civilized man might not look upon it and live without
blushing.
It glanced past the rag-shop in the cellar, whence welled up
stenches to poison the town, into an apartment three flights up that
held two women, one young, the other old and bent. The young one
had a baby at her breast. She was rocking it tenderly in her arms,
singing in the soft Italian tongue a lullaby, while the old granny
listened eagerly, her elbows on her knees, and a stumpy clay pipe,
blackened with age, between her teeth. Her eyes were set on the
wall, on which the musty paper hung in tatters, fit frame for the
wretched, poverty-stricken room, but they saw neither poverty nor
want; her aged limbs felt not the cold draught from without, in
which they shivered; she looked far over the seas to sunny Italy,
whose music was in her ears.
"O dolce Napoli," she mumbled between her toothless jaws, "O suol
beato——"
The song ended in a burst of passionate grief. The old granny and
the baby woke up at once. They were not in sunny Italy; not under
southern, cloudless skies. They were in "The Bend," in Mulberry
Street, and the wintry wind rattled the door as if it would say, in the
language of their new home, the land of the free: "Less music! More
work! Root, hog, or die!"
Around the corner the sunbeam danced with the wind into Mott
Street, lifted the blouse of a Chinaman and made it play tag with his
pigtail. It used him so roughly that he was glad to skip from it down
a cellar-way that gave out fumes of opium strong enough to scare
even the north wind from its purpose. The soles of his felt shoes
showed as he disappeared down the ladder that passed for cellar
steps. Down there, where daylight never came, a group of yellow,
almond-eyed men were bending over a table playing fan-tan. Their
very souls were in the game, every faculty of the mind bent on the
issue and the stake. The one blouse that was indifferent to what
went on was stretched on a mat in a corner. One end of a clumsy
pipe was in his mouth, the other held over a little spirit-lamp on the
divan on which he lay. Something fluttered in the flame with a
pungent, unpleasant smell. The smoker took a long draught, inhaling
the white smoke, then sank back on his couch in senseless content.
Upstairs tiptoed the noiseless felt shoes, bent on some house
errand, to the "household" floors above, where young white girls
from the tenements of The Bend and the East Side live in slavery
worse, if not more galling, than any of the galley with ball and chain
—the slavery of the pipe. Four, eight, sixteen, twenty-odd such
"homes" in this tenement, disgracing the very name of home and
family, for marriage and troth are not in the bargain.
In one room, between the half-drawn curtains of which the sunbeam
works its way in, three girls are lying on as many bunks, smoking all.
They are very young, "under age," though each and every one
would glibly swear in court to the satisfaction of the police that she
is sixteen, and therefore free to make her own bad choice. Of these,
one was brought up among the rugged hills of Maine; the other two
are from the tenement crowds, hardly missed there. But their
companion? She is twirling the sticky brown pill over the lamp,
preparing to fill the bowl of her pipe with it. As she does so, the
sunbeam dances across the bed, kisses the red spot on her cheek
that betrays the secret her tyrant long has known,—though to her it
is hidden yet,—that the pipe has claimed its victim and soon will
pass it on to the Potter's Field.
"Nell," says one of her chums in the other bunk, something stirred
within her by the flash, "Nell, did you hear from the old farm to
home since you come here?"
Nell turns half around, with the toasting-stick in her hand, an ugly
look on her wasted features, a vile oath on her lips.
"To hell with the old farm," she says, and putting the pipe to her
mouth inhales it all, every bit, in one long breath, then falls back on
her pillow in drunken stupor.
That is what the sun of a winter day saw and heard in Mott Street.
It had travelled far toward the west, searching many dark corners
and vainly seeking entry to others; had glided with equal impartiality
the spires of five hundred churches and the tin cornices of thirty
thousand tenements, with their million tenants and more; had
smiled courage and cheer to patient mothers trying to make the
most of life in the teeming crowds, that had too little sunshine by
far; hope to toiling fathers striving early and late for bread to fill the
many mouths clamoring to be fed.
The brief December day was far spent. Now its rays fell across the
North River and lighted up the windows of the tenements in Hell's
Kitchen and Poverty Gap. In the Gap especially they made a brave
show; the windows of the crazy old frame-house under the big tree
that sat back from the street looked as if they were made of beaten
gold. But the glory did not cross the threshold. Within it was dark
and dreary and cold. The room at the foot of the rickety, patched
stairs was empty. The last tenant was beaten to death by her
husband in his drunken fury. The sun's rays shunned the spot ever
after, though it was long since it could have made out the red daub
from the mould on the rotten floor.
Upstairs, in the cold attic, where the wind wailed mournfully through
every open crack, a little girl sat sobbing as if her heart would break.
She hugged an old doll to her breast. The paint was gone from its
face; the yellow hair was in a tangle; its clothes hung in rags. But
she only hugged it closer. It was her doll. They had been friends so
long, shared hunger and hardship together, and now——
Her tears fell faster. One drop trembled upon the wan cheek of the
doll. The last sunbeam shot athwart it and made it glisten like a
priceless jewel. Its glory grew and filled the room. Gone were the
black walls, the darkness, and the cold. There was warmth and light
and joy. Merry voices and glad faces were all about. A flock of
children danced with gleeful shouts about a great Christmas tree in
the middle of the floor. Upon its branches hung drums and trumpets
and toys, and countless candles gleamed like beautiful stars.
Farthest up, at the very top, her doll, her very own, with arms
outstretched, as if appealing to be taken down and hugged. She
knew it, knew the mission-school that had seen her first and only
real Christmas, knew the gentle face of her teacher, and the writing
on the wall she had taught her to spell out: "In His name." His
name, who, she had said, was all little children's friend. Was He also
her dolly's friend, and would He know it among the strange people?
The light went out; the glory faded. The bare room, only colder and
more cheerless than before, was left. The child shivered. Only that
morning the doctor had told her mother that she must have
medicine and food and warmth, or she must go to the great hospital
where papa had gone before, when their money was all spent.
Sorrow and want had laid the mother upon the bed he had barely
left. Every stick of furniture, every stitch of clothing on which money
could be borrowed, had gone to the pawnbroker. Last of all, she had
carried mamma's wedding-ring to pay the druggist. Now there was
no more left, and they had nothing to eat. In a little while mamma
would wake up, hungry.
The little girl smothered a last sob and rose quickly. She wrapped
the doll in a threadbare shawl as well as she could, tiptoed to the
door, and listened a moment to the feeble breathing of the sick
mother within. Then she went out, shutting the door softly behind
her, lest she wake her.
Up the street she went, the way she knew so well, one block and a
turn round the saloon corner, the sunset glow kissing the track of
her bare feet in the snow as she went, to a door that rang a noisy
bell as she opened it and went in. A musty smell filled the close
room. Packages, great and small, lay piled high on shelves behind
the worn counter. A slovenly woman was haggling with the
pawnbroker about the money for a skirt she had brought to pledge.
"Not a cent more than a quarter," he said, contemptuously, tossing
the garment aside. "It's half worn out it is, dragging it back and
forth over the counter these six months. Take it or leave it. Hallo!
What have we here? Little Finnegan, eh? Your mother not dead yet?
It's in the poor-house ye will be if she lasts much longer. What the
——"
He had taken the package from the trembling child's hand—the
precious doll—and unrolled the shawl. A moment he stood staring in
dumb amazement at its contents. Then he caught it up and flung it
with an angry oath upon the floor, where it was shivered against the
coal-box.
"Get out o' here, ye Finnegan brat," he shouted; "I'll tache ye to
come a-guyin' o' me. I'll——"
The door closed with a bang upon the frightened child, alone in the
cold night. The sun saw not its home-coming. It had hidden behind
the night clouds, weary of the sight of man and his cruelty.
Evening had worn into night. The busy city slept. Down by the
wharves, now deserted, a poor boy sat on the bulwark, hungry, foot-
sore, and shivering with cold. He sat thinking of friends and home,
thousands of miles away over the sea, whom he had left six months
before to go among strangers. He had been alone ever since, but
never more so than that night. His money gone, no work to be
found, he had slept in the streets for nights. That day he had eaten
nothing; he would rather die than beg, and one of the two he must
do soon.
There was the dark river rushing at his feet; the swirl of the unseen
waters whispered to him of rest and peace he had not known since
—it was so cold—and who was there to care, he thought bitterly. No
one would ever know. He moved a little nearer the edge, and
listened more intently.
A low whine fell on his ear, and a cold, wet face was pressed against
his. A little crippled dog that had been crouching silently beside him
nestled in his lap. He had picked it up in the street, as forlorn and
friendless as himself, and it had stayed by him. Its touch recalled
him to himself. He got up hastily, and, taking the dog in his arms,
went to the police station near by, and asked for shelter. It was the
first time he had accepted even such charity, and as he lay down on
his rough plank he hugged a little gold locket he wore around his
neck, the last link with better days, and thought with a hard sob of
home. In the middle of the night he awoke with a start. The locket
was gone. One of the tramps who slept with him had stolen it. With
bitter tears he went up and complained to the Sergeant at the desk,
and the Sergeant ordered him to be kicked out into the street as a
liar, if not a thief. How should a tramp boy have come honestly by a
gold locket? The doorman put him out as he was bidden, and when
the little dog showed its teeth, a policeman seized it and clubbed it
to death on the step.
Far from the slumbering city the rising moon shines over a wide
expanse of glistening water. It silvers the snow upon a barren heath
between two shores, and shortens with each passing minute the
shadows of countless headstones that bear no names, only
numbers. The breakers that beat against the bluff wake not those
who sleep there. In the deep trenches they lie, shoulder to shoulder,
an army of brothers, homeless in life, but here at rest and at peace.
A great cross stands upon the lonely shore. The moon sheds its rays
upon it in silent benediction and floods the garden of the unknown,
unmourned dead with its soft light. Out on the Sound the fishermen
see it flashing white against the starlit sky, and bare their heads
reverently as their boats speed by, borne upon the wings of the west
wind.
NIBSY'S CHRISTMAS
It was Christmas Eve over on the East Side. Darkness was closing in
on a cold, hard day. The light that struggled through the frozen
windows of the delicatessen store and the saloon on the corner, fell
upon men with empty dinner-pails who were hurrying homeward,
their coats buttoned tightly, and heads bent against the steady blast
from the river, as if they were butting their way down the street.
The wind had forced the door of the saloon ajar, and was whistling
through the crack; but in there it seemed to make no one afraid.
Between roars of laughter, the clink of glasses and the rattle of dice
on the hardwood counter were heard out in the street. More than
one of the passers-by who came within range was taken with an
extra shiver in which the vision of wife and little ones waiting at
home for his coming was snuffed out, as he dropped in to brace up.
The lights were long out when the silent streets reëchoed his
unsteady steps toward home, where the Christmas welcome had
turned to dread.
But in this twilight hour they burned brightly yet, trying hard to
pierce the bitter cold outside with a ray of warmth and cheer. Where
the lamps in the delicatessen store made a mottled streak of
brightness across the flags, two little boys stood with their noses
flattened against the window. The warmth inside, and the lights, had
made little islands of clear space on the frosty pane, affording
glimpses of the wealth within, of the piles of smoked herring, of
golden cheese, of sliced bacon and generous, fat-bellied hams; of
the rows of odd-shaped bottles and jars on the shelves that held
there was no telling what good things, only it was certain that they
must be good from the looks of them.
And the heavenly smell of spices and things that reached the boys
through the open door each time the tinkling bell announced the
coming or going of a customer! Better than all, back there on the
top shelf the stacks of square honey-cakes, with their frosty coats of
sugar, tied in bundles with strips of blue paper.
The wind blew straight through the patched and threadbare jackets
of the lads as they crept closer to the window, struggling hard by
breathing on the pane to make their peep-holes bigger, to take in
the whole of the big cake with the almonds set in; but they did not
heed it.
"Jim!" piped the smaller of the two, after a longer stare than usual;
"hey, Jim! them's Sante Claus's. See 'em?"
"Sante Claus!" snorted the other, scornfully, applying his eye to the
clear spot on the pane. "There ain't no ole duffer like dat. Them's
honey-cakes. Me 'n' Tom had a bite o' one wunst."
"There ain't no Sante Claus?" retorted the smaller shaver, hotly, at
his peep-hole. "There is, too. I seen him myself when he cum to our
alley last——"
"What's youse kids a-scrappin' fur?" broke in a strange voice.
Another boy, bigger, but dirtier and tougher-looking than either of
the two, had come up behind them unobserved. He carried an
armful of unsold "extras" under one arm. The other was buried to
the elbow in the pocket of his ragged trousers.
The "kids" knew him, evidently, and the smallest eagerly accepted
him as umpire.
"It's Jim w'at says there ain't no Sante Claus, and I seen him——"
"Jim!" demanded the elder ragamuffin, sternly, looking hard at the
culprit; "Jim! yere a chump! No Sante Claus? What're ye givin' us?
Now, watch me!"
With utter amazement the boys saw him disappear through the door
under the tinkling bell into the charmed precincts of smoked herring,
jam, and honey-cakes. Petrified at their peep-holes, they watched
him, in the veritable presence of Santa Claus himself with the fir-
branch, fish out five battered pennies from the depths of his pocket
and pass them over to the woman behind the jars, in exchange for
one of the bundles of honey-cakes tied with blue. As if in a dream
they saw him issue forth with the coveted prize.
"There, kid!" he said, holding out the two fattest and whitest cakes
to Santa Claus's champion; "there's yer Christmas. Run along, now,
to yer barracks; and you, Jim, here's one for you, though yer don't
desarve it. Mind ye let the kid alone."
"This one'll have to do for me grub, I guess. I ain't sold me 'Newses,'
and the ole man'll kick if I bring 'em home."
Before the shuffling feet of the ragamuffins hurrying homeward had
turned the corner, the last mouthful of the newsboy's supper was
smothered in a yell of "Extree!" as he shot across the street to
intercept a passing stranger.
As the evening wore on, it grew rawer and more blustering still.
Flakes of dry snow that stayed where they fell, slowly tracing the
curb-lines, the shutters, and the doorsteps of the tenements with
gathering white, were borne up on the storm from the water. To the
right and left stretched endless streets between the towering
barracks, as beneath frowning cliffs pierced with a thousand glowing
eyes that revealed the watch-fires within—a mighty city of cave-
dwellers held in the thraldom of poverty and want.