paper_cropper 0.0.3 → 0.0.4

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: bb38a063d00da380ab37d233baac25f9823b7311
4
- data.tar.gz: 03272e89f0479ac96037200e8232f1e014179e82
3
+ metadata.gz: 7629c8e9811d613f894aa4300c2e78b515c31b5a
4
+ data.tar.gz: 081ca60672ff1b4161984c908e75ffbdb0672fba
5
5
  SHA512:
6
- metadata.gz: 27d4ae20dee2532ab20ec09f55e11abf7b66f5b472eae48d6eb59a59ed5de62da1cd23a4d36a5e1b9c5e4a2c30be324c6eed97e50684541092b6484c7004e5a6
7
- data.tar.gz: 4ae4577f753ab92c730333b995367560dab86fe4a0a116182637a2d168084f2ffc1dcd38b06b0c86418f23c254256a3fd0970ab6b7110b7985ccd149fbf808be
6
+ metadata.gz: ba14300199a193190faede4e930867146c8ea5d75f8eebe3f618f0501afca5a0a98ed212738404fa16734cab00144a0ef34ac017ac031e494d9d0185439e557c
7
+ data.tar.gz: 8226250fb09a2c213df5ca0944add0010b470161d59a3a194eb0400326416a79a7d9af06b9605bed574521c6e441b5e833d2fec86d7c30c209a5833de8b1e93e
data/README.md CHANGED
@@ -30,7 +30,7 @@ crop_attached_file :cover, aspect: false
30
30
  Take care of permitted params. Add the following fields to ```permitted``` strong attributes:
31
31
 
32
32
  ```ruby
33
- params.require(:model).permit(:cover, :cover_crop_x, :cover_crop_y, :cover_crop_width, :cover_crop_height)
33
+ params.require(:model).permit(:cover, :cover_crop_x, :cover_crop_y, :cover_crop_width, :cover_crop_height, :cover_crop_ratio)
34
34
  ```
35
35
 
36
36
  ## javascripts
@@ -89,6 +89,7 @@ for example:
89
89
  <input class="crop-image-value-y" type="hidden" name="cover_crop_y" value="">
90
90
  <input class="crop-image-value-width" type="hidden" name="cover_crop_width" value="">
91
91
  <input class="crop-image-value-height" type="hidden" name="cover_crop_height" value="">
92
+ <input class="crop-image-value-ratio" type="hidden" name="cover_crop_ratio" value="">
92
93
 
93
94
  <!-- [required] Wrap the image or canvas element with a block element (container) -->
94
95
  <div class="crop-image-wrapper">
@@ -16,6 +16,7 @@
16
16
  <input class="crop-image-value-y" type="hidden" name="cover_crop_y" value="">
17
17
  <input class="crop-image-value-width" type="hidden" name="cover_crop_width" value="">
18
18
  <input class="crop-image-value-height" type="hidden" name="cover_crop_height" value="">
19
+ <input class="crop-image-value-ratio" type="hidden" name="cover_crop_ratio" value="">
19
20
 
20
21
  <!-- File input for change the image -->
21
22
  <input class="crop-image-file-input" type="file">
@@ -46,6 +47,7 @@ function PaperCropper(container, opt) {
46
47
  this.inputY = $(container).find('.crop-image-value-y');
47
48
  this.inputWidth = $(container).find('.crop-image-value-width');
48
49
  this.inputHeight = $(container).find('.crop-image-value-height');
50
+ this.inputRatio = $(container).find('.crop-image-value-ratio');
49
51
 
50
52
  var aspect = $(container).attr('data-crop-image-range');
51
53
  if( isNaN(aspect) ) {
@@ -54,6 +56,10 @@ function PaperCropper(container, opt) {
54
56
  this.aspect = parseFloat(aspect);
55
57
  }
56
58
 
59
+ if ( isNaN(this.inputRatio.val()) ) {
60
+ this.inputRatio.val(1);
61
+ }
62
+
57
63
  this.init();
58
64
  }
59
65
 
@@ -78,6 +84,9 @@ PaperCropper.prototype.init = function() {
78
84
  crop: function(event){
79
85
  that.cropperCrop(event);
80
86
  },
87
+ zoom: function (event) {
88
+ that.cropperZomm(event);
89
+ },
81
90
  built: function() {
82
91
  console.log('cropper build')
83
92
  that.cropperBuild();
@@ -109,7 +118,7 @@ PaperCropper.prototype.init = function() {
109
118
  /** Callback method used when cropper are full loaded */
110
119
  PaperCropper.prototype.cropperBuild = function() {
111
120
  // set initial values
112
- this.setCropperData(this.inputX.val(), this.inputY.val(), this.inputWidth.val(), this.inputHeight.val());
121
+ this.setCropperData(this.inputX.val(), this.inputY.val(), this.inputWidth.val(), this.inputHeight.val(), this.inputRatio.val());
113
122
  }
114
123
 
115
124
  /** Callback method used when the user changes the crop */
@@ -122,6 +131,12 @@ PaperCropper.prototype.cropperCrop = function (event) {
122
131
  this.inputHeight.val(parseInt(event.detail.height));
123
132
  }
124
133
 
134
+ PaperCropper.prototype.cropperZomm = function (event) {
135
+ console.log('zoom:', event.detail)
136
+ console.log('zoom crop data:',this.cropper.getData())
137
+ this.inputRatio.val(parseFloat(event.detail.ratio));
138
+ }
139
+
125
140
  /** Callback method used when the user changes the file */
126
141
  PaperCropper.prototype.fileInputChange = function (event) {
127
142
  var input = event.target;
@@ -136,7 +151,8 @@ PaperCropper.prototype.fileInputChange = function (event) {
136
151
  }
137
152
 
138
153
  /** Set the cropper data */
139
- PaperCropper.prototype.setCropperData = function (x, y, width, height) {
154
+ PaperCropper.prototype.setCropperData = function (x, y, width, height, ratio) {
155
+ this.cropper.zoomTo(parseFloat(ratio));
140
156
  this.cropper.setData({
141
157
  'x': parseInt(x),
142
158
  'y': parseInt(y),
@@ -15,6 +15,7 @@ module PaperCropper
15
15
  out << form_helper.hidden_field(:"#{attachment_name}_crop_y", class: 'crop-image-value-y')
16
16
  out << form_helper.hidden_field(:"#{attachment_name}_crop_width", class: 'crop-image-value-width')
17
17
  out << form_helper.hidden_field(:"#{attachment_name}_crop_height", class: 'crop-image-value-height')
18
+ out << form_helper.hidden_field(:"#{attachment_name}_crop_ratio", class: 'crop-image-value-ratio')
18
19
 
19
20
  out << form_helper.file_field(attachment_name, class: 'crop-image-file-input', label_col: "col-sm-3", control_col: "col-sm-9")
20
21
 
@@ -84,8 +84,8 @@ module PaperCropper
84
84
  ["#{attachment_name}_name", "#{attachment_name}_content_type",
85
85
  "#{attachment_name}_file_size", "#{attachment_name}_updated_at",
86
86
  "#{attachment_name}_crop_x", "#{attachment_name}_crop_y",
87
- "#{attachment_name}_crop_width",
88
- "#{attachment_name}_crop_height"
87
+ "#{attachment_name}_crop_width", "#{attachment_name}_crop_height",
88
+ "#{attachment_name}_crop_ratio"
89
89
  ].any? { |attr|
90
90
  method= "#{attr}_changed?".to_sym
91
91
  if respond_to?(method)
@@ -6,7 +6,8 @@ module PaperCropper
6
6
  crop_x: :integer,
7
7
  crop_y: :integer,
8
8
  crop_width: :integer,
9
- crop_height: :integer
9
+ crop_height: :integer,
10
+ crop_ratio: [:decimal, {precision: 8, scale: 4}]
10
11
  }
11
12
 
12
13
  #
@@ -18,8 +19,10 @@ module PaperCropper
18
19
  options = attachment_names.extract_options!
19
20
 
20
21
  attachment_names.each do |attachment_name|
21
- COLUMNS.each_pair do |column_name, column_type|
22
- column_options = options.merge(options[column_name.to_sym] || {})
22
+ COLUMNS.each_pair do |column_name, column_definition|
23
+ column_type, default_options = column_definition
24
+ custom_options = options.merge(options[column_name.to_sym] || {})
25
+ column_options = (default_options || {}).merge(custom_options)
23
26
  add_column(table_name, "#{attachment_name}_#{column_name}", column_type, column_options)
24
27
  end
25
28
  end
@@ -42,8 +45,10 @@ module PaperCropper
42
45
  def crop_attachment(*attachment_names)
43
46
  options = attachment_names.extract_options!
44
47
  attachment_names.each do |attachment_name|
45
- COLUMNS.each_pair do |column_name, column_type|
46
- column_options = options.merge(options[column_name.to_sym] || {})
48
+ COLUMNS.each_pair do |column_name, column_definition|
49
+ column_type, default_options = column_definition
50
+ custom_options = options.merge(options[column_name.to_sym] || {})
51
+ column_options = (default_options || {}).merge(custom_options)
47
52
  column("#{attachment_name}_#{column_name}", column_type, column_options)
48
53
  end
49
54
  end
@@ -2,6 +2,13 @@ module PaperCropper
2
2
  # Changelog based on Semantic Versioning: http://semver.org
3
3
  # REMEMBER: Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable.
4
4
 
5
+ unless defined?(PaperCropper::VERSION)
6
+ VERSION = '0.0.4'.freeze
7
+ end
8
+
9
+ # 0.0.4 PATCH
10
+ # [FIX] Remember ratio attribute used to zoom in and out.
11
+
5
12
  # 0.0.3 PATCH
6
13
  # [FIX] Invalid method call when invoking attachment_changed?.
7
14
  # [DOC] Improve README.
@@ -11,7 +18,4 @@ module PaperCropper
11
18
  # [FEATURE] Added ActiveRecord extensions to force attachment updated_at field to be setted
12
19
  # on every attachment change.
13
20
 
14
- unless defined?(PaperCropper::VERSION)
15
- VERSION = '0.0.3'.freeze
16
- end
17
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_cropper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coditramuntana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-27 00:00:00.000000000 Z
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails