@@ -15,13 +15,6 @@ define( [
1515
1616"use strict" ;
1717
18- /**
19- * Gets a window from an element
20- */
21- function getWindow ( elem ) {
22- return jQuery . isWindow ( elem ) ? elem : elem . nodeType === 9 && elem . defaultView ;
23- }
24-
2518jQuery . offset = {
2619 setOffset : function ( elem , options , i ) {
2720 var curPosition , curLeft , curCSSTop , curTop , curOffset , curCSSLeft , calculatePosition ,
@@ -86,7 +79,7 @@ jQuery.fn.extend( {
8679 } ) ;
8780 }
8881
89- var docElem , win , rect , doc ,
82+ var doc , docElem , rect , win ,
9083 elem = this [ 0 ] ;
9184
9285 if ( ! elem ) {
@@ -104,8 +97,8 @@ jQuery.fn.extend( {
10497 rect = elem . getBoundingClientRect ( ) ;
10598
10699 doc = elem . ownerDocument ;
107- win = getWindow ( doc ) ;
108100 docElem = doc . documentElement ;
101+ win = doc . defaultView ;
109102
110103 return {
111104 top : rect . top + win . pageYOffset - docElem . clientTop ,
@@ -183,7 +176,14 @@ jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function(
183176
184177 jQuery . fn [ method ] = function ( val ) {
185178 return access ( this , function ( elem , method , val ) {
186- var win = getWindow ( elem ) ;
179+
180+ // Coalesce documents and windows
181+ var win ;
182+ if ( jQuery . isWindow ( elem ) ) {
183+ win = elem ;
184+ } else if ( elem . nodeType === 9 ) {
185+ win = elem . defaultView ;
186+ }
187187
188188 if ( val === undefined ) {
189189 return win ? win [ prop ] : elem [ method ] ;
0 commit comments