sibu 0.6.9 → 0.7.0

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: 11718eee8d05389ba6c3e54992c419d06e87039f
4
- data.tar.gz: 64985305666f99c3f52636d5447a37389044b0f5
3
+ metadata.gz: b9ddba74b9a3e07f92b235acc1e3e55296b4a089
4
+ data.tar.gz: 3bf94af416c1228aa9f9f2f364ff1ebfafdba401
5
5
  SHA512:
6
- metadata.gz: ef9befafde933e52bdcd6617efb75385d79e7cd7c075fab9fa6e0d04396840e4131d858180b1ac5f7c0a52cef9737fe3bef600e6104399dfb318a10289cd8490
7
- data.tar.gz: 2cb79f2f07fb033870f71f38f4975c3ce757f584e65fc872bd12c7cb27a84cb87859c0f275b18d0f137598e9b7991bd7cf61f799b1e8b88e65962bc6a0eab2b1
6
+ metadata.gz: 9feac3ec7a28165c73edb37cd9c2c3dc47e2a81b8b7efbfab5253fc87e3fc12c3f44fa19f1ba0f653e2e93dc7ce7521ddce3b3153ae8091019809a958acfb9b6
7
+ data.tar.gz: 24c55a51899aa8c68b7fda529dfa50b469a14a072df6a86329c8adfffd633bd83271fc407b9a7239c9639d76ca59dfba41b6cfaa81b26f7a810fa912b6911b20
@@ -2,7 +2,6 @@
2
2
  //= require jquery_ujs
3
3
  //= require sibu/common
4
4
  //= require ../quill/quill
5
- //= require ../cropper/cropper
6
5
  //= require_self
7
6
 
8
7
  var Inline = Quill.import('blots/inline');
@@ -110,31 +109,61 @@ function initQuillEditor(container) {
110
109
  return quill;
111
110
  }
112
111
 
113
- function initCropper(imgId) {
114
- var wrapper = $(".sibu_crop").first();
115
- var srcImg = $("#content_panel").find(".sb-editing img[data-id='" + imgId + "']").first();
116
- var srcContainer = srcImg.parent();
117
- var ratio = parseFloat(srcContainer.css("width")) / parseFloat(wrapper.css("width"));
118
- var wrapperHeight = Math.min(320, parseFloat(srcContainer.css("height")) / ratio) + "px";
119
- wrapper.css("height", wrapperHeight);
120
- return new Cropper(wrapper.find("img")[0], {
121
- crop: function(event) {
122
- var data = event.detail;
123
- var cropper = this.cropper;
124
- var imageData = cropper.getImageData();
125
- var previewWidth = parseFloat(srcContainer.css("width"));
126
- var imageScaledRatio = data.width / previewWidth;
127
- var width = imageData.naturalWidth / imageScaledRatio + 'px';
128
- var height = imageData.naturalHeight / imageScaledRatio + 'px';
129
- var marginLeft = -data.x / imageScaledRatio + 'px';
130
- var marginTop = -data.y / imageScaledRatio + 'px';
131
- // console.log("crop detail : " + JSON.stringify(data));
132
- // console.log('img data : ' + JSON.stringify(imageData));
133
- $("#element_style").val("width: " + width + "; height: " + height + "; margin-left: " + marginLeft + "; margin-top: " + marginTop +"; max-width: none; max-height: none;");
134
- }
135
- });
112
+ function initCustomCenter() {
113
+ var wrapper = $(".sibu_center > img"), centerPos = $(".sibu_center > #sibu_center_pos");
114
+ displayCurrentCenter(wrapper[0], centerPos);
115
+ wrapper.click(function(e) {
116
+ var rect = e.target.getBoundingClientRect();
117
+ var x = e.clientX - rect.left;
118
+ var y = e.clientY - rect.top;
119
+ console.log('x : ' + x + ' - y : ' + y);
120
+ centerPos.css("top", y + "px");
121
+ centerPos.css("left", x + "px");
122
+ $("#element_class").val(`posx_${Math.floor((x / rect.width) * 10) * 10} posy_${Math.floor((y / rect.height) * 10) * 10}`);
123
+ })
124
+ }
125
+
126
+ function displayCurrentCenter(img, centerPos) {
127
+ var val = $("#element_class").val();
128
+ var rect = img.getBoundingClientRect();
129
+ if (val && val.indexOf('posx') !== -1 && val.indexOf('posy') !== -1) {
130
+ var xpos = val.slice(val.indexOf("posx_") + 5, val.indexOf("posx_") + 7);
131
+ var ypos = val.slice(val.indexOf("posy_") + 5, val.indexOf("posy_") + 7);
132
+ centerPos.css("top", Math.round(+ypos * (rect.height / 100)) + "px");
133
+ centerPos.css("left", Math.round(+xpos * (rect.width / 100)) + "px");
134
+ } else {
135
+ centerPos.css("top", (Math.round(rect.height / 2) - 15) + "px");
136
+ centerPos.css("left", (Math.round(rect.width / 2) - 7) + "px");
137
+ }
138
+ centerPos.show();
136
139
  }
137
140
 
141
+
142
+ //function initCropper(imgId) {
143
+ // var wrapper = $(".sibu_crop").first();
144
+ // var srcImg = $("#content_panel").find(".sb-editing img[data-id='" + imgId + "']").first();
145
+ // var srcContainer = srcImg.parent();
146
+ // var ratio = parseFloat(srcContainer.css("width")) / parseFloat(wrapper.css("width"));
147
+ // var wrapperHeight = Math.min(320, parseFloat(srcContainer.css("height")) / ratio) + "px";
148
+ // wrapper.css("height", wrapperHeight);
149
+ // return new Cropper(wrapper.find("img")[0], {
150
+ // crop: function(event) {
151
+ // var data = event.detail;
152
+ // var cropper = this.cropper;
153
+ // var imageData = cropper.getImageData();
154
+ // var previewWidth = parseFloat(srcContainer.css("width"));
155
+ // var imageScaledRatio = data.width / previewWidth;
156
+ // var width = imageData.naturalWidth / imageScaledRatio + 'px';
157
+ // var height = imageData.naturalHeight / imageScaledRatio + 'px';
158
+ // var marginLeft = -data.x / imageScaledRatio + 'px';
159
+ // var marginTop = -data.y / imageScaledRatio + 'px';
160
+ // // console.log("crop detail : " + JSON.stringify(data));
161
+ // // console.log('img data : ' + JSON.stringify(imageData));
162
+ // $("#element_style").val("width: " + width + "; height: " + height + "; margin-left: " + marginLeft + "; margin-top: " + marginTop +"; max-width: none; max-height: none;");
163
+ // }
164
+ // });
165
+ //}
166
+
138
167
  function refreshAfterEdit(reload, sectionId) {
139
168
  var baseUrl = window.location.href.split('?')[0];
140
169
  if (reload) {
@@ -207,6 +207,19 @@ $sibu-color3 : #333 !default;
207
207
  font-weight: bold;
208
208
  }
209
209
  }
210
+
211
+ .sibu_center {
212
+ position: relative;
213
+
214
+ #sibu_center_pos {
215
+ position: absolute;
216
+ z-index: 3;
217
+ font-size: 20px;
218
+ font-weight: bold;
219
+ color: white;
220
+ text-shadow: 0 2px grey;
221
+ }
222
+ }
210
223
  }
211
224
 
212
225
  #editor-container .ql-editor {
@@ -1,6 +1,5 @@
1
1
  /*
2
2
  *= require ../quill/quill.snow
3
- *= require ../cropper/cropper
4
3
  *= require_self
5
4
  */
6
5
 
@@ -74,9 +74,10 @@ module Sibu
74
74
  if action_name == 'show'
75
75
  content["src"] = ("/#{conf[:deployment_path]}" + content["src"]) if @online && conf[:deployment_path]
76
76
  else
77
- opts.merge!({data: {id: elt_id(elt), type: "media", repeat: repeat, size: size}}) if action_name != 'show'
77
+ opts.merge!({data: {id: elt_id(elt), type: "media", repeat: repeat, size: size}})
78
78
  end
79
- wrapper ? content_tag(wrapper, content_tag(:img, nil, content.except("id")), opts) : content_tag(:img, nil, content.except("id").merge(opts))
79
+ wrapper ? content_tag(wrapper, content_tag(:img, nil, content.except("id")), opts)
80
+ : content_tag(:img, nil, content.except("id").merge(opts.stringify_keys) {|k, old, new| k == 'class' ? [old, new].join(' ') : new})
80
81
  end
81
82
 
82
83
  def grp(elt, opts = {}, &block)
@@ -11,10 +11,8 @@ class Sibu::ImageUploader < Shrine
11
11
  images_config = Rails.application.config.sibu[:images]
12
12
  image_type = io.mime_type
13
13
 
14
- if image_type == "image/svg+xml"
15
-
14
+ if image_type == "image/svg+xml" || io.metadata['filename'].end_with?('.svg')
16
15
  {original: io, large: io.download, medium: io.download, small: io.download}
17
-
18
16
  else
19
17
  large = resize_to_limit!(original, images_config[:large], images_config[:large]) {|cmd| cmd.auto_orient}
20
18
  medium = resize_to_limit(large, images_config[:medium], images_config[:medium])
@@ -17,3 +17,7 @@ module Sibu
17
17
  end
18
18
  end
19
19
  end
20
+
21
+ # ['beds-green.svg', 'camp-white.svg', 'doc-green.svg', 'doc-white.svg', 'earth-white.svg', 'family-sec_blue.svg',
22
+ # 'family-white.svg', 'flag.svg', 'hands-green.svg', 'home-green.svg', 'house-white.svg', 'marker.svg', 'men-green.svg',
23
+ # 'money-blue.svg', 'money-green.svg', 'quotes.svg', 'tel-green.svg', 'tel-white.svg', 'tv-green.svg']
@@ -19,12 +19,13 @@
19
19
  <% if @element["src"] == DEFAULT_IMG || @element["src"].blank? %>
20
20
  <p>Veuillez sélectionner une image.</p>
21
21
  <% end %>
22
- <div class="sibu_is_cropped" style="display: <%= (@element["src"] == DEFAULT_IMG || @element["src"].blank?) ? 'none' : 'block' %>">
23
- <%= check_box_tag('is_cropped', true, !@element["style"].blank?, id: 'is_cropped', class: 'checkbox') %>
24
- <%= label_tag 'is_cropped', "Recadrer l'image" %>
22
+ <div class="sibu_custom_center" style="display: <%= (@element["src"] == DEFAULT_IMG || @element["src"].blank?) ? 'none' : 'block' %>">
23
+ <%= check_box_tag('custom_center', true, !@element["class"].blank?, id: 'custom_center', class: 'checkbox') %>
24
+ <%= label_tag 'custom_center', "Recentrer l'image" %>
25
25
  </div>
26
- <div class="sibu_crop">
26
+ <div class="sibu_center">
27
27
  <%= image_tag(@element["src"]) unless @element["src"] == DEFAULT_IMG || @element["src"].blank? %>
28
+ <div id="sibu_center_pos" style="display: none;">✕</div>
28
29
  </div>
29
30
  <div class="sibu_field" style="display: <%= (@element["src"] == DEFAULT_IMG || @element["src"].blank?) ? 'none' : 'block' %>">
30
31
  <%= label_tag 'element[alt]', 'Légende / texte alternatif' %>
@@ -34,7 +35,7 @@
34
35
  </div>
35
36
  <%= hidden_field_tag 'element[id]', @element["id"] %>
36
37
  <%= hidden_field_tag 'element[src]', @element["src"] %>
37
- <%= hidden_field_tag 'element[style]', @element["style"] %>
38
+ <%= hidden_field_tag 'element[class]', @element["class"] %>
38
39
  <%= hidden_field_tag :element_id, @element_id %>
39
40
  <%= hidden_field_tag :section_id, @section_id %>
40
41
  <%= hidden_field_tag :entity, @entity_type %>
@@ -39,36 +39,36 @@ editPanel.slideDown("fast", function() {
39
39
  });
40
40
  <% when 'media' %>
41
41
  var images = editPanel.find(".sibu_image img");
42
- var isCropped = $("#is_cropped"), cropper;
42
+ var customCenter = $("#custom_center"), customCtr;
43
43
  images.click(function() {
44
44
  if(!$(this).hasClass('selected')) {
45
45
  images.removeClass('selected');
46
46
  $(this).addClass('selected');
47
47
  $("#element_src").val($(this).data("src"));
48
48
  $("#element_alt").val($(this).data("alt"));
49
- editPanel.find(".sibu_crop").html('<img src="' + $("#element_src").val() + '"/>');
49
+ editPanel.find(".sibu_center").html('<img src="' + $("#element_src").val() + '"/>');
50
50
  editPanel.find(".sibu_selected_image > p:first-child").hide();
51
- editPanel.find(".sibu_selected_image").find(".sibu_is_cropped").show();
51
+ editPanel.find(".sibu_selected_image").find(".sibu_custom_center").show();
52
52
  editPanel.find(".sibu_selected_image").find(".sibu_field").show();
53
- if(isCropped.is(":checked")) {
54
- cropper = initCropper("<%= @element_id %>");
53
+ if(customCenter.is(":checked")) {
54
+ customCtr = initCustomCenter();
55
55
  }
56
56
  }
57
57
  });
58
- if(editPanel.find(".sibu_crop img").size() > 0) {
59
- if(isCropped.is(":checked")) {
60
- cropper = initCropper("<%= @element_id %>");
58
+ if(editPanel.find(".sibu_center img").size() > 0) {
59
+ if(customCenter.is(":checked")) {
60
+ customCtr = initCustomCenter("<%= @element_id %>");
61
61
  }
62
62
  }
63
- isCropped.change(function() {
63
+ customCenter.change(function() {
64
64
  if($(this).is(":checked")) {
65
- cropper = initCropper("<%= @element_id %>");
65
+ customCtr = initCustomCenter("<%= @element_id %>");
66
66
  } else {
67
67
  $("#element_style").val("");
68
- $(".sibu_crop").attr("style", "");
69
- if(cropper) {
70
- cropper.destroy();
71
- }
68
+ $(".sibu_center").attr("style", "");
69
+ // if(cropper) {
70
+ // cropper.destroy();
71
+ // }
72
72
  }
73
73
  });
74
74
  <% when 'link' %>
@@ -1,3 +1,3 @@
1
1
  module Sibu
2
- VERSION = '0.6.9'
2
+ VERSION = '0.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sibu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Baptiste Vilain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-02 00:00:00.000000000 Z
11
+ date: 2018-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails