Use a key name less likely to result in collisions for events on plain JS objects...
[jquery.git] / src / offset.js
index a3776c2..bbb19c2 100644 (file)
@@ -5,7 +5,7 @@ var rtable = /^t(?:able|d|h)$/i,
 
 if ( "getBoundingClientRect" in document.documentElement ) {
        jQuery.fn.offset = function( options ) {
-               var elem = this[0];
+               var elem = this[0], box;
 
                if ( options ) { 
                        return this.each(function( i ) {
@@ -21,8 +21,14 @@ if ( "getBoundingClientRect" in document.documentElement ) {
                        return jQuery.offset.bodyOffset( elem );
                }
 
-               var box = elem.getBoundingClientRect(),
-                       doc = elem.ownerDocument,
+               try {
+                       box = elem.getBoundingClientRect();
+
+               } catch(e) {
+                       return { top: 0, left: 0 };
+               }
+
+               var doc = elem.ownerDocument,
                        body = doc.body,
                        docElem = doc.documentElement,
                        win = getWindow(doc),
@@ -280,7 +286,7 @@ jQuery.each( ["Left", "Top"], function( i, name ) {
 });
 
 function getWindow( elem ) {
-       return ("scrollTo" in elem && elem.document) ?
+       return jQuery.isWindow( elem ) ?
                elem :
                elem.nodeType === 9 ?
                        elem.defaultView || elem.parentWindow :