// Avoid the context menu popup
window.addEventListener("contextmenu", function(e) {
e.preventDefault();
}, false);
// Listen for mousedown
window.addEventListener("mousedown", function(e) {
handle(e, true);
}, false);
// Listen for mouseup
window.addEventListener("mouseup", function(e) {
handle(e, false);
}, false);
// Our main handler
function handle(e, down) {
var id;
switch (e.button) {
case 0: // Primary button ("left")
id = "primary-status";
break;
case 2: // Secondary button ("right")
id = "secondary-status";
break;
}
if (id) {
document.getElementById(id).innerHTML = down ? "Down" : "Up";
}
}