-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
37 lines (28 loc) · 889 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import ComponentLoader from './src/ComponentLoader';
export default ComponentLoader;
$.fn.adtAjax = function (e, options) {
return $.nette.ajax(options || {}, this[0], e);
};
$.observe = function(selector, callback) {
const initedElements = [];
const body = document.getElementsByTagName('body')[0];
const applyCallback = function(element) {
$(element).find(selector).each(function() {
if (initedElements.includes(this)) return;
callback(this);
initedElements.push(this);
});
}
const mutationObserver = new MutationObserver(function(entries) {
entries.map((entry) => {
entry.addedNodes.forEach(function(element) {
if (!(element instanceof HTMLElement)) {
return;
}
applyCallback(element);
});
});
});
applyCallback(body);
mutationObserver.observe(body, { attributes: false, childList: true, characterData: false, subtree:true });
}