best_in_place 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/assets/javascripts/best_in_place.js +26 -18
- data/lib/best_in_place/helper.rb +2 -2
- data/lib/best_in_place/version.rb +1 -1
- data/spec/integration/js_spec.rb +16 -0
- data/test_app/app/assets/images/no.png +0 -0
- data/test_app/app/assets/images/yes.png +0 -0
- data/test_app/app/views/users/show.html.erb +6 -0
- metadata +18 -3
@@ -185,7 +185,7 @@ BestInPlaceEditor.prototype = {
|
|
185
185
|
},
|
186
186
|
|
187
187
|
initNil: function() {
|
188
|
-
if (this.element.
|
188
|
+
if (this.element.html() === "")
|
189
189
|
{
|
190
190
|
this.isNil = true;
|
191
191
|
this.element.html(this.nil);
|
@@ -225,19 +225,24 @@ BestInPlaceEditor.prototype = {
|
|
225
225
|
// Handlers ////////////////////////////////////////////////////////////////
|
226
226
|
|
227
227
|
loadSuccessCallback : function(data) {
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
228
|
+
data = $.trim(data);
|
229
|
+
|
230
|
+
if(data && data!=""){
|
231
|
+
var response = jQuery.parseJSON(jQuery.trim(data));
|
232
|
+
if (response !== null && response.hasOwnProperty("display_as")) {
|
233
|
+
this.element.attr("data-original-content", this.element.text());
|
234
|
+
this.original_content = this.element.text();
|
235
|
+
this.element.html(response["display_as"]);
|
236
|
+
}
|
237
|
+
this.element.trigger(jQuery.Event("best_in_place:success"), data);
|
238
|
+
this.element.trigger(jQuery.Event("ajax:success"), data);
|
233
239
|
}
|
234
|
-
this.element.trigger(jQuery.Event("ajax:success"), data);
|
235
240
|
|
236
241
|
// Binding back after being clicked
|
237
242
|
jQuery(this.activator).bind('click', {editor: this}, this.clickHandler);
|
238
243
|
this.element.trigger(jQuery.Event("best_in_place:deactivate"));
|
239
244
|
|
240
|
-
if (this.collectionValue !== null) {
|
245
|
+
if (this.collectionValue !== null && this.formType == "select") {
|
241
246
|
this.collectionValue = this.previousCollectionValue;
|
242
247
|
this.previousCollectionValue = null;
|
243
248
|
}
|
@@ -246,8 +251,8 @@ BestInPlaceEditor.prototype = {
|
|
246
251
|
loadErrorCallback : function(request, error) {
|
247
252
|
this.element.html(this.oldValue);
|
248
253
|
|
249
|
-
this.element.trigger(jQuery.Event("best_in_place:error"), [request, error])
|
250
|
-
this.element.trigger(jQuery.Event("ajax:error"));
|
254
|
+
this.element.trigger(jQuery.Event("best_in_place:error"), [request, error]);
|
255
|
+
this.element.trigger(jQuery.Event("ajax:error"), request, error);
|
251
256
|
|
252
257
|
// Binding back after being clicked
|
253
258
|
jQuery(this.activator).bind('click', {editor: this}, this.clickHandler);
|
@@ -261,9 +266,12 @@ BestInPlaceEditor.prototype = {
|
|
261
266
|
|
262
267
|
setHtmlAttributes : function() {
|
263
268
|
var formField = this.element.find(this.formType);
|
264
|
-
|
265
|
-
|
266
|
-
|
269
|
+
|
270
|
+
if(this.html_attrs){
|
271
|
+
var attrs = jQuery.parseJSON(this.html_attrs);
|
272
|
+
for(var key in attrs){
|
273
|
+
formField.attr(key, attrs[key]);
|
274
|
+
}
|
267
275
|
}
|
268
276
|
}
|
269
277
|
};
|
@@ -454,15 +462,13 @@ BestInPlaceEditor.forms = {
|
|
454
462
|
|
455
463
|
"checkbox" : {
|
456
464
|
activateForm : function() {
|
457
|
-
|
458
|
-
var output = newValue ? this.values[1] : this.values[0];
|
459
|
-
this.element.html(output);
|
465
|
+
this.collectionValue = !this.getValue();
|
460
466
|
this.setHtmlAttributes();
|
461
467
|
this.update();
|
462
468
|
},
|
463
469
|
|
464
470
|
getValue : function() {
|
465
|
-
return
|
471
|
+
return this.collectionValue;
|
466
472
|
}
|
467
473
|
},
|
468
474
|
|
@@ -595,6 +601,8 @@ jQuery.fn.best_in_place = function() {
|
|
595
601
|
*/
|
596
602
|
|
597
603
|
(function(jQuery){
|
604
|
+
if (typeof jQuery.fn.elastic !== 'undefined') return;
|
605
|
+
|
598
606
|
jQuery.fn.extend({
|
599
607
|
elastic: function() {
|
600
608
|
// We will create a div clone of the textarea
|
@@ -702,7 +710,7 @@ jQuery.fn.best_in_place = function() {
|
|
702
710
|
});
|
703
711
|
|
704
712
|
// And this line is to catch the browser paste event
|
705
|
-
$textarea.
|
713
|
+
$textarea.on("input paste", function(e){ setTimeout( update, 250); });
|
706
714
|
|
707
715
|
// Run update once when elastic is initialized
|
708
716
|
update();
|
data/lib/best_in_place/helper.rb
CHANGED
@@ -25,11 +25,11 @@ module BestInPlace
|
|
25
25
|
collection = opts[:collection].to_json
|
26
26
|
end
|
27
27
|
if opts[:type] == :checkbox
|
28
|
-
|
28
|
+
value = !!real_object.send(field)
|
29
29
|
if opts[:collection].blank? || opts[:collection].size != 2
|
30
30
|
opts[:collection] = ["No", "Yes"]
|
31
31
|
end
|
32
|
-
display_value =
|
32
|
+
display_value = value ? opts[:collection][1] : opts[:collection][0]
|
33
33
|
collection = opts[:collection].to_json
|
34
34
|
end
|
35
35
|
classes = ["best_in_place"]
|
data/spec/integration/js_spec.rb
CHANGED
@@ -267,6 +267,22 @@ describe "JS behaviour", :js => true do
|
|
267
267
|
end
|
268
268
|
end
|
269
269
|
|
270
|
+
it "should be able to use bip_bool to change a boolean value using an image" do
|
271
|
+
@user.save!
|
272
|
+
visit user_path(@user)
|
273
|
+
|
274
|
+
within("#receive_email_image") do
|
275
|
+
page.should have_xpath("//img[contains(@src,'no.png')]")
|
276
|
+
end
|
277
|
+
|
278
|
+
bip_bool @user, :receive_email
|
279
|
+
|
280
|
+
visit user_path(@user)
|
281
|
+
within("#receive_email_image") do
|
282
|
+
page.should have_xpath("//img[contains(@src,'yes.png')]")
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
270
286
|
it "should correctly use an OK submit button when so configured for an input" do
|
271
287
|
@user.save!
|
272
288
|
visit user_path(@user)
|
Binary file
|
Binary file
|
@@ -58,6 +58,12 @@
|
|
58
58
|
<%= best_in_place @user, :receive_email, :type => :checkbox, :collection => ["No thanks", "Yes of course"] %>
|
59
59
|
</td>
|
60
60
|
</tr>
|
61
|
+
<tr>
|
62
|
+
<td>Receive newsletter (image)?</td>
|
63
|
+
<td id="receive_email_image">
|
64
|
+
<%= best_in_place @user, :receive_email, :type => :checkbox, :collection => [image_tag('no.png'), image_tag('yes.png')] %>
|
65
|
+
</td>
|
66
|
+
</tr>
|
61
67
|
<tr>
|
62
68
|
<td>Favorite color</td>
|
63
69
|
<td id="favorite_color">
|
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.
|
4
|
+
version: 2.0.3
|
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:
|
12
|
+
date: 2013-01-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- test_app/Gemfile
|
133
133
|
- test_app/README
|
134
134
|
- test_app/Rakefile
|
135
|
+
- test_app/app/assets/images/no.png
|
135
136
|
- test_app/app/assets/images/red_pen.png
|
136
137
|
- test_app/app/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png
|
137
138
|
- test_app/app/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png
|
@@ -147,6 +148,7 @@ files:
|
|
147
148
|
- test_app/app/assets/images/ui-icons_ef8c08_256x240.png
|
148
149
|
- test_app/app/assets/images/ui-icons_ffd27a_256x240.png
|
149
150
|
- test_app/app/assets/images/ui-icons_ffffff_256x240.png
|
151
|
+
- test_app/app/assets/images/yes.png
|
150
152
|
- test_app/app/assets/javascripts/application.js
|
151
153
|
- test_app/app/assets/stylesheets/.gitkeep
|
152
154
|
- test_app/app/assets/stylesheets/jquery-ui-1.8.16.custom.css.erb
|
@@ -228,12 +230,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
228
230
|
- - ! '>='
|
229
231
|
- !ruby/object:Gem::Version
|
230
232
|
version: '0'
|
233
|
+
segments:
|
234
|
+
- 0
|
235
|
+
hash: -1762438104594404996
|
231
236
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
237
|
none: false
|
233
238
|
requirements:
|
234
239
|
- - ! '>='
|
235
240
|
- !ruby/object:Gem::Version
|
236
241
|
version: '0'
|
242
|
+
segments:
|
243
|
+
- 0
|
244
|
+
hash: -1762438104594404996
|
237
245
|
requirements: []
|
238
246
|
rubyforge_project: best_in_place
|
239
247
|
rubygems_version: 1.8.24
|
@@ -241,4 +249,11 @@ signing_key:
|
|
241
249
|
specification_version: 3
|
242
250
|
summary: It makes any field in place editable by clicking on it, it works for inputs,
|
243
251
|
textareas, select dropdowns and checkboxes
|
244
|
-
test_files:
|
252
|
+
test_files:
|
253
|
+
- spec/helpers/best_in_place_spec.rb
|
254
|
+
- spec/integration/double_init_spec.rb
|
255
|
+
- spec/integration/js_spec.rb
|
256
|
+
- spec/integration/live_spec.rb
|
257
|
+
- spec/integration/text_area_spec.rb
|
258
|
+
- spec/spec_helper.rb
|
259
|
+
- spec/support/retry_on_timeout.rb
|