diff --git a/ui/ui.datepicker.js b/ui/ui.datepicker.js index 5f1891fd8..a2bc36623 100644 --- a/ui/ui.datepicker.js +++ b/ui/ui.datepicker.js @@ -693,8 +693,10 @@ $.extend(Datepicker.prototype, { offset.top -= (isFixed && offset.top == (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0; // now check if datepicker is showing outside window viewport - move to a better place if so. - offset.left -= (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ? Math.abs(offset.left + dpWidth - viewWidth) : 0; - offset.top -= (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ? Math.abs(offset.top + dpHeight + inputHeight*2 - viewHeight) : 0; + offset.left -= Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ? + Math.abs(offset.left + dpWidth - viewWidth) : 0); + offset.top -= Math.min(offset.top, (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ? + Math.abs(offset.top + dpHeight + inputHeight * 2 - viewHeight) : 0); return offset; },