diff --git a/src/containers/editable-popover.js b/src/containers/editable-popover.js index e781f40..867f5bf 100644 --- a/src/containers/editable-popover.js +++ b/src/containers/editable-popover.js @@ -93,78 +93,78 @@ placement = inside ? placement.split(' ')[1] : placement; - tpb = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2} - tpt = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2} - tpl = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth} - tpr = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width} + tpb = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}; + tpt = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}; + tpl = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}; + tpr = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}; - switch (placement) { - case 'bottom': - if ((tpb.top + actualHeight) > ($(window).scrollTop() + $(window).height())) { - if (tpt.top > $(window).scrollTop()) { - placement = 'top' - } else if ((tpr.left + actualWidth) < ($(window).scrollLeft() + $(window).width())) { - placement = 'right' - } else if (tpl.left > $(window).scrollLeft()) { - placement = 'left' - } else { - placement = 'right' - } - } - break - case 'top': - if (tpt.top < $(window).scrollTop()) { - if ((tpb.top + actualHeight) < ($(window).scrollTop() + $(window).height())) { - placement = 'bottom' - } else if ((tpr.left + actualWidth) < ($(window).scrollLeft() + $(window).width())) { - placement = 'right' - } else if (tpl.left > $(window).scrollLeft()) { - placement = 'left' - } else { - placement = 'right' - } - } - break - case 'left': - if (tpl.left < $(window).scrollLeft()) { - if ((tpr.left + actualWidth) < ($(window).scrollLeft() + $(window).width())) { - placement = 'right' - } else if (tpt.top > $(window).scrollTop()) { - placement = 'top' - } else if (tpt.top > $(window).scrollTop()) { - placement = 'bottom' - } else { - placement = 'right' - } - } - break - case 'right': - if ((tpr.left + actualWidth) > ($(window).scrollLeft() + $(window).width())) { - if (tpl.left > $(window).scrollLeft()) { - placement = 'left' - } else if (tpt.top > $(window).scrollTop()) { - placement = 'top' - } else if (tpt.top > $(window).scrollTop()) { - placement = 'bottom' - } - } - break - } + switch (placement) { + case 'bottom': + if ((tpb.top + actualHeight) > ($(window).scrollTop() + $(window).height())) { + if (tpt.top > $(window).scrollTop()) { + placement = 'top'; + } else if ((tpr.left + actualWidth) < ($(window).scrollLeft() + $(window).width())) { + placement = 'right'; + } else if (tpl.left > $(window).scrollLeft()) { + placement = 'left'; + } else { + placement = 'right'; + } + } + break; + case 'top': + if (tpt.top < $(window).scrollTop()) { + if ((tpb.top + actualHeight) < ($(window).scrollTop() + $(window).height())) { + placement = 'bottom'; + } else if ((tpr.left + actualWidth) < ($(window).scrollLeft() + $(window).width())) { + placement = 'right'; + } else if (tpl.left > $(window).scrollLeft()) { + placement = 'left'; + } else { + placement = 'right'; + } + } + break; + case 'left': + if (tpl.left < $(window).scrollLeft()) { + if ((tpr.left + actualWidth) < ($(window).scrollLeft() + $(window).width())) { + placement = 'right'; + } else if (tpt.top > $(window).scrollTop()) { + placement = 'top'; + } else if (tpt.top > $(window).scrollTop()) { + placement = 'bottom'; + } else { + placement = 'right'; + } + } + break; + case 'right': + if ((tpr.left + actualWidth) > ($(window).scrollLeft() + $(window).width())) { + if (tpl.left > $(window).scrollLeft()) { + placement = 'left'; + } else if (tpt.top > $(window).scrollTop()) { + placement = 'top'; + } else if (tpt.top > $(window).scrollTop()) { + placement = 'bottom'; + } + } + break; + } - switch (placement) { - case 'bottom': - tp = tpb; - break - case 'top': - tp = tpt; - break - case 'left': - tp = tpl; - break - case 'right': - tp = tpr; - break - } + switch (placement) { + case 'bottom': + tp = tpb; + break; + case 'top': + tp = tpt; + break; + case 'left': + tp = tpl; + break; + case 'right': + tp = tpr; + break; + } $tip .offset(tp)