aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSaptak Sengupta <saptak013@gmail.com>2018-03-05 23:27:03 +0530
committerMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2018-03-05 18:57:03 +0100
commit662083ed7bfea6bad5f9cd4060dab77c1f32aacd (patch)
tree20121cf09841f13d743d90e39b5f53c491ff6d29 /src
parent09684ba3f210594e41ecddf369ac94c688d53ccb (diff)
downloadjquery-662083ed7bfea6bad5f9cd4060dab77c1f32aacd.tar.gz
jquery-662083ed7bfea6bad5f9cd4060dab77c1f32aacd.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/css/curCSS.js8
-rw-r--r--src/css/var/isHiddenWithinTree.js6
-rw-r--r--src/manipulation.js7
-rw-r--r--src/manipulation/buildFragment.js9
-rw-r--r--src/var/isAttached.js11
5 files changed, 27 insertions, 14 deletions
diff --git a/src/css/curCSS.js b/src/css/curCSS.js
index aa1414d26..7fed20f17 100644
--- a/src/css/curCSS.js
+++ b/src/css/curCSS.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 );
}
diff --git a/src/css/var/isHiddenWithinTree.js b/src/css/var/isHiddenWithinTree.js
index 3cfb93e16..fd963a031 100644
--- a/src/css/var/isHiddenWithinTree.js
+++ b/src/css/var/isHiddenWithinTree.js
@@ -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";
};
diff --git a/src/manipulation.js b/src/manipulation.js
index 142e296ad..3c6d59262 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -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 ) &&
diff --git a/src/manipulation/buildFragment.js b/src/manipulation/buildFragment.js
index 782de0c61..34bcc70c2 100644
--- a/src/manipulation/buildFragment.js
+++ b/src/manipulation/buildFragment.js
@@ -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
index 000000000..1dd798268
--- /dev/null
+++ b/src/var/isAttached.js
@@ -0,0 +1,11 @@
+define( [
+ "../core",
+ "../selector" // Get jQuery.contains
+], function( jQuery ) {
+ "use strict";
+
+ return function isAttached( obj ) {
+ return jQuery.contains( obj.ownerDocument, obj );
+ };
+
+} );