Skip to content

Commit

Permalink
Merge pull request bernat#166 from gposton/master
Browse files Browse the repository at this point in the history
add classes to best_in_place span
  • Loading branch information
Roger Campos committed Nov 16, 2012
2 parents 096b4e5 + 6826c9f commit eccac00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Options:
this field.
- **:object_name**: Used for overriding the default params key used for the object (the data-object attribute). Useful for e.g. STI scenarios where best_in_place should post to a common controller for different models.
- **:data**: Hash of custom data attributes to be added to span. Can be used to provide data to the ajax:success callback.
- **:classes**: Additional classes to apply to the best_in_place span. Accepts either a string or Array of strings

###best_in_place_if
**best_in_place_if condition, object, field, OPTIONS**
Expand Down Expand Up @@ -189,6 +190,15 @@ The 'ajax:success' event is triggered upon success. Use bind:

$('.best_in_place').bind("ajax:success", function(){$(this).closest('tr').effect('highlight'));});

To bind a callback that is specific to a particular field, use the 'classes' option in the helper method and
then bind to that class.

<%= best_in_place @user, :name, :classes => 'highlight_on_success' %>
<%= best_in_place @user, :mail, :classes => 'bounce_on_success' %>

$('.highlight_on_success').bind("ajax:success", function(){$(this).closest('tr').effect('highlight'));});
$('.bounce_on_success').bind("ajax:success", function(){$(this).closest('tr').effect('bounce'));});

### Providing data to the callback

Use the :data option to add HTML5 data attributes to the best_in_place span. For example, in your view:
Expand Down
9 changes: 8 additions & 1 deletion lib/best_in_place/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ def best_in_place(object, field, opts = {})
value = fieldValue ? opts[:collection][1] : opts[:collection][0]
collection = opts[:collection].to_json
end
out = "<span class='best_in_place'"
unless opts[:classes].nil?
# the next three lines enable this opt to handle both a stings and a arrays
classes = []
classes << opts[:classes]
classes = classes.flatten
opts[:classes] = classes.join(' ')
end
out = "<span class='best_in_place #{opts[:classes]}'"
out << " id='#{BestInPlace::Utils.build_best_in_place_id(real_object, field)}'"
out << " data-url='#{opts[:path].blank? ? url_for(object) : url_for(opts[:path])}'"
out << " data-object='#{opts[:object_name] || BestInPlace::Utils.object_to_key(real_object)}'"
Expand Down

0 comments on commit eccac00

Please sign in to comment.