You may want to check out the collision options for .position()
$('#filter-menu-button-menu').menu({
"position": {
my: "right top",
at: "left top",
collision: 'flipfit'
}
});
"flipfit": First applies the flip logic, placing the element on whichever side allows more of the element to be visible. Then the fit logic is applied to ensure as much of the element is visible as possible.