code: function clamp(pos) {
          pos.top = Math.max(Math.min(pos.top, bounds.bottom - containerNode.offsetHeight), bounds.top);
          pos.left = Math.max(Math.min(pos.left, bounds.right - containerNode.offsetWidth), bounds.left);
        }
docs: Clamps the repositioning of the menu within the confines of
  bounding element (often the screen/body)