4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/simple_crop/action_view_extensions/form_helper.rb', line 4
def simple_crop(object_name, method, options = {})
default_options = {"select" => :original, "crop" => :original, "script" => true}
options = options.stringify_keys!
options = default_options.merge(options)
script = options["script"]
output = InstanceTag.new(object_name, method, self, options).to_simple_crop_tag(options)
output << InstanceTag.new(object_name, method, self, options).to_simple_crop_preview_tag(options) unless (options["select"] == options["crop"])
output << InstanceTag.new(object_name, :simple_crop_x, self).to_input_field_tag("hidden")
output << InstanceTag.new(object_name, :simple_crop_y, self).to_input_field_tag("hidden")
output << InstanceTag.new(object_name, :simple_crop_w, self).to_input_field_tag("hidden")
output << InstanceTag.new(object_name, :simple_crop_h, self).to_input_field_tag("hidden")
output << InstanceTag.new(object_name, :simple_crop_style, self).to_input_field_tag("hidden", {:value => options["crop"]})
if script === true
output << %Q(<script type="text/javascript" charset="utf-8">$(window).load(function() {$('img[data-crop-for="#{sanitized_object_name(object_name)}"]').SimpleCrop();});</script>).html_safe
elsif not script === false
content_for script do
%Q($('img[data-crop-for="#{sanitized_object_name(object_name)}"]').SimpleCrop();).html_safe
end
end
output
end
|