From 82e9e0578b7e5c5b669fbf2b39a5658c7c036056 Mon Sep 17 00:00:00 2001 From: Iran Reyes Fleitas Date: Thu, 22 Jan 2015 15:23:36 -0200 Subject: [PATCH] Include width in the inmutable object rect --- src/nsPopover.js | 51 ++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/src/nsPopover.js b/src/nsPopover.js index 0bedea0..a8abda5 100644 --- a/src/nsPopover.js +++ b/src/nsPopover.js @@ -380,25 +380,38 @@ } function getBoundingClientRect(elm) { - var w = window; - var doc = document.documentElement || document.body.parentNode || document.body; - var x = (isDef(w.pageXOffset)) ? w.pageXOffset : doc.scrollLeft; - var y = (isDef(w.pageYOffset)) ? w.pageYOffset : doc.scrollTop; - var rect = elm.getBoundingClientRect(); - - // ClientRect class is immutable, so we need to return a modified copy - // of it when the window has been scrolled. - if (x || y) { - return { - bottom:rect.bottom+y, - left:rect.left + x, - right:rect.right + x, - top:rect.top + y, - height:rect.height, - width:rect.width - }; - } - return rect; + var w = window; + var doc = document.documentElement || document.body.parentNode || document.body; + var x = (isDef(w.pageXOffset)) ? w.pageXOffset : doc.scrollLeft; + var y = (isDef(w.pageYOffset)) ? w.pageYOffset : doc.scrollTop; + var rect = elm.getBoundingClientRect(); + + var compatibleRect = null; + if (rect.width === undefined) { + compatibleRect = {}; + compatibleRect.bottom = rect.bottom; + compatibleRect.left = rect.left; + compatibleRect.right = rect.right; + compatibleRect.top = rect.top; + compatibleRect.height = rect.height; + compatibleRect.width = rect.right - rect.left; + } + else + compatibleRect = rect; + + // ClientRect class is immutable, so we need to return a modified copy + // of it when the window has been scrolled. + if (x || y) { + return { + bottom: compatibleRect.bottom + y, + left: compatibleRect.left + x, + right: compatibleRect.right + x, + top: compatibleRect.top + y, + height: compatibleRect.height, + width: compatibleRect.width + }; + } + return compatibleRect; } function toBoolean(value) {