6
6
* Released under the MIT license
7
7
* https://js.foundation/
8
8
*
9
- * Date: 2019-08-20
9
+ * Date: 2019-10-01
10
10
*/
11
11
( function ( window ) {
12
12
var i ,
@@ -251,10 +251,7 @@ function Sizzle( selector, context, results, seed ) {
251
251
252
252
// Try to shortcut find operations (as opposed to filters) in HTML documents
253
253
if ( ! seed ) {
254
-
255
- if ( ( context ? context . ownerDocument || context : preferredDoc ) !== document ) {
256
- setDocument ( context ) ;
257
- }
254
+ setDocument ( context ) ;
258
255
context = context || document ;
259
256
260
257
if ( documentIsHTML ) {
@@ -602,7 +599,11 @@ setDocument = Sizzle.setDocument = function( node ) {
602
599
doc = node ? node . ownerDocument || node : preferredDoc ;
603
600
604
601
// Return early if doc is invalid or already selected
605
- if ( doc === document || doc . nodeType !== 9 || ! doc . documentElement ) {
602
+ // Support: IE 11+, Edge 17 - 18+
603
+ // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
604
+ // two documents; shallow comparisons work.
605
+ // eslint-disable-next-line eqeqeq
606
+ if ( doc == document || doc . nodeType !== 9 || ! doc . documentElement ) {
606
607
return document ;
607
608
}
608
609
@@ -611,9 +612,13 @@ setDocument = Sizzle.setDocument = function( node ) {
611
612
docElem = document . documentElement ;
612
613
documentIsHTML = ! isXML ( document ) ;
613
614
614
- // Support: IE 9-11 , Edge
615
+ // Support: IE 9 - 11+ , Edge 12 - 18+
615
616
// Accessing iframe documents after unload throws "permission denied" errors (jQuery #13936)
616
- if ( preferredDoc !== document &&
617
+ // Support: IE 11+, Edge 17 - 18+
618
+ // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
619
+ // two documents; shallow comparisons work.
620
+ // eslint-disable-next-line eqeqeq
621
+ if ( preferredDoc != document &&
617
622
( subWindow = document . defaultView ) && subWindow . top !== subWindow ) {
618
623
619
624
// Support: IE 11, Edge
@@ -928,7 +933,11 @@ setDocument = Sizzle.setDocument = function( node ) {
928
933
}
929
934
930
935
// Calculate position if both inputs belong to the same document
931
- compare = ( a . ownerDocument || a ) === ( b . ownerDocument || b ) ?
936
+ // Support: IE 11+, Edge 17 - 18+
937
+ // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
938
+ // two documents; shallow comparisons work.
939
+ // eslint-disable-next-line eqeqeq
940
+ compare = ( a . ownerDocument || a ) == ( b . ownerDocument || b ) ?
932
941
a . compareDocumentPosition ( b ) :
933
942
934
943
// Otherwise we know they are disconnected
@@ -939,13 +948,20 @@ setDocument = Sizzle.setDocument = function( node ) {
939
948
( ! support . sortDetached && b . compareDocumentPosition ( a ) === compare ) ) {
940
949
941
950
// Choose the first element that is related to our preferred document
942
- if ( a === document ||
943
- a . ownerDocument === preferredDoc &&
951
+ // Support: IE 11+, Edge 17 - 18+
952
+ // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
953
+ // two documents; shallow comparisons work.
954
+ // eslint-disable-next-line eqeqeq
955
+ if ( a == document || a . ownerDocument == preferredDoc &&
944
956
contains ( preferredDoc , a ) ) {
945
957
return - 1 ;
946
958
}
947
- if ( b === document ||
948
- b . ownerDocument === preferredDoc &&
959
+
960
+ // Support: IE 11+, Edge 17 - 18+
961
+ // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
962
+ // two documents; shallow comparisons work.
963
+ // eslint-disable-next-line eqeqeq
964
+ if ( b == document || b . ownerDocument == preferredDoc &&
949
965
contains ( preferredDoc , b ) ) {
950
966
return 1 ;
951
967
}
@@ -975,8 +991,14 @@ setDocument = Sizzle.setDocument = function( node ) {
975
991
976
992
// Parentless nodes are either documents or disconnected
977
993
if ( ! aup || ! bup ) {
978
- return a === document ? - 1 :
979
- b === document ? 1 :
994
+
995
+ // Support: IE 11+, Edge 17 - 18+
996
+ // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
997
+ // two documents; shallow comparisons work.
998
+ /* eslint-disable eqeqeq */
999
+ return a == document ? - 1 :
1000
+ b == document ? 1 :
1001
+ /* eslint-enable eqeqeq */
980
1002
aup ? - 1 :
981
1003
bup ? 1 :
982
1004
sortInput ?
@@ -1009,8 +1031,13 @@ setDocument = Sizzle.setDocument = function( node ) {
1009
1031
siblingCheck ( ap [ i ] , bp [ i ] ) :
1010
1032
1011
1033
// Otherwise nodes in our document sort first
1012
- ap [ i ] === preferredDoc ? - 1 :
1013
- bp [ i ] === preferredDoc ? 1 :
1034
+ // Support: IE 11+, Edge 17 - 18+
1035
+ // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
1036
+ // two documents; shallow comparisons work.
1037
+ /* eslint-disable eqeqeq */
1038
+ ap [ i ] == preferredDoc ? - 1 :
1039
+ bp [ i ] == preferredDoc ? 1 :
1040
+ /* eslint-enable eqeqeq */
1014
1041
0 ;
1015
1042
} ;
1016
1043
@@ -1022,11 +1049,7 @@ Sizzle.matches = function( expr, elements ) {
1022
1049
} ;
1023
1050
1024
1051
Sizzle . matchesSelector = function ( elem , expr ) {
1025
-
1026
- // Set document vars if needed
1027
- if ( ( elem . ownerDocument || elem ) !== document ) {
1028
- setDocument ( elem ) ;
1029
- }
1052
+ setDocument ( elem ) ;
1030
1053
1031
1054
if ( support . matchesSelector && documentIsHTML &&
1032
1055
! nonnativeSelectorCache [ expr + " " ] &&
@@ -1055,7 +1078,11 @@ Sizzle.matchesSelector = function( elem, expr ) {
1055
1078
Sizzle . contains = function ( context , elem ) {
1056
1079
1057
1080
// Set document vars if needed
1058
- if ( ( context . ownerDocument || context ) !== document ) {
1081
+ // Support: IE 11+, Edge 17 - 18+
1082
+ // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
1083
+ // two documents; shallow comparisons work.
1084
+ // eslint-disable-next-line eqeqeq
1085
+ if ( ( context . ownerDocument || context ) != document ) {
1059
1086
setDocument ( context ) ;
1060
1087
}
1061
1088
return contains ( context , elem ) ;
@@ -1064,7 +1091,11 @@ Sizzle.contains = function( context, elem ) {
1064
1091
Sizzle . attr = function ( elem , name ) {
1065
1092
1066
1093
// Set document vars if needed
1067
- if ( ( elem . ownerDocument || elem ) !== document ) {
1094
+ // Support: IE 11+, Edge 17 - 18+
1095
+ // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
1096
+ // two documents; shallow comparisons work.
1097
+ // eslint-disable-next-line eqeqeq
1098
+ if ( ( elem . ownerDocument || elem ) != document ) {
1068
1099
setDocument ( elem ) ;
1069
1100
}
1070
1101
@@ -2098,7 +2129,12 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
2098
2129
len = elems . length ;
2099
2130
2100
2131
if ( outermost ) {
2101
- outermostContext = context === document || context || outermost ;
2132
+
2133
+ // Support: IE 11+, Edge 17 - 18+
2134
+ // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
2135
+ // two documents; shallow comparisons work.
2136
+ // eslint-disable-next-line eqeqeq
2137
+ outermostContext = context == document || context || outermost ;
2102
2138
}
2103
2139
2104
2140
// Add elements passing elementMatchers directly to results
@@ -2107,7 +2143,12 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
2107
2143
for ( ; i !== len && ( elem = elems [ i ] ) != null ; i ++ ) {
2108
2144
if ( byElement && elem ) {
2109
2145
j = 0 ;
2110
- if ( ! context && elem . ownerDocument !== document ) {
2146
+
2147
+ // Support: IE 11+, Edge 17 - 18+
2148
+ // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
2149
+ // two documents; shallow comparisons work.
2150
+ // eslint-disable-next-line eqeqeq
2151
+ if ( ! context && elem . ownerDocument != document ) {
2111
2152
setDocument ( elem ) ;
2112
2153
xml = ! documentIsHTML ;
2113
2154
}
0 commit comments