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 7 CREATING RESPONSIVE WEB APPS};Modernizr.load([{test: window.matchMedia,nope: 'matchMedia.js',complete: function() {var screenQuery = window.matchMedia('screen AND (max-width:500px)');deviceConfig.smallScreen = ko.observable(screenQuery.matches);if (screenQuery.addListener) {screenQuery.addListener(function(mq) {deviceConfig.smallScreen(mq.matches);});}deviceConfig.largeScreen = ko.computed(function() {return !deviceConfig.smallScreen();});}}, {test: Modernizr.touch,yep: 'jquery.touchSwipe-1.2.5.js',callback: function() {$('html').swipe({swipeLeft: advanceCategory,swipeRight: advanceCategory});}},{complete: function() {callback(deviceConfig);}}]);When you pass an array of objects to the Modernizr.load method, each test is per<strong>for</strong>med in turn. Ihave added a test that uses the Modernizr.touch check and that loads the touchSwipe library if touchsupport is present.• Tip Make sure you included the touch tests if you downloaded your own version of Modernizr. The version Iincluded in the source code <strong>for</strong> this chapter contains all of the available tests.Notice that I used the callback property to set up support <strong>for</strong> handling swipes. Functions set usingthe callback property are executed when the specified resources are loaded, whereas functions specifiedusing complete are executed at the end of the test, irrespective of the test result. I want to handle swipeevents only if touchSwipe has been loaded (which itself indicates that touch support is present), so Ihave used callback to give Modernizr my function.The touchSwipe library is applied using the swipe method. In this example, I have selected the htmlelement as the target <strong>for</strong> detecting swipe gestures. Some browsers limit the body element size so that itdoesn’t fill the entire window when the content is smaller than the available space. This isn’t usually a190www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!