Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Also block mouseup and mousedown events when not activated
Fixes: #13
  • Loading branch information
mauricelam committed Nov 20, 2016
1 parent 4fa7cfa commit 693d4d6
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions ScrollableMap.js
Expand Up @@ -52,26 +52,35 @@ var ScrollableMap = function (div, type, id) {
Pref.onPreferenceChanged('frameRequireFocus', function(pair){
(pair.value) ? hideControls() : showControls();
});
div.addEventListener('click', didClickMap, true);
div.addEventListener('click', handleClick, true);
div.addEventListener('mousedown', blockEventIfNotActivated, true);
div.addEventListener('mouseup', blockEventIfNotActivated, true)
$(div).mouseleave(hideControls);
if (mapRequiresActivation()){
setTimeout(hideControls, 500);
}
}

function didClickMap (event) {
function blockEventIfNotActivated(event) {
if (pref('frameRequireFocus') && mapRequiresActivation() && !mapClicked) {
event.stopPropagation();
event.preventDefault();
}
}

function handleClick(event) {
showControls(event);
lastTarget = null;
}

function showControls(event){
if (!mapClicked) {
function showControls(event) {
if (pref('frameRequireFocus') && mapRequiresActivation() && !mapClicked) {
if (event) event.stopPropagation();
mapClicked = true;
$(div).removeClass('scrollMapsHideControls');
}
}
function hideControls(){
function hideControls() {
if (mapRequiresActivation() && pref('enabled') && pref('frameRequireFocus')) {
mapClicked = false;
$(div).addClass('scrollMapsHideControls');
Expand Down

0 comments on commit 693d4d6

Please sign in to comment.