Skip to content

Commit

Permalink
Pad against document borders
Browse files Browse the repository at this point in the history
  • Loading branch information
cgst committed Jul 13, 2010
1 parent 7dcfb54 commit c87d4fc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,18 @@ $.fn.popover = function(options) {
floater.height(floater.height() + diffHeight);
}

// Padding against document borders
var padding = 18;

// Calculate leftOff
leftOff = offset.left + ( buttonWidth - contentWidth)/2;
var diffWidth = 0
if (leftOff < 0) {
leftOff = offset.left + (buttonWidth - contentWidth)/2;
var diffWidth = 0;
if (leftOff < padding) {
// out of the document at left
diffWidth = -leftOff;
diffWidth = leftOff - padding;
} else if (leftOff + contentWidth > docWidth) {
// left of the screen right
diffWidth = leftOff + contentWidth - docWidth;
diffWidth = leftOff + contentWidth - docWidth + padding;
}

// position triangle
Expand Down

0 comments on commit c87d4fc

Please sign in to comment.