12.07.2015 Views

Pro JavaScript for Web Apps pdf - EBook Free Download

Pro JavaScript for Web Apps pdf - EBook Free Download

Pro JavaScript for Web Apps pdf - EBook Free Download

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 8 CREATING MOBILE WEB APPSListing 8-11. The getIndexOfCategory Functionfunction getIndexOfCategory(category) {var result = -1;<strong>for</strong> (var i = 0; i < cheeseModel.products.length; i++) {if (cheeseModel.products[i].category == category ||cheeseModel.products[i].shortName == category) {result = i;break;}}return result;}Listing 8-12 shows the changes in mobile.html to make use of this function.Listing 8-12. Managing Page Transition Animation Directionvar cheeseModel = {};detectDeviceFeatures(function(deviceConfig) {cheeseModel.device = deviceConfig;checkForVersionPreference();$.getJSON("products.json", function(data) {cheeseModel.products = data;enhanceViewModel();$(document).ready(function() {ko.applyBindings(cheeseModel);$('*.deferred').each(function(index, elem) {ko.applyBindings(cheeseModel, elem);});$('button.left, button.right').live("click", function(e) {e.preventDefault();advanceCategory(e, $(e.target).hasClass("left") ? "left" : "right");$.mobile.changePage($('div[data-category="'+ cheeseModel.selectedCategory() + '"]'),{reverse: $(e.target).hasClass("left")});})$('a[data-role=button]').click(function(e) {e.preventDefault();var cIndex = getIndexOfCategory(cheeseModel.selectedCategory());var newIndex = getIndexOfCategory(this.hash.slice(1));$.mobile.changePage(this.hash, {reverse: cIndex > newIndex});});$.mobile.initializePage();226www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!