Forward Navigation Via Toolbar Buttons

Forward Navigation Via Toolbar Buttons

In this example, we will learn to use the toolbar buttons for forward navigation. To understand how it is done, let’s create a small application with six panels: Home, Categories, Subcategories, Select Books, Items in Cart and Checking Out. Let’s assume that the ids assigned to the six panels are home, bookscategories, subcategories, booksdisplay, showcart, and checkout respectively. The purpose of each panels is as follows :

1.     Home—The first panel (idhome) that appears on execution of application (see Figure 1.1 (a)).

2.     Categories—This panel (id bookscategories) displays book categories when the Books list item is selected from the Home panel (see Figure 1.1(b))

3.     Subcategories—This panel (id subcategories) displays book subcategories when a book category is selected from the Categories panel (see Figure 1.1(c)).

4.     Select Books—This panel (id booksdisplay) displays the books belonging to the selected category and subcategory.  The panel appears when a subcategory fromSubcategories panel is selected. From this panel, the user can select books to be added to the cart (see Figure 1.2 (a)).

Note: The list items that appear in Categories, Subcategories, and the Select Books panels are hard-coded and are just dummies for the time being.

5.     Items in Cart—This panel (id showcart) displays the books in the cart. For the time being, only dummy books selected will be in the cart. This panel has a Checkout button, which jumps to the Checking Out panel (see Figure 1.2 (b)).

Note: For now, cart contents are hard-coded.

6.     Checking Out—This is the last panel of the checkout process only has a Back button for returning to the previous screen (see Figure 1.2 (c)).

Figure 1.1. (a) Home panel with Show Cart button (b)  Categories panel showing book categories (c) Subcategories panel showing book subcategories

Figure 1.2. (a) Select Books panel showing books in the selected category and subcategory (b)  Items in the Cart panel, and the Back and Checkout buttons   (c) Checking Out panel

We can create the Back buttons in all the screen panels by adding hyperlinks to the toolbars with the class name back. These href hyperlinks all point to #, which simply jumps to the first previous page in the in page history.

The only problem we face is making the two Show Cart and Checkout buttons work. But before we can deal with actual functionality, we first have to learn how to put buttons on the right side of the toolbar.

The back and cancel buttons appear on the left side of the toolbar. Only buttons with the button class name appear on the right side. To make the button jump to a panel with a specific id, we need to set the button href to point to it. You might think, at this point, that the code for a right-side button that navigates to the showcart id would look like this:

<a href=”#showcart”>Show Cart</a>

Although the code appears to be correct, it won’t actually do what we want it to, because no animation has been specified in the hyperlink. The default slide animation won’t work with this code fragment. It’s a simple matter, though, to specify any of the other animation effects that will work: slideup, dissolve, fade, flip, pop, swap, and cube.

Functional code for the showcart id, using the slideup animation is:

<a href=”#showcart”>Show Cart</a>

Similarly, the following fragment creates a Checkout button on the right side of the toolbar that jumps to the checkout panel with a flip animation:

<a href=”#checkout”>Checkout</a>

The complete code is shown in Listing 1.1.

Listing 1.1. Forward and Reverse Navigation

<html>

<head>

<title>Book Store</title>

<link rel=”stylesheet” media=”screen” href=”jqtouch/jqtouch.css”>

<link rel=”stylesheet” media=”screen”

href=”themes/apple/theme.css”>

<script src=”jqtouch/jquery.1.3.2.min.js”></script>

<script src=”jqtouch/jqtouch.js”></script>

<script>

var jQT = new $.jQTouch();

</script>

</head>

<body>

<div>

<div>

<h1>Home</h1>

<a href=”#showcart”>Show Cart</a>

</div>

<ul>

<li><a href=”#bookscategories”>Books</a></li>

</ul>

</div>

<div>

<div>

<a  href=”#”>Home</a>

<h1>Categories</h1>

</div>

<ul>

<li><a  href=”#subcategories”>Literature & Fiction</a></li>

<li><a  href=”#subcategories”>Home & Garden</a></li>

<li><a  href=”#subcategories”>Computers & Internet</a></li>

<li><a  href=”#subcategories”>Cooking, Food & Wine</a></li>

</ul>

</div>

<div>

<div>

<a  href=”#”>Back</a>

<h1>Subcategories</h1>

</div>

<ul>

<li><a href=”#booksdisplay”>Subcategory1</a></li>

<li><a href=”#booksdisplay”>Subcategory2</a></li>

<li><a href=”#booksdisplay”>Subcategory3</a></li>

</ul>

</div>

<div>

<div>

<a  href=”#” >Back</a>

<h1>Select Books</h1>

</div>

<ul>

<li><a href=”#showcart”>Book 1</a></li>

<li><a href=”#showcart”>Book 2</a></li>

<li><a href=”#showcart”>Book 3</a></li>

<li><a href=”#showcart”>Book 3</a></li>

</ul>

</div>

<div>

<div>

<a  class=”back” href=”#” >Back</a>

<a href=”#checkout”>Checkout</a>

<h1>Items in Cart</h1>

</div>

<p> Book1 by author xyz </p>

<p> Book2 by author pqr </p>

</div>

<div>

<div>

<a  class=”back” href=”#”>Back</a>

<h1>Checking Out</h1>

</div>

<p> You have not Signed Up yet </p>

</div>

</body>

</html>

Note: Buttons of class back or cancel may only appear on the left side of a toolbatr. Only buttons of class button may appear on the right.

For more information, refer to my book: “Beginning Web Development for Smartphones: Developing Web Applications with PHP, MySQL and jQTouch” available at http://www.amazon.com/Beginning-Web-Development-Smartphones-ebook/dp/B0042X9CHI/ref=sr_1_2?ie=UTF8&m=AH9CGK6QR37LL&s=digital-text&qid=1284780488&sr=8-2

Leave a Comment