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 4 USING URL ROUTING}, item);item.quantity.subscribe(function() {updateState();});}, cheeseModel.products, "items");cheeseModel.total = ko.computed(function() {var total = 0;map<strong>Pro</strong>ducts(function(elem) {total += elem.subtotal();}, cheeseModel.products, "items");return total;});$('div.cheesegroup').not("#basket").css("width", "50%");$('div.navSelectors').buttonset();ko.applyBindings(cheeseModel);$(window).bind("popstate", function(event) {var state = history.state ? history.state : event.originalEvent.state;restoreState(state);crossroads.parse(location.hash.slice(1));});crossroads.addRoute("category/:newCat:", function(newCat) {cheeseModel.selectedCategory(newCat ?newCat : cheeseModel.products[0].category);updateState();});crossroads.addRoute("remove/{id}", function(id) {map<strong>Pro</strong>ducts(function(item) {if (item.id == id) {item.quantity(0);}}, cheeseModel.products, "items");});$('#basketTable a').button({icons: {primary: "ui-icon-closethick"},text: false});function updateState() {var state = {category: cheeseModel.selectedCategory()};map<strong>Pro</strong>ducts(function(item) {if (item.quantity() > 0) {state[item.id] = item.quantity();}}, cheeseModel.products, "items");history.replaceState(state, "",102www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!