|
16 | 16 | // List of mutation types that are observable. |
17 | 17 | var mtypes = ['childList', 'attributes']; |
18 | 18 |
|
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 |
21 | 20 | var fraternisers = ['+', '~']; |
| 21 | + var complexTypes = ['ATTR', 'PSEUDO', 'ID', 'CLASS']; |
22 | 22 |
|
23 | 23 | function grok(msobserver) { |
24 | 24 | if (!$.find.tokenize) { |
|
28 | 28 | // https://github.com/jquery/sizzle/issues/242 |
29 | 29 | msobserver.isCombinatorial = true; |
30 | 30 | msobserver.isFraternal = true; |
| 31 | + msobserver.isComplex = true; |
31 | 32 | return; |
32 | 33 | } |
33 | 34 |
|
34 | 35 | msobserver.isCombinatorial = false; |
35 | 36 | msobserver.isFraternal = false; |
| 37 | + msobserver.isComplex = false; |
36 | 38 |
|
37 | 39 | // Search for combinators. |
38 | 40 | let token = $.find.tokenize(msobserver.selector.trim()); |
|
43 | 45 |
|
44 | 46 | if (fraternisers.indexOf(token[i][j].type) != -1) |
45 | 47 | msobserver.isFraternal = true; |
| 48 | + |
| 49 | + if (complexTypes.indexOf(token[i][j].type) != -1) |
| 50 | + msobserver.isComplex = true; |
46 | 51 | } |
47 | 52 | } |
48 | 53 | } |
|
130 | 135 | }); |
131 | 136 |
|
132 | 137 | // 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 ); |
134 | 140 | }; |
135 | 141 |
|
136 | 142 | // Deprecated API (does not work with jQuery >= 3.1.1): |
|
145 | 151 |
|
146 | 152 | $.initialize.defaults = { |
147 | 153 | target: document.documentElement, // Defaults observe the entire document. |
148 | | - observer: { childList: true, subtree: true, attributes: true } |
| 154 | + observer: null |
149 | 155 | } |
150 | 156 |
|
151 | 157 | })(jQuery); |
0 commit comments