adt-js-components 1.7.2 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ComponentLoader.js +5 -0
- package/src/RedrawSnippet/index.js +44 -0
package/package.json
CHANGED
package/src/ComponentLoader.js
CHANGED
|
@@ -69,6 +69,10 @@ const initRecaptcha = () => {
|
|
|
69
69
|
init('recaptcha', 'Recaptcha');
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
+
const initRedrawSnippet = () => {
|
|
73
|
+
init('redraw-snippet', 'RedrawSnippet');
|
|
74
|
+
};
|
|
75
|
+
|
|
72
76
|
const initSelect2 = () => {
|
|
73
77
|
init('select2', 'Select2');
|
|
74
78
|
};
|
|
@@ -122,6 +126,7 @@ export default {
|
|
|
122
126
|
initGLightbox,
|
|
123
127
|
initGoogleMaps,
|
|
124
128
|
initRecaptcha,
|
|
129
|
+
initRedrawSnippet,
|
|
125
130
|
initSelect2,
|
|
126
131
|
initSubmitForm,
|
|
127
132
|
initTinyMCE,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
async function run(options) {
|
|
2
|
+
function applyEventHandlers(el) {
|
|
3
|
+
var $el= $(el);
|
|
4
|
+
if ($el.is('button, input[type="button"], input[type="submit"]')) {
|
|
5
|
+
$el.on('click', sendNetteAjax);
|
|
6
|
+
} else if ($el.is('input:not([type="button"]):not([type="submit"]), select, textarea')) {
|
|
7
|
+
$el.on('input', sendNetteAjax);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function sendNetteAjax(e) {
|
|
12
|
+
const $el = $(e.currentTarget);
|
|
13
|
+
$el.closest('form').find('[name="' + $el.attr('data-adt-redraw-snippet') + '"]').netteAjax(e);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const observer = new MutationObserver(mutations => {
|
|
17
|
+
mutations.forEach(mutation => {
|
|
18
|
+
if (mutation.type === "childList") {
|
|
19
|
+
mutation.addedNodes.forEach(node => {
|
|
20
|
+
if (node.nodeType === 1) {
|
|
21
|
+
if (node.hasAttribute("data-adt-redraw-snippet")) {
|
|
22
|
+
applyEventHandlers(node);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
node.querySelectorAll('[data-adt-redraw-snippet]').forEach(child => {
|
|
26
|
+
applyEventHandlers(child);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
observer.observe(document.body, {
|
|
35
|
+
childList: true,
|
|
36
|
+
subtree: true,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
document.querySelectorAll('[data-adt-redraw-snippet]').forEach(function(el) {
|
|
40
|
+
applyEventHandlers(el);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default { run }
|