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 5 CREATING OFFLINE WEB APPSAccepting Changes to the ManifestThe most significant change in behavior <strong>for</strong> a cached application is that refreshing the web page doesn’tcause the application content to be cached. The idea is that updates to a cached application need to bemanaged to avoid inconsistent changes. Uncommenting the blackwave.png line in the manifest andreloading, <strong>for</strong> example, wouldn’t change the background to black.Listing 5-4 shows the minimum amount of code that is needed in a web app to support updates. I’llshow you how to use more of the Application Cache API later in the chapter, but we need these changesbe<strong>for</strong>e we can go any further.Listing 5-4. Accepting Changes in the Manifest...var cheeseModel = {products: [{category: "British Cheese", items : [{id: "stilton", name: "Stilton", price: 9},{id: "stinkingbishop", name: "Stinking Bishop", price: 17},{id: "cheddar", name: "Cheddar", price: 17}]},{category: "French Cheese", items: [{id: "camembert", name: "Camembert", price: 18},{id: "tomme", name: "Tomme de Savoie", price: 19},{id: "morbier", name: "Morbier", price: 9}]},{category: "Italian Cheese", items: [{id: "gorgonzola", name: "Gorgonzola", price: 8},{id: "fontina", name: "Fontina", price: 11},{id: "parmesan", name: "Parmesan", price: 16}]}]};$(document).ready(function() {$('#buttonDiv input:submit').button();$('div.navSelectors').buttonset();});enhanceViewModel();ko.applyBindings(cheeseModel);hasher.initialized.add(crossroads.parse, crossroads);hasher.changed.add(crossroads.parse, crossroads);hasher.init();crossroads.addRoute("category/:cat:", function(cat) {cheeseModel.selectedCategory(cat || cheeseModel.products[0].category);});$(window.applicationCache).bind("updateready", function() {window.applicationCache.swapCache();});115www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!