|
76 | 76 | // the URL passed in. Generate markup for the items in the |
77 | 77 | // category, inject it into an embedded page, and then make |
78 | 78 | // that page the current active page. |
79 | | -function showCategory( urlObj, options ) |
| 79 | +function showCategory( url, options ) |
80 | 80 | { |
81 | | - var categoryName = urlObj.hash.replace( /.*category=/, "" ), |
| 81 | + var categoryName = url.split( "." )[ 0 ], |
82 | 82 |
|
83 | 83 | // Get the object that represents the category we |
84 | 84 | // are interested in. Note, that at this point we could |
|
88 | 88 |
|
89 | 89 | // The pages we use to display our content are already in |
90 | 90 | // the DOM. The id of the page we are going to write our |
91 | | - // content into is specified in the hash before the '?'. |
92 | | - pageSelector = urlObj.hash.replace( /\?.*$/, "" ); |
| 91 | + // content into is category-items |
| 92 | + pageSelector = "#category-items"; |
93 | 93 |
|
94 | 94 | if ( category ) { |
95 | 95 | // Get the page we are going to dump our content into. |
|
139 | 139 | // to be the url that shows up in the browser's location field, |
140 | 140 | // so set the dataUrl option to the URL for the category |
141 | 141 | // we just loaded. |
142 | | - options.dataUrl = urlObj.href; |
| 142 | + options.dataUrl = url; |
143 | 143 |
|
144 | 144 | // Now call changePage() and tell it to switch to |
145 | 145 | // the page we just modified. |
|
156 | 156 | // We are being asked to load a page by URL, but we only |
157 | 157 | // want to handle URLs that request the data for a specific |
158 | 158 | // category. |
159 | | - var u = $.mobile.path.parseUrl( data.toPage ), |
160 | | - re = /^#category-item/; |
161 | | - if ( u.hash.search(re) !== -1 ) { |
| 159 | + var u = data.toPage; |
| 160 | + |
| 161 | + if ( u.match( /\/([^\/\.]+\.html)/ ) ) { |
| 162 | + |
162 | 163 | // We're being asked to display the items for a specific category. |
163 | 164 | // Call our internal method that builds the content for the category |
164 | 165 | // on the fly based on our in-memory category data structure. |
165 | | - showCategory( u, data.options ); |
166 | | - |
167 | | - // Make sure to tell changepage we've handled this call so it doesn't |
168 | | - // have to do anything. |
| 166 | + showCategory( RegExp.$1, data.options ); |
| 167 | + |
169 | 168 | e.preventDefault(); |
170 | 169 | } |
171 | 170 | } |
|
175 | 174 | </head> |
176 | 175 |
|
177 | 176 | <body> |
178 | | -<div id="home" data-role="page"> |
| 177 | +<div data-role="page"> |
179 | 178 | <div data-role="header"><h1>Categories</h1></div> |
180 | 179 | <div data-role="content"> |
181 | 180 | <h2>Select a Category Below:</h2> |
182 | 181 | <ul data-role="listview" data-inset="true"> |
183 | | - <li><a href="#category-items?category=animals">Animals</a></li> |
184 | | - <li><a href="#category-items?category=colors">Colors</a></li> |
185 | | - <li><a href="#category-items?category=vehicles">Vehicles</a></li> |
| 182 | + <li><a href="animals.html">Animals</a></li> |
| 183 | + <li><a href="colors.html">Colors</a></li> |
| 184 | + <li><a href="vehicles.html">Vehicles</a></li> |
186 | 185 | </ul> |
187 | 186 | </div> |
188 | 187 | </div> |
|
0 commit comments