Repository URL to install this package:
|
Version:
1.2.9 ▾
|
import { isFunction, isNil, isObj } from 'exotic'
export const IS_BROWSER = typeof window === 'object'
export function isClickOutsideElement(event, dom): boolean {
// get direct click event target
const { target } = event
// get container that we'll wait to be clicked outside
const container = dom
// if target is container - container was not clicked outside
// if container contains clicked target - click was not outside of it
if (
target !== container &&
isObj(container) &&
isFunction(container.contains) &&
!container.contains(target)
) {
// clicked outside - fire callback
return true
} else {
return false
}
}
// toBoolean
export function isClickInsideElement(event, dom): boolean {
if (isNil(dom) === true) {
return false
} else {
return isClickOutsideElement(event, dom) === false
}
}