Skip to content

Commit

Permalink
Merge pull request #4 from poradz/poradz-position-fix
Browse files Browse the repository at this point in the history
Prevented the popover position from overflowing outside the window
  • Loading branch information
djibe committed Feb 10, 2019
2 parents 2b9326f + e7642a4 commit 191ca92
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions dist/bootstrap4-clockpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,18 @@
// Set popover position and update placement class, if needed
ClockPicker.prototype.locate = function() {
var element = this.element,
popover = this.popover,
offset = element.offset(),
width = element.outerWidth(),
height = element.outerHeight(),
placement = this.options.placement,
align = this.options.align,
styles = {},
self = this;
popover = this.popover,
offset = element.offset(),
width = element.outerWidth(),
height = element.outerHeight(),
placement = this.options.placement,
align = this.options.align,
windowHeight = $win.height(),
windowWidth = $win.width(),
popoverHeight = popover.height(),
popoverWidth = popover.width(),
styles = {},
self = this;

if (placement === "top-adaptive" || placement === "bottom-adaptive") {
var preferredPlacement = placement.substr(0, placement.indexOf("-"));
Expand Down Expand Up @@ -568,7 +572,15 @@
styles.top = offset.top + height - popover.outerHeight();
break;
}


// Correct the popover position outside the window
if (popoverHeight + styles.top > windowHeight) {
styles.top = windowHeight - popoverHeight;
}
if (popoverWidth + styles.left > windowWidth) {
styles.left = windowWidth - popoverWidth;
}

popover.css(styles);
};

Expand Down

0 comments on commit 191ca92

Please sign in to comment.