dynamic_scaffold 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d38fc22e5839b2a4f2fda31b49b33750e787500a6d031d19e713bef0cf77019
4
- data.tar.gz: 5a40a274745f8f9f39e8928f5aa0063c188142a9b714593137e5b0a75d3ad09c
3
+ metadata.gz: 870a77249eb9787da82b0b1baa43e4c1a637bc4e87c1864492954f2ce98d5b71
4
+ data.tar.gz: 11fd6107a0974ba41efd2847056732ab9092dd4419e3da2b722b846064098fce
5
5
  SHA512:
6
- metadata.gz: 5a1bb89adddf8b3ad91d241cac6090f3e6bc9b8a58f6a2160f9f546529a62763451acf61230ebf0abfd166b4527dc6427ae3c659578b8035e2ff220704d1bba3
7
- data.tar.gz: 152ed6d4b6bacce23dd7eb49619211796bb6cc12b885677a59789714477028717b63deb74a9582911e5c695c36714c1f57f2cd7b4a23bcaba38d44b81386ad2e
6
+ metadata.gz: ef79f42adc0334b5ef1594f3adbf506d5c3f0772df4a11379bf69d89b9c11ae9987e62460b3c822489f7aa8c0ab08dc1c147b76cf3f39b4c4e47aba990ada451
7
+ data.tar.gz: 75cfb87526cddcee3608ef3df9c2d15e3885adc7a3caaad1388846c6777cc590cc6c4a88f777542520b475e8820122d5b77b908c9307263585698c17a301696b
@@ -6,7 +6,8 @@ document.addEventListener('dynamic_scaffold:load', function (){
6
6
  const preview = wrapper.querySelector('.js-ds-image-preview')
7
7
  const img = preview.querySelector('img')
8
8
  const cropper_input = wrapper.querySelector('.js-ds-image-cropper')
9
-
9
+ const cropper_display = wrapper.querySelector('.js-ds-image-cropper-display')
10
+
10
11
  // init preview display
11
12
  preview.style.display = 'inline-block'
12
13
 
@@ -28,19 +29,37 @@ document.addEventListener('dynamic_scaffold:load', function (){
28
29
  })
29
30
  }
30
31
 
31
- // change event
32
+
33
+ function initCropper(detail){
34
+ const options = JSON.parse(cropper_input.getAttribute('data-options'))
35
+ options.crop = function(event){
36
+ cropper_input.value = JSON.stringify(event.detail)
37
+ cropper_display.innerHTML = 'W:' + Math.round(event.detail.width) + ' x H:' + Math.round(event.detail.height)
38
+ }
39
+ options.ready = function(){
40
+ if(detail){
41
+ this.cropper.setData(detail)
42
+ }
43
+ }
44
+ const result = new Cropper(img, options)
45
+
46
+ return result
47
+ }
48
+
49
+
32
50
  var cropper = undefined
51
+ if(cropper_input && cropper_input.value){
52
+ cropper = initCropper(JSON.parse(cropper_input.value))
53
+ }
54
+
55
+ // change event
33
56
  input.addEventListener('change', function(e){
34
57
  const reader = new FileReader();
35
58
  reader.onload = function (e) {
36
59
  if(cropper) cropper.destroy()
37
60
  img.src = e.target.result
38
61
  if(cropper_input){
39
- const options = JSON.parse(cropper_input.getAttribute('data-options'))
40
- options.crop = function(event){
41
- cropper_input.value = JSON.stringify(event.detail)
42
- }
43
- cropper = new Cropper(img, options)
62
+ cropper = initCropper()
44
63
  }
45
64
 
46
65
  preview.style.display = 'inline-block'
@@ -30,9 +30,6 @@
30
30
  <% elsif elem.type? :carrierwave_image %>
31
31
  <%- image = form.object.public_send(elem.name) -%>
32
32
  <div class="js-ds-image-wrapper">
33
- <%- if elem.cropper.present? -%>
34
- <%= form.hidden_field "cropper_#{elem.name}", class: "js-ds-image-cropper", data:{options: elem.cropper.to_json} %>
35
- <%- end -%>
36
33
  <div class="js-ds-image-preview panel panel-default card mb-1">
37
34
  <% if elem.options[:removable] %>
38
35
  <div class="text-right panel-heading card-header">
@@ -42,6 +39,12 @@
42
39
  </div>
43
40
  <% end %>
44
41
  <div class="panel-body card-body">
42
+ <%- if elem.cropper.present? -%>
43
+ <%= form.hidden_field "cropper_#{elem.name}", class: "js-ds-image-cropper", data:{options: elem.cropper.to_json} %>
44
+ <div class="text-right" style="height: 24px;">
45
+ <span class="js-ds-image-cropper-display badge badge-primary"></span>
46
+ </div>
47
+ <%- end -%>
45
48
  <div style="<%= elem.preview_image_style %>">
46
49
  <img src="<%= image.url if image.file.present? %>" alt="" class="img-responsive img-fluid">
47
50
  </div>
@@ -1,3 +1,3 @@
1
1
  module DynamicScaffold
2
- VERSION = '0.8.1'.freeze
2
+ VERSION = '0.8.2'.freeze
3
3
  end
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: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masamoto Miyata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-25 00:00:00.000000000 Z
11
+ date: 2018-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: classnames-rails-view