100% found this document useful (4 votes)
30 views

Full Download (Ebook) Beginning iOS Application Development with HTML and JavaScript by Richard Wagner ISBN 9781118159002, 9781118226070, 9781118237519, 9781118264058, 1118159004, 1118226070, 111823751X, 1118264053 PDF DOCX

The document provides information on various ebooks available for download, including 'Beginning iOS Application Development with HTML and JavaScript' by Richard Wagner. It includes links to download the ebooks and lists several other recommended titles with their respective ISBNs. The content also outlines the structure of the iOS development book, detailing chapters on application design, development, and advanced techniques.

Uploaded by

aedaafazad6
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
30 views

Full Download (Ebook) Beginning iOS Application Development with HTML and JavaScript by Richard Wagner ISBN 9781118159002, 9781118226070, 9781118237519, 9781118264058, 1118159004, 1118226070, 111823751X, 1118264053 PDF DOCX

The document provides information on various ebooks available for download, including 'Beginning iOS Application Development with HTML and JavaScript' by Richard Wagner. It includes links to download the ebooks and lists several other recommended titles with their respective ISBNs. The content also outlines the structure of the iOS development book, detailing chapters on application design, development, and advanced techniques.

Uploaded by

aedaafazad6
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

Visit https://ebooknice.

com to download the full version and


explore more ebooks

(Ebook) Beginning iOS Application Development with


HTML and JavaScript by Richard Wagner ISBN
9781118159002, 9781118226070, 9781118237519,
9781118264058, 1118159004, 1118226070, 111823751X,
_____ Click the link below to download _____
1118264053
https://ebooknice.com/product/beginning-ios-
application-development-with-html-and-
javascript-2522968

Explore and download more ebooks at ebooknice.com


Here are some recommended products that might interest you.
You can download now and explore!

(Ebook) Biota Grow 2C gather 2C cook by Loucas, Jason; Viles, James


ISBN 9781459699816, 9781743365571, 9781925268492, 1459699815,
1743365578, 1925268497

https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374

ebooknice.com

(Ebook) Beginning iOS Application Development with HTML and JavaScript


by Richard Wagner ISBN 9781118159002, 1118159004

https://ebooknice.com/product/beginning-ios-application-development-
with-html-and-javascript-5468382

ebooknice.com

(Ebook) Matematik 5000+ Kurs 2c Lärobok by Lena Alfredsson, Hans


Heikne, Sanna Bodemyr ISBN 9789127456600, 9127456609

https://ebooknice.com/product/matematik-5000-kurs-2c-larobok-23848312

ebooknice.com

(Ebook) SAT II Success MATH 1C and 2C 2002 (Peterson's SAT II Success)


by Peterson's ISBN 9780768906677, 0768906679

https://ebooknice.com/product/sat-ii-success-
math-1c-and-2c-2002-peterson-s-sat-ii-success-1722018

ebooknice.com
(Ebook) Master SAT II Math 1c and 2c 4th ed (Arco Master the SAT
Subject Test: Math Levels 1 & 2) by Arco ISBN 9780768923049,
0768923042

https://ebooknice.com/product/master-sat-ii-math-1c-and-2c-4th-ed-
arco-master-the-sat-subject-test-math-levels-1-2-2326094

ebooknice.com

(Ebook) Cambridge IGCSE and O Level History Workbook 2C - Depth Study:


the United States, 1919-41 2nd Edition by Benjamin Harrison ISBN
9781398375147, 9781398375048, 1398375144, 1398375047

https://ebooknice.com/product/cambridge-igcse-and-o-level-history-
workbook-2c-depth-study-the-united-states-1919-41-2nd-edition-53538044

ebooknice.com

(Ebook) Beginning Windows Store Application Development – HTML and


JavaScript Edition by Scott Isaacs, Kyle Burns ISBN 9781430257790,
1430257792

https://ebooknice.com/product/beginning-windows-store-application-
development-html-and-javascript-edition-4568338

ebooknice.com

(Ebook) Beginning Windows Store Application Development-HTML and


JavaScript Edition by Burns, Kyle;Isaacs, Scott ISBN 9781430257806,
1430257806

https://ebooknice.com/product/beginning-windows-store-application-
development-html-and-javascript-edition-11358966

ebooknice.com

(Ebook) Beginning JavaScript und CSS development with jQuery by


Richard York ISBN 9780470227794, 0470227796

https://ebooknice.com/product/beginning-javascript-und-css-
development-with-jquery-4097814

ebooknice.com
ffirs.indd iv 12/21/11 2:29:58 PM
BEGINNING
IOS APPLICATION DEVELOPMENT
WITH HTML AND JAVASCRIPT®

INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii

 PART I GETTING STARTED


CHAPTER 1 Introducing iOS Development Using Web Technologies . . . . . . . . . . . . . 3
CHAPTER 2 Working with Core Technologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
CHAPTER 3 The Document Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
CHAPTER 4 Writing Your First Hello World Application . . . . . . . . . . . . . . . . . . . . . . . . 65
CHAPTER 5 Enabling and Optimizing Web Sites for the iPhone and iPad . . . . . . . . 79

 PART II APPLICATION DESIGN


CHAPTER 6 Designing the iPhone UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
CHAPTER 7 Designing for iPad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
CHAPTER 8 Styling with CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

 PART III APPLICATION DEVELOPMENT


CHAPTER 9 Programming the Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
CHAPTER 10 Handling Touch Interactions and Events . . . . . . . . . . . . . . . . . . . . . . . . . 189
CHAPTER 11 Special Effects and Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
CHAPTER 12 Integrating with iOS Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
CHAPTER 13 Packaging Apps as Bookmarks: Bookmarklets
and Data URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235

 PART IV ADVANCED PROGRAMMING TECHNIQUES


CHAPTER 14 Programming the Canvas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
CHAPTER 15 Offline Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
CHAPTER 16 Building with Web App Frameworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
CHAPTER 17 Bandwidth and Performance Optimizations . . . . . . . . . . . . . . . . . . . . . . 303
CHAPTER 18 Debug and Deploy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317

ffirs.indd i 12/21/11 2:29:56 PM


 PART V NEXT STEPS: DEVELOPING NATIVE IOS APPLICATIONS
WITH HTML AND JAVASCRIPT
CHAPTER 19 Preparing for Native iOS Development . . . . . . . . . . . . . . . . . . . . . . . . . . 333
CHAPTER 20 PhoneGap: Native Apps from Your HTML, CSS,
and JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
CHAPTER 21 Submitting Your App to the App Store . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
APPENDIX Exercise Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375

INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .381

ffirs.indd ii 12/21/11 2:29:58 PM


BEGINNING

iOS Application Development


with HTML and JavaScript®

ffirs.indd iii 12/21/11 2:29:58 PM


ffirs.indd iv 12/21/11 2:29:58 PM
BEGINNING

iOS Application Development


with HTML and JavaScript®

Richard Wagner

John Wiley & Sons, Inc.

ffirs.indd v 12/21/11 2:29:58 PM


Beginning iOS Application Development with HTML and JavaScript®
Published by
John Wiley & Sons, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com

Copyright © 2012 by John Wiley & Sons, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 978-1-118-15900-2
ISBN: 978-1-118-22607-0 (ebk)
ISBN: 978-1-118-23751-9 (ebk)
ISBN: 978-1-118-26405-8 (ebk)

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108
of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers,
MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the
Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201)
748-6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with
respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including
without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or
promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is
sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional
services. If professional assistance is required, the services of a competent professional person should be sought. Neither
the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is
referred to in this work as a citation and/or a potential source of further information does not mean that the author or the
publisher endorses the information the organization or Web site may provide or recommendations it may make. Further,
readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this
work was written and when it is read.

For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with
standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to
media such as a CD or DVD that is not included in the version you purchased, you may download this material at
http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com.

Library of Congress Control Number: 2011945668

Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are
trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affi liates, in the United States and other coun-
tries, and may not be used without written permission. JavaScript is a registered trademark of Oracle America, Inc. All
other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product
or vendor mentioned in this book.

ffirs.indd vi 12/21/11 2:30:03 PM


To KimmyWags and the J-Team

ffirs.indd vii 12/21/11 2:30:03 PM


ffirs.indd viii 12/21/11 2:30:04 PM
ABOUT THE AUTHOR

RICHARD WAGNER is Lead Product Architect of Mobile/Web at Maark, LLC. Previously, he was
the head of engineering for the Web scripting company Nombas and VP of Product Development
for NetObjects, where he was the chief architect of a CNET award-winning JavaScript tool named
NetObjects ScriptBuilder. He is an experienced web designer and developer and the author of
several Web-related books on the underlying technologies of the iOS application platform.

ffirs.indd ix 12/21/11 2:30:04 PM


ffirs.indd x 12/21/11 2:30:04 PM
CREDITS

EXECUTIVE EDITOR PRODUCTION MANAGER


Carol Long Tim Tate

PROJECT EDITOR VICE PRESIDENT AND EXECUTIVE GROUP


Kelly Talbot PUBLISHER
Richard Swadley
TECHNICAL EDITOR
Michael Gilbert VICE PRESIDENT AND EXECUTIVE
PUBLISHER
PRODUCTION EDITOR Neil Edde
Kathleen Wisor
ASSOCIATE PUBLISHER
COPY EDITOR Jim Minatel
Charlotte Kughen
PROJECT COORDINATOR, COVER
EDITORIAL MANAGER Katie Crocker
Mary Beth Wakefield
PROOFREADER
FREELANCER EDITORIAL MANAGER Sheilah Ledwidge, Word One
Rosemarie Graham
INDEXER
ASSOCIATE DIRECTOR OF MARKETING Robert Swanson
David Mayhew
COVER DESIGNER
MARKETING MANAGER
Ryan Sneed
Ashley Zurcher
COVER IMAGE
BUSINESS MANAGER
© Sam Burt Photography / iStockPhoto
Amy Knies

ffirs.indd xi 12/21/11 2:30:04 PM


ffirs.indd xii 12/21/11 2:30:05 PM
ACKNOWLEDGMENTS

THE IPHONE AND IPAD HAVE EMERGED as my favorite pieces of technology I have ever owned. As
such, the topic of iOS application development has been a joy to write about. However, the book
was also a joy because of the stellar team I had working with me on this book. First and foremost,
I’d like to thank Kelly Talbot for his masterful role as project editor. He kept the project on track
and running smoothly from start to fi nish. I’d also like to thank Michael Gilbert for his insights and
ever-watchful eye that ensured technical accuracy in this book. Further, thanks also to Charlotte
Kughen for her editing prowess.

ffirs.indd xiii 12/21/11 2:30:05 PM


ffirs.indd xiv 12/21/11 2:30:05 PM
CONTENTS

INTRODUCTION xxiii

PART I: GETTING STARTED

CHAPTER 1: INTRODUCING IOS DEVELOPMENT USING WEB


TECHNOLOGIES 3

Discovering the Safari on iOS Platform 3


Key Safari Features for Web Developers 6
Four Ways to Develop Web Apps for iOS 7
The Finger Is Not a Mouse 9
Limitations and Constraints 10
Setting Up Your Development Environment on a Local Network 11
CHAPTER 2: WORKING WITH CORE TECHNOLOGIES 15

Exploring HTML 5 Media Elements 15


Scripting JavaScript 18
Syntax and Basic Rules 18
Variables 20
Operators 26
Reserved Words 27
Basic Conditional Expressions 28
Loops 31
Comments 33
Functions 35
Data Types 39

CHAPTER 3: THE DOCUMENT OBJECT MODEL 47

What Is the DOM? 47


DOM as a Tree 48
Accessing the DOM from JavaScript 51
Accessing a Specific Element 51
Accessing a Set of Elements 52
Accessing Family Members 53
Retrieving Attributes 53
Manipulating the DOM 55
Creating an Element and Other Nodes 55

ftoc.indd xv 12/21/11 2:35:54 PM


CONTENTS

Adding a Node to the DOM 55


Creating Other Elements 57
Setting a Value to an Attribute 59
Moving a Node 60
Cloning a Node 60
Removing a Node from the DOM 61
Removing an Attribute 62

CHAPTER 4: WRITING YOUR FIRST HELLO WORLD APPLICATION 65

Setting Up 66
Creating Your Index Page 66
Creating the Main Screen 67
Adding Detail Pages 70
CHAPTER 5: ENABLING AND OPTIMIZING WEB SITES
FOR THE IPHONE AND IPAD 79

Tier 1: iOS Compatibility 80


Tier 2: Navigation-Friendly Websites 82
Working with the Viewport 82
Turning Your Page into Blocks 85
Defining Multiple Columns (Future Use) 87
Tier 3: Custom Styling 87
Media Queries 88
Text Size Adjustment 88
Case Study: Enabling an Existing Web Site 89
Tier 4: Parallel Sites 92

PART II: APPLICATION DESIGN

CHAPTER 6: DESIGNING THE IPHONE UI 99

Evolving UI Design 99
The iPhone Viewport 100
Exploring iOS Design Patterns 102
Categorizing Apps 103
Navigation List-based UI Design 104
Application Modes 105
Exploring Screen Layout 106
Title Bar 106
Edge-to-Edge Navigation Lists 107
Rounded Rectangle Design Destination Pages 108

xvi

ftoc.indd xvi 12/21/11 2:35:55 PM


CONTENTS

Designing for Touch 109


Working with Fonts 110
Best Practices in iOS UI Design 111
Adding Finishing Touches 112
CHAPTER 7: DESIGNING FOR IPAD 117

Special iPad Considerations 117


Design Essentials 118
Dealing with Scrolling 118
Split View Design Pattern 119
Designing a UI for iPad 120

CHAPTER 8: STYLING WITH CSS 135

CSS Selectors Supported in Safari 135


Text Styles 137
Controlling Text Sizing with -webkit-text-size-adjust 138
Handling Overflowed Text with text-overflow 139
Creating Subtle Shadows with text-shadow 142
Styling Block Elements 142
Image-Based Borders with -webkit-border-image 142
Rounded Corners with -webkit-border-radius 143
Gradient Push Buttons with -webkit-appearance 144
Multiple Background Images 144
Setting Transparencies 145
Creating CSS-based iOS Buttons 147
Identifying Incompatibilities 148

PART III: APPLICATION DEVELOPMENT


CHAPTER 9: PROGRAMMING THE INTERFACE 153

Top Level of Application 154


Examining Top-Level Styles 155
Adding the Top Toolbar 157
Adding a Top-Level Navigation Menu 159
Displaying a Panel with an Internal URL 160
Creating a Secondary Navigation List 162
Designing for Long Navigation Lists 163
Creating a Destination Page 164
Adding a Dialog 168

xvii

ftoc.indd xvii 12/21/11 2:35:55 PM


CONTENTS

Scripting UI Behavior 178


On Document Load 179
Loading a Standard iUI Page 181
Handling Link Clicks 183
Loading a Dialog 184

CHAPTER 10: HANDLING TOUCH INTERACTIONS AND EVENTS 189

Three Types of Touch Events 189


Mouse-Emulation Events 190
Many Events Handled by Default 190
Conditional Events 190
Mouse Events: Think “Click,” Not “Move” 191
Click-Enabling Elements 192
Event Flow 192
Unsupported Events 192
Touch Events 194
Gesture Events 196
Detecting an Orientation Change 196
Changing a Style Sheet When Orientation Changes 198
Changing Element Positioning Based on Orientation Change 203
Trapping for Key Events with the On-Screen Keyboard 204
CHAPTER 11: SPECIAL EFFECTS AND ANIMATION 207

Gradients 207
Creating CSS Gradients 207
Creating Gradients with JavaScript 210
Adding Shadows 212
Adding Reflections 213
Working with Masks 215
Creating Transform Effects 217
Creating Animations 218
CHAPTER 12: INTEGRATING WITH IOS SERVICES 223

Making Phone Calls from Your App 224


Sending Emails 226
Sending SMS Messages 229
Pointing on Google Maps 230

xviii

ftoc.indd xviii 12/21/11 2:35:56 PM


CONTENTS

CHAPTER 13: PACKAGING APPS AS BOOKMARKS:


BOOKMARKLETS AND DATA URLS 235

Working with Bookmarklets 236


Adding a Bookmarklet to Safari on iOS 236
Exploring How Bookmarklets Can Be Used 237
Storing an Application in a Data URL 239
Constraints and Issues with Using Data URLs 239
Developing a Data URL App 240

PART IV: ADVANCED PROGRAMMING TECHNIQUES

CHAPTER 14: PROGRAMMING THE CANVAS 251

Identifying the User Agent 251


Programming the iOS Canvas 254
Defining the Canvas Element 254
Getting a Context 254
Drawing a Simple Rectangle 256
Drawing Other Shapes 257
Drawing an Image 259
Advanced Drawing 261
Drawing with Encoded Images 262
Adding Color and Transparency 264
Creating an Image Pattern 265
CHAPTER 15: OFFLINE APPLICATIONS 269

HTML 5 Offline Application Cache 269


Create a Manifest File 270
Reference the Manifest File 271
Programmatically Control the Cache 271
Checking Connection Status 273
Using Key-Value Storage 276
Saving a Key Value 276
Loading Key-value Data 277
Deleting Key-value Data 278
Going SQL with the JavaScript Database 283
Open a Database 283
Querying a Table 283

xix

ftoc.indd xix 12/21/11 2:35:56 PM


CONTENTS

CHAPTER 16: BUILDING WITH WEB APP FRAMEWORKS 287

Using jQuery Mobile 288


Using iWebKit 293
CHAPTER 17: BANDWIDTH AND PERFORMANCE
OPTIMIZATIONS 303

Optimization Strategies 303


Best Practices to Minimize Bandwidth 304
General 304
Images 305
CSS and JavaScript 305
Compressing Your Application 306
Gzip File Compression 306
JavaScript Code Compression 307
JavaScript Performance Optimizations 308
Smart DOM Access 309
Local and Global Variables 311
Dot Notation and Property Lookups 311
Avoiding Nested Properties 311
Accessing a Named Object 312
Property Lookups Inside Loops 312
String Concatenation 313
What to Do and Not to Do 314

CHAPTER 18: DEBUG AND DEPLOY 317

Simulating the iPhone or iPad on Your Development Computer 318


Xcode’s iOS Simulator 318
Using Safari on Mac or Windows 320
Working with Desktop Safari Debugging Tools 322
Working with the Develop Menu 322
Working with Safari’s Web Inspector 323
Working with the Scripts Inspector 325
Debugging on an iOS Device 326
Debug Console 326
DOM Viewer 327

xx

ftoc.indd xx 12/21/11 2:35:57 PM


CONTENTS

PART V: NEXT STEPS: DEVELOPING NATIVE IOS APPLICATIONS


WITH HTML AND JAVASCRIPT

CHAPTER 19: PREPARING FOR NATIVE IOS DEVELOPMENT 333

Downloading Xcode 333


Joining the iOS Developer Program 334
Getting an iOS Developer Certificate 335
Retrieving the Developer Certificate 337
Adding a Device for Testing 337
Creating an App ID 338
Creating a Provisioning Profile 340
Installing the Development Provisioning Profile 341
CHAPTER 20: PHONEGAP: NATIVE APPS FROM
YOUR HTML, CSS, AND JAVASCRIPT 345

Installing PhoneGap 345


Creating a New PhoneGap Project in Xcode 346
Running the Base Project 348
Adding Web Files to the Xcode Project 348
Merging Your Web App Code 349
Tweaking the Xcode Project 357
Allowing External References 357
Opening External Links in Safari 358
Adding an Icon and Launch Image 359
Running the Finished App 360
CHAPTER 21: SUBMITTING YOUR APP TO THE APP STORE 363

Step 1: Getting a Distribution Certificate 364


Step 2: Creating a Distribution Provisioning Profile 365
Step 3: Building a Distribution Release of Your App 368
Step 4: Submitting Your App to the App Store 369
APPENDIX: EXERCISE ANSWERS 375

INDEX 381

xxi

ftoc.indd xxi 12/21/11 2:35:57 PM


flast.indd xxii 12/21/11 8:06:32 AM
INTRODUCTION

THE AMAZING SUCCESS OF THE IPHONE and iPad over the past four years has proven that
application developers are now smack deep in a brave new world of sophisticated, multifunctional
mobile applications. No longer do applications and various media need to live in separate silos.
Instead, mobile web-based applications can bring together elements of web apps, native apps,
multimedia video and audio, and the mobile device.
This book covers the various aspects of developing web-based applications for iOS. Specifically, you will
discover how to create a mobile application from the ground up, utilize existing open source frameworks
to speed up your development times, emulate the look and feel of built-in Apple applications, capture
finger touch interactions, and optimize applications for Wi-Fi and wireless networks.

WHO THIS BOOK IS FOR


This book is aimed primarily for beginning and intermediate web developers who want to build new
applications for iOS or migrate existing web apps to this platform. In general, readers will fi nd it
helpful to have a working knowledge of the following technologies:
➤ HTML/XHTML
➤ CSS
➤ JavaScript
➤ Ajax
However, if you are a less experienced working with these technologies, be sure to take advantage of
the early chapters at the start of the book.

WHAT THIS BOOK COVERS


This book introduces readers to the web application platform for iOS. It guides readers through the
process of building new applications from scratch and migrating existing web applications to this
new mobile platform. As it does so, it helps readers design a user interface that is optimized for iOS
touch-screen displays and integrate their applications with iPhone services, including Phone, Mail,
Google Maps, and GPS.

HOW THIS BOOK IS STRUCTURED


The chapter-level breakdown is as follows:
1. Introducing iOS Development Using Web Technologies. Explores the Safari development
platform and walks you through different ways you can develop apps for iOS.

flast.indd xxiii 12/21/11 8:06:32 AM


INTRODUCTION

2. Working with Core Technologies. Provides an overview of some of the key technologies
you’ll be working with as you develop iOS web apps.
3. The Document Object Model. Explores how you can work with an HTML page as a tree in
order to navigate and control various parts in your app.
4. Writing Your First Hello World Application. Guides you through the steps needed to create
your fi rst iOS app.
5. Enabling and Optimizing Web Sites for iPhone and iPad. Covers how to make an existing
website compatible with mobile versions of Safari and then how to optimize the site for use
as a full-fledged web application.
6. Designing the iPhone UI. Gives an overview of the key design concepts and principles you
need to use when developing a highly usable interface for Safari on iPhone and iPod touch
devices.
7. Designing for iPad. Looks at how to design UI’s for the iPad and how they differ from
iPhone designs.
8. Styling with CSS. Discusses specific Safari-specific styles that are useful for developing web
apps for iOS.
9. Programming the Interface. Provides a code-level look at developing an iPhone and iPad web
application interface.
10. Handling Touch Interactions and Events. The heart of an iOS device is its touch screen
interface. This chapter explores how to handle touch interactions and capture JavaScript events.
11. Special Effects and Animation. The Safari canvas provides an ideal environment for
advanced graphic techniques, including gradients and masks
12. Integrating with iOS Services. Discusses how a web application can integrate with core
services, including Phone, Mail, Google Maps, and GPS.
13. Packaging Apps as Bookmarks: Bookmarklets and Data URLs. This chapter explains how
you can use two little used web technologies to support limited offl ine support.
14. Programming the Canvas. The mobile version of Safari provides full support for canvas
drawing and painting, opening up opportunities for developers. This chapter dives into these
advanced techniques.
15. Offl ine Applications. Covers how you can use HTML 5 offl ine cache to create local web
apps that don’t need a live server connection.
16. Building with Web App Frameworks. Highlights the major open source iPhone web app
frameworks and shows you how to be productive quickly with each of them.
17. Bandwidth and Performance Optimizations. Deals with the all-important issue of
performance of web-based applications and what techniques developers can do to minimize
constraints and maximize bandwidth and app execution performance.
18. Debug and Deploy. Discusses various methods of debugging Safari web applications.

xxiv

flast.indd xxiv 12/21/11 8:06:33 AM


INTRODUCTION

19. Preparing for Native iOS Development. Walks you through all of the steps needed to join the
Apple Developer Program and obtaining necessary credentials for publishing to the App Store.
20. PhoneGap: Native Apps from Your HTML, CSS, and JavaScript. How do you know when you
need to move your web app to a native iPhone? This chapters explores migration strategies and
shows you how you can take your Web app and wrap it inside of a native iOS shell.
21. Submitting Your App to the App Store. This fi nal chapter wraps up the discussion by
showing you how to take your app and submit it to the App Store for public distribution.

WHAT YOU NEED TO USE THIS BOOK


In order to work with the examples of the book, you will need:
➤ iPhone, iPad, or iPod touch
➤ Safari for Mac or Windows
The complete source code for the examples is available for download from our website at
www.wrox.com.

CONVENTIONS
To help you get the most from the text and keep track of what’s happening, we’ve used a number of
conventions throughout the book.

TRY IT OUT
The Try It Out is an exercise you should work through, following the text in the book.
1. They usually consist of a set of steps.
2. Each step has a number.
3. Follow the steps through with your copy of the database.

How It Works
After each Try It Out, the code you’ve typed will be explained in detail.

WARNING Boxes with a warning icon like this one hold important, not-to-be-
forgotten information that is directly relevant to the surrounding text.

NOTE The pencil icon indicates notes, tips, hints, tricks, or asides to the
current discussion.

xxv

flast.indd xxv 12/21/11 8:06:33 AM


INTRODUCTION

As for styles in the text:


➤ We highlight new terms and important words when we introduce them.
➤ We show keyboard strokes like this: Ctrl+A.
➤ We show fi le names, URLs, and code within the text like so: persistence.properties.
➤ We present code in two different ways:

We use a monofont type with no highlighting for most code examples.


We use bold to emphasize code that is particularly important in the present
context or to show changes from a previous code snippet.

SOURCE CODE
As you work through the examples in this book, you may choose either to type in all the code
manually, or to use the source code files that accompany the book. All the source code used in this
book is available for download at http://www.wrox.com. When at the site, simply locate the book’s
title (use the Search box or one of the title lists) and click the Download Code link on the book’s
detail page to obtain all the source code for the book. Code that is included on the website is
highlighted by the following icon:

Listings include the fi lename in the title. If it is just a code snippet, you’ll fi nd the fi lename in a code
note such as this:
Code snippet filename

NOTE Because many books have similar titles, you may find it easiest to search
by ISBN; this book’s ISBN is 978-1-118-15900-2.

Once you download the code, just decompress it with your favorite compression tool. Alternately,
you can go to the main Wrox code download page at http://www.wrox.com/dynamic/books
/download.aspx to see the code available for this book and all other Wrox books.

ERRATA
The editors and I worked hard to ensure that the contents of this book are accurate and that there
are no errors either in the text or in the code examples. However, in cases future iOS releases impact
what’s been said here, I recommend making a visit to www.wrox.com and checking out the book’s

xxvi

flast.indd xxvi 12/21/11 8:06:44 AM


INTRODUCTION

Errata link. You will be taken to a page which lists all errata that has been submitted for the book
and posted by Wrox editors.
If you discover an issue that is not found on the Errata page, I would be grateful for you to let us know
about it. To do so, go to www.wrox.com/contact/techsupport.shtml and provide this information
in the online form. The Wrox team will double check your information and, as appropriate, post it on
the Errata page as well as correct the problem in future versions of the book.

P2P.WROX.COM
For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a web-based
system for you to post messages relating to Wrox books and related technologies and interact with
other readers and technology users. The forums offer a subscription feature to e-mail you topics
of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other
industry experts, and your fellow readers are present on these forums.
At http://p2p.wrox.com, you will fi nd a number of different forums that will help you, not only as
you read this book, but also as you develop your own applications. To join the forums, just follow
these steps:
1. Go to p2p.wrox.com and click the Register link.
2. Read the terms of use and click Agree.
3. Complete the required information to join, as well as any optional information you wish to
provide, and click Submit.
4. You will receive an e-mail with information describing how to verify your account and
complete the joining process.

NOTE You can read messages in the forums without joining P2P, but in order to
post your own messages, you must join.

Once you join, you can post new messages and respond to messages other users post. You can
read messages at any time on the Web. If you would like to have new messages from a particular
forum e-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum
listing.
For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to
questions about how the forum software works, as well as many common questions specific to P2P
and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

xxvii

flast.indd xxvii 12/21/11 8:06:48 AM


flast.indd xxviii 12/21/11 8:06:51 AM
BEGINNING

iOS Application Development


with HTML and JavaScript®

flast.indd xxix 12/21/11 8:06:51 AM


flast.indd xxx 12/21/11 8:06:51 AM
PART I
Getting Started

 CHAPTER 1: Introducing iOS Development Using Web Technologies

 CHAPTER 2: Working with Core Technologies

 CHAPTER 3: The Document Object Model

 CHAPTER 4: Writing Your First Hello World Application

 CHAPTER 5: Enabling and Optimizing Web Sites for the


iPhone and iPad

c01.indd 1 12/22/11 8:48:47 AM


c01.indd 2 12/22/11 8:48:52 AM
1
Introducing iOS Development
Using Web Technologies
WHAT YOU WILL LEARN IN THIS CHAPTER:

➤ Using Safari on iOS as a development environment


➤ Developing touch-oriented apps
➤ Setting up your development environment

The introduction of the iPhone, and the subsequent unveilings of the iPod touch and iPad,
revolutionized the way people interacted with hand-held devices. No longer did users have
to use a keypad for screen navigation or browse the Web through “dumbed down” pages.
These mobile devices brought touch screen input, a revolutionary interface design, and a fully
functional web browser right into the palms of people’s hands.
Seeing the platform’s potential, the developer community jumped on board. Although native
applications may receive most of the attention, you can still create apps for iOS devices
without writing a single line of Objective-C. In fact, the Safari on iOS browser provides
a compelling application development platform for web developers who want to create
custom apps for iOS using familiar web technologies.

DISCOVERING THE SAFARI ON IOS PLATFORM


An iOS web application runs inside the built-in Safari browser that is based on web standards,
including the following:
➤ HTML/XHTML (HTML 4.01 and XHTML 1.9, XHTML mobile profi le
document types)
➤ CSS (CSS 2.1 and partial CSS3)

c01.indd 3 12/22/11 8:48:52 AM


4 ❘ CHAPTER 1 INTRODUCING IOS DEVELOPMENT USING WEB TECHNOLOGIES

➤ JavaScript (ECMAScript 3 (ECMA 262), JavaScript 1.4)


➤ AJAX (for example, XMLHTTPRequest)
➤ SVG (Scalable Vector Graphics) 1.1
➤ HTML5 media tags
➤ Ancillary technologies (video and audio media, PDF, and so on)
Safari on iOS (which I refer to throughout the book
interchangeably as Safari or Safari on iOS) becomes
the platform upon which you develop applications and
becomes the shell in which your apps must operate
(see Figure 1-1).
Safari is built with the same open source WebKit browser
engine as Safari for OS X and Safari for Windows. However,
although the Safari family of browsers is built on a common
framework, you’ll fi nd it helpful to think of Safari on iOS as
a close sibling to its Mac and Windows counterparts rather
than as an identical twin to either of them. Safari on iOS, for
example, does not provide the full extent of CSS or JavaScript
functionality that its desktop counterpart does.
In addition, Safari on iOS provides only a limited number of
settings that users can configure. As Figure 1-2 shows, users
can turn off and on support for JavaScript, plug-ins, and a
pop-up blocker. Users can also choose whether they want to
FIGURE 1-1
always accept cookies, accept cookies only from sites they
visit, or never accept cookies. A user can also manually clear
the history, cookies, and cache from this screen.
Quite obviously, native apps and Web apps are not identical to
each other — both from developer and end-user standpoints.
From a developer standpoint, the major difference is the
programming language — utilizing Web technologies rather
than Objective-C. However, there are also key end-user
implications, including the following:
➤ Performance: The performance of a Safari-based
web application is not going to be as responsive as a
native compiled application, both because of the
interpretive nature of the programming languages
as well as the fact that the application operates over
Wi-Fi and 3G networks. (Remember, some iPad models
and all models of the iPod touch support Wi-Fi access
only.) However, in spite of the technological constraints,
you can perform many optimizations to achieve
acceptable performance. FIGURE 1-2

c01.indd 4 12/22/11 8:48:54 AM


Discovering the Safari on iOS Platform ❘ 5

Table 1-1 shows the bandwidth performance of Wi-Fi, 3G, and the older EDGE networks.

TABLE 1-1: Network Performance

NETWORK BANDWIDTH

Wi-Fi 54 Mbps

3G Up to 7.2 Mbps

EDGE 70–135 Kbps, 200 Kbps burst

➤ Launching: Native applications are all launched from the main Home screen of the iOS
device (see Figure 1-3). In the original iPhone OS release, Apple provided no way for web
apps to be launched from here, which meant that web apps to be accessed from the Safari
Bookmarks list. Fortunately, the most recent iOS enables users to add “Web Clip” icons
for their web app (such as the Color Mail web app shown in Figure 1-4) so that they can
appear on the Home screen, too.

FIGURE 1-3 FIGURE 1-4

➤ User interface (UI): Native iOS applications often adhere to Apple UI design guidelines.
When you design a web app, you should never feel compelled to try to perfectly re-create

c01.indd 5 12/22/11 8:48:55 AM


6 ❘ CHAPTER 1 INTRODUCING IOS DEVELOPMENT USING WEB TECHNOLOGIES

a native-looking UI. At the same time, you should create a UI that is ideally suited for a
mobile, touch device. Fortunately, using open source frameworks and standard web
technologies, you can do so using a combination of HTML, CSS, and JavaScript.
Figures 1-5 and 1-6 compare the UI design of a native application and a Safari-based
web app.
What’s more, recent upgrades to the iOS now enable you to hide all Safari browser UI elements
through meta tags, so you can essentially emulate the look and feel of a native app.
(See Figure 1-7.)

FIGURE 1-5 FIGURE 1-6 FIGURE 1-7

KEY SAFARI FEATURES FOR WEB DEVELOPERS


There are several capabilities available to web app developers with the recent releases of iOS. These
are highlighted in the following list.
➤ Geolocation: Safari on iOS supports HTML5 geolocation capabilities, which enables
JavaScript to interact with the iPhone or iPad’s GPS service to retrieve the current location
of the device (see Figures 1-8 and 1-9). As a result, you can create apps that can broadcast
the location of a GPS-enabled iOS device.

c01.indd 6 12/22/11 8:48:56 AM


Four Ways to Develop Web Apps for iOS ❘ 7

FIGURE 1-8 FIGURE 1-9

Google, for example, uses this capability with its Web-based Latitude service for sharing
your location with your friends.
➤ HTML5 Media Tags: Safari on iOS supports HTML5 video and audio elements for
embedding video and audio content in Web pages. These new elements eliminate the need
for complicated embed and object tags for embedding multimedia elements and enable
you to utilize a powerful JavaScript API. What’s more, because iOS devices don’t support
Flash, you can use the video tag to embed QuickTime .mov fi les. Because Safari is the fi rst
major browser to provide full support for HTML5 media tags, you have to be careful in
their usage on standard websites because other browsers may not support it yet. However,
because you are creating an app specifically for iOS, you can make full use of these tags.
➤ CSS animation and effects: The new release of Safari supports CSS animation, which
enables you to manipulate elements in various ways, such as scaling, rotating, fading, and
skewing. Safari on iOS also supports CSS effects, which enable you to create gradients,
masks, and reflections entirely through CSS.
➤ SVG: SVG (Scalable Vector Graphics) is an XML-based format for creating static and
animated vector graphics. With SVG support, Safari on iOS not only provides a way to
work with scalable graphics, but actually provides a technology that could replace the
need for Flash to create animated media.

FOUR WAYS TO DEVELOP WEB APPS FOR IOS


A web application that you can run in any browser and an iOS web application are certainly made
using the same common ingredients — HTML, CSS, JavaScript, and AJAX — but they are not
identical. In fact, there are four approaches to consider when developing for iOS devices:
➤ Level 1 — Fully compatible website or application: The ground level approach is to develop
a website or app that is “iOS friendly” and is fully compatible with the Apple mobile devices

c01.indd 7 12/22/11 8:48:57 AM


8 ❘ CHAPTER 1 INTRODUCING IOS DEVELOPMENT USING WEB TECHNOLOGIES

(see Figure 1-10). These sites avoid using technologies


that the Apple mobile devices do not support,
including Flash, Java, and other plug-ins. The basic
structure of the presentation layer also maximizes use
of blocks and columns to make it easy for users to
navigate and zoom within the site. This basic approach
does not do anything specific for iOS users, but makes
sure that there are no barriers to a satisfactory
browsing experience.
➤ Level 2 — Website or application optimized for Safari
on iOS: The second level of support for iOS is to not
only provide a basic level of experience for the user
of Safari on iOS but also to provide an optimized user
experience for users who use Safari browsers, such as
utilizing some of the enhanced WebKit CSS properties
supported by Safari.
➤ Level 3 — Dedicated mobile website or application:
FIGURE 1-10
A third level of support is to provide a website or app
tailored to the viewport dimensions of iPhone and/or
iPad and provide a strong web browsing experience for all mobile device users
(see Figures 1-11 and 1-12). However, although these sites are tailored for mobile viewing,
they are not designed to take full advantage of iOS capabilities. And, in many cases, these
are often stripped-down versions of a more complete website or application.

FIGURE 1-11 FIGURE 1-12

c01.indd 8 12/22/11 8:48:57 AM


The Finger Is Not a Mouse ❘ 9

➤ Level 4 — iOS web application: The fi nal approach is to


provide a web application that is designed exclusively
for iPhone and/or iPad and has a UI design that
resembles a native app or one that takes full advantage
of the capabilities of iOS devices (see Figure 1-13).
One of the design goals is to minimize users’ awareness
that they are even inside of a browser environment.
Moreover, a full-fledged iOS application will, as
is relevant, integrate with iOS-specific services,
including Phone, Mail, and Maps apps.
Therefore, as you consider your application specifications, be
sure to identify which level of user experience you want to
provide iOS users and design your application accordingly. In
this book, I focus primarily on developing web applications
optimized for iOS.

THE FINGER IS NOT A MOUSE FIGURE 1-13

As you develop applications for iOS, one key design


consideration that you need to drill into your consciousness is that the fi nger is not a mouse. On
the desktop, a user can use a variety of input devices — such as an Apple Magic Mouse, a Logitech
trackball, or a laptop touchpad. But, on screen, the mouse pointer for each of these pieces of
hardware is always identical in shape, size, and behavior. However, on iOS, the pointing device is
always going to be unique. Ballerinas, for example, probably input with tiny, thin fi ngers, while
NFL players use big, fat input devices. Most of the rest of us will fall somewhere in between.
Additionally, fi ngers are also not nearly as precise as mouse pointers are, making interface sizing
and positioning issues very important, whether you are creating an iOS-friendly website or a
full-fledged iPhone or iPad web application.
Additionally, fi nger input does not always correspond to a mouse input. A mouse has a left click,
right click, scroll, and mouse move. In contrast, a fi nger has a tap, fl ick, drag, and pinch. However,
as an application developer, you want to manage what types of gestures your application supports.
Some of the gestures that are used for browsing websites (such as the double-tap zoom) are actually
not something you normally want to support inside of an iOS web app. Table 1-2 displays the
gestures that are supported on iOS as well as an indication as to whether this type of gesture should
be supported on a website or full web application.

TABLE 1-2: Finger Gestures

GESTURE RESULT WEB SITE APP

Tap Equivalent to a mouse click Yes Yes

Drag Moves around the viewport Yes Yes

Flick Scrolls up and down a page or list Yes Yes

continues

c01.indd 9 12/22/11 8:48:58 AM


10 ❘ CHAPTER 1 INTRODUCING IOS DEVELOPMENT USING WEB TECHNOLOGIES

TABLE 1-2 (continued)

GESTURE RESULT WEB SITE APP

Double-tap Zooms in and centers a block of content Yes No

Pinch open Zooms in on content Yes No

Pinch close Zooms out to display more of a page Yes No

Touch and hold Displays an info bubble Yes No

Two-finger scroll Scrolls up and down an iframe or element with CSS Yes Yes
overflow:auto property

LIMITATIONS AND CONSTRAINTS


Because iPhone, iPad, and iPod touch are mobile devices, they are obviously going to have resource
constraints that you need to be fully aware of as you develop applications. Table 1-3 lists the
resource limitations and technical constraints. What’s more, certain technologies (listed in Table 1-4)
are unsupported, and you need to steer away from them when you develop for iOS devices.

TABLE 1-3: Resource Constraints

RESOURCE LIMITATION

Downloaded text resource (HTML, 10MB


CSS, JavaScript files)

JPEG images 128MB (all JPEG images over 2MB are subsampled
— decoding the image to 16x fewer pixels)

PNG, GIF, and TIFF images 8MB (in other words, width*height*4<8MB)

Animated GIFs Less than 2MB ensures that frame rate is maintained
(over 2MB, only the first frame is displayed)

Non-streamed media files 10MB

PDF, Word, Excel documents 30MB and up (very slow)

JavaScript stack and object allocation 10MB

JavaScript execution limit 5 seconds for each top-level entry point (catch is
called after 5 seconds in a try/catch block)

Open pages in Mobile Safari 8 pages

c01.indd 10 12/22/11 8:48:59 AM


Setting Up Your Development Environment on a Local Network ❘ 11

TABLE 1-4: Technologies Not Supported by iPhone and iPod touch

AREA TECHNOLOGIES NOT SUPPORTED

Web technologies Flash media (SWF and FLV), Java applets, SOAP, XSLT,
and Plug-in installation

Mobile technologies WML

File access Local file system access

Security Diffie-Hellman protocol, DSA keys, self-signed certificates,


and custom x.509 certificates

JavaScript events Several mouse-related events

JavaScript commands showModalDialog()

Bookmark icons .ico files

HTML Input type=”file”, tool tips

CSS Hover styles, position:fixed

SETTING UP YOUR DEVELOPMENT ENVIRONMENT


ON A LOCAL NETWORK
Because iOS does not allow you to access the local file system, you cannot place your application
directly onto the device itself. As a result, you need to access your web application through another
computer. On a live application, you obviously want to place your application on a publicly
accessible Web server. However, testing is another matter. If you have a Wi-Fi network at your
office or home, I recommend running a web server on your main desktop computer to use as your
test server during deployment.
If you are running Mac OS X, you already have Apache web server installed on your system.
To enable iOS access, go to System Preferences, Sharing Services and turn the Web Sharing
option on (see Figure 1-14). When this feature is enabled, the URL for the website is shown
at the bottom of the window. You use this base URL to access your web fi les from an
iOS device.

c01.indd 11 12/22/11 8:49:00 AM


12 ❘ CHAPTER 1 INTRODUCING IOS DEVELOPMENT USING WEB TECHNOLOGIES

FIGURE 1-14

You can add fi les either in the computer’s website directory (/Library/WebServer/Documents) or
your personal website directory (/Users/YourName/Sites) and then access them from the URL bar
on your iPhone or iPad (see Figure 1-15).

FIGURE 1-15

c01.indd 12 12/22/11 8:49:00 AM


Setting Up Your Development Environment on a Local Network ❘ 13

EXERCISES

1. What’s the difference between a native iOS app and a web app?

2. Can a web app be placed on the Home screen alongside native apps?

3. Does finger input always correspond to mouse input?

Answers to the Exercises can be found in Appendix A.

c01.indd 13 12/22/11 8:49:01 AM


14 ❘ CHAPTER 1 INTRODUCING IOS DEVELOPMENT USING WEB TECHNOLOGIES

 WHAT YOU LEARNED IN THIS CHAPTER


TOPIC KEY CONCEPTS

Key Safari features for developers Geolocation support, HTML5 media tags, CSS animation
and effects, and SVG

Supporting mobile devices on your Level 1: Fully compatible website/application


website
Level 2: Website/application optimized for Safari on iOS

Level 3: Dedicated mobile website/application

Level 4: iOS web application

c01.indd 14 12/22/11 8:49:01 AM


2
Working with Core Technologies
WHAT YOU WILL LEARN IN THIS CHAPTER:

➤ Adding video to your app


➤ Discovering basic JavaScript coding techniques
➤ Working with functions and arrays

Although a native iPhone app is built entirely in Objective-C, an iPhone web app is composed
of a variety of core technologies that serve as interlocking building blocks. HTML provides
structure for the user interface and application data. CSS is used for styling and presentation.
JavaScript and Ajax provide the programming logic used to power the app. And, depending on
the app, it may have a back-end application server, such as Java or PHP.
Books on programming native iPhone apps often have a primer chapter on the basics of
Objective-C to make sure everything is speaking the same language, so to speak. And,
although it’s outside the scope of this book to include a complete primer on the core web
technologies you will work with to develop an iPhone web app, I do want to explore some of
the key technologies you need to be sure you know about in order to be successful.
The information in this chapter is presented with the assumption that you at least know the
basics of HTML and at least have a working knowledge of CSS. Most of the material covered
here is about the scripting logic layer. However, fi rst I want to highlight the HTML 5 tags that
Safari on iOS supports for embedding media into your web app.

EXPLORING HTML 5 MEDIA ELEMENTS


In the early days of the iPhone, working with video inside of an iPhone web app usually
consisted of a simple link to a YouTube clip, which would then launch the YouTube app.
Because Safari on iOS doesn’t support Flash video (.flv), there were few alternatives to an
ordinary link when working with video. However, one of the key HTML 5 technologies that
Safari on iOS now supports is the video element.

c02.indd 15 12/21/11 3:35:53 PM


16 ❘ CHAPTER 2 WORKING WITH CORE TECHNOLOGIES

You use the video element to defi ne a video clip or stream, much like an img tag defi nes an
image on your page. The promise of the video tag is that it eliminates the complicated hoops that
developers have to go through with embedded media content. Instead of mixing complicated object
defi nitions and script, you can embed media with a simple tag defi nition.
Unfortunately for normal websites, the video element remains something of a tease because many
desktop browsers don’t yet support HTML 5. As a result, developers either have to add additional
code for unsupported browsers or else avoid its use altogether.
However, if you are creating an iOS web app, you don’t have this same dilemma. Safari on iOS
provides full support for HTML 5. Therefore, if you need to utilize video in your app make sure to
take advantage of the video tag.
Note that the video does not play inside of the web page as an embedded video; instead it launches
the built-in iOS media player, which occupies the full screen of the device. The user then clicks the
Done button to return to your app.
The basic syntax for the element is shown below:

<video src=”../video/trailer.mov” controls=”true” poster=”picture.jpg”


width=”300” height=”200”/>

TABLE 2-1: Attributes for the video Element

ATTRIBUTE DESCRIPTION

autoplay When set to true, the video plays as soon as it is ready to play.

controls If true, the user is shown playback controls.

end Specifies the end point to stop playing the video. If not defined, the video plays to
the end.

height Defines the height of the video player.

loopend Defines the ending point of a loop.

loopstart Defines the starting point of a loop.

playcount Specifies the number of times a video clip is played. Defaults to 1.

poster Specifies the URL of a “poster image” to show before the video begins playing.

src Defines the URL of the video.

start Sets the point at which the video begins to play. If not defined, the video starts
playing at the beginning.

width Defines the width of the video player.

Supported video formats include QuickTime (.mov) and MPEG (.mp4). Note that Safari on iPhone
does not support Flash media (.flv) and OggTheora (.ogg).

c02.indd 16 12/21/11 3:35:55 PM


Exploring HTML 5 Media Elements ❘ 17

TRY IT OUT Adding a Video


Adding a video into your app now becomes as easy as adding the video tag to your page.
1. Create the following HTML document in your text editor and then save the document as
BIDHJ-Ch02-Ex1.html.

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”


“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Video</title>
<meta name=”viewport” content=”width=320; initial-scale=1.0;
maximum-scale=1.0; user-scalable=0;”/>
<style type=”text/css”>

body
{
background-color: #080808;
margin: 10;
color: #ffffff;
font-family: Helvetica, sans-serif;
font-size:10px;
}

</style>

</head>
<body>
</body>
</html>

Code snippet BIDHJ-Ch02-Ex1.html

2. Add the following div element in the body and save your fi le:

<div style=”text-align:center”>
<p>Check out the new trailer for our upcoming video game release.</p>
<video src=”../videos/tlr2_h.640.mov” controls=”true” width=”300”/>
</div>

Code snippet BIDHJ-Ch02-Ex1.html

How It Works
When this document loads, the poster image of the video is displayed in the rectangular area of the
video element (see Figure 2-1). When the user touches the video player Safari displays the video in
the built-in media player, as shown in Figure 2-2.
The audio element works in much the same way, though its attributes are a subset of the video tag’s
set. They include src, autobuffer, autoplay, loop, and controls. Figure 2-3 shows the audio fi le
being played in the media player.

c02.indd 17 12/21/11 3:35:56 PM


18 ❘ CHAPTER 2 WORKING WITH CORE TECHNOLOGIES

FIGURE 2-1 FIGURE 2-2 FIGURE 2-3

SCRIPTING JAVASCRIPT
The scripting layer of your iOS web app is often the “brains behind the operation” — the place on
the client-side in which you add your programming logic. That’s why as you begin to develop more
and more sophisticated web apps for the iOS platform, you’ll fi nd that the technology you’ll rely
more and more on is JavaScript. Therefore, before you go any farther in this book, you need to have
a solid grasp on how to script with JavaScript. Use this section as a primer for the core essentials of
programming with JavaScript.

Syntax and Basic Rules


Like any other programming language, JavaScript has its own syntax rules and conventions.
Consider the following script:

<script>

// Defining a variable
var message = “Hello”;

// Creating a function, a module of code


function showGreeting(allow)
{
// If allow is true, then show the message variable
if (allow == true)

c02.indd 18 12/21/11 3:35:57 PM


Exploring the Variety of Random
Documents with Different Content
ruthless kind of irony that fixed upon such shoulders as these the
responsibility for as grave a miscarriage as ever darkened the annals
of English justice.
“In his private life he had known great sorrows. His only son was
drowned twenty years ago while a freshman at Oxford. Had he lived,
he was destined for that profession for which his father had so
profound a reverence. Nothing could have been more exquisite than
Joseph Brudenell’s childlike devotion to his calling, yet he was
always haunted by the consciousness that the ideals he had set up
were beyond his grasp. This son was to have been the truer, the
wiser, the stronger, the more penetrating man; yet it was never to be.
The accident that deprived him of this enlarged and completer
edition of himself added something to his latter years that his faithful
circle of old friends found wistful and affecting. And only last week he
lost the devoted daughter who had been the stay of his declining
years.
“It is safe to say that no man was ever called to the bar who was
more honestly beloved by all who understood the secret workings of
his mind than was Joseph Brudenell. Subtle it was not, it was not
agile, and it was not profound; indeed the possession of that simple
and unsagacious implement conferred only one claim to
preëminence. It is as a great and honest gentleman that Joseph
Brudenell will be called to the Valhalla of his gods. He was past
master in one art only: the art which embraces the amenities of life.
Unsympathetic critics he has had in his public capacity. He has been
called a pedant, a weakling, one deficient in insight; even his
scholarship, which was so laboriously honorable, has not escaped
inquiry; but the void left by that massive and ungainly form can never
be filled. In this time, at least, his like will not be seen. A rare jewel
has been resolved to its element; earth is the poorer by an English
gentleman.”
These words served to heighten Northcote’s indignation against
himself. The stab he had directed at the judge increased in infamy.
Already it seemed as if he had paid an exorbitant price for his
success. However, in the midst of his anguish and perplexity, he
heard feet on his staircase. There came a knock to his door. It was
the solicitor.
“Well, my boy,” said Mr. Whitcomb, shaking his hand affectionately,
“do you see you have killed the judge?”
“Yes,” said Northcote, “but I saved the life of your client.”
XXXII
MEDIOCRITY ASPIRING TO VIRTUE

The advocate handed the Age to the solicitor.


“You may have seen it,” he said. “I am honored with a leading
article.”
“I have read it. It means your removal from the top story to the
basement.”
“I don’t understand.”
“It ensures that your professional emoluments will not be less than
two thousand a year.”
“That would be very well had I not arrived at the conclusion that the
game is not worth the candle. The penalties are too great.”
“Why consider them, dear boy? Why not accept the gifts of the gods
in a thankful and contrite spirit?”
“You would have me drink the nectar that they offer although they
hand it in a poisoned cup?”
“You are a queer fellow. You accept starvation with a dignified
humility, but the instant you touch success—and such a success!—
you make a face.”
“Such a success—there you have it all!”
“My dear fellow, whoever in this world got off the mark with such a
flying start? You have awoke this morning to find yourself famous.”
“Bah! I am poisoned; I have got my death!”
“Within five years, if you keep your head, you will be making a
princely income.”
“I know it.”
“And two days ago you could not afford to pay for a fire in the middle
of winter.”
“You are perfectly right.”
“Two days ago you could not fill your belly when you were hungry.”
“I shall never taste hunger again—that honest, bitter, medicinal
hunger that merges the mind in the soul. I shall never taste again
that ascetic clarity which makes the heart supple and arms the
brain.”
“You talk like a Methodist.”
“My father was a country preacher.”
“I expect this is the swing of the pendulum. You must have
undergone great mental excitement in making your effort—and what
an effort it was! And now the clock has swung right back; you are
below par: you have got the blues.”
“I hate myself; I hate my cursed profession.”
“Yes, the mercury has fallen. The higher the rise the greater the
drop. But make an effort to be rational. Look at this.”
The solicitor handed the advocate a brief. It was marked with a
retaining fee of a hundred guineas.
“Two days ago that was beyond the dreams of your avarice. And
now it is a mere forerunner of the beginning. You will be compelled
to change your quarters and keep a clerk.”
“You remind me of the devil—the real authentic mediæval
Mephistopheles,” said Northcote, with his fingers trembling upon the
tape. “You are in the pay of the genie, you smug-hearted materialist.”
“Ah, the genie again! I am afraid to confess that that genie of yours
gave me a very bad quarter of an hour,” cried Mr. Whitcomb,
laughing heartily at the recollection. “I was never in such a panic in
my life. Had it not been the last moment, and had it not been
impossible to get any one else, you would never have held that brief.
You and your genie frightened me to death. I woke up in a cold
sweat in the middle of the night, wondering what would happen if you
brought the infernal thing into court.”
“Well, I did bring it into court, did I not?”
“You would never have got your verdict without it.”
“Yet you were afraid?”
“That was before I knew what it was. But as soon as you got up to
talk to the jury, and you could have heard a pin drop over the court, I
gave in.”
“That is true enough,” said Northcote, in the hollow tone which had
discomposed the solicitor at the restaurant, “but once having
summoned this thing to my aid, once having taken it into court with
me, once, as you might say, having let it taste blood in the arena, I
shall be compelled to have it with me every time. It is already out of
my control.”
“So much the better for you and for those who command your
services. This genie of yours will one day be worth thirty thousand a
year in cool coin of the realm. If you will deign to take the advice of
one who is perfectly willing to be a father to you, I say to you, don’t
overdo it. Employ as many devils as you please,—five, ten, or a
hundred and ten,—but don’t be tempted into taking enough work to
break down your nervous system. Keep that intact and you are
predestined for the Woolsack.”
“I feel it; and yet, do you know, Whitcomb, it hangs in the balance
whether I ever walk into court any more.”
“If you think so, it is little you know of your nature. What you call the
genie will have the last word to say on that subject.”
“Like every other mud-colored materialist your intelligence is
admirably lucid as far as it goes.”
“Compliments are flying. But is it not the faculty of youth to despise
the common sense to which one day it is only too glad to return?”
“I would spew mediocrity out of my mouth,” said Northcote, suddenly
overmastered by arrogance.
“Common sense and mediocrity are not quite the same; but you can
take it from me, dear boy, that genius has always to learn sooner or
later that mediocrity has its uses.”
The solicitor was amazed to see tears spring to the eyes of the
advocate.
“I have learnt that already,” he said huskily; “I learnt it last night after
the rising of the court.”
“I presume you are referring to poor old Bow-wow, the type of all
mediocrity.”
“Yes, to the poor dear old blunderer who, after the manner of his
kind, consecrated his life to a public display of his incapacity. Yet I
weep for Adonais, he is dead!”
“I say, my boy,” said the solicitor, amazed by the depth of emotion
that was revealed in the face of the young man, “you did not
suppose for one moment that I was in earnest when I said you had
killed him?”
“You struck so near to the truth,” said the young man, “that you made
me bleed.”
“Well, this is a consummate kind of folly. You must feed well; build
yourself up; go away for Christmas; take a rest. Future greatness
cannot be allowed to play ducks and drakes with its chances.”
“I swear to you, Whitcomb, the weight of a feather would make me
throw up the bar.”
“Impossible! That voice, that presence, that imagination, that
extraordinary dynamic quality—in other words, your genie, leaves
you no choice.”
“I swear to you, Whitcomb, if it were not for my countrified old
mother, who has worked her fingers to the bone to provide an
education for me, I would never go into court any more.”
“Ah, well, I shall continue to send you briefs all the same. I cannot
recall another man who has got a start such as yours, and I shall be
astounded if through a whim you show yourself unworthy of your
good fortune. Here is a check for ‘the monkey’ you won of me at
lunch yesterday.”
“Five hundred pounds! I don’t remember anything of the
circumstances.”
“I laid five hundred to fifty against your getting a verdict.”
“When?”
“At lunch yesterday.”
“You must not take any notice of that. I was very excited. I am afraid I
was not myself.”
“Why afraid? The money is yours.”
“I don’t want it; I won’t have it.”
Mr. Whitcomb had thrust the check in the hands of the advocate,
who tore it up immediately.
“Well,” said the solicitor, “I should say at the present time you have
undeniable claims to be considered the most remarkable man in
London. I can’t fathom what has come over you.”
“I was thrown off my balance a little yesterday,” said Northcote
hoarsely.
“Yesterday, my friend, you were a great man; to-day, you are a prig.”
“You are right. Yesterday, a great man stooping to foulness; to-day, a
mediocrity aspiring to virtue.”
“Well, my dear boy,” said the solicitor earnestly, “my last words are
these. Be guided by your talent. Greatness is written all over you; it
is in your eyes; it proceeds out of your mouth. Play up to your
destiny, like a wise fellow, and leave hymns and sermons and
disquisitions upon morality to the official purveyors of those
condiments.”
“You are the devil!”
“Well, Faust, dear old boy, if it come to that, it does amuse me
sometimes to think that I have not dabbled in human nature in divers
forms during the last twenty years without getting to know a little
about it. And I put it to you, do you suppose I took the trouble—I, one
of the most sagacious criminal lawyers in London—to climb up to
this attic without my dinner at ten o’clock of a December night,
without having taken your size in hats and your chest
measurement?”
“I say, you are the devil.”
“Your estimate is too liberal. There is nothing of his Satanic Majesty
about me; but, all the same, I am always perfectly willing to employ
him. I am always prepared to pay him liberally to fight these causes
of mine, wherever and whenever he is to be found. What you call the
genie is, after all, a euphemism for the devil, although under the
more chaste patronymic I failed at first to recognize that elderly
swaggerer.”
“Well, yes, you are shrewd. But you leave a bad taste in the mouth.”
“Everything does that this morning. But I am not surprised that you
are feeling cheap. The human frame has to pay for such colossal
efforts. In the meantime, you have no need to worry about anything.
The mercury will rise again; things will all come right; and you will
attain an eminence that few could occupy. In the meantime, divert
yourself with these, and mention your own time for the consultation.”
Leaving two briefs, one of which was marked with the sum to which
he had previously referred, Mr. Whitcomb descended the stairs,
much to the relief of the advocate.
XXXIII
THE HIGHWAY OF THE MANY

Success had spread out both hands to Northcote, but the emotion
she had aroused in him was not one of gratitude. He had spent
many days of suffering, of mental darkness, during the years of his
obscurity, but none had engulfed him in such humiliation as this upon
which he had entered now. He had tasted coldness and hunger; he
had known the stings of rage and despair; but these sensations
appeared salutary in comparison with a hopelessness such as this.
How could he cherish an illusion in the matter, he who knew so
much? He had made his choice deliberately under the spur of need;
he had foreseen its enormous penalties; he had foreseen the
degradation that was implied in the honors and emoluments that
would accrue from its exercise. Yet, now these things had come
upon him, he smote his breast and lifted up his voice in woe. Less
than a week ago, in the freedom of his penury, in the license of his
failure, he had had the power to spurn these lures. Yet in almost the
next breath he had yielded to the call of his ambition; and in his first
walk upon the perilous path he had elected to choose, he had shown
an ease and lightness of motion that were audacious, astonishing.
What was there to deplore? His triumph had been so patent as to
win the applause of the world. For the first time in his life money was
in his pocket. That woman of courage who had striven so heroically
for his welfare would meet with her reward. She would be enabled to
end her days at ease. In those somewhat unilluminated eyes Money
had always seemed to divide the place of honor with Duty. She
would go to her grave, this upright and courageous one, with a p an
upon her lips, because her son, her one talent, had in her old age
been increased to her tenfold. Those worn hands would need to toil
no more.
After all, this success, which to an honest nature was so embittering,
had a curious virtue of its own if it could fulfil such an office. And it
was hardly for the like of himself to be troubled with these
intimations. Morality, like other privileges, was for those who could
afford to enjoy it; it was for those who had a snug little annuity in the
funds. Those who had shivered in penury, who had known the look
of want, had purchased their right to walk unfearingly by the light of
their necessity. And he had only parted with his dreams after all; he
had only transmuted airy nothings into explicit gold of the state. Let
the visionary who nourished his heart upon the unattainable despise
Crœsus as before, but let the well-fed and valiant materialist render
due homage to that lusty and pagan old fellow. You could not keep
your cake and eat it; you could not resign your ideals and yet hope to
inhabit your castle in Spain.
It always came back to the question of the Choice. Was it not a sign-
post that headed every path; did it not denote the convergence and
the parting of every road? It was his own will which had selected the
broad and muddy highway of the many, instead of the narrow and
precipitous mountain ascent which was only for the feet of the few. In
a choice of this kind there might be an affront to his nature, but once
having embraced it, it was weakness to repine. He must shed this
ferocious arrogance of his. He was now of the common herd, no
longer of the sacred few.
The strangeness of his position held his thoughts all day. That which
he had purchased had been obtained at a cost beyond rubies; it was
not worth one-half he had paid for it, but as he could never recover
his outlay he was bound to go on. It remained for him now to play the
part of the cynic and philosopher. It was not the highest style of the
hypersensitive man on the defensive, but the patchwork target would
have to serve until he found the cunning to provide himself with a
more efficient cover for his wounds. Yet when all was said the shaft
had sunk to a cruel depth in that quivering nature. Heart and mind
were lacerated.
At the table at the aerated breadshop at which he took his lunch, two
middle-aged clerks from a city counting-house, musty, cowed, and
solemn men, were discussing the trial wherein the morning journals
with their unerring instinct had discovered the element of sensation.
“——so she got off?”
“Yes, they brought in a verdict of not guilty. My father-in-law was on
the jury. He says it was her lawyer’s speech that saved her. He says
there wasn’t a dry eye in the court, and the poor old judge cried just
like a child.”
“No!”
“Yes! He says he never heard a speech like that before in his life,
and he says if he lives to be a hundred years old he will never forget
it.”
“Who was her lawyer? Sir Somebody, K. C., M. P.?”
“My father-in-law says not. He says he was quite a young chap
without any reputation. But such a voice—he says it just went
through you and made you shiver.”
“Something like Irving?”
“My father-in-law says he must have been acting, yet there didn’t
seem to be a bit of the actor about him. That’s where he was so
wonderful; struck no attitudes; never even raised his voice. Every
word seemed to come straight out of him, as though he just couldn’t
help it, and yet at first all the jury thought she was a thorough bad
one.”
“So she was, I expect.”
“I dare say; but after what her lawyer had said they never thought of
bringing in a verdict of guilty. My father-in-law says he was a
wonderfully read young fellow, and he must have known the Bible
almost by heart from the way in which he used it in his speech. And
such an eye as he had too! My father-in-law says it looked like that
of an eagle; and when the jury retired to consider the verdict the
foreman, who had got a weak heart, had to have brandy or he would
have fainted dead away.”
“It was very strange that the judge should have died suddenly.”
“Excitement killed him, they do say.”
“You would think that a judge would be so used to that sort of thing
that it wouldn’t affect him.”
“Well, my father-in-law has been many times on the common jury,
but he says this young lawyer beat all he had ever heard. He says it
doesn’t matter how clever the ordinary lawyer may be, you can
always tell when he’s putting it on. But this young chap was so quiet
and solemn that he simply made you shiver.”
“Just a trick.”
“They all knew that, yet he made them so that they couldn’t help their
feelings. My father-in-law says as soon as they retired to the jury-
room to find their verdict, old Bill Oaks—you know the old prize-
fighter what keeps the Blue Swan at Hackney—who was on the jury,
he just spat in the corner and wiped his eyes on his sleeve, and he
says, ‘Well, mateys, I’d reckon we’d ’ang no more women.’”
“Bill Oaks said that?”
“Those were his words. And it just shows the power that young chap
must have had to make a common fellow like old Bill Oaks say a
thing like that.”
“Some men are born lucky. With a mind of that sort he will have
made a fortune in no time. In a year or so he will be keeping his
yacht and driving his motor-car. It is a funny world when you come to
think about it. Here is a chap like me, been a clerk in the Providential
for thirty-five years. My hours are nine-thirty till five; I have never
once been late, nor had a day off for illness; and my salary per week
is thirty-eight and a tizzey, with a pound a week pension at sixty
provided I keep up my payments to the fund. I have never done a
wrong action as far as I know; I go to church once on Sunday; I
teach in the Sunday school; I give five shillings to the poor every
Christmas; I have brought up five children well and decently; I
always acted the part of the gentleman to my wife while she was
alive, and now she is dead I always keep fresh flowers on her grave
summer and winter; I’ve paid my rates and taxes regular; the
landlord has never had to ask me twice for the rent; and what’s it all
amount to? Why, I leave off just where I began. Yet I consider myself
a cut above this young man, with all his gifts, who will make a fortune
by saving murderers from the gallows.”
The speaker, a sallow, stunted little fellow, uttered his words in a
quiet, yet dogged staccato, as though he were issuing a challenge
which he knew could not be taken up. His sharp, quaint cockney
speech was almost musical in its incisive energy.
“Happiness don’t depend on money,” said his friend.
“You have got to have money, though, before you can believe it.”
Northcote overheard this conversation while he munched a
sandwich. It afforded him the keenest interest. He moved out into the
eager crowd which thronged the Strand. Yet again his old passion for
perambulating the streets came upon him. There was a sense of
adventure in dodging the traffic at a breakneck pace, and in elbowing
his way through the press. Until the evening he wandered about in
the mud and the December mists. He was sick and weary; the
conflict within him gave him no rest; yet there was a fierce joy to be
gained in mingling with the virile, many-sided life that was about him
everywhere.
Thoroughly tired out at last, he took a frugal dinner at a restaurant,
and accompanied it with a bottle of inexpensive wine. He lingered
over his meal and made an attempt to read an evening paper, but
found he could not do so. The vortex in which his nature had been
plunged absorbed the whole of his thoughts.
XXXIV
MAGDALENE OR DELILAH

About nine he returned to his lodging. He lit the lamp, drew the
curtains across the window, and built up a good fire. He set himself
to do three hours’ reading before he turned into bed. However, that
power of will it was his wont to exert to its fullest capacity was for
once insubordinate. There were not two consecutive sentences upon
any of the pages which he tried that displayed a meaning. He had
never known this impotence before.
In the midst of these futile attempts to fix his mind on the task before
it, he thought he heard the creaking of the stairs. He listened acutely.
Late as was the hour, the clerk of some attorney might be bringing
him more briefs. A moment later his door was softly tried and opened
as softly as some one entered the room.
To the profound astonishment of the young man he saw that it was
the figure of a woman. She was tall and pale and clad sombrely in
close black draperies. Her entrance was somewhat stealthy, yet it
had neither reluctance nor timidity. Unhesitatingly she approached
the chair in which the advocate sat with a book on his knee. He rose
to greet her with an air of bewilderment.
“I knew you were a great student,” said his visitor in a low voice,
letting two large and dark eyes fall upon the page of the book.
“I beg your pardon,” said Northcote, “I am afraid I don’t know you.”
“You do not know me?” said his visitor in a tone that entered his
blood. “I will give you a moment to think.”
Northcote seemed to recoil with a half-born pang of recollection
which refused to take shape.
“I have not the faintest knowledge of having met you before,” he
said, feeling how vain was the effort to fix his thought.
“Think,” said his visitor.
“It is in vain.”
“I should not have expected you to have so short a memory,” said
the woman. “You saw me yesterday and you saw me the day before
that.”
“I do not recognize you at all,” said Northcote faintly.
“Should I have remembered that you were a busy man who was
unable to spare a thought outside of his profession?”
There was something curiously stealthy in the fall of the voice which
startled the advocate.
“That is a voice I seem to recall,” he said, with an air almost of
distress.
“A voice you seem to recall,” said his visitor, with a sombre laughter
which made his heart beat violently. “How strange it is that you
should recall it! You only heard it once, and that was in the stifling
darkness of a prison!”
Northcote gave a cry of stupefaction.
“Impossible, impossible!” he said weakly. “You—you cannot be the
woman Emma Harrison!”
“Emma Murray, alias Warden, alias Harrison,” said his visitor, whose
tone of gentleness was now charged with deliberation.
“Then how and why do you dare to come here?” cried Northcote.
“I bring you my thanks,” she said, with a sudden consummate
transition to humility. “I bring the gratitude of an outcast to him who
has delivered her from a deeper shame than any she has suffered.”
At first the bewilderment of the advocate would not yield; the
revelation of the last creature in the world he looked to see in his
attic had seemed to arrest his nature. But hardly had she rendered
him her homage with somewhat of the sombre dignity of one who
seeks by suffering to efface her stains, than the old devouring
curiosity of two evenings previously returned to him. In the prison he
had not seen her face; in the dock he had not permitted his eyes
once to stray towards her. She was engraved in the tablets of his
imagination as a foul and sordid creature, dead to feeling, yet
susceptible of the loss of freedom, horrified by the too-definite
thought of a barbarous doom; yet over and above everything a
denizen of the gutter, wretched, stupid, and unclean. It was amazing
to see her stand before him in this frank guise.
Peering at her through the subdued flames of the fire and the lamp,
he saw that she had contrived to inhabit her stains in a kind of
chastity. It was a trick of her calling, perhaps; yet if trick it was, it was
subtle, consummate, and complete. As far as his eyes could pierce
the texture of her secrecy, her face was that of a woman of forty. It
was pale and unembellished; the cheeks were wan; the features, but
slightly defaced, were possessed of a certain original fineness of
line, like the handiwork of some little known craftsman who had been
touched by genius. There were the remains of a not inconsiderable
splendor strewn about her, particularly in her dark, enfolding, and
luminous eyes. Suffering was everywhere visible, even in the hair,
whose natural sallow hue was peeping through its dye. In form she
was large, but not massive; ample, flowing in contour, with the
powerful, yet graceful, moulding of a panther.
“Had you not expected something different?” she said, standing up
before a scrutiny he did not disguise, and speaking with a
mournfulness that seemed to challenge him.
“You have guessed my thoughts,” said Northcote, without lowering
his gaze.
“I was not always as I was,” she said, letting each syllable fall
passionless. “I sank deeply, but I am risen again. I am praying that
with the aid of one I may scale the heights. I even hope to reach that
which in the beginning was above my stature.”
“I am glad to hear it,” Northcote muttered.
“That is cruel,” said his visitor with a shiver. “Such a phrase from
your mouth wounds me like a sword.”
“I am afraid I don’t understand,” said Northcote, almost with
indifference.
“This is not him whom I came to see,” said the woman. “This is not
him who saved my base body; him who, if he will, may redeem my
whole nature.”
“I?” cried the incredulous young advocate.
“You, my deliverer!”
“I—I don’t think I like you; I think you had better go away,” said the
young man, with a brutality of which he was unconscious.
The woman replied to this speech by sinking slowly to her knees.
She lifted the noble line of her chin, which intense suffering had
seemed to refine, up towards him with an ineffable gesture of
appeal. It almost vouchsafed to him a sense of his own degradation.
“I see you as the one whose noble strength will heal me,” she said,
prostrating herself more completely, and clasping her arms about his
ankles.
“Better rise, better leave me,” said Northcote, bewildered by a sense
of pity for his own impotence.
“You are striking me again,” said the woman with a shudder that
even to Northcote seemed terrible, “but every blow you give may
help to make me whole.”
“What can heal a murderess, a prostitute?” he asked, with a candor
of selection that was intended to lacerate.
“You. You who brought me out of prison—you who delivered me from
a shame to which even I dared not yield.”
“Get up,” said Northcote, filled with an unaccountable pang. “Sit
there, and try to compose yourself a little.”
With an indescribable impulse, which he had no means of fathoming,
he raised the trembling, shuddering form by the shoulders, and let it
into the chair nearest the fire. The act was wholly without
premeditation, but there was nothing in it that partook of the uncouth
harshness of his voice. A few scalding drops crept out of her eyes on
to his hands, and when he lifted her the heat of her body
communicated itself to the tips of his fingers.
“Oh, why do you not speak to me with the voice with which you
terrified my judges?” she moaned.
“I cannot make up my mind about you,” said Northcote calmly. “I do
not know whether you are the Magdalene, or whether you are
Delilah.”
“When you pleaded for my life before my judges yesterday in the
court, I looked upon you as Jesus,” said the woman, pressing the
tips of her fingers against the balls of her eyes.
“At that hour I felt myself to be no less. And I believe there were
those among my hearers who had that hallucination too.”
“Would he have cut me into pieces when I crept to him for
sanctuary?”
The young man pressed his hands to his sides. An ineffable anguish
had pierced him.
“No man ever felt less like that Nazarene than do I this day,” he
cried, with a face that was transfigured with terror. “A holocaust has
taken place in my nature. I know that I shall never take my stand with
the gods any more. Henceforward I am filled with roughness,
brutality, and rage; I hate myself, I hate my species.”
“Wherefore, O my prince!”
“Am I not fallen deeper than her I redeemed from her last ignominy?
Have I not prostituted a supreme talent; have I not poisoned the
wells of truth?”
“Can this be he who preached the Sermon upon the Mount? Can this
be he who said to the woman taken in adultery, ‘Daughter, go thy
ways, and sin no more’?”
Already the roughness of the advocate was melted into blood and
tears. His callous rage had yielded before the figure of the
Magdalene. This nondescript animal he had picked out of a sewer
had proved to be a woman who had bled for abasement, and who
strove for reinstatement by bleeding for it again.
“I have a curiosity about your history,” said Northcote, with a gaze
that devoured her. “You see you are pictured in my imagination as
the denizen of a slum.”
“I entered upon life,” said the woman, yielding to the domination of
his eyes, “as the eldest daughter of an artist whose existence was a
misery. He was a painter of masterpieces that no one would buy. He
had not been in his grave a year when they began to realize sums
that during his life would have appeared to him as fabulous. His two
girls, who comprised his family, never got the benefit of the
recognition that had been denied to their maker; but the dealers in
pictures, who had begrudged him so much as oils and canvas, grew
rich by trading upon a great name.
“My childhood was bitter, cruel, and demoralizing. Art for the sake of
art was the doctrine of my poor father, and in pursuing it he took to
drink. That honest and virtuous world which I have never been
allowed to enter, viewed him afar off as an outcast, as an idle and
dissolute vagabond, as a worthless citizen, whose nature was
reflected in his calling. Perhaps he was all this; perhaps he was
more. Yet he would shut himself up in a little back parlor in the
squalid little house in which we lived, and there he would work in a
frenzy for days together. He would emerge with his nerves in rags,
his skin pale, his eyes bloodshot, his linen foul, his clothes and
person in disorder, yet under his arm was a new masterpiece, twelve
inches by sixteen, which he would carry round to a dealer, who
would bully and browbeat him, and screw him down to the last
shilling, which he already owed for the rent. He would return home
worn out in mind and body by his labors; and for weeks he was
unable to bear the sight of a brush or a skin of paint. It was then he
would seek to assuage his morbid irritation with the aid of drink.
‘They will place a tablet over this hovel when I am dead,’ he would
say, ‘but while I am alive the rope which is needed to hang me
outbuys the worth of this tattered carcass.’
“My poor father, rare artist as he was, was right in this estimate of
himself. As a man, as a father, as a citizen, I cannot find a word to
say for him. He never brought a moment of happiness to either of his
girls. He dwelt in a world of his own; a beautiful and enchanted
world, the Promised Land of his art. He was a man of strange
ambition; of an ambition that had something ferocious in it; of an
ambition that was unfitted to cope with the sordid and material aims,
by whose aid persons of not one-tenth part of his quality achieved
wealth, respectability, power, and the fame of the passing hour.
There was a thread of noble austerity in my poor father’s genius,
which remained in it, like a vein of gold embedded in the mud of a
polluted river, throughout the whole time of his degradation and his
ruin. His pride seemed to grow more scornful with each year that
witnessed more completely the consummation of the darkening and
overthrow of his nature. I can remember his saying of a picture by
the president of the Academy, ‘I would rather have my flesh pecked
by daws than prostitute myself with such blasphemies as that;’ and
at that time he stood upon the verge of the grave of a drunken
madman.
“I have said he was not a good citizen. Nor was he a good father to
his girls. He did not offer them physical violence; but it never
occurred to him to shield them from the indignities thrust upon them
by want and debt, and the despair which was sown in their hearts by
the foulness of every breath they drew. It would need my father’s
own gift to limn the picture of this beautiful talent living its appointed
life in its own way, yet indifferent to the most elementary duties of a
righteous parent and an honest citizen. As a young man he had
been handsome, with a fine, delicate, even an entrancing beauty; it
was one of his favorite sayings that the face of every true artist
borrowed something from heaven. I can only recall that face in its
latter days, when it was that of a petulant, arrogantly imperious, yet
hideous and bloated old creature, whose body and soul had been
undermined; but from the numerous pictures he painted of himself in
his youth he had the divine look of a poet.
“I have always considered it as both cruel and ironical of nature that
she should have bestowed upon the daughters of this drunkard and
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like