jQuery Mobile Web Development Essentials - Third Edition - Raymond Camden - E-Book

jQuery Mobile Web Development Essentials - Third Edition E-Book

Raymond Camden

0,0
39,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Build a powerful and practical jQuery-based framework in order to create mobile-optimized websites

About This Book

  • Build websites with jQuery Mobile that work beautifully across a wide range of mobile devices
  • Become a competent jQuery Mobile developer and learn the building blocks of jQuery Mobile's component-driven design
  • This book covers key concepts but with a focus on providing the practical skills required

Who This Book Is For

This book is for any web developer who is looking to create mobile-optimized websites. Basic knowledge of HTML is required. Minor familiarity with JavaScript would help but is not required.

What You Will Learn

  • Create mobile-optimized sites using simple HTML
  • Structure your sites so users can browse them on mobile devices
  • Find out how to work with multiple pages in the JQM framework and embed multiple pages in HTML files
  • Enhance simple pages using various toolbars
  • Include mobile-optimized forms for interactive sites
  • Convert desktop sites into mobile versions
  • Use HTML5's local storage feature in jQuery Mobile to include persistent client-side storage
  • Explore the rich sets of widgets and themes available and discover how to modify them for use in your jQuery Mobile site

In Detail

jQuery Mobile is a HTML5-based touch-optimized web framework. jQuery Mobile can be used to build responsive cross-platform websites and apps for a wide range of smartphones, tablets, and desktop devices. The jQuery Mobile framework can be integrated with other mobile app frameworks such as PhoneGap, IBM Worklight, and more.

Introduction to jQuery Mobile explains how to add the framework to your HTML pages to create rich, mobile-optimized web pages with minimal effort. You'll learn how to use jQuery Mobile's automatic enhancements and configure the framework for customized, powerful mobile-friendly websites. We then dig into forms, events, and styling. You'll see how jQuery Mobile automatically enhances content, and will find out how to use the JavaScript API to build complex sites. We'll introduce you to how jQuery Mobile can be themed as well looking into how JavaScript can be used for deep sets of customizations. The examples are ready to run and can be used to help kick-start your own site. Along the way, you will leverage all the concepts you learn to build three sample mobile applications.

Style and approach

Through a set of easy to follow instructions, we'll show you how to use jQuery Mobile's features one easy-to-use widget at a time. You'll see examples for each feature as well as screenshots to demonstrate what they should look like on a mobile device. You can then take these example files and modify them as you learn to experiment.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 221

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

jQuery Mobile Web Development Essentials Third Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What is jQuery Mobile?
What's the cost?
What do you need to know?
What about native apps?
Help!
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Preparing Your First jQuery Mobile Project
Important preliminary points
Building an HTML page
Getting jQuery Mobile
Implementing jQuery Mobile
Working with data attributes
Summary
2. Working with jQuery Mobile Pages
Important preliminary points
Adding multiple pages to one file
jQuery Mobile, links, and you
Working with multiple files
jQuery Mobile and URLs
Additional customization
Page titles
Prefetching content
Changing page transitions
Summary
3. Enhancing Pages with Headers, Footers, and Toolbars
Important preliminary points
Adding headers
Icon sneak peek
Working with back buttons
Working with footers
Creating fixed and fullscreen headers and footers
Fullscreen headers and footers
Working with navigation bars
Persisting navigation bar footers across multiple pages
Summary
4. Working with Lists
Creating lists
Working with list features
Creating inset lists
Creating list dividers
Autodividers
Creating lists with count bubbles
Using thumbnails and icons
Creating split button lists
Summary
5. Getting Practical – Building a Simple Hotel Mobile Website
Welcome to Hotel Camden
The home page
Finding the hotel
Listing the hotel rooms
Contacting the hotel
Summary
6. Working with Forms and jQuery Mobile
Before you begin
What jQuery Mobile does with forms
Working with radio buttons and checkboxes
Working with select menus
Custom select fields
Search, toggle, and slider fields
Search fields
Flip switch fields
Slider fields
Using native form controls
Working with mini fields
Summary
7. Creating Grids, Panels, and Other Widgets
Laying out content with grids
Making responsive grids
Working with collapsible content
Using popups
Responsive tables
Working with panels
Using filterable widgets
Working with tabs
Summary
8. Moving Further with the Notekeeper Mobile Application
What is a mobile application?
Designing your first mobile application
Listing out the requirements
Building your wireframes
Designing the Add Note wireframe
The Display Notes wireframe
The View Note/Delete button wireframe
Writing the HTML
Adding functionality with JavaScript
Storing Notekeeper data
Using localStorage
Effective use of boilerplates
Building the Add Note feature
Adding bindings
Collecting and storing data
Building the Display Notes feature
Dynamically adding notes to our listview
Viewing a note
Using the .on() method
Dynamically creating a new page
Deleting a note
Summary
9. jQuery Mobile Configuration, Utilities, and JavaScript Methods
Configuring jQuery Mobile
Using jQuery Mobile utilities
Page methods and utilities
Utilities related to path and URL
jQuery Mobile widget and form utilities
Summary
10. Working with Events
Working with physical events
Handling page events
What about $(document).ready?
Creating a real example
Summary
11. Enhancing jQuery Mobile
What's possible for designs?
The visual building blocks of jQuery Mobile
Border-radius
Applying drop shadows
Using text-shadow
Using box-shadow
CSS gradients
The basics of jQuery Mobile theming
Bars (.ui-bar-?)
Content blocks (.ui-body-?)
Buttons and listviews (.ui-btn-?)
Mixing and matching swatches
Site-wide active state
Default icons
Creating and using a custom theme
What's ThemeRoller?
Using ThemeRoller
Preview
Colors
Inspector
Tools
Creating a theme for Notekeeper
Exporting your theme
Updating the Notekeeper app
Adding our custom theme
Summary
12. Creating Native Applications
HTML as a native application
Working with PhoneGap
Adding the PhoneGap functionality
Summary
13. Becoming an Expert – Building an RSS Reader Application
RSS reader – the application
Creating the RSS reader application
The displayFeeds function
Storing our feeds
Adding an RSS feed
Viewing a feed
Creating the entry view
Going further
Summary
Index

jQuery Mobile Web Development Essentials Third Edition

jQuery Mobile Web Development Essentials Third Edition

Copyright © 2016 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: May 2012

Second edition: September 2013

Third edition: March 2016

Production reference: 1210316

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78355-505-5

www.packtpub.com

Credits

Authors

Raymond Camden

Andy Matthews

Reviewer

Eliecer Daza

Commissioning Editor

Usha Iyer

Acquisition Editor

Kevin Colaco

Content Development Editor

Rashmi Suvarna

Technical Editor

Rahul C. Shah

Copy Editor

Akshata Lobo

Project Coordinator

Judie Jose

Proofreader

Safis Editing

Indexer

Priya Sane

Graphics

Kirk D'Penha

Production Coordinator

Shantanu N. Zagade

Cover Work

Shantanu N. Zagade

About the Authors

Raymond Camden is a developer advocate for IBM. His work focuses on the StrongLoop platform, Bluemix, hybrid mobile development, Node.js, HTML5, and web standards in general. He's a published author and presents at conferences and user groups on a variety of topics. Raymond can be reached at his blog (http://www.raymondcamden.com), @raymondcamden on Twitter, or via e-mail at <[email protected]>.

Raymond Camden is the author of many development books, including Apache Cordova in Action, Manning Publications and Client-Side Data Storage, O'Reilly Media, Inc.

I'd like to thank everyone on the jQuery and jQuery Mobile teams for making tools that have changed my life. Without your hard work and dedication, the Web would be less awesome.

Andy Matthews has been working as a software engineer for nearly 20 years with experience in a wide range of industries and a skillset that includes UI/UX, graphic design, and programming. He is the coauthor of the books Creating Mobile Apps with jQuery Mobile and jQuery Mobile Web Development Essentials by Packt Publishing. He has written for online publications, such as Adobe, NetTuts, and .NET Magazine. He has spoken at conferences all over the country, and has developed a number of projects for the open source community.

Thanks to Packt for publishing this book. Thanks to the jQuery Mobile team for creating such a great and easy to use open source project.

About the Reviewer

Eliecer Daza has been a web developer since 2005. He has ample experience in Java, Python, Perl, jQuery, and jQuery Mobile being a Java developer for more than 8 years. He has developed software for information management and customer relationship management (CMR) for health promoting enterprises (EPS), public transportation, and education companies in the private and public sectors. He has been working as a Python developer for more than 4 years, working with responsive websites and new languages and technologies.

His main areas of interest lie in the development of Linux, Python, Android, and Google Services. He has a huge interest in nurturing blog spaces about Linux administration and programming.

Look for me on my page at http://www.eliecerdaza.com.

My heartfelt appreciation to God, my beloved mother and friend, my family, and my girlfriend July.

www.PacktPub.com

eBooks, discount offers, and more

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser
 

As always, I dedicate this book to my wife, Jeanne. You are the best thing in my life. I love you completely.

  --Raymond Camden
 

Thanks to my wife and children who tolerate my time spent learning and writing.

  --Andy Matthews

Preface

What is jQuery Mobile?

On August 11, 2010, nearly six years ago, John Resig (creator of jQuery) announced the jQuery Mobile project. While it focused on the UI framework, it was also a recognition of jQuery itself as a tool for mobile websites and that work would be done to the core framework itself to make it work better on devices. Release after release, the jQuery Mobile project evolved into a powerful framework, encompassing more platforms, more features, and better performance with every update.

But what do we mean when we say a UI framework? What does it mean for developers and designers? jQuery Mobile provides a way to turn regular HTML (and CSS) into mobile-friendly websites. As you will see soon in the first chapter, you can take a regular HTML page, add the required bits for jQuery Mobile (essentially, lines of HTML), and your page is transformed into a mobile-friendly version instantly.

Unlike other frameworks, jQuery Mobile is focused on HTML. In fact, for a framework tied to jQuery, you can do a heck of a lot of work without writing one line of JavaScript. It's a powerful, practical way of creating mobile websites that any existing HTML developer can pick up and adapt within a few hours. Compare this to other frameworks, such as Sencha Touch. Sencha Touch is also a powerful framework, but its approach is radically different, using JavaScript to help define and layout pages. jQuery Mobile is much friendlier to people who are more familiar with HTML as opposed to JavaScript. jQuery Mobile is touch-friendly, which will make sense to anyone who has used a smartphone and struggled to click the exact spot on a website with tiny text and hard-to-spot links. It will make sense to anyone who has accidentally clicked on a Reset button instead of Submit. jQuery Mobile will enhance your content to help solve these issues. Regular buttons become large, fat, and easy-to-hit buttons. Links can be turned into list-based navigation systems. Content can be split into virtual pages with smooth transitions. You will be surprised just how jQuery Mobile works without writing much code at all.

What's the cost?

Ah, the million dollar question. Luckily, this one is easy to answer: nothing. jQuery Mobile, like jQuery itself, is completely free to use for any purpose. Not only that, it's open source. Don't like how something works? You can change it. Want something not supported by the framework? You can add it. To be fair, digging deep into the code base is probably something most folks will not be comfortable doing. However, the fact that you can if you need to, and the fact that other people can, will lead to a product that will be open to development by the community at large.

What do you need to know?

Finally, along with not paying a dime to get, and work with, jQuery Mobile, the best thing is that you probably already have all the skills necessary to work with the framework. As you will see in the upcoming chapters, jQuery Mobile is an HTML-based framework. If you know HTML, even just simple HTML, you can use the jQuery Mobile framework. Knowledge of CSS and JavaScript is a plus, but not entirely required (while jQuery Mobile uses a lot of CSS and JavaScript behind the scenes, you don't actually have to write any of this yourself!).

What about native apps?

jQuery Mobile does not create native applications. You'll see later in the book how you can combine jQuery Mobile with hybrid mobile technologies, such as Apache Cordova, to create native apps; but in general, jQuery Mobile is for building websites. The question on whether to develop a website or a mobile app is not something this book can answer. You need to look at your business needs and see what will satisfy them. Because we are not building mobile apps themselves, you do not have to worry about setting up any accounts with Google or Apple, or paying any fees for the marketplace. Any user with a mobile device that includes a browser will be able to view your mobile-optimized websites.

Again, if you want to develop true mobile apps with jQuery Mobile, it's definitely an option.

Help!

While we'd like to think that this book will cover every single possible topic you would need for all your jQuery Mobile needs, most likely there will be things we can't cover. If you need help, there are a couple of places you can try.

First, the jQuery Mobile docs (http://jquerymobile.com/demos/) cover syntax, features, and development in general, much like this book. While the material may cover some of the same ground, if you find something confusing here, try the official docs. Sometimes, a second explanation can really help.

Second, the jQuery Mobile forum (http://forum.jquery.com/jquery-mobile) is an open-ended discussion list for jQuery Mobile topics. This is the perfect place to ask questions. Also, it's a good place to learn about problems other people are having. You may even be able to help them. One of the best ways to learn a new topic is by helping others.

What this book covers

Chapter 1, Preparing Your First jQuery Mobile Project, works you through your first jQuery Mobile project. It details what must be added to your project's directory and source code.

Chapter 2, Working with jQuery Mobile Pages, continues the work in the previous chapter and introduces the concept of jQuery Mobile pages.

Chapter 3, Enhancing Pages with Headers, Footers, and Toolbars, explains how to enhance your pages with nicely formatted headers and footers.

Chapter 4, Working with Lists, describes how to create jQuery Mobile list views. These are mobile-optimized lists, which are especially great for navigation.

Chapter 5, Getting Practical – Building a Simple Hotel Mobile Website, walks you through creating your first real (albeit simple) jQuery Mobile application.

Chapter 6, Working with Forms and jQuery Mobile, explains the process of using jQuery Mobile-optimized forms. Layout and special form features are covered in detail.

Chapter 7, Creating Grids, Panels, and Other Widgets, walks you through special jQuery Mobile UI items for creating grid-based layouts and other common UI elements.

Chapter 8, Moving Further with the Notekeeper Mobile Application, walks you through the process of creating another website, an HTML5-enhanced note-taking application.

Chapter 9, jQuery Mobile Configuration, Utilities, and JavaScript Methods, describes the various JavaScript-based utilities your code may have need of.

Chapter 10, Working with Events, details the events thrown by various jQuery Mobile-related features, like pages loading and unloading.

Chapter 11, Enhancing jQuery Mobile, demonstrates how to change the default appearance of your jQuery Mobile websites by selecting and creating unique themes.

Chapter 12, Creating Native Applications, takes what you've learned previously and shows how to use the open source PhoneGap project to create real native applications.

Chapter 13, Becoming an Expert – Building an RSS Reader Application, expands upon the previous chapter by creating an application that lets you add and read RSS feeds on mobile devices.

What you need for this book

Nothing! Technically, you need a computer and a browser as well, but jQuery Mobile is built with HTML, CSS, and JavaScript. No Integrated Development Environment (IDE) or special tool will be required to work with the framework. If you've got any editor on your system (and all operating systems include a free editor of some sort), you can develop with jQuery Mobile.

Who this book is for

This book is for anyone looking to embrace mobile development and expand their skill set beyond the desktop.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "You can find all the source code for this chapter in the c1 folder of the ZIP file you downloaded from GitHub."

A block of code is set as follows:

Listing 1-1: test1.html <html> <head> <title>First Mobile Example</title> </head> <body> <h1>Welcome</h1> <p> Welcome to our first mobile web site. It's going to be the best site you've ever seen. Once we get some content. And a business plan. But the hard part is done! </p> <p> <i>Copyright Megacorp &copy; 2015</i> </p> </body> </html>

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "There are a few options here, but you want the ZIP file option."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

This book contains many code samples. You are not expected to type them in. You should not type them all in. Rather, you should download them from the public GitHub repository setup for the book: https://github.com/cfjedimaster/jQuery-Mobile-Book. The GitHub repository will be updated as typos and other mistakes are found in the book. Therefore, it is possible the code may not match exactly the text in the book.

If you are not familiar with GitHub, then simply click on the Downloads tab and then either Download as zip or Download as tar.gz to quickly get an archived collection of all the files.

You should extract these les onto a local web server. If you do not have one installed, we recommend installing Apache (http://httpd.apache.org/). Apache works on all platforms, is free, and is typically easy to install. Once extracted, you can edit these files, view them in your browser, or copy them as a starting point for your own projects.

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/jQueryMobileWebDevelopmentEssentialsThirdEdition_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. Preparing Your First jQuery Mobile Project

You know what jQuery Mobile is, the history of it, as well as its features and goals. Now, we're actually going to build our first jQuery Mobile website (well, web page) and see how easy it is to use.

In this chapter, we will be covering the following topics:

Creating a simple HTML pageAdding jQuery Mobile to the pageUpdating the HTML to make use of the data attributes jQuery Mobile recognizes

Important preliminary points

You can find all the source code for this chapter in the c1 folder of the ZIP file you downloaded from GitHub. If you wish to type everything out by hand, we recommend you to use similar filenames.

Building an HTML page

Let's begin with a simple web page that is not mobile-optimized. To be clear, we aren't saying it can't be viewed on a mobile device. Not at all! But it may not be usable on a mobile device. It may be hard to read (the text may be too small). It may be too wide. It may use forms that don't work well on a touchscreen. We don't know the kinds of problems we will face until we start testing (and we've all tested our websites on mobile devices to see how well they work, right?).

Let's have a look at Listing 1-1:

Listing 1-1: test1.html <html> <head> <title>First Mobile Example</title> </head> <body> <h1>Welcome</h1> <p> Welcome to our first mobile web site. It's going to be the best site you've ever seen. Once we get some content. And a business plan. But the hard part is done! </p> <p> <i>Copyright Megacorp &copy; 2015</i> </p> </body> </html>

As we said, it isn't too complex, right? Let's take a quick look at this in the browser:

Not so bad, right? But let's take a look at the same page in a mobile simulator:

Wow, the text is in a barely readable font size. You've probably seen web pages like this before on your mobile device. You can, of course, typically use pinch and zoom or double-click actions to increase the size of the text. But it would be preferable to have the page render immediately in a mobile-friendly view. This is where jQuery Mobile enters.

Getting jQuery Mobile

In the preface, we talked about how jQuery Mobile is just a set of files. This wasn't said to minimize the amount of work done to create those files or to play down how powerful they are, but to emphasize that using jQuery Mobile means that you don't have to install any special tools or server. You can download the files and simply include them in your page. And if that's too much work, you have an even simpler solution. jQuery Mobile's files are hosted on a Content Delivery Network (CDN). This is a resource hosted by them and it is guaranteed (as much as anything like this can be) to be online and available. Multiple websites are already using these CDN hosted files. This means that when users hit your website, they may already have the resources in their cache. For this book, we will be making use of the CDN hosted files. Just for this first example, we'll download the ZIP file and extract the files we need.

Tip

I recommend doing this anyway for the times when you're on an airplane and wanting to whip up a quick mobile website.

To grab the files, visit http://jquerymobile.com/download. There are a few options here, but you want the ZIP file option. Go ahead and download the ZIP file and extract it (the ZIP file you downloaded earlier from GitHub has a copy already). The following screenshot demonstrates what you should see after extracting the content from the ZIP file:

Note

An important note: at the time this book was written, jQuery Mobile was at version 1.4.5. Obviously, by the time you read this book, a later version may be released. The filenames you see listed in the previous screenshot are version-specific, so keep in mind that they may look a bit different for you.

The ZIP file contains demos