dynamic_scaffold 1.11.0 → 1.12.0

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: fa5ec9c069fde80c1ee44d34bafe454d67c1b8e9ad291175b65f2174d4fedd73
4
- data.tar.gz: d23f8d2d63c3657288a1c1ac1b76fd81c68720b60e8d22d0ba986d52b1f4b610
3
+ metadata.gz: c42e88067995f3753891fcc0e2a29aa8a8b8fd7ff9b093780f20455db67eb731
4
+ data.tar.gz: 1872ac09ed02e4a0524e7bc0d26900d1e493596bcafe47b177bfda380e741d9a
5
5
  SHA512:
6
- metadata.gz: cdc7b66a1db5b926895223a02a37fe69db8a4d1dd0f765f80419fe2b185956d9b8f519180baaa4f7fce692840ac754d03557c58853f8333d374adc582cc71115
7
- data.tar.gz: a915af903ec7fa690bb03922146306f30664547e2644ad806b846107008495b20f0b6a2142fcd5fa413f28a3678e39f4a90b3c94a83c2da92aaa9c8cede871c6
6
+ metadata.gz: 9f893ff9dbb40db07c63c6929c11ccae374ac17e82621bf8f878325b7b2393da1f7ffc12e354ccac152579b8f888d2c66780179c015be4cb361bfa9e7837835b
7
+ data.tar.gz: d2ce03bded48b344d364a737b38bed3a4aa4129b431189fcb213092c5385652cb148513aaef7bb4070ee62b53d3edd42225405335d1357947ddec65a7a374c42
@@ -3,3 +3,4 @@
3
3
  //= require dynamic_scaffold/pagination
4
4
  //= require dynamic_scaffold/sorter
5
5
  //= require dynamic_scaffold/image
6
+ //= require dynamic_scaffold/auto_width
@@ -0,0 +1,32 @@
1
+ var calcWidth = function(){
2
+ var firstRow = document.querySelector('.js-ds-list-row:first-child')
3
+
4
+ var wrapperWidth = firstRow.clientWidth
5
+
6
+ var autoWidthItemIndexes = Array.prototype.filter.call(firstRow.querySelectorAll('.js-ds-list-item'), function(item){
7
+ return item.classList.contains('ds-auto-width')
8
+ }).map(function(item){
9
+ return parseInt(item.getAttribute('data-index'), 10)
10
+ })
11
+
12
+ autoWidthItemIndexes.forEach(function(index){
13
+ var items = document.querySelectorAll('.js-ds-list-item[data-index="' + index + '"]')
14
+
15
+ Array.prototype.forEach.call(items, function(item){
16
+ item.style.width = 'auto'
17
+ })
18
+
19
+ var maxWidth = Array.prototype.reduce.call(items, function(currentMax, item){
20
+ return Math.max(currentMax, item.offsetWidth)
21
+ }, 0)
22
+
23
+ maxWidth = Math.min(maxWidth, wrapperWidth)
24
+
25
+ Array.prototype.forEach.call(items, function(item){
26
+ item.style.width = maxWidth + 'px'
27
+ })
28
+ })
29
+ }
30
+
31
+ document.addEventListener('dynamic_scaffold:load', calcWidth)
32
+ document.addEventListener('dynamic_scaffold:window_resized', calcWidth)
@@ -13,6 +13,7 @@ if (window.Element && !Element.prototype.closest) {
13
13
  };
14
14
  }
15
15
 
16
+ // dynamic_scaffold:load
16
17
  (function(){
17
18
  var fireEvent = function(){
18
19
  var event = document.createEvent("HTMLEvents");
@@ -25,7 +26,25 @@ if (window.Element && !Element.prototype.closest) {
25
26
  // Not fire after the initial page load
26
27
  if (e.data.timing.visitEnd) fireEvent()
27
28
  })
28
- })()
29
+ })();
30
+
31
+
32
+ // dynamic_scaffold:window_resized
33
+ (function(){
34
+ var fireEvent = function(){
35
+ var event = document.createEvent("HTMLEvents");
36
+ event.initEvent('dynamic_scaffold:window_resized', false, false)
37
+ document.dispatchEvent(event)
38
+ }
39
+
40
+ var timeout = 0
41
+ window.addEventListener('resize', function(e){
42
+ this.clearTimeout(timeout)
43
+ timeout = setTimeout(function(){
44
+ fireEvent()
45
+ }, 300)
46
+ })
47
+ })();
29
48
 
30
49
  // promise polyfill
31
50
  // IE 11 has no Promise? Are you kidding?
@@ -38,9 +38,9 @@
38
38
  <div class="ds-list-heading"><%= dynamic_scaffold.list.title(record) %></div>
39
39
  <% end %>
40
40
  <div class="ds-list-items">
41
- <%dynamic_scaffold.list.items.each do |disp|%>
41
+ <%dynamic_scaffold.list.items.each_with_index do |disp, index|%>
42
42
  <%- if disp.show?(self, record) -%>
43
- <%= content_tag :div, class: class_names('ds-list-item', disp.classnames), **disp.html_attributes do%>
43
+ <%= content_tag :div, class: class_names('ds-list-item js-ds-list-item', disp.classnames), **{**disp.html_attributes, 'data-index': index} do%>
44
44
  <div class="ds-list-label"><%= disp.label %></div>
45
45
  <div class="ds-list-value"><%= disp.value self, record %></div>
46
46
  <%end%>
@@ -1,3 +1,3 @@
1
1
  module DynamicScaffold
2
- VERSION = '1.11.0'.freeze
2
+ VERSION = '1.12.0'.freeze
3
3
  end
@@ -62,7 +62,7 @@ class <%= @class_scope.present? ? "#{@class_scope}::" : '' %><%= @plural_model_n
62
62
  # Please see https://github.com/gomo/dynamic_scaffold#customize-list for details.
63
63
 
64
64
  <%- @model.column_names.each do |column| -%>
65
- config.list.item(:<%= column %>, style: 'width: 120px;')
65
+ config.list.item(:<%= column %>, class: 'ds-auto-width')
66
66
  <%- end -%>
67
67
 
68
68
  # You can customize the form fields through `config.form`.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masamoto Miyata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-23 00:00:00.000000000 Z
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: classnames-rails-view
@@ -252,6 +252,7 @@ files:
252
252
  - app/assets/images/dynamic_scaffold/fontawesome/step-forward.svg
253
253
  - app/assets/images/dynamic_scaffold/fontawesome/times.svg
254
254
  - app/assets/javascripts/dynamic_scaffold.js
255
+ - app/assets/javascripts/dynamic_scaffold/auto_width.js
255
256
  - app/assets/javascripts/dynamic_scaffold/common.js
256
257
  - app/assets/javascripts/dynamic_scaffold/delete.js
257
258
  - app/assets/javascripts/dynamic_scaffold/image.js