aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2016-12-19 12:00:46 -0500
committerGitHub <noreply@github.com>2016-12-19 12:00:46 -0500
commitbf3a43eff8682b59cec785be6003753fa4b93706 (patch)
treef7eb43c9c8a2595ecc2a64462eb5438c92b10a7a
parent8cb4cd71ef018854f75646270bacd4c4d3da9cde (diff)
downloadjquery-bf3a43eff8682b59cec785be6003753fa4b93706.tar.gz
jquery-bf3a43eff8682b59cec785be6003753fa4b93706.zip
Offset: Eliminate little-used internal function
Fixes gh-3449 Closes gh-3456
-rw-r--r--src/offset.js20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/offset.js b/src/offset.js
index 5baefdb21..467526d2a 100644
--- a/src/offset.js
+++ b/src/offset.js
@@ -15,13 +15,6 @@ define( [
"use strict";
-/**
- * Gets a window from an element
- */
-function getWindow( elem ) {
- return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
-}
-
jQuery.offset = {
setOffset: function( elem, options, i ) {
var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
@@ -86,7 +79,7 @@ jQuery.fn.extend( {
} );
}
- var docElem, win, rect, doc,
+ var doc, docElem, rect, win,
elem = this[ 0 ];
if ( !elem ) {
@@ -104,8 +97,8 @@ jQuery.fn.extend( {
rect = elem.getBoundingClientRect();
doc = elem.ownerDocument;
- win = getWindow( doc );
docElem = doc.documentElement;
+ win = doc.defaultView;
return {
top: rect.top + win.pageYOffset - docElem.clientTop,
@@ -183,7 +176,14 @@ jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function(
jQuery.fn[ method ] = function( val ) {
return access( this, function( elem, method, val ) {
- var win = getWindow( elem );
+
+ // Coalesce documents and windows
+ var win;
+ if ( jQuery.isWindow( elem ) ) {
+ win = elem;
+ } else if ( elem.nodeType === 9 ) {
+ win = elem.defaultView;
+ }
if ( val === undefined ) {
return win ? win[ prop ] : elem[ method ];