Search

12/10/2012

GENERALIZED INPUT ON THE CROSS-DEVICE WEB

GENERALIZED INPUT ON THE CROSS-DEVICE WEB

$(window).mousedown(function(e) { down(e.pageY); });
$(window).mousemove(function(e) { move(e.pageY); });
$(window).mouseup(function() { up(); });

// Setup touch event handlers.
$(window).bind('touchstart', function(e) {
  e.preventDefault();
  down(e.originalEvent.touches[0].pageY);
});
$(window).bind('touchmove', function(e) {
  e.preventDefault();
  move(e.originalEvent.touches[0].pageY);
});
$(window).bind('touchend', function(e) {
  e.preventDefault();
  up();
});
Microsoft is taking a very smart approach with IE10 to address this issue by introducing pointer events. The idea is to consolidate all input that deals with one or more points on the screen into a single unified model. Unfortunately, it's not being proposed as a standardized spec. Also, because it's not universally available, it will be yet another thing developers need to support (if they want to support Windows 8/Metro apps). So now our sample above gets even more boilerplate, with at least three more calls like the following:
$(window).bind('MSPointerDown', function(e) {
  // Extract x, y, and call shared handler.
});
$(window).bind('MSPointerMove', function(e) {
  // Extract x, y, and call shared handler.
});
$(window).bind('MSPointerUp', function(e) {
  // Extract x, y, and call shared handler.
});

沒有留言: