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 ROUTINGvar viewModel = {items: ko.observableArray(["Apple", "Orange", "Banana"]),selectedItem: ko.observable("Apple")};$(document).ready(function() {ko.applyBindings(viewModel);$('div.catSelectors').buttonset();crossroads.addRoute("select/:item:", function(item) {if (!item) {item = "Apple";} else if (viewModel.items.indexOf(item)== -1) {viewModel.items.push(item);}if (viewModel.selectedItem() != item) {viewModel.selectedItem(item);}$('div.catSelectors').buttonset();if (Modernizr.history) {history.replaceState(viewModel.items(), document.title, location);}});crossroads.addRoute("", function() {viewModel.selectedItem("Apple");})if (Modernizr.history) {$(window).bind("popstate", function(event) {var state = history.state ? history.state: event.originalEvent.state;if (state) {viewModel.items.removeAll();$.each(state, function(index, item) {viewModel.items.push(item);});}96www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!