Skip to content

Commit

Permalink
Improve closeOnOutsideClick behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed Sep 19, 2018
1 parent dadd509 commit 48eddcd
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 105 deletions.
42 changes: 20 additions & 22 deletions dist/ctrly.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,27 +392,6 @@ function ctrly() {
}
function addEventListeners(control, target) {
var removeFuncs = [];
var active = false;
var activate = function activate() {
active = true;
};
var deactivate = function deactivate() {
active = false;
};
if (options.closeOnOutsideClick || options.closeOnScroll) {
removeFuncs.push(on(target, 'mouseenter', activate, {
passive: true
}));
removeFuncs.push(on(target, 'mouseleave', deactivate, {
passive: true
}));
removeFuncs.push(on(target, 'touchstart', activate, {
passive: true
}));
removeFuncs.push(on(target, 'touchend', deactivate, {
passive: true
}));
}
if (options.closeOnBlur && !options.trapFocus) {
removeFuncs.push(on(document, 'focusin', function (e) {
if (!target.contains(e.target)) {
Expand All @@ -432,14 +411,33 @@ function ctrly() {
}
if (options.closeOnOutsideClick) {
removeFuncs.push(on(document, 'click', function (e) {
if (!active && keyCode(e) === 1 && !closest(e.target, controlSelector)) {
if (keyCode(e) === 1 && !target.contains(e.target) && !closest(e.target, controlSelector)) {
close(target);
}
}, {
passive: true
}));
}
if (options.closeOnScroll) {
var active = false;
var activate = function activate() {
active = true;
};
var deactivate = function deactivate() {
active = false;
};
removeFuncs.push(on(target, 'mouseenter', activate, {
passive: true
}));
removeFuncs.push(on(target, 'mouseleave', deactivate, {
passive: true
}));
removeFuncs.push(on(target, 'touchstart', activate, {
passive: true
}));
removeFuncs.push(on(target, 'touchend', deactivate, {
passive: true
}));
removeFuncs.push(on(window, 'scroll', function () {
if (!active) {
close(target);
Expand Down
42 changes: 20 additions & 22 deletions dist/ctrly.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,27 +398,6 @@
}
function addEventListeners(control, target) {
var removeFuncs = [];
var active = false;
var activate = function activate() {
active = true;
};
var deactivate = function deactivate() {
active = false;
};
if (options.closeOnOutsideClick || options.closeOnScroll) {
removeFuncs.push(on(target, 'mouseenter', activate, {
passive: true
}));
removeFuncs.push(on(target, 'mouseleave', deactivate, {
passive: true
}));
removeFuncs.push(on(target, 'touchstart', activate, {
passive: true
}));
removeFuncs.push(on(target, 'touchend', deactivate, {
passive: true
}));
}
if (options.closeOnBlur && !options.trapFocus) {
removeFuncs.push(on(document, 'focusin', function (e) {
if (!target.contains(e.target)) {
Expand All @@ -438,14 +417,33 @@
}
if (options.closeOnOutsideClick) {
removeFuncs.push(on(document, 'click', function (e) {
if (!active && keyCode(e) === 1 && !closest(e.target, controlSelector)) {
if (keyCode(e) === 1 && !target.contains(e.target) && !closest(e.target, controlSelector)) {
close(target);
}
}, {
passive: true
}));
}
if (options.closeOnScroll) {
var active = false;
var activate = function activate() {
active = true;
};
var deactivate = function deactivate() {
active = false;
};
removeFuncs.push(on(target, 'mouseenter', activate, {
passive: true
}));
removeFuncs.push(on(target, 'mouseleave', deactivate, {
passive: true
}));
removeFuncs.push(on(target, 'touchstart', activate, {
passive: true
}));
removeFuncs.push(on(target, 'touchend', deactivate, {
passive: true
}));
removeFuncs.push(on(window, 'scroll', function () {
if (!active) {
close(target);
Expand Down
2 changes: 1 addition & 1 deletion dist/ctrly.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 48eddcd

Please sign in to comment.