From ace4fc3e8704444008765b21a2178bd75146858b Mon Sep 17 00:00:00 2001 From: boris-chervenkov Date: Tue, 12 Mar 2013 17:30:40 +0200 Subject: [PATCH] Fixes scroll issue in position:fixed elements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the datepicker is placed within position:fixed elements, e.g. modals and fixed navbars, scrolling the page also moves the datepicker away. Tested when placed within: - normal element, e.g. within a form - fixed element - modal Tested on: Chrome 25 (MacOS 10.8) Safari 6 (MacOS 10.8) Firefox 19 (MacOS 10.8) Internet Explorer 7 (Windows XP) --- src/js/bootstrap-datetimepicker.js | 31 ++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/js/bootstrap-datetimepicker.js b/src/js/bootstrap-datetimepicker.js index 9a439ba8a..09c41dd38 100644 --- a/src/js/bootstrap-datetimepicker.js +++ b/src/js/bootstrap-datetimepicker.js @@ -260,9 +260,20 @@ }, place: function(){ + var position = 'absolute'; var offset = this.component ? this.component.offset() : this.$element.offset(); + offset.top = offset.top + this.height; + + if (this._isInFixed()) { + var $window = $(window); + position = 'fixed'; + offset.top -= $window.scrollTop(); + offset.left -= $window.scrollLeft(); + } + this.widget.css({ - top: offset.top + this.height, + position: position, + top: offset.top, left: offset.left }); }, @@ -1024,7 +1035,23 @@ if (!this.isInput) { $(document).off('mousedown.datetimepicker' + this.id); } - } + }, + + _isInFixed: function() { + if (this.$element) { + var parents = this.$element.parents(); + var inFixed = false; + for (var i=0; i