From e7642a48d0bbcaa68a3fbba68cf7a50fd268b312 Mon Sep 17 00:00:00 2001 From: Tomasz Poradzewski Date: Wed, 6 Feb 2019 10:25:38 +0100 Subject: [PATCH] Prevented the popover position from overflowing outside the window --- dist/bootstrap4-clockpicker.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/dist/bootstrap4-clockpicker.js b/dist/bootstrap4-clockpicker.js index a02a432..aedcdbc 100644 --- a/dist/bootstrap4-clockpicker.js +++ b/dist/bootstrap4-clockpicker.js @@ -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("-")); @@ -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); };