best_in_place 3.0.3 → 3.1.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: 84ce49122f38b9152cae6c9ce661307dd0f3d528
4
- data.tar.gz: ad3e88ba32e9c656706661ef05e807f9fdfc7fb3
3
+ metadata.gz: 69cca3a71a33da7518f1fb792624d505c10e9018
4
+ data.tar.gz: 9782236c6e4508607b856b0690ef29abaef84780
5
5
  SHA512:
6
- metadata.gz: 1502b356495066e3c08541b068e8af62bd58bcc0c32d0ff84b5fdb570ffdd663fb9fa864ea2f78c77326ff0d359cf42b9819402a5052bf1245a5f47c19e11993
7
- data.tar.gz: db75bf52797e26f7bb11253b4cadaaaede87ec84d46dfe736bfead6960469c76bc10fa5fb7284f211241f48da035f63d792a1197a8d2d79cb84ab458eb31d3a5
6
+ metadata.gz: 9d5d31fa17f831062346c9b21e9eac994cf948fe551d2c5699dc43c69ae508421374a4281cf58e3ef1860504a6e80736ff2cbf7665e05e3961359d2757a79d3c
7
+ data.tar.gz: 5b4d5c558752d542e434060724909c356defa96932105e17d8b63d440562f1858a286714f131e68e97789d1f947b4b669b258bbbce65b6424ac2eb1e1704edf2
data/Appraisals CHANGED
@@ -1,10 +1,12 @@
1
1
  appraise "rails-3.2" do
2
2
  gem 'rails', github: "rails/rails", branch: '3-2-stable'
3
3
  gem 'strong_parameters'
4
+ gem 'test-unit'
4
5
  end
5
6
 
6
7
  appraise "rails-4.0" do
7
8
  gem "rails", github: "rails/rails", branch: '4-0-stable'
9
+ gem 'test-unit'
8
10
  end
9
11
 
10
12
  appraise "rails-4.1" do
@@ -18,4 +20,4 @@ end
18
20
  appraise "rails-edge" do
19
21
  gem "rails", github: "rails/rails"
20
22
  gem 'arel', github: 'rails/arel'
21
- end
23
+ end
@@ -1,4 +1,6 @@
1
1
  #Changelog
2
+ - unreleased
3
+ - add option[:skip_blur] to play nice with wysiwhtml5
2
4
 
3
5
  - v.3.0.3 :
4
6
  - Pass all callback arguments on $.ajax
@@ -15,14 +17,14 @@
15
17
  - Support all supported version of actionpack/rails
16
18
  - Dropped dependency on jquery gem
17
19
  - Namespaced all data attributes to avoid conflict.
18
- - Jquery-ui datepicker was extracted to best_in_place.jquery-ui.js
20
+ - Jquery-ui datepicker was extracted to best_in_place.jquery-ui.js
19
21
  - Added BestInPlaceEditor.defaults
20
22
  - Deprecated opts[:sanitize] in favor of option[:raw]
21
- - You have to require jquery.purr before best_in_place.purr
22
- - You have to require jquery-ui.datepicker before best_in_place.jquery-ui
23
+ - You have to require jquery.purr before best_in_place.purr
24
+ - You have to require jquery-ui.datepicker before best_in_place.jquery-ui
23
25
  - Added opts[:value] to set custom original-value
24
26
  - You can override the default container
25
-
27
+
26
28
  - v.2x : glitch in the Matrix
27
29
 
28
30
  - v.1.1.0 Changed $ by jQuery for compatibility (thanks @tschmitz), new
data/README.md CHANGED
@@ -11,8 +11,6 @@ Javascript file to the application it allows all the fields with the proper defi
11
11
 
12
12
  The editor works by PUTting the updated value to the server and GETting the updated record afterwards to display the updated value.
13
13
 
14
- [**SEE DEMO**](http://bipapp.heroku.com/)
15
-
16
14
  ---
17
15
 
18
16
  ##Installation
@@ -87,7 +85,7 @@ Options:
87
85
  - **:cancel_button**: (Inputs and textareas only) If set to a string, then a Cancel button will be shown with the string as its label.
88
86
  - **:cancel_button_class**: (Inputs and textareas only) Specifies any extra classes to set on the Cancel button.
89
87
  - **:sanitize**: True by default. If set to false the input/textarea will accept html tags.
90
- - **:html_attrs**: Hash of html arguments such as maxlength, default-value, etc. that will be set on the rendered input **not** the best_in_place span.
88
+ - **:html_attrs**: Hash of html arguments such as maxlength, default-value, etc. that will be set on the rendered input **not** the best_in_place span.
91
89
  - **:inner_class**: Class that is set to the rendered input.
92
90
  - **:display_as**: A **model** method which will be called in order to display this field. Cannot be used when using `display_with`.
93
91
  - **:display_with**: A **helper** method or proc will be called in order to display this field. Cannot be used with `display_as`.
@@ -97,9 +95,10 @@ Options:
97
95
  - **:value**: Customize the starting value of the inline input (defaults to to the field's value)
98
96
  - **:id**: The HTML id of the best_in_place span. If not specified one is automatically generated.
99
97
  - **:param**: If you wish to specific the object explicitly use this option.
100
- - **:confirm**: If set to true displays a confirmation message when abandoning changes (pressing the escape key);
98
+ - **:confirm**: If set to true displays a confirmation message when abandoning changes (pressing the escape key).
99
+ - **:skip_blur**: If set to true, blurring the input will not cause changes to be abandoned in textareas.
101
100
 
102
- HTML Options:
101
+ HTML Options:
103
102
 
104
103
  If you provide an option that is not explicitly a best_in_place option it will be passed through when creating the best_in_place span.
105
104
 
@@ -141,7 +140,7 @@ Examples (code in the views):
141
140
 
142
141
  <%= best_in_place @user, :name, :as => :input %>
143
142
 
144
- <%= best_in_place @user, :name, :as => :input, :nil => "Click me to add content!" %>
143
+ <%= best_in_place @user, :name, :as => :input, :place_holder => "Click me to add content!" %>
145
144
 
146
145
  ### Textarea
147
146
 
@@ -161,10 +160,15 @@ The value will always be converted to a string for display.
161
160
 
162
161
  ### Checkbox
163
162
 
164
- <%= best_in_place @user, :receive_emails, :as => :checkbox, :collection => ["No, thanks", "Yes, of course!"] %>
163
+ <%= best_in_place @user, :receive_emails, as: :checkbox, collection: ["No, thanks", "Yes, of course!"] %>
164
+ <%= best_in_place @user, :receive_emails, as: :checkbox, collection: {false: "Nope", true: "Yep"} %>
165
165
 
166
- The first value is always the negative boolean value and the second the positive. Structure: `["false value", "true value"]`.
166
+ If you use array as a collection, the first value is always the negative boolean value and the second the positive. Structure: `["false value", "true value"]`.
167
167
  If not defined, it will default to *Yes* and *No* options.
168
+ Default true and false values are stored in locales
169
+
170
+ t(:'best_in_place.yes', default: 'Yes')
171
+ t(:'best_in_place.no', default: 'No')
168
172
 
169
173
  ### Date
170
174
 
@@ -243,8 +247,8 @@ then bind to that class.
243
247
  <%= best_in_place @user, :name, :classes => 'highlight_on_success' %>
244
248
  <%= best_in_place @user, :mail, :classes => 'bounce_on_success' %>
245
249
 
246
- $('.highlight_on_success').bind("ajax:success", function(){$(this).closest('tr').effect('highlight'));});
247
- $('.bounce_on_success').bind("ajax:success", function(){$(this).closest('tr').effect('bounce'));});
250
+ $('.highlight_on_success').bind("ajax:success", function(){$(this).closest('tr').effect('highlight');});
251
+ $('.bounce_on_success').bind("ajax:success", function(){$(this).closest('tr').effect('bounce');});
248
252
 
249
253
  ### Providing data to the callback
250
254
 
@@ -328,6 +332,15 @@ And finally we need a controller:
328
332
 
329
333
  And this is how it is done!
330
334
 
335
+ ## Configuration
336
+
337
+ You can configure some global options for best_in_place. Currently these options are available:
338
+
339
+ BestInPlace.configure do |config|
340
+ config.container = :div
341
+ config.skip_blur = true
342
+ end
343
+
331
344
 
332
345
  ## Notification
333
346
 
@@ -18,6 +18,7 @@ gem "appraisal"
18
18
  gem "launchy"
19
19
  gem "rails", :github => "rails/rails", :branch => "3-2-stable"
20
20
  gem "strong_parameters"
21
+ gem "test-unit"
21
22
 
22
23
  platforms :mri_21 do
23
24
  gem "byebug"
@@ -17,6 +17,7 @@ gem "sqlite3"
17
17
  gem "appraisal"
18
18
  gem "launchy"
19
19
  gem "rails", :github => "rails/rails", :branch => "4-0-stable"
20
+ gem "test-unit"
20
21
 
21
22
  platforms :mri_21 do
22
23
  gem "byebug"
@@ -120,11 +120,11 @@ BestInPlaceEditor.prototype = {
120
120
  this.previousCollectionValue = value;
121
121
 
122
122
  // search for the text for the span
123
- editor.element.html(this.arrayToObject(this.values)[value]);
123
+ $.each(this.values, function(index, arr){ if (String(arr[0]) === String(value)) editor.element.html(arr[1]); });
124
124
  break;
125
125
 
126
126
  case "checkbox":
127
- editor.element.html(this.arrayToObject(this.values)[value]);
127
+ $.each(this.values, function(index, arr){ if (String(arr[0]) === String(value)) editor.element.html(arr[1]); });
128
128
  break;
129
129
 
130
130
  default:
@@ -140,6 +140,7 @@ BestInPlaceEditor.prototype = {
140
140
  }
141
141
 
142
142
  editor.element.data('bipValue', value);
143
+ editor.element.attr('data-bip-value', value);
143
144
 
144
145
  editor.element.trigger(jQuery.Event("best_in_place:update"));
145
146
 
@@ -173,6 +174,7 @@ BestInPlaceEditor.prototype = {
173
174
  self.okButtonClass = self.okButtonClass || $parent.data("bipOkButtonClass");
174
175
  self.cancelButton = self.cancelButton || $parent.data("bipCancelButton");
175
176
  self.cancelButtonClass = self.cancelButtonClass || $parent.data("bipCancelButtonClass");
177
+ self.skipBlur = self.skipBlur || $parent.data("bipSkipBlur");
176
178
  });
177
179
 
178
180
  // Load own attributes (overrides all others)
@@ -186,18 +188,19 @@ BestInPlaceEditor.prototype = {
186
188
  self.okButtonClass = self.element.data("bipOkButtonClass") || self.okButtonClass || BestInPlaceEditor.defaults.okButtonClass;
187
189
  self.cancelButton = self.element.data("bipCancelButton") || self.cancelButton;
188
190
  self.cancelButtonClass = self.element.data("bipCancelButtonClass") || self.cancelButtonClass || BestInPlaceEditor.defaults.cancelButtonClass;
189
-
191
+ self.skipBlur = self.element.data("bipSkipBlur") || self.skipBlur || BestInPlaceEditor.defaults.skipBlur;
192
+
190
193
  // Fix for default values of 0
191
194
  if (self.element.data("bipPlaceholder") == null) {
192
195
  self.placeHolder = BestInPlaceEditor.defaults.locales[''].placeHolder;
193
196
  } else {
194
197
  self.placeHolder = self.element.data("bipPlaceholder");
195
198
  }
196
-
199
+
197
200
  self.inner_class = self.element.data("bipInnerClass");
198
201
  self.html_attrs = self.element.data("bipHtmlAttrs");
199
202
  self.original_content = self.element.data("bipOriginalContent") || self.original_content;
200
-
203
+
201
204
  // if set the input won't be satinized
202
205
  self.display_raw = self.element.data("bip-raw");
203
206
 
@@ -220,6 +223,7 @@ BestInPlaceEditor.prototype = {
220
223
  'use strict';
221
224
  // TODO add placeholder for select and checkbox
222
225
  if (this.element.html() === "") {
226
+ this.element.addClass('bip-placeholder');
223
227
  this.element.html(this.placeHolder);
224
228
  }
225
229
  },
@@ -236,19 +240,6 @@ BestInPlaceEditor.prototype = {
236
240
  alert(BestInPlaceEditor.defaults.locales[''].uninitializedForm);
237
241
  },
238
242
 
239
- arrayToObject: function(list, values) {
240
- if (list == null) return {};
241
- var result = {};
242
- for (var i = 0, length = list.length; i < length; i++) {
243
- if (values) {
244
- result[list[i]] = values[i];
245
- } else {
246
- result[list[i][0]] = list[i][1];
247
- }
248
- }
249
- return result;
250
- },
251
-
252
243
  // Trim and Strips HTML from text
253
244
  sanitizeValue: function (s) {
254
245
  'use strict';
@@ -299,6 +290,7 @@ BestInPlaceEditor.prototype = {
299
290
  this.element.html(response.display_as);
300
291
  }
301
292
  }
293
+ this.element.toggleClass('bip-placeholder', this.isPlaceHolder());
302
294
 
303
295
  this.element.trigger(jQuery.Event("best_in_place:success"), [data, status, xhr]);
304
296
  this.element.trigger(jQuery.Event("ajax:success"), [data, status, xhr]);
@@ -469,15 +461,17 @@ BestInPlaceEditor.forms = {
469
461
  .attr('class', this.inner_class !== null ? this.inner_class : ''),
470
462
  currentCollectionValue = this.collectionValue,
471
463
  key, value,
472
- a = this.arrayToObject(this.values);
473
- for (key in a) {
474
- value = a[key];
464
+ a = this.values;
465
+
466
+ $.each(a, function(index, arr){
467
+ key = arr[0];
468
+ value = arr[1];
475
469
  var option_elt = jQuery(document.createElement('option'))
476
470
  .val(key)
477
471
  .html(value);
478
472
  if (String(key) === String(currentCollectionValue)) option_elt.attr('selected', 'selected');
479
473
  select_elt.append(option_elt);
480
- };
474
+ });
481
475
  output.append(select_elt);
482
476
 
483
477
  this.element.html(output);
@@ -493,9 +487,9 @@ BestInPlaceEditor.forms = {
493
487
  var e = document.createEvent("MouseEvents");
494
488
  e.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
495
489
  this.element.find("select")[0].dispatchEvent(e);
496
- }
490
+ }
497
491
  catch(e) {
498
- // browser doesn't support this, e.g. IE8
492
+ // browser doesn't support this, e.g. IE8
499
493
  }
500
494
  },
501
495
 
@@ -569,7 +563,9 @@ BestInPlaceEditor.forms = {
569
563
  this.element.find("input[type='button']").bind('click', {editor: this}, BestInPlaceEditor.forms.textarea.cancelButtonHandler);
570
564
  }
571
565
 
572
- this.element.find("textarea").bind('blur', {editor: this}, BestInPlaceEditor.forms.textarea.blurHandler);
566
+ if (!this.skipBlur) {
567
+ this.element.find("textarea").bind('blur', {editor: this}, BestInPlaceEditor.forms.textarea.blurHandler);
568
+ }
573
569
  this.element.find("textarea").bind('keyup', {editor: this}, BestInPlaceEditor.forms.textarea.keyupHandler);
574
570
  this.blurTimer = null;
575
571
  this.userClicked = false;
@@ -631,7 +627,8 @@ BestInPlaceEditor.defaults = {
631
627
  ajaxMethod: "put", //TODO Change to patch when support to 3.2 is dropped
632
628
  ajaxDataType: 'text',
633
629
  okButtonClass: '',
634
- cancelButtonClass: ''
630
+ cancelButtonClass: '',
631
+ skipBlur: false
635
632
  };
636
633
 
637
634
  // Default locale
@@ -14,10 +14,11 @@ module BestInPlace
14
14
  end
15
15
 
16
16
  class Configuration
17
- attr_accessor :container
17
+ attr_accessor :container, :skip_blur
18
18
 
19
19
  def initialize
20
20
  @container = :span
21
+ @skip_blur = false
21
22
  end
22
23
  end
23
24
 
@@ -1,7 +1,7 @@
1
1
  module BestInPlace
2
2
  module Helper
3
3
  def best_in_place(object, field, opts = {})
4
-
4
+
5
5
  best_in_place_assert_arguments(opts)
6
6
  type = opts[:as] || :input
7
7
  field = field.to_s
@@ -20,11 +20,8 @@ module BestInPlace
20
20
  if opts[:collection] or type == :checkbox
21
21
  collection = opts[:collection]
22
22
  value = value.to_s
23
- collection = if collection.blank?
24
- best_in_place_default_collection
25
- else
26
- best_in_place_collection_builder(type, collection)
27
- end
23
+ collection = best_in_place_default_collection if collection.blank?
24
+ collection = best_in_place_collection_builder(type, collection)
28
25
  display_value = collection.flat_map{|a| a[0].to_s == value ? a[1] : nil }.compact[0]
29
26
  collection = collection.to_json
30
27
  options[:data]['bip-collection'] = html_escape(collection)
@@ -49,6 +46,8 @@ module BestInPlace
49
46
  options[:data]['bip-cancel-button-class'] = opts[:cancel_button_class].presence
50
47
  options[:data]['bip-original-content'] = html_escape(opts[:value] || value).presence
51
48
 
49
+ options[:data]['bip-skip-blur'] = opts.has_key?(:skip_blur) ? opts[:skip_blur].presence : BestInPlace.skip_blur
50
+
52
51
  options[:data]['bip-url'] = url_for(opts[:url] || object)
53
52
 
54
53
  options[:data]['bip-confirm'] = opts[:confirm].presence
@@ -133,68 +132,47 @@ module BestInPlace
133
132
  end
134
133
  end
135
134
 
136
- def best_in_place_deprecated_options(args)
137
- if deprecated_option = args.delete(:path)
138
- args[:url] = deprecated_option
139
- ActiveSupport::Deprecation.warn('[Best_in_place] :path is deprecated in favor of :url ')
140
- end
141
-
142
- if deprecated_option = args.delete(:object_name)
143
- args[:param] = deprecated_option
144
- ActiveSupport::Deprecation.warn('[Best_in_place] :object_name is deprecated in favor of :param ')
145
- end
146
-
147
- if deprecated_option = args.delete(:type)
148
- args[:as] = deprecated_option
149
- ActiveSupport::Deprecation.warn('[Best_in_place] :type is deprecated in favor of :as ')
150
- end
151
-
152
- if deprecated_option = args.delete(:classes)
153
- args[:class] = deprecated_option
154
- ActiveSupport::Deprecation.warn('[Best_in_place] :classes is deprecated in favor of :class ')
135
+ def best_in_place_deprecated_options(opts)
136
+ deprecations = [
137
+ {from: :path, to: :url},
138
+ {from: :object_name, to: :param},
139
+ {from: :type, to: :as},
140
+ {from: :classes, to: :class},
141
+ {from: :nil, to: :place_holder},
142
+ {from: :use_confirm, to: :confirm},
143
+ {from: :sanitize, to: :raw}
144
+ ]
145
+
146
+ deprecations.each do |deprecation|
147
+ if deprecated_option = opts.delete(deprecation[:from])
148
+ opts[deprecation[:from]] = deprecated_option
149
+ ActiveSupport::Deprecation.warn("[Best_in_place] :#{deprecation[:from]} is deprecated in favor of :#{deprecation[:to]} ")
150
+ end
155
151
  end
152
+ end
156
153
 
157
- if deprecated_option = args.delete(:nil)
158
- args[:place_holder] = deprecated_option
159
- ActiveSupport::Deprecation.warn('[Best_in_place] :nil is deprecated in favor of :place_holder ')
160
- end
154
+ def best_in_place_collection_builder(type, collection)
155
+ return Array(collection) if collection.is_a?(Hash)
161
156
 
162
- if deprecated_option = args.delete(:use_confirm)
163
- args[:confirm] = deprecated_option
164
- ActiveSupport::Deprecation.warn('[Best_in_place] :use_confirm is deprecated in favor of :confirm ')
157
+ if type == :checkbox
158
+ best_in_place_collection_checkbox(collection)
159
+ else # :select
160
+ best_in_place_collection_select(collection)
165
161
  end
162
+ end
166
163
 
167
- if deprecated_option = args.delete(:sanitize)
168
- args[:raw] = !deprecated_option
169
- ActiveSupport::Deprecation.warn('[Best_in_place] :sanitize is deprecated in favor of :raw ')
164
+ def best_in_place_collection_checkbox(collection)
165
+ if collection.length == 2
166
+ [['false', collection[0]], ['true', collection[1]]]
167
+ else
168
+ fail ArgumentError, '[Best_in_place] :collection array should have 2 values'
170
169
  end
171
170
  end
172
171
 
173
- def best_in_place_collection_builder(type, collection)
174
- collection = case collection
175
- when Array
176
- if type == :checkbox
177
- if collection.length == 2
178
- {'false' => collection[0], 'true' => collection[1]}.stringify_keys
179
- else
180
- fail ArgumentError, '[Best_in_place] :collection array should have 2 values'
181
- end
182
- else # :select
183
- case collection[0]
184
- when Array
185
- collection
186
- else
187
- if collection[0].length == 2
188
- collection.to_a
189
- else
190
- collection.each_with_index.map{|a,i| [i+1,a]}
191
- end
192
- end
193
- end
194
- else
195
- collection.to_a
196
- end
197
- collection
172
+ def best_in_place_collection_select(collection)
173
+ return Array(collection) if collection[0].is_a?(Array) || collection[0].length == 2
174
+
175
+ collection.each_with_index.map { |a, i| [i+1, a] }
198
176
  end
199
177
 
200
178
  def best_in_place_default_collection
@@ -1,3 +1,3 @@
1
1
  module BestInPlace
2
- VERSION = '3.0.3'
2
+ VERSION = '3.1.0'
3
3
  end
@@ -31,6 +31,12 @@ describe BestInPlace::Helper, type: :helper do
31
31
  expect(span).not_to be_empty
32
32
  end
33
33
 
34
+ it "should show deprecation warning" do
35
+ expect(ActiveSupport::Deprecation).to receive(:warn).with("[Best_in_place] :path is deprecated in favor of :url ")
36
+
37
+ helper.best_in_place @user, :name, path: "http://example.com"
38
+ end
39
+
34
40
  it "should not allow both display_as and display_with option" do
35
41
  expect { helper.best_in_place(@user, :money, :display_with => :number_to_currency, :display_as => :custom) }.to raise_error(ArgumentError)
36
42
  end
@@ -141,7 +147,7 @@ describe BestInPlace::Helper, type: :helper do
141
147
  span = nk.css("span")
142
148
  expect(span.text).to eq("")
143
149
  end
144
-
150
+
145
151
  end
146
152
 
147
153
  it "should have the given inner_class" do
@@ -320,7 +326,7 @@ describe BestInPlace::Helper, type: :helper do
320
326
  end
321
327
 
322
328
  it "should have the default data-bip-collection" do
323
- expect(@span.attribute("data-bip-collection").value).to eq("{\"true\":\"Yes\",\"false\":\"No\"}")
329
+ expect(@span.attribute("data-bip-collection").value).to eq("[[\"true\",\"Yes\"],[\"false\",\"No\"]]")
324
330
  end
325
331
 
326
332
  it "should render the current option as No" do
@@ -355,8 +361,8 @@ describe BestInPlace::Helper, type: :helper do
355
361
  expect(@span.text).to eq("Net")
356
362
  end
357
363
 
358
- it "should render the proper data-bip-collection" do
359
- expect(@span.attribute("data-bip-collection").value).to eq({false: @good_collection[0], true: @good_collection[1]}.to_json)
364
+ it 'should render the proper data-bip-collection' do
365
+ expect(@span.attribute('data-bip-collection').value).to eq([['false', @good_collection[0]], ['true', @good_collection[1]]].to_json)
360
366
  end
361
367
 
362
368
  it "should raise an argument error on bad collection" do
@@ -480,24 +486,24 @@ describe BestInPlace::Helper, type: :helper do
480
486
  end
481
487
 
482
488
  end
483
-
489
+
484
490
  describe "with html parameters" do
485
491
  before do
486
492
  @attrs = {tabindex: 1, width: "300px", height: "24px"}
487
493
  nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name, @attrs)
488
494
  @span = nk.css("span")
489
495
  end
490
-
496
+
491
497
  it 'should pass through html attributes to the best_in_place span' do
492
498
  expect(@attrs.select {|key, value| @span.attribute(key.to_s) }).to eq(@attrs)
493
499
  end
494
-
500
+
495
501
  it 'should have the proper values set' do
496
502
  expect(@attrs.map {|key, value| @span.attribute(key.to_s).value }).to eq(@attrs.map {|key, value| value.to_s })
497
503
  end
498
-
504
+
499
505
  end
500
-
506
+
501
507
  end
502
508
 
503
509
  context 'custom container' do
@@ -521,6 +527,30 @@ describe BestInPlace::Helper, type: :helper do
521
527
  BestInPlace.container = @old_container
522
528
  end
523
529
  end
530
+
531
+ context '.configure' do
532
+ describe 'skip_blur' do
533
+ before(:each) do
534
+ @old_skip_blur = BestInPlace.skip_blur
535
+ @user.save
536
+ BestInPlace.skip_blur = true
537
+ end
538
+
539
+ after(:each) do
540
+ BestInPlace.skip_blur = @old_skip_blur
541
+ end
542
+
543
+ it 'should override blur globally' do
544
+ nk = Nokogiri::HTML.parse(helper.best_in_place(@user, :name))
545
+ expect(nk.css("span").attribute("data-bip-skip-blur").value).to eq("true")
546
+ end
547
+
548
+ it 'should use helper params' do
549
+ nk = Nokogiri::HTML.parse(helper.best_in_place(@user, :name, skip_blur: false))
550
+ expect(nk.css("span").attribute("data-bip-skip-blur")).to be_nil
551
+ end
552
+ end
553
+ end
524
554
  end
525
555
 
526
556
  describe "#best_in_place_if" do
@@ -111,6 +111,17 @@ describe "JS behaviour", :js => true do
111
111
  end
112
112
  end
113
113
 
114
+ it 'should update the DOM when a field value changes' do
115
+ @user.save!
116
+ visit user_path(@user)
117
+
118
+ expect(find('#receive_email')).to have_content('No thanks')
119
+
120
+ bip_bool @user, :receive_email
121
+
122
+ expect(page).to have_selector('#receive_email span[data-bip-value=true]')
123
+ end
124
+
114
125
  it "should be able to update last but one item in list" do
115
126
  @user.save!
116
127
  @user2 = User.create :name => "Test",
@@ -193,7 +204,7 @@ describe "JS behaviour", :js => true do
193
204
 
194
205
  expect(find('#country')).to have_content('Italy')
195
206
 
196
- bip_select @user, :country, "France"
207
+ bip_select @user, :country, 'France'
197
208
 
198
209
  expect(find('#country')).to have_content('France')
199
210
 
@@ -264,6 +275,22 @@ describe "JS behaviour", :js => true do
264
275
  expect(find('#birth_date')).to have_content(today.beginning_of_month.strftime('%d-%m-%Y'))
265
276
  end
266
277
 
278
+ it "should be able to use bip_bool to change the default boolean values" do
279
+ @user.save!
280
+ visit user_path(@user)
281
+
282
+
283
+ expect(find('#receive_email_default')).to have_content('No')
284
+
285
+ bip_bool @user, :receive_email_default
286
+
287
+ expect(find('#receive_email_default')).to have_content('Yes')
288
+
289
+ visit user_path(@user)
290
+
291
+ expect(find('#receive_email_default')).to have_content('Yes')
292
+ end
293
+
267
294
  it "should be able to use bip_bool to change a boolean value" do
268
295
  @user.save!
269
296
  visit user_path(@user)
@@ -17,6 +17,7 @@ class User < ActiveRecord::Base
17
17
 
18
18
  alias_attribute :money_custom, :money
19
19
  alias_attribute :money_value, :money
20
+ alias_attribute :receive_email_default, :receive_email
20
21
  alias_attribute :receive_email_image, :receive_email
21
22
  alias_attribute :description_simple, :description
22
23
 
@@ -52,10 +52,16 @@
52
52
  <%= best_in_place @user, :country, as: :select, :collection => @countries, :inner_class => :some_class %>
53
53
  </td>
54
54
  </tr>
55
+ <tr>
56
+ <td>Receive newsletter? (default display)</td>
57
+ <td id="receive_email_default">
58
+ <%= best_in_place @user, :receive_email_default, as: :checkbox %>
59
+ </td>
60
+ </tr>
55
61
  <tr>
56
62
  <td>Receive newsletter?</td>
57
63
  <td id="receive_email">
58
- <%= best_in_place @user, :receive_email, as: :checkbox, collection: {'false' => "No thanks", 'true' => "Yes of course"} %>
64
+ <%= best_in_place @user, :receive_email, as: :checkbox, collection: ['No thanks', 'Yes of course'] %>
59
65
  </td>
60
66
  </tr>
61
67
  <tr>
@@ -137,7 +143,7 @@
137
143
  <%= best_in_place @user, :zero_field, place_holder: 0 %>
138
144
  </td>
139
145
  </tr>
140
-
146
+
141
147
  </table>
142
148
  <br/>
143
149
  <hr/>
@@ -1,4 +1,4 @@
1
- COUNTRIES_HASH = { 1 => 'Spain', 2 => 'Italy', 3 => 'Germany', 4 => 'France' }
1
+ COUNTRIES_HASH = { 1 => 'Spain', 3 => 'Germany', 2 => 'Italy', 4 => 'France' }
2
2
  COUNTRIES_HASH_STRING_KEYS = { es: 'Spain', it: 'Italy', de: 'Germany', fr: 'France' }
3
3
  COUNTRIES_ARRAY = %w(Spain Italy Germany France)
4
4
  COUNTRIES_ARRAY_OF_ARRAYS = [[1, 'Spain'], [3, 'Germany'], [2, 'Italy'], [4, 'France']]
@@ -53,7 +53,7 @@
53
53
  // Set up the close button
54
54
  var close = document.createElement('a');
55
55
  jQuery(close).attr({
56
- class: 'close',
56
+ 'class': 'close',
57
57
  href: '#close'
58
58
  }).appendTo(notice).click(function() {
59
59
  removeNotice();
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: best_in_place
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernat Farrero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-26 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  version: '0'
159
159
  requirements: []
160
160
  rubyforge_project:
161
- rubygems_version: 2.2.2
161
+ rubygems_version: 2.4.8
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: It makes any field in place editable by clicking on it, it works for inputs,