best_in_place 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,7 +46,7 @@ BestInPlaceEditor.prototype = {
46
46
  }
47
47
  }
48
48
 
49
- var elem = this.isNil ? "-" : this.sanitize ? this.element.text() : this.element.html();
49
+ var elem = this.isNil ? "-" : this.element.html();
50
50
  this.oldValue = elem;
51
51
  this.display_value = to_display;
52
52
  jQuery(this.activator).unbind("click", this.clickHandler);
@@ -55,8 +55,8 @@ BestInPlaceEditor.prototype = {
55
55
  },
56
56
 
57
57
  abort : function() {
58
- if (this.isNil) this.element.text(this.nil);
59
- else this.element.text(this.oldValue);
58
+ if (this.isNil) this.element.html(this.nil);
59
+ else this.element.html(this.oldValue);
60
60
  jQuery(this.activator).bind('click', {editor: this}, this.clickHandler);
61
61
  this.element.trigger(jQuery.Event("best_in_place:abort"));
62
62
  this.element.trigger(jQuery.Event("best_in_place:deactivate"));
@@ -101,7 +101,11 @@ BestInPlaceEditor.prototype = {
101
101
  } else if (this.formType == "checkbox") {
102
102
  editor.element.html(this.getValue() ? this.values[1] : this.values[0]);
103
103
  } else {
104
- editor.element.text(this.getValue() !== "" ? this.getValue() : this.nil);
104
+ if (this.getValue() !== "") {
105
+ editor.element.text(this.getValue());
106
+ } else {
107
+ editor.element.html(this.nil);
108
+ }
105
109
  }
106
110
  editor.element.trigger(jQuery.Event("best_in_place:update"));
107
111
  },
@@ -184,7 +188,7 @@ BestInPlaceEditor.prototype = {
184
188
  if (this.element.text() === "")
185
189
  {
186
190
  this.isNil = true;
187
- this.element.text(this.nil);
191
+ this.element.html(this.nil);
188
192
  }
189
193
  },
190
194
 
@@ -225,7 +229,7 @@ BestInPlaceEditor.prototype = {
225
229
  if (response !== null && response.hasOwnProperty("display_as")) {
226
230
  this.element.attr("data-original-content", this.element.text());
227
231
  this.original_content = this.element.text();
228
- this.element.text(response["display_as"]);
232
+ this.element.html(response["display_as"]);
229
233
  }
230
234
  this.element.trigger(jQuery.Event("ajax:success"), data);
231
235
 
@@ -240,7 +244,7 @@ BestInPlaceEditor.prototype = {
240
244
  },
241
245
 
242
246
  loadErrorCallback : function(request, error) {
243
- this.element.text(this.oldValue);
247
+ this.element.html(this.oldValue);
244
248
 
245
249
  this.element.trigger(jQuery.Event("best_in_place:error"), [request, error])
246
250
  this.element.trigger(jQuery.Event("ajax:error"));
@@ -273,11 +277,11 @@ BestInPlaceEditor.prototype = {
273
277
  BestInPlaceEditor.forms = {
274
278
  "input" : {
275
279
  activateForm : function() {
276
- var output = $(document.createElement('form'))
280
+ var output = jQuery(document.createElement('form'))
277
281
  .addClass('form_in_place')
278
282
  .attr('action', 'javascript:void(0);')
279
283
  .attr('style', 'display:inline');
280
- var input_elt = $(document.createElement('input'))
284
+ var input_elt = jQuery(document.createElement('input'))
281
285
  .attr('type', 'text')
282
286
  .attr('name', this.attributeName)
283
287
  .val(this.display_value);
@@ -287,14 +291,14 @@ BestInPlaceEditor.forms = {
287
291
  output.append(input_elt);
288
292
  if(this.okButton) {
289
293
  output.append(
290
- $(document.createElement('input'))
294
+ jQuery(document.createElement('input'))
291
295
  .attr('type', 'submit')
292
296
  .attr('value', this.okButton)
293
297
  )
294
298
  }
295
299
  if(this.cancelButton) {
296
300
  output.append(
297
- $(document.createElement('input'))
301
+ jQuery(document.createElement('input'))
298
302
  .attr('type', 'button')
299
303
  .attr('value', this.cancelButton)
300
304
  )
@@ -361,11 +365,11 @@ BestInPlaceEditor.forms = {
361
365
  "date" : {
362
366
  activateForm : function() {
363
367
  var that = this,
364
- output = $(document.createElement('form'))
368
+ output = jQuery(document.createElement('form'))
365
369
  .addClass('form_in_place')
366
370
  .attr('action', 'javascript:void(0);')
367
371
  .attr('style', 'display:inline'),
368
- input_elt = $(document.createElement('input'))
372
+ input_elt = jQuery(document.createElement('input'))
369
373
  .attr('type', 'text')
370
374
  .attr('name', this.attributeName)
371
375
  .attr('value', this.sanitizeValue(this.display_value));
@@ -406,16 +410,16 @@ BestInPlaceEditor.forms = {
406
410
 
407
411
  "select" : {
408
412
  activateForm : function() {
409
- var output = $(document.createElement('form'))
413
+ var output = jQuery(document.createElement('form'))
410
414
  .attr('action', 'javascript:void(0)')
411
415
  .attr('style', 'display:inline');
412
416
  selected = '',
413
417
  oldValue = this.oldValue,
414
- select_elt = $(document.createElement('select')),
418
+ select_elt = jQuery(document.createElement('select')),
415
419
  currentCollectionValue = this.collectionValue;
416
420
 
417
421
  jQuery.each(this.values, function (index, value) {
418
- var option_elt = $(document.createElement('option'))
422
+ var option_elt = jQuery(document.createElement('option'))
419
423
  // .attr('value', value[0])
420
424
  .val(value[0])
421
425
  .html(value[1]);
@@ -469,21 +473,21 @@ BestInPlaceEditor.forms = {
469
473
  height = this.element.css('height');
470
474
 
471
475
  // construct form
472
- var output = $(document.createElement('form'))
476
+ var output = jQuery(document.createElement('form'))
473
477
  .attr('action', 'javascript:void(0)')
474
478
  .attr('style', 'display:inline')
475
- .append($(document.createElement('textarea'))
479
+ .append(jQuery(document.createElement('textarea'))
476
480
  .val(this.sanitizeValue(this.display_value)));
477
481
  if(this.okButton) {
478
482
  output.append(
479
- $(document.createElement('input'))
483
+ jQuery(document.createElement('input'))
480
484
  .attr('type', 'submit')
481
485
  .attr('value', this.okButton)
482
486
  );
483
487
  }
484
488
  if(this.cancelButton) {
485
489
  output.append(
486
- $(document.createElement('input'))
490
+ jQuery(document.createElement('input'))
487
491
  .attr('type', 'button')
488
492
  .attr('value', this.cancelButton)
489
493
  )
@@ -1,6 +1,6 @@
1
1
  //= require jquery.purr
2
2
 
3
- $(document).on('best_in_place:error', function(event, request, error) {
3
+ jQuery(document).on('best_in_place:error', function(event, request, error) {
4
4
  // Display all error messages from server side validation
5
5
  jQuery.each(jQuery.parseJSON(request.responseText), function(index, value) {
6
6
  if( typeof(value) == "object") {value = index + " " + value.toString(); }
@@ -21,12 +21,12 @@
21
21
  default: false
22
22
  */
23
23
 
24
- (function($) {
24
+ (function(jQuery) {
25
25
 
26
- $.purr = function(notice, options)
26
+ jQuery.purr = function(notice, options)
27
27
  {
28
28
  // Convert notice to a jQuery object
29
- notice = $(notice);
29
+ notice = jQuery(notice);
30
30
 
31
31
  // Add a class to denote the notice as not sticky
32
32
  notice.addClass('purr');
@@ -41,10 +41,10 @@
41
41
  }
42
42
 
43
43
  // Convert cont to a jQuery object
44
- cont = $(cont);
44
+ cont = jQuery(cont);
45
45
 
46
46
  // Add the container to the page
47
- $('body').append(cont);
47
+ jQuery('body').append(cont);
48
48
 
49
49
  notify();
50
50
 
@@ -52,7 +52,7 @@
52
52
  {
53
53
  // Set up the close button
54
54
  var close = document.createElement('a');
55
- $(close).attr({
55
+ jQuery(close).attr({
56
56
  className: 'close',
57
57
  href: '#close'
58
58
  }).appendTo(notice).click(function() {
@@ -61,7 +61,7 @@
61
61
  });
62
62
 
63
63
  // If ESC is pressed remove notice
64
- $(document).keyup(function(e) {
64
+ jQuery(document).keyup(function(e) {
65
65
  if (e.keyCode == 27) {
66
66
  removeNotice();
67
67
  }
@@ -141,7 +141,7 @@
141
141
  };
142
142
  };
143
143
 
144
- $.fn.purr = function(options)
144
+ jQuery.fn.purr = function(options)
145
145
  {
146
146
  options = options || {};
147
147
  options.fadeInSpeed = options.fadeInSpeed || 500;
@@ -152,10 +152,10 @@
152
152
 
153
153
  this.each(function()
154
154
  {
155
- new $.purr( this, options );
155
+ new jQuery.purr( this, options );
156
156
  }
157
157
  );
158
158
 
159
159
  return this;
160
160
  };
161
- })( jQuery );
161
+ })( jQuery );
@@ -48,7 +48,7 @@ module BestInPlace
48
48
  out << " data-activator='#{opts[:activator]}'" unless opts[:activator].blank?
49
49
  out << " data-ok-button='#{opts[:ok_button]}'" unless opts[:ok_button].blank?
50
50
  out << " data-cancel-button='#{opts[:cancel_button]}'" unless opts[:cancel_button].blank?
51
- out << " data-nil='#{opts[:nil]}'" unless opts[:nil].blank?
51
+ out << " data-nil='#{attribute_escape(opts[:nil])}'" unless opts[:nil].blank?
52
52
  out << " data-use-confirm='#{opts[:use_confirm]}'" unless opts[:use_confirm].nil?
53
53
  out << " data-type='#{opts[:type]}'"
54
54
  out << " data-inner-class='#{opts[:inner_class]}'" if opts[:inner_class]
@@ -1,3 +1,3 @@
1
1
  module BestInPlace
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -65,6 +65,28 @@ describe "JS behaviour", :js => true do
65
65
  page.should have_content("Nothing to show")
66
66
  end
67
67
  end
68
+
69
+ it "should render html content for nil option" do
70
+ @user.favorite_color = ""
71
+ @user.save!
72
+ visit user_path(@user)
73
+ within("#favorite_color") do
74
+ page.should have_xpath("//span[@class='nil']")
75
+ end
76
+ end
77
+
78
+ it "should render html content for nil option after edit" do
79
+ @user.favorite_color = "Blue"
80
+ @user.save!
81
+ visit user_path(@user)
82
+
83
+ bip_text @user, :favorite_color, ""
84
+
85
+ within("#favorite_color") do
86
+ page.should have_xpath("//span[@class='nil']")
87
+ end
88
+ end
89
+
68
90
  end
69
91
 
70
92
  it "should be able to update last but one item in list" do
@@ -648,6 +670,43 @@ describe "JS behaviour", :js => true do
648
670
  within("#alt_money") { page.should have_content("€58.00") }
649
671
  end
650
672
 
673
+ it "should keep link after edit with display_with :link_to" do
674
+ @user.save!
675
+ visit users_path
676
+ within("tr#user_#{@user.id} > .name > span") do
677
+ page.should have_content("Lucia")
678
+ page.should have_xpath("//a[contains(@href,'#{user_path(@user)}')]")
679
+ end
680
+ id = BestInPlace::Utils.build_best_in_place_id @user, :name
681
+ page.execute_script <<-JS
682
+ jQuery("#edit_#{@user.id}").click();
683
+ jQuery("##{id} input[name='name']").val('Maria Lucia');
684
+ jQuery("##{id} form").submit();
685
+ JS
686
+ within("tr#user_#{@user.id} > .name > span") do
687
+ page.should have_content("Maria Lucia")
688
+ page.should have_xpath("//a[contains(@href,'#{user_path(@user)}')]")
689
+ end
690
+ end
691
+
692
+ it "should keep link after aborting edit with display_with :link_to" do
693
+ @user.save!
694
+ visit users_path
695
+ within("tr#user_#{@user.id} > .name > span") do
696
+ page.should have_content("Lucia")
697
+ page.should have_xpath("//a[contains(@href,'#{user_path(@user)}')]")
698
+ end
699
+ id = BestInPlace::Utils.build_best_in_place_id @user, :name
700
+ page.execute_script <<-JS
701
+ jQuery("#edit_#{@user.id}").click();
702
+ jQuery("##{id} input[name='name']").blur();
703
+ JS
704
+ within("tr#user_#{@user.id} > .name > span") do
705
+ page.should have_content("Lucia")
706
+ page.should have_xpath("//a[contains(@href,'#{user_path(@user)}')]")
707
+ end
708
+ end
709
+
651
710
  describe "display_with using a lambda" do
652
711
 
653
712
 
@@ -873,6 +932,7 @@ describe "JS behaviour", :js => true do
873
932
 
874
933
  bip_select @user, :country, "France"
875
934
 
935
+ sleep 1 # Increase if browser is slow
876
936
  id = BestInPlace::Utils.build_best_in_place_id @user, :country
877
937
  page.execute_script <<-JS
878
938
  $("##{id}").click();
@@ -54,3 +54,7 @@ div.field, div.actions {
54
54
  font-size: 12px;
55
55
  list-style: square;
56
56
  }
57
+
58
+ span.nil {
59
+ color: #999;
60
+ }
@@ -63,6 +63,7 @@
63
63
  <td id="favorite_color">
64
64
  <%- opts = { :ok_button => 'Do it!', :cancel_button => 'Nope' } %>
65
65
  <%- opts.delete(:ok_button) if params[:suppress_ok_button] %>
66
+ <%- opts[:nil] = "<span class='nil'>Click to add your favorite color</span>" %>
66
67
  <%= best_in_place @user, :favorite_color, opts %>
67
68
  </td>
68
69
  </tr>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: best_in_place
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-16 00:00:00.000000000 Z
12
+ date: 2012-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails