File size: 345 Bytes
fbf8165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
export function clickOutside(node) {
	
	window.addEventListener('click', handleClick);
	
	function handleClick(e){   
  if (!node.contains(e.target)){
    node.dispatchEvent(new CustomEvent('outsideclick'))
  }
}

	return {
		destroy() {
			// the node has been removed from the DOM
			window.removeEventListener('click', handleClick)
		}
	};
}