Skip to content
This repository has been archived by the owner on Aug 21, 2019. It is now read-only.

Commit

Permalink
unescaping HTML for input field, and allow options to be passed to ed…
Browse files Browse the repository at this point in the history
…itable_field
  • Loading branch information
afeld committed Feb 2, 2011
1 parent 224053d commit 1c3ebb3
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/jeditable-rails/helpers/jeditable_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ module JeditableHelper
def editable_field(object, property, options={})
name = "#{object.class.to_s.underscore}[#{property}]"
value = object.send property
update_url = options.delete(:update_url) || url_for(object)
args = {:method => 'PUT', :name => name}.merge(options)
%{
<span class="editable" data-name="#{name}">#{value}</span>
<script type="text/javascript">
$(function(){
$(".editable[data-name='#{name}']").editable("#{url_for(object)}", {
method: 'PUT',
name: "#{name}"
});
$(function(){
var args = {data: function(value, settings) {
// Unescape HTML
var retval = value
.replace(/&amp;/gi, '&')
.replace(/&gt;/gi, '>')
.replace(/&lt;/gi, '<')
.replace(/&quot;/gi, "\\\"");
return retval;
}};
$.extend(args, #{args.to_json});
$(".editable[data-name='#{name}']").editable("#{update_url}", args);
});
</script>
}.html_safe
Expand Down

0 comments on commit 1c3ebb3

Please sign in to comment.