🌐 AI搜索 & 代理 主页
Skip to content

Commit bf3a43e

Browse files
authored
Offset: Eliminate little-used internal function
Fixes gh-3449 Closes gh-3456
1 parent 8cb4cd7 commit bf3a43e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/offset.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
2518
jQuery.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

Comments
 (0)