From 1ce5e9f3aea1c5d2f63d9e0b5a81cf229daccf13 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Wed, 2 Jul 2014 10:09:26 -0700 Subject: [PATCH 1/2] possible fix for #14013 --- dist/js/bootstrap.js | 9 ++++++--- js/tooltip.js | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/dist/js/bootstrap.js b/dist/js/bootstrap.js index 53da1c77c0..afb3d26e7d 100644 --- a/dist/js/bootstrap.js +++ b/dist/js/bootstrap.js @@ -1418,11 +1418,14 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re $element = $element || this.$element var el = $element[0] var isBody = el.tagName == 'BODY' - return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : null, { - scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop(), + var isSvg = window.SVGElement && el instanceof window.SVGElement + var outerDims = isSvg ? {} : { width: isBody ? $(window).width() : $element.outerWidth(), height: isBody ? $(window).height() : $element.outerHeight() - }, isBody ? { top: 0, left: 0 } : $element.offset()) + } + return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : null, { + scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() + }, outerDims, isBody ? { top: 0, left: 0 } : $element.offset()) } Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) { diff --git a/js/tooltip.js b/js/tooltip.js index 9cdb6c9e4d..68c5714cdd 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -318,11 +318,14 @@ $element = $element || this.$element var el = $element[0] var isBody = el.tagName == 'BODY' - return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : null, { - scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop(), + var isSvg = window.SVGElement && el instanceof window.SVGElement + var outerDims = isSvg ? {} : { width: isBody ? $(window).width() : $element.outerWidth(), height: isBody ? $(window).height() : $element.outerHeight() - }, isBody ? { top: 0, left: 0 } : $element.offset()) + } + return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : null, { + scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() + }, outerDims, isBody ? { top: 0, left: 0 } : $element.offset()) } Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) { From f9ffb4993215687bb241cab1151956e6df1922cd Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Sun, 6 Jul 2014 00:16:52 -0700 Subject: [PATCH 2/2] refactor/reformat Tooltip.getPosition per @fat's feedback --- js/tooltip.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/js/tooltip.js b/js/tooltip.js index 68c5714cdd..b305bc5ab5 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -316,16 +316,20 @@ Tooltip.prototype.getPosition = function ($element) { $element = $element || this.$element + var el = $element[0] var isBody = el.tagName == 'BODY' - var isSvg = window.SVGElement && el instanceof window.SVGElement + var isSvg = window.SVGElement && el instanceof window.SVGElement + + var elRect = typeof el.getBoundingClientRect == 'function' ? el.getBoundingClientRect() : null + var elOffset = isBody ? { top: 0, left: 0 } : $element.offset() + var scroll = { scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() } var outerDims = isSvg ? {} : { width: isBody ? $(window).width() : $element.outerWidth(), height: isBody ? $(window).height() : $element.outerHeight() } - return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : null, { - scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() - }, outerDims, isBody ? { top: 0, left: 0 } : $element.offset()) + + return $.extend({}, elRect, scroll, outerDims, elOffset) } Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) {