vanilla_nested 1.6.1 → 1.6.2
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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/vanilla_nested.js +25 -28
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7d2002ba8ba1ccf4f6e749969bff008be4a64f2a30d2e3ec011947d1cf0956e
|
4
|
+
data.tar.gz: e0a2d6e189be30823c4a68a95fbc48fb07c83fb1b02e1e46b4cfa1f8cf2c2323
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a35ecfef2084cc706603b16a2ec45088d1d061a5007ea98ba2643769e21e6c4ea24b7f80b2057bbf80e33c5c01b0cfc52c84312b3bc16a248f65329a8a0bcd18
|
7
|
+
data.tar.gz: 372d0a1a456a17cd339fa95dcb7b65a8d16c9940acee89aeb5a803f15af0e73ff757f93b85a756dbbe9a64cc25dc8142d203b2331c8dc6f7fe171679e4622ee1
|
@@ -1,10 +1,7 @@
|
|
1
1
|
(function(){
|
2
2
|
// Get the html from the data attribute and insert the new fields on the container
|
3
3
|
// "event" is the click event of the link created by the rails helper
|
4
|
-
window.addVanillaNestedFields = function(
|
5
|
-
event.preventDefault();
|
6
|
-
|
7
|
-
let element = event.target;
|
4
|
+
window.addVanillaNestedFields = function(element) {
|
8
5
|
if (!element.classList.contains('vanilla-nested-add'))
|
9
6
|
element = element.closest('.vanilla-nested-add')
|
10
7
|
|
@@ -30,10 +27,6 @@
|
|
30
27
|
|
31
28
|
_dispatchEvent(container, 'vanilla-nested:fields-added', element, {added: inserted})
|
32
29
|
|
33
|
-
let removeLink = inserted.querySelector('.vanilla-nested-remove');
|
34
|
-
if (removeLink)
|
35
|
-
removeLink.addEventListener('click', removeVanillaNestedFields, true);
|
36
|
-
|
37
30
|
// dispatch an event if we reached the limit configured on the model
|
38
31
|
if (data.limit) {
|
39
32
|
let nestedElements = container.querySelectorAll('[name$="[_destroy]"][value="0"]').length;
|
@@ -44,10 +37,7 @@
|
|
44
37
|
|
45
38
|
// Removes the fields or hides them until the undo timer times out
|
46
39
|
// "event" is the click event of the link created by the rails helper
|
47
|
-
window.removeVanillaNestedFields = function(
|
48
|
-
event.preventDefault();
|
49
|
-
|
50
|
-
let element = event.target;
|
40
|
+
window.removeVanillaNestedFields = function(element) {
|
51
41
|
if (!element.classList.contains('vanilla-nested-remove'))
|
52
42
|
element = element.closest('.vanilla-nested-remove')
|
53
43
|
|
@@ -154,27 +144,34 @@
|
|
154
144
|
}
|
155
145
|
|
156
146
|
function initVanillaNested() {
|
157
|
-
document.
|
158
|
-
|
147
|
+
document.addEventListener('click', ev => {
|
148
|
+
const addVanillaNested =
|
149
|
+
ev.target.classList.contains('vanilla-nested-add') ||
|
150
|
+
ev.target.closest('.vanilla-nested-add');
|
151
|
+
|
152
|
+
if (addVanillaNested) {
|
153
|
+
ev.preventDefault();
|
154
|
+
addVanillaNestedFields(ev.target);
|
155
|
+
}
|
159
156
|
})
|
160
157
|
|
161
|
-
document.
|
162
|
-
|
158
|
+
document.addEventListener('click', ev => {
|
159
|
+
const removeVanillaNested =
|
160
|
+
ev.target.classList.contains('vanilla-nested-remove') ||
|
161
|
+
ev.target.closest('.vanilla-nested-remove');
|
162
|
+
|
163
|
+
if (removeVanillaNested) {
|
164
|
+
ev.preventDefault();
|
165
|
+
removeVanillaNestedFields(ev.target);
|
166
|
+
}
|
163
167
|
})
|
164
168
|
}
|
165
169
|
|
170
|
+
let vanillaNestedInitialized = false;
|
166
171
|
document.addEventListener('DOMContentLoaded', function(){
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
const notEmpty = (obj) => Object.keys(obj).length;
|
172
|
-
|
173
|
-
document.addEventListener('turbolinks:load', function(e){
|
174
|
-
if (notEmpty(e.data.timing)) initVanillaNested();
|
175
|
-
})
|
176
|
-
|
177
|
-
document.addEventListener('turbo:load', function(e){
|
178
|
-
if (notEmpty(e.detail.timing)) initVanillaNested();
|
172
|
+
if (!vanillaNestedInitialized) {
|
173
|
+
vanillaNestedInitialized = true;
|
174
|
+
initVanillaNested();
|
175
|
+
}
|
179
176
|
})
|
180
177
|
})()
|