Fix minor JavaScript issues with event handling and popover positioning.