Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable mouse left key default #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions spotlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ var RevealSpotlight = window.RevealSpotlight || (function () {
var presentingCursor;
var spotlightCursor;
var initialPresentationMode;
var disablingUserSelect;
var fadeInAndOut;
var style;
var lockPointerInsideCanvas;
var getMousePos;
var allowedMouseButtons;

var drawBoard;
var isSpotlightOn = true;
Expand Down Expand Up @@ -86,23 +86,23 @@ var RevealSpotlight = window.RevealSpotlight || (function () {
spotlightOnKeyPressAndHold = false;
}

if (config.hasOwnProperty("disablingUserSelect")) {
disablingUserSelect = config.disablingUserSelect;
} else {
disablingUserSelect = true;
}

if (config.hasOwnProperty("fadeInAndOut")) {
fadeInAndOut = config.fadeInAndOut;
} else {
fadeInAndOut = false;
}

if (config.hasOwnProperty("allowedMouseButtons")) {
allowedMouseButtons = config.allowedMouseButtons;
} else {
allowedMouseButtons = [0, 1]; // left key and middle key
}
}

function setupCanvas() {
var container = document.createElement('div');
container.id = "spotlight";
container.style.cssText = "position:absolute;top:0;left:0;bottom:0;right:0;z-index:99;";
container.style.cssText = "position:absolute;top:0;left:0;bottom:0;right:0;z-index:99;pointer-events: none;";
if (fadeInAndOut) {
container.style.cssText += "transition: " + fadeInAndOut + "ms opacity;";
}
Expand All @@ -116,7 +116,6 @@ var RevealSpotlight = window.RevealSpotlight || (function () {
container.appendChild(canvas);
document.body.appendChild(container);
container.style.opacity = 0;
container.style['pointer-events'] = 'none';
return {
container,
canvas,
Expand All @@ -141,16 +140,19 @@ var RevealSpotlight = window.RevealSpotlight || (function () {
}, false);
}

function isAllowedButton(button) {
return ~allowedMouseButtons.indexOf(button);
}
function addMouseToggleSpotlightListener() {

window.addEventListener("mousedown", function (e) {
if (!isCursorOn) {
if (!isCursorOn && isAllowedButton(e.button)) {
setSpotlight(true, e);
}
}, false);

window.addEventListener("mouseup", function (e) {
if (!isCursorOn) {
if (!isCursorOn && isAllowedButton(e.button)) {
setSpotlight(false, e);
}
}, false);
Expand Down Expand Up @@ -183,14 +185,12 @@ var RevealSpotlight = window.RevealSpotlight || (function () {
drawBoard.canvas.requestPointerLock();
}
container.style.opacity = 1;
container.style['pointer-events'] = null;
document.body.style.cursor = spotlightCursor;
if (mouseEvt) {
showSpotlight(mouseEvt);
}
} else {
container.style.opacity = 0;
container.style['pointer-events'] = 'none';
document.body.style.cursor = presentingCursor;
}
}
Expand All @@ -203,19 +203,11 @@ var RevealSpotlight = window.RevealSpotlight || (function () {
isCursorOn = isOn;
if (isOn) {
setSpotlight(false);
if (disablingUserSelect) {
document.body.style.userSelect = null;
document.body.style.MozUserSelect = null;
}
document.body.style.cursor = null;
if(lockPointerInsideCanvas && document.pointerLockElement === drawBoard.canvas){
document.exitPointerLock();
}
} else {
if (disablingUserSelect) {
document.body.style.userSelect = "none";
document.body.style.MozUserSelect = "none";
}
if (lockPointerInsideCanvas && document.pointerLockElement != drawBoard.canvas) {
drawBoard.canvas.requestPointerLock();
}
Expand Down