Hide popup menu when click outside

Hide popup menu when click outside
Changed references to document and window to $document and $window