Headerbar: Improving hideBarIfClickOutside function