In reply to a post on gist.github.com

My take on generic prev/next controls on keyup, using only bean for events, based on previous work by Aaron Parecki and Tantek Çelik:


// Generic prev/next navigation on arrow key press
bean.on(document.body, 'keyup', function (e) {
  var prevEl, nextEl;
  
  if (document.activeElement !== document.body) return;
  if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return;
  
  if (e.keyCode === 37) {
    prevEl = document.querySelector('[rel~=previous]');
    if (prevEl) bean.fire(prevEl, 'click');
  } else if (e.keyCode === 39) {
    nextEl = document.querySelector('[rel~=next]');
    if (nextEl) bean.fire(nextEl, 'click');
  }
}); 
updated: