Skip to content

Commit 5be52bd

Browse files
committed
Ignore attribute mutations if the selector is not based on attributes.
1 parent 573fb61 commit 5be52bd

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

jquery.initialize.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
// List of mutation types that are observable.
1717
var mtypes = ['childList', 'attributes'];
1818

19-
// Combinators https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors#Combinators
20-
var combinators = [' ', '>', '+', '~'];
19+
var combinators = [' ', '>', '+', '~']; // https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors#Combinators
2120
var fraternisers = ['+', '~'];
21+
var complexTypes = ['ATTR', 'PSEUDO', 'ID', 'CLASS'];
2222

2323
function grok(msobserver) {
2424
if (!$.find.tokenize) {
@@ -28,11 +28,13 @@
2828
// https://github.com/jquery/sizzle/issues/242
2929
msobserver.isCombinatorial = true;
3030
msobserver.isFraternal = true;
31+
msobserver.isComplex = true;
3132
return;
3233
}
3334

3435
msobserver.isCombinatorial = false;
3536
msobserver.isFraternal = false;
37+
msobserver.isComplex = false;
3638

3739
// Search for combinators.
3840
let token = $.find.tokenize(msobserver.selector.trim());
@@ -43,6 +45,9 @@
4345

4446
if (fraternisers.indexOf(token[i][j].type) != -1)
4547
msobserver.isFraternal = true;
48+
49+
if (complexTypes.indexOf(token[i][j].type) != -1)
50+
msobserver.isComplex = true;
4651
}
4752
}
4853
}
@@ -130,7 +135,8 @@
130135
});
131136

132137
// Observe the target element.
133-
observer.observe(options.target, options.observer );
138+
let defaultObeserverOpts = { childList: true, subtree: true, attributes: msobserver.isComplex };
139+
observer.observe(options.target, options.observer || defaultObeserverOpts );
134140
};
135141

136142
// Deprecated API (does not work with jQuery >= 3.1.1):
@@ -145,7 +151,7 @@
145151

146152
$.initialize.defaults = {
147153
target: document.documentElement, // Defaults observe the entire document.
148-
observer: { childList: true, subtree: true, attributes: true }
154+
observer: null
149155
}
150156

151157
})(jQuery);

0 commit comments

Comments
 (0)