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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 4 USING URL ROUTINGcrossroads.parse(location.hash.slice(1));});} else {hasher.initialized.add(crossroads.parse, crossroads);hasher.changed.add(crossroads.parse, crossroads);hasher.init();}});The selected item is: Storing the Application StateThe first set of changes in the listing stores the application state when the main application routematches a URL. By responding to the URL change, I am able to preserve the state whenever the userclicks one of the navigation elements or enters a URL directly. Here is the code that stores the state:......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);}});...97www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!