Skip to content
Permalink
Browse files

Core: Use isAttached to check for attachment of element

This change replaces the use of contains to check for attachment
by isAttached function

Closes gh-3977
Ref gh-3504
  • Loading branch information...
SaptakS authored and mgol committed Mar 5, 2018
1 parent 09684ba commit 662083ed7bfea6bad5f9cd4060dab77c1f32aacd
Showing with 27 additions and 14 deletions.
  1. +4 −4 src/css/curCSS.js
  2. +3 −3 src/css/var/isHiddenWithinTree.js
  3. +4 −3 src/manipulation.js
  4. +5 −4 src/manipulation/buildFragment.js
  5. +11 −0 src/var/isAttached.js
@@ -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 );
}

@@ -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";
};
@@ -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 ) &&
@@ -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 );
}

@@ -0,0 +1,11 @@
define( [
"../core",
"../selector" // Get jQuery.contains
], function( jQuery ) {
"use strict";

return function isAttached( obj ) {
return jQuery.contains( obj.ownerDocument, obj );
};

} );

0 comments on commit 662083e

Please sign in to comment.
You can’t perform that action at this time.