active_admin_jcrop 0.0.7 → 0.0.9

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
  SHA1:
3
- metadata.gz: 9e9fce20298ee9a26815ef13a02cbe86fe31aeac
4
- data.tar.gz: 5f215eaf265c9193974ddd7952beee004866c01e
3
+ metadata.gz: 4b03393f55f2e7881e3168b565fb83aedeb07594
4
+ data.tar.gz: 2ad93b59eb75b9e5d5a85625873b0506a2bb2ad6
5
5
  SHA512:
6
- metadata.gz: a9042855b869ae6f22d8423a86aa0094e59b22d153113242088738b1bb657a5d5322b409d0b166d2ac0aa7feda42fa1fb3b1442a477eac02283fba09576442ca
7
- data.tar.gz: 7e0154e0c0ff9a551cbd5b894755fa44f579fe6d7ca50b06f2b92dac95109584cb76b47f847b320d9a53cc52b1dac8a9b797abbc5780fa103bc28b267e4782e7
6
+ metadata.gz: 3740f7f1e85f17c8a25691a8918882897c6752422f0cd3746ed2f2d4c76103729d1a4777bf279cee1d9dd585d0ea5339f5b749f9544155fa9c2f6aca4c4d9645
7
+ data.tar.gz: 10ba7db5c5eaaaf992a4754477aa4acc89fe9adc2318fb20ebfd4b853cacaaf15bd41d3301fe65e9a4788da689d19439d517e0c8abd77cbb499d0c3d98ec5e90
@@ -44,14 +44,44 @@ window.active_admin_jcrop =
44
44
 
45
45
  }
46
46
  ]
47
- options = $.extend {onSelect: update_cropper, onChange: update_cropper }, image.data('jcropOptions')
48
- image.Jcrop(options)
47
+ options = $.extend {}, image.data('jcropOptions')
48
+ options.onSelect = (coords) ->
49
+ update_cropper(coords)
50
+ if image.data('jcropOptions').showDimensions
51
+ content.find('.crop_modal_dimensions').first().text("#{coords.w}x#{coords.h}")
52
+ if fn = image.data('jcropOptions').onSelect
53
+ if typeof fn is 'string'
54
+ window[fn] coords
55
+ else if typeof fn is 'function'
56
+ fn coords
57
+ return
58
+ options.onChange = (coords) ->
59
+ update_cropper(coords)
60
+ if image.data('jcropOptions').showDimensions
61
+ content.find('.crop_modal_dimensions').first().text("#{coords.w}x#{coords.h}")
62
+ if fn = image.data('jcropOptions').onChange
63
+ if typeof fn is 'string'
64
+ window[fn] coords
65
+ else if typeof fn is 'function'
66
+ fn coords
67
+ return
68
+ options.onRelease = ->
69
+ if fn = image.data('jcropOptions').onRelease
70
+ if typeof fn is 'string'
71
+ window[fn] coords
72
+ else if typeof fn is 'function'
73
+ fn coords
74
+ return
75
+ image.Jcrop(options)
76
+ return
49
77
 
50
78
  update_cropper = (coords) ->
51
79
  active_admin_jcrop.cropper.crop_x = coords.x
52
80
  active_admin_jcrop.cropper.crop_y = coords.y
53
81
  active_admin_jcrop.cropper.crop_w = coords.w
54
82
  active_admin_jcrop.cropper.crop_h = coords.h
83
+ return
84
+ return
55
85
 
56
86
  $ ->
57
87
  active_admin_jcrop.start()
@@ -1,3 +1,6 @@
1
+ .crop_modal_dimensions {
2
+ float: left;
3
+ }
1
4
  .crop_modal_content {
2
5
  display: none;
3
6
  overflow: scroll;
@@ -2,11 +2,12 @@
2
2
 
3
3
  <%= content_tag :div, class: "crop_modal_content" do %>
4
4
  <center>
5
+ <div class="crop_modal_dimensions"></div>
5
6
  <%= image_tag object.send(field).url, class: 'cropping_image', data: {
6
7
  object_class: object.class.to_s.underscore,
7
8
  object_id: object.id,
8
9
  crop_field: field,
9
- jcropper_url: send("jcropper_#{ActiveAdmin.application.default_namespace.to_s}_#{object.class.to_s.underscore}_path", object),
10
+ jcropper_url: send("jcropper_#{ActiveAdmin.application.default_namespace.to_s}_#{object.class.to_s.demodulize.underscore}_path", object),
10
11
  translate_save_cropped_image: I18n.t("active_admin.crop.save_cropped_image").titleize,
11
12
  translate_cancel: I18n.t("active_admin.crop.cancel").titleize,
12
13
  jcrop_options: jcrop_options.to_json
@@ -1,3 +1,3 @@
1
1
  module ActiveAdminJcrop
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -2,31 +2,46 @@ module Formtastic
2
2
  module Inputs
3
3
  class JcropableInput < ::Formtastic::Inputs::FileInput
4
4
  include Base
5
-
5
+
6
+ VALID_OPTIONS = %i(
7
+ aspectRatio
8
+ minSize
9
+ maxSize
10
+ setSelect
11
+ bgColor
12
+ bgOpacity
13
+ boxWidth
14
+ boxHeight
15
+ onSelect
16
+ onChange
17
+ onRelease
18
+ showDimensions
19
+ )
20
+
6
21
  def to_html
7
22
  input_wrapping do
8
23
  label_html <<
9
24
  builder.file_field(method, input_html_options) <<
10
25
  jcrop_feature
11
26
  end
12
- end
27
+ end
13
28
 
14
29
  private
15
30
 
16
31
  def jcrop_feature
17
32
  if @object.send(method).present?
18
- template.render(partial: "active_admin_jcrop/jcrop_modal", locals: {field: method, object: @object, jcrop_options: jcrop_options})
19
- else
33
+ template.render(partial: "active_admin_jcrop/jcrop_modal", locals: {field: method, object: @object, jcrop_options: jcrop_options})
34
+ else
20
35
  ''
21
36
  end
22
37
  end
23
38
 
24
39
  def jcrop_options
25
40
  options[:jcrop_options] ||= {}
26
- options[:jcrop_options].assert_valid_keys(:aspectRatio, :minSize, :maxSize, :setSelect, :bgColor, :bgOpacity, :boxWidth)
41
+ options[:jcrop_options].assert_valid_keys(*VALID_OPTIONS)
27
42
  options[:jcrop_options].reverse_merge!(setSelect: [0,0,100,100])
28
43
  end
29
44
 
30
45
  end
31
46
  end
32
- end
47
+ end
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin_jcrop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Nacif
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-07 00:00:00.000000000 Z
11
+ date: 2015-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -311,7 +311,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
311
311
  version: '0'
312
312
  requirements: []
313
313
  rubyforge_project:
314
- rubygems_version: 2.2.2
314
+ rubygems_version: 2.4.5
315
315
  signing_key:
316
316
  specification_version: 4
317
317
  summary: Jcrop plugin for ActiveAdmin, enable image cropping solution on image fields