vanilla_nested 1.4.0 → 1.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d47f68290b80623181ca454d3c30088e5c8178f6b7846b01affdbf07ec51e94
4
- data.tar.gz: 20a430b78106da4df2220667b05b9ef0e14172768750b4e198b6642cf1689470
3
+ metadata.gz: 5058319d40fc1193fff7a37443ed4f295ae7c11bcf5d51540c50916441010fb0
4
+ data.tar.gz: ac1c6ed4857206ea7d24b3ef4ad873e2e1c1e1befdf57b286a361d561d9fe270
5
5
  SHA512:
6
- metadata.gz: 94bc333d6a5ba8949068ff25a77f76eb4073bd0fe91bffea4cae5fa9865edbaaa274ed98618b5c532898073673e7709bbb6dc9abadfe84c29259eace7bf16f05
7
- data.tar.gz: 979c5c4f836a8dc4685723a3226864f8d0b8a11c5df08ed4a78a228afa7f1199e907adac3f45c8c99d8671937c4bd5fe8052a10f2f717cf462c14fc5a2ce6ccb
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
- if (sel = data.fieldsWrapperSelector) wrapper = element.closest(sel);
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 => child.style.display = 'initial');
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 => child.style.display = 'none');
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
- if (classes = data.undoLinkClasses)
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
  })()
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanilla_nested
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ariel Juodziukynas <arieljuod@gmail.com>