vanilla_nested 1.4.0 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/vanilla_nested.js +25 -5
- data/lib/vanilla_nested.rb +6 -0
- 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: 5058319d40fc1193fff7a37443ed4f295ae7c11bcf5d51540c50916441010fb0
|
4
|
+
data.tar.gz: ac1c6ed4857206ea7d24b3ef4ad873e2e1c1e1befdf57b286a361d561d9fe270
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b336496c74a33d2b7771fe8b9e0579374a273e9461c9d755570d56fa760e82a407677a840eedf27fbe5b8772351b42de5809df8d841a61236af0b1ed60019798
|
7
|
+
data.tar.gz: 1ef398b2dfc1dae51001379360f1ad816e43df2d1fec24f40e4cd6fc869f65df75eab0da128aa66800d639d21c1eb9e74e68dba56888b3a4cdc37b915bf92925
|
@@ -53,7 +53,8 @@
|
|
53
53
|
|
54
54
|
const data = element.dataset;
|
55
55
|
let wrapper = element.parentElement;
|
56
|
-
|
56
|
+
const sel = data.fieldsWrapperSelector;
|
57
|
+
if (sel) wrapper = element.closest(sel);
|
57
58
|
|
58
59
|
if (data.undoTimeout) {
|
59
60
|
hideFieldsWithUndo(wrapper, element);
|
@@ -81,14 +82,28 @@
|
|
81
82
|
// Unhides the children given a fields wrapper
|
82
83
|
// "wrapper" is the wrapper of the link to remove fields
|
83
84
|
function unhideFields(wrapper) {
|
84
|
-
[...wrapper.children].forEach(child =>
|
85
|
+
[...wrapper.children].forEach(child => {
|
86
|
+
if (child.dataset.hasAttributeStyle) {
|
87
|
+
child.style.display = child.dataset.originalDisplay;
|
88
|
+
} else {
|
89
|
+
child.removeAttribute("style");
|
90
|
+
}
|
91
|
+
});
|
85
92
|
}
|
86
93
|
|
87
94
|
// Hides an element and adds an "undo" link to unhide it
|
88
95
|
// "wrapper" is the wrapper to hide
|
89
96
|
// "element" is the link to remove the wrapper
|
90
97
|
function hideFieldsWithUndo(wrapper, element) {
|
91
|
-
[...wrapper.children].forEach(child =>
|
98
|
+
[...wrapper.children].forEach(child => {
|
99
|
+
// store original style for after undo
|
100
|
+
if (child.getAttribute("style")) {
|
101
|
+
child.dataset.hasAttributeStyle = true;
|
102
|
+
child.dataset.originalDisplay = child.style.display;
|
103
|
+
}
|
104
|
+
|
105
|
+
child.style.display = 'none';
|
106
|
+
});
|
92
107
|
|
93
108
|
// add the 'undo' link with it's callback
|
94
109
|
const undoLink = _createUndoWithElementsData(element.dataset);
|
@@ -129,7 +144,8 @@
|
|
129
144
|
const undo = document.createElement('A');
|
130
145
|
|
131
146
|
undo.classList.add('vanilla-nested-undo');
|
132
|
-
|
147
|
+
const classes = data.undoLinkClasses;
|
148
|
+
if (classes)
|
133
149
|
undo.classList.add(...classes.split(' '));
|
134
150
|
|
135
151
|
undo.innerText = data.undoText;
|
@@ -151,10 +167,14 @@
|
|
151
167
|
initVanillaNested();
|
152
168
|
})
|
153
169
|
|
154
|
-
// Don't run turbolinks event callback for first load, we already do it with DOMContentLoaded
|
170
|
+
// Don't run turbolinks/turbo event callback for first load, we already do it with DOMContentLoaded
|
155
171
|
const notEmpty = (obj) => Object.keys(obj).length;
|
156
172
|
|
157
173
|
document.addEventListener('turbolinks:load', function(e){
|
158
174
|
if (notEmpty(e.data.timing)) initVanillaNested();
|
159
175
|
})
|
176
|
+
|
177
|
+
document.addEventListener('turbo:load', function(e){
|
178
|
+
if (notEmpty(e.detail.timing)) initVanillaNested();
|
179
|
+
})
|
160
180
|
})()
|
data/lib/vanilla_nested.rb
CHANGED
@@ -9,5 +9,11 @@ module VanillaNested
|
|
9
9
|
ActionView::Base.send :include, VanillaNested::ViewHelpers
|
10
10
|
end
|
11
11
|
end
|
12
|
+
|
13
|
+
initializer "vanilla_nested.assets" do
|
14
|
+
if Rails.application.config.respond_to?(:assets)
|
15
|
+
Rails.application.config.assets.precompile += %w( vanilla_nested.js )
|
16
|
+
end
|
17
|
+
end
|
12
18
|
end
|
13
19
|
end
|