You can do this easily by simply canceling the click event in the capture phase of the body:
document.body.addEventListener("click", allowClick, true);
function allowClick(event) {
if (panMode) {
event.stopPropagation();
}
}
See this fiddle for an example of ignoring a click based on a global flag. (Tested in the latest Firefox, Chrome and IEs.)
See javascript.info for a clear description of the capture and bubble phases of events in Javascript.