]> source.dussan.org Git - jquery.git/commitdiff
Offset: Eliminate little-used internal function
authorRichard Gibson <richard.gibson@gmail.com>
Mon, 19 Dec 2016 17:00:46 +0000 (12:00 -0500)
committerGitHub <noreply@github.com>
Mon, 19 Dec 2016 17:00:46 +0000 (12:00 -0500)
Fixes gh-3449
Closes gh-3456

src/offset.js

index 5baefdb21f4a5269de6b6b2861da3c63e99a74f6..467526d2aa481bf22939c290e784a14fc63f8ddf 100644 (file)
@@ -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 ];