From d920bee9546d599124b49f007c08af5e177f19bf Mon Sep 17 00:00:00 2001 From: Thiago Pontes Date: Wed, 28 Jan 2015 18:34:10 -0200 Subject: [PATCH] Check if element is on the DOM before calling getBoundingClientRect to avoid IE10 errors --- src/zepto.js | 2 ++ test/zepto.html | 1 + 2 files changed, 3 insertions(+) diff --git a/src/zepto.js b/src/zepto.js index c5bd6eccf..ae6b10fbb 100644 --- a/src/zepto.js +++ b/src/zepto.js @@ -678,6 +678,8 @@ var Zepto = (function() { $this.css(props) }) if (!this.length) return null + if (!$.contains(document.documentElement, this[0])) + return {top: 0, left: 0} var obj = this[0].getBoundingClientRect() return { left: obj.left + window.pageXOffset, diff --git a/test/zepto.html b/test/zepto.html index aaca98680..23b073db2 100644 --- a/test/zepto.html +++ b/test/zepto.html @@ -1095,6 +1095,7 @@

Zepto Core unit tests

t.assertNull($('#doesnotexist').offset()) var el = $('#some_element') t.assertIdentical(el, el.offset({})) + t.assertSame($('
').offset(), {left: 0, top: 0}) }, testWidth: function(t){