bootsy 2.0.3 → 2.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: 0213f918a5956944c5acf8b19c39b19d7a8139c3
4
- data.tar.gz: 1dc567550503b2daa0105d46261a6b0ec7164bd1
3
+ metadata.gz: c1ddff8c40bea449166a32a7552f45057683c2c7
4
+ data.tar.gz: efabca1e49324f70720f65e55d2d16c8074b1018
5
5
  SHA512:
6
- metadata.gz: 68014bbb2ad7a158a58e2d0fb95b60e560cded6304677fb6f9d4a07313138d460ebd5e1ad1b41aeac547c9d5444b862c80b0d2f2700e907628f9baa408953423
7
- data.tar.gz: 4cd2263f8df331ec3dc7ce7df519db0c1632c2bb4181e86d97f6180efb34623a44aa9eae756b2788e687f07b1c88ab075b378cd2e5bc5f7c031a064dc162fe6d
6
+ metadata.gz: a92ff11d4e8587e2b3dc45a60878c09e061597619ee4ecdc2dc1d262045167f718e5f5c81dc2eba4075655c85222f8088a69e135c42b734518b65e8bfc089d8b
7
+ data.tar.gz: 8db257d88f60e9236ff75411bc1af7488c6e8705d1208c4c32cb796d37c8d76595369f47c2c4a409c82c9593225fe6e5024a9e75837cac64d639c3dfb6f22be6
@@ -1,10 +1,11 @@
1
1
  window.Bootsy = window.Bootsy || {};
2
2
 
3
3
  Bootsy.Area = function($el) {
4
- this.$el = $el;
5
- this.modal = $el.siblings('.bootsy-modal');
6
- this.locale = $el.data('bootsy-locale') || $('html').attr('lang') || 'en';
4
+ this.$el = $el;
5
+ this.modal = $el.siblings('.bootsy-modal');
6
+ this.locale = $el.data('bootsy-locale') || $('html').attr('lang') || 'en';
7
7
  this.unsavedChanges = false;
8
+ this.initialized = false;
8
9
 
9
10
  this.options = {
10
11
  locale: this.locale,
@@ -189,90 +190,96 @@ Bootsy.Area.prototype.setImageGalleryId = function(id) {
189
190
 
190
191
  // Init components
191
192
  Bootsy.Area.prototype.init = function() {
192
- var insert = this.insertImage.bind(this);
193
-
194
- if ((this.options.image === true) && (this.options.uploader === true)) {
195
- this.modal.on('click', '.bootsy-image .insert', function(e) {
196
- var img, imageObject;
197
- var imagePrefix = '/' + $(this).attr('data-image-size') + '_';
198
-
199
- if ($(this).data('image-size') === 'original') {
200
- imagePrefix = '/';
201
- }
202
-
203
- img = $(this).parents('.bootsy-image').find('img');
204
-
205
- imageObject = {
206
- src: img.attr('src').replace('/thumb_', imagePrefix),
207
- alt: img.attr('alt').replace('Thumb_', '')
193
+ var insert;
194
+
195
+ if (!this.initialized) {
196
+ insert = this.insertImage.bind(this);
197
+
198
+ if ((this.options.image === true) && (this.options.uploader === true)) {
199
+ this.modal.on('click', '.bootsy-image .insert', function(e) {
200
+ var img, imageObject;
201
+ var imagePrefix = '/' + $(this).attr('data-image-size') + '_';
202
+
203
+ if ($(this).data('image-size') === 'original') {
204
+ imagePrefix = '/';
205
+ }
206
+
207
+ img = $(this).parents('.bootsy-image').find('img');
208
+
209
+ imageObject = {
210
+ src: img.attr('src').replace('/thumb_', imagePrefix),
211
+ alt: img.attr('alt').replace('Thumb_', '')
212
+ };
213
+
214
+ imageObject.align = $(this).data('position');
215
+
216
+ insert(imageObject);
217
+ });
218
+
219
+ // Let's use the uploader, not the static image modal
220
+ this.options.image = false;
221
+ this.options.customCommand = true;
222
+ this.options.customCommandCallback = this.openImagesModal.bind(this);
223
+ this.options.customTemplates = {
224
+ customCommand: function(locale, options) {
225
+ var size = (options && options.size) ? ' btn-'+options.size : '';
226
+
227
+ return '<li>' +
228
+ '<a class="btn btn-default ' + size + '" data-wysihtml5-command="customCommand" title="' + locale.image.insert + '" tabindex="-1">' +
229
+ '<span class="glyphicon glyphicon-picture"></span>' +
230
+ '</a>' +
231
+ '</li>';
232
+ }
208
233
  };
209
234
 
210
- imageObject.align = $(this).data('position');
235
+ // In order to avoid form nesting
236
+ this.modal.parents('form').after(this.modal);
211
237
 
212
- insert(imageObject);
213
- });
238
+ this.modal.on('click', 'a[href="#refresh-gallery"]', this.setImageGallery.bind(this));
214
239
 
215
- // Let's use the uploader, not the static image modal
216
- this.options.image = false;
217
- this.options.customCommand = true;
218
- this.options.customCommandCallback = this.openImagesModal.bind(this);
219
- this.options.customTemplates = {
220
- customCommand: function(locale, options) {
221
- var size = (options && options.size) ? ' btn-'+options.size : '';
240
+ this.modal.on('ajax:before', '.destroy-btn', this.showGalleryLoadingAnimation.bind(this));
222
241
 
223
- return '<li>' +
224
- '<a class="btn btn-default ' + size + '" data-wysihtml5-command="customCommand" title="' + locale.image.insert + '" tabindex="-1">' +
225
- '<span class="glyphicon glyphicon-picture"></span>' +
226
- '</a>' +
227
- '</li>';
228
- }
229
- };
242
+ this.modal.on('ajax:success', '.destroy-btn', function(evt, data) {
243
+ this.deleteImage(data.id);
244
+ }.bind(this));
230
245
 
231
- // In order to avoid form nesting
232
- this.modal.parents('form').after(this.modal);
246
+ this.modal.on('ajax:success', '.bootsy-upload-form', function(evt, data) {
247
+ this.setImageGalleryId(data.gallery_id);
248
+ this.addImage(data.image);
249
+ this.setUploadForm(data.form);
250
+ }.bind(this));
251
+ }
233
252
 
234
- this.modal.on('click', 'a[href="#refresh-gallery"]', this.setImageGallery.bind(this));
253
+ this.editor = this.$el.wysihtml5($.extend(Bootsy.options, this.options)).data('wysihtml5').editor;
235
254
 
236
- this.modal.on('ajax:before', '.destroy-btn', this.showGalleryLoadingAnimation.bind(this));
255
+ // Mechanism for unsaved changes alert
256
+ if (this.options.alertUnsavedChanges !== false) {
257
+ window.onbeforeunload = this.unsavedChangesAlert.bind(this);
258
+ }
237
259
 
238
- this.modal.on('ajax:success', '.destroy-btn', function(evt, data) {
239
- this.deleteImage(data.id);
240
- }.bind(this));
260
+ this.$el.closest('form').submit(function(e) {
261
+ this.unsavedChanges = false;
241
262
 
242
- this.modal.on('ajax:success', '.bootsy-upload-form', function(evt, data) {
243
- this.setImageGalleryId(data.gallery_id);
244
- this.addImage(data.image);
245
- this.setUploadForm(data.form);
263
+ return true;
246
264
  }.bind(this));
247
- }
248
265
 
249
- this.editor = this.$el.wysihtml5($.extend(Bootsy.options, this.options)).data('wysihtml5').editor;
250
-
251
- // Mechanism for unsaved changes alert
252
- if (this.options.alertUnsavedChanges !== false) {
253
- window.onbeforeunload = this.unsavedChangesAlert.bind(this);
254
- }
255
-
256
- this.$el.closest('form').submit(function(e) {
257
- this.unsavedChanges = false;
258
-
259
- return true;
260
- }.bind(this));
266
+ this.editor.on('change', function() {
267
+ this.unsavedChanges = true;
268
+ }.bind(this));
261
269
 
262
- this.editor.on('change', function() {
263
- this.unsavedChanges = true;
264
- }.bind(this));
270
+ this.modal.modal({ show: false });
265
271
 
266
- this.modal.modal({ show: false });
272
+ this.modal.on('shown.bs.modal', function() {
273
+ if (this.modal.data('gallery-loaded') !== true) {
274
+ this.setImageGallery();
275
+ }
276
+ }.bind(this));
267
277
 
268
- this.modal.on('shown.bs.modal', function() {
269
- if (this.modal.data('gallery-loaded') !== true) {
270
- this.setImageGallery();
271
- }
272
- }.bind(this));
278
+ this.modal.on('hide.bs.modal', this.editor.currentView.element.focus);
273
279
 
274
- this.modal.on('hide.bs.modal', this.editor.currentView.element.focus);
280
+ this.hideRefreshButton();
281
+ this.hideEmptyAlert();
275
282
 
276
- this.hideRefreshButton();
277
- this.hideEmptyAlert();
283
+ this.initialized = true;
284
+ }
278
285
  };
@@ -1,13 +1,19 @@
1
1
  window.Bootsy = window.Bootsy || {};
2
2
 
3
3
  Bootsy.init = function() {
4
- Bootsy.areas = [];
4
+ Bootsy.areas = {};
5
5
 
6
- $('textarea.bootsy_text_area').each(function() {
6
+ $('textarea.bootsy_text_area').filter(':visible').each(function(index) {
7
7
  var area = new Bootsy.Area($(this));
8
+ var areaIdx = $(this).attr('id') || index;
9
+
10
+ if(Bootsy.areas[areaIdx] !== undefined) {
11
+ areaIdx = $(this).attr('id') + index;
12
+ }
13
+
8
14
  area.init();
9
15
 
10
- Bootsy.areas.push(area);
16
+ Bootsy.areas[areaIdx] = area;
11
17
  });
12
18
  };
13
19
 
@@ -1,7 +1,7 @@
1
1
  module Bootsy
2
2
  module FormBuilder
3
3
  def bootsy_area method, options = {}
4
- @template.bootsy_area @object, method, options.merge(object: @object)
4
+ @template.bootsy_area @object_name, method, objectify_options(options)
5
5
  end
6
6
  end
7
7
  end
@@ -1,21 +1,22 @@
1
1
  module Bootsy
2
2
  module FormHelper
3
- def bootsy_area(object, method, options = {})
3
+ def bootsy_area(object_name, method, options = {})
4
+ object = options[:object]
4
5
  container = options.delete(:container)
5
- bootsy_options = Bootsy.editor_options.merge(options.delete(:editor_options) || {})
6
6
 
7
+ bootsy_options = Bootsy.editor_options.merge(options.delete(:editor_options) || {})
7
8
  bootsy_options[:uploader] = enable_uploader?(object, options.delete(:uploader), container)
8
9
 
9
- options[:data] = data_options(options, bootsy_options)
10
+ options[:data] = data_options(options, bootsy_options)
10
11
  options[:class] = class_attr(options)
11
12
 
12
- output = self.text_area(object_name(object), method, options)
13
+ output = self.text_area(object_name, method, options)
13
14
 
14
15
  if bootsy_options[:uploader]
15
16
  output += self.render 'bootsy/images/modal', { container: container || object }
16
17
 
17
18
  if container.blank? || (container == object)
18
- output += self.hidden_field(object_name(object), :bootsy_image_gallery_id, class: 'bootsy_image_gallery_id')
19
+ output += self.hidden_field(object_name, :bootsy_image_gallery_id, class: 'bootsy_image_gallery_id')
19
20
  end
20
21
  end
21
22
 
@@ -27,7 +28,7 @@ module Bootsy
27
28
  def enable_uploader?(object, uploader, container)
28
29
  if uploader == false
29
30
  false
30
- elsif container.is_a? Container
31
+ elsif container.is_a?(Container)
31
32
  true
32
33
  elsif container.blank? && object.is_a?(Container)
33
34
  true
@@ -48,14 +49,6 @@ module Bootsy
48
49
  classes << 'bootsy_text_area'
49
50
  end
50
51
 
51
- def object_name(object)
52
- if object.is_a?(String) || object.is_a?(Symbol)
53
- object
54
- else
55
- ActiveModel::Naming.param_key(object.class)
56
- end
57
- end
58
-
59
52
  def data_options(options, bootsy_options)
60
53
  (options[:data] || {}).merge Hash[ bootsy_options.map { |k,v| ["bootsy-#{k}", v] } ]
61
54
  end
@@ -1,3 +1,3 @@
1
1
  module Bootsy
2
- VERSION = '2.0.3'
2
+ VERSION = '2.0.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootsy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volmer Soares
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-17 00:00:00.000000000 Z
11
+ date: 2013-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick
@@ -52,90 +52,6 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.2.1
55
- - !ruby/object:Gem::Dependency
56
- name: rspec-rails
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '2.14'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: '2.14'
69
- - !ruby/object:Gem::Dependency
70
- name: factory_girl_rails
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ~>
74
- - !ruby/object:Gem::Version
75
- version: '4.2'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ~>
81
- - !ruby/object:Gem::Version
82
- version: '4.2'
83
- - !ruby/object:Gem::Dependency
84
- name: database_cleaner
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ~>
88
- - !ruby/object:Gem::Version
89
- version: '1.2'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ~>
95
- - !ruby/object:Gem::Version
96
- version: '1.2'
97
- - !ruby/object:Gem::Dependency
98
- name: cucumber-rails
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ~>
102
- - !ruby/object:Gem::Version
103
- version: '1.4'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ~>
109
- - !ruby/object:Gem::Version
110
- version: '1.4'
111
- - !ruby/object:Gem::Dependency
112
- name: shoulda-matchers
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ~>
116
- - !ruby/object:Gem::Version
117
- version: '2.4'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ~>
123
- - !ruby/object:Gem::Version
124
- version: '2.4'
125
- - !ruby/object:Gem::Dependency
126
- name: selenium-webdriver
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ~>
130
- - !ruby/object:Gem::Version
131
- version: '2.37'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ~>
137
- - !ruby/object:Gem::Version
138
- version: '2.37'
139
55
  description: A beautiful WYSIWYG editor with image uploads for Rails.
140
56
  email:
141
57
  - volmerius@gmail.com