]> source.dussan.org Git - jquery.git/commitdiff
Core: Use isAttached to check for attachment of element
authorSaptak Sengupta <saptak013@gmail.com>
Mon, 5 Mar 2018 17:57:03 +0000 (23:27 +0530)
committerMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Mon, 5 Mar 2018 17:57:03 +0000 (18:57 +0100)
This change replaces the use of contains to check for attachment
by isAttached function

Closes gh-3977
Ref gh-3504

src/css/curCSS.js
src/css/var/isHiddenWithinTree.js
src/manipulation.js
src/manipulation/buildFragment.js
src/var/isAttached.js [new file with mode: 0644]

index aa1414d26156765950150333a45d59bc57342169..7fed20f17b9b70905e6282738fc96a79e9fea3c9 100644 (file)
@@ -1,11 +1,11 @@
 define( [
        "../core",
+       "../var/isAttached",
        "./var/rboxStyle",
        "./var/rnumnonpx",
        "./var/getStyles",
-       "./support",
-       "../selector" // Get jQuery.contains
-], function( jQuery, rboxStyle, rnumnonpx, getStyles, support ) {
+       "./support"
+], function( jQuery, isAttached, rboxStyle, rnumnonpx, getStyles, support ) {
 
 "use strict";
 
@@ -26,7 +26,7 @@ function curCSS( elem, name, computed ) {
        if ( computed ) {
                ret = computed.getPropertyValue( name ) || computed[ name ];
 
-               if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
+               if ( ret === "" && !isAttached( elem ) ) {
                        ret = jQuery.style( elem, name );
                }
 
index 3cfb93e160ded3f6a1adcffeab1d49ff67aa62ad..fd963a0314f897a9eb8fd437a0ad063f9f9bce31 100644 (file)
@@ -1,9 +1,9 @@
 define( [
        "../../core",
-       "../../selector"
+       "../../var/isAttached"
 
        // css is assumed
-], function( jQuery ) {
+], function( jQuery, isAttached ) {
        "use strict";
 
        // isHiddenWithinTree reports if an element has a non-"none" display style (inline and/or
@@ -27,7 +27,7 @@ define( [
                        // Support: Firefox <=43 - 45
                        // Disconnected elements can have computed display: none, so first confirm that elem is
                        // in the document.
-                       jQuery.contains( elem.ownerDocument, elem ) &&
+                       isAttached( elem ) &&
 
                        jQuery.css( elem, "display" ) === "none";
        };
index 142e296ad0e196d580f5f0d1b34b2d2d4b6ae43f..3c6d59262302a04c658ab1c2d4a7a9b0144c94db 100644 (file)
@@ -1,5 +1,6 @@
 define( [
        "./core",
+       "./var/isAttached",
        "./var/concat",
        "./var/isFunction",
        "./var/push",
@@ -23,7 +24,7 @@ define( [
        "./traversing",
        "./selector",
        "./event"
-], function( jQuery, concat, isFunction, push, access,
+], function( jQuery, isAttached, concat, isFunction, push, access,
        rcheckableType, rtagName, rscriptType,
        wrapMap, getAll, setGlobalEval, buildFragment, support,
        dataPriv, dataUser, acceptData, DOMEval, nodeName ) {
@@ -223,7 +224,7 @@ function remove( elem, selector, keepData ) {
                }
 
                if ( node.parentNode ) {
-                       if ( keepData && jQuery.contains( node.ownerDocument, node ) ) {
+                       if ( keepData && isAttached( node ) ) {
                                setGlobalEval( getAll( node, "script" ) );
                        }
                        node.parentNode.removeChild( node );
@@ -241,7 +242,7 @@ jQuery.extend( {
        clone: function( elem, dataAndEvents, deepDataAndEvents ) {
                var i, l, srcElements, destElements,
                        clone = elem.cloneNode( true ),
-                       inPage = jQuery.contains( elem.ownerDocument, elem );
+                       inPage = isAttached( elem );
 
                // Fix IE cloning issues
                if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
index 782de0c6117cef48287de91c3c934e4ac3355c17..34bcc70c212ac12dac77277dd938921da11b0269 100644 (file)
@@ -1,19 +1,20 @@
 define( [
        "../core",
        "../core/toType",
+       "../var/isAttached",
        "./var/rtagName",
        "./var/rscriptType",
        "./wrapMap",
        "./getAll",
        "./setGlobalEval"
-], function( jQuery, toType, rtagName, rscriptType, wrapMap, getAll, setGlobalEval ) {
+], function( jQuery, toType, isAttached, rtagName, rscriptType, wrapMap, getAll, setGlobalEval ) {
 
 "use strict";
 
 var rhtml = /<|&#?\w+;/;
 
 function buildFragment( elems, context, scripts, selection, ignored ) {
-       var elem, tmp, tag, wrap, contains, j,
+       var elem, tmp, tag, wrap, attached, j,
                fragment = context.createDocumentFragment(),
                nodes = [],
                i = 0,
@@ -77,13 +78,13 @@ function buildFragment( elems, context, scripts, selection, ignored ) {
                        continue;
                }
 
-               contains = jQuery.contains( elem.ownerDocument, elem );
+               attached = isAttached( elem );
 
                // Append to fragment
                tmp = getAll( fragment.appendChild( elem ), "script" );
 
                // Preserve script evaluation history
-               if ( contains ) {
+               if ( attached ) {
                        setGlobalEval( tmp );
                }
 
diff --git a/src/var/isAttached.js b/src/var/isAttached.js
new file mode 100644 (file)
index 0000000..1dd7982
--- /dev/null
@@ -0,0 +1,11 @@
+define( [
+       "../core",
+       "../selector" // Get jQuery.contains
+], function( jQuery ) {
+       "use strict";
+
+       return function isAttached( obj ) {
+               return jQuery.contains( obj.ownerDocument, obj );
+       };
+
+} );