lib/carrierwave/jcrop/helpers.rb
def cropbox(attachment, opts={})
        attachment = attachment.to_sym
        object = self.object
        attachment_instance = self.object.send(attachment)

        if(attachment_instance.class.ancestors.include?(CarrierWave::Uploader::Base) && object.send(attachment).present?)
          ## Fixes Issue #1 : Colons in html id attributes with Namespaced Models
          model_name = self.object.class.name.downcase.split("::").last
          hidden_elements  = self.hidden_field(:"#{attachment}_crop_x", id: "#{model_name}_#{attachment}_crop_x")
          [:crop_y, :crop_w, :crop_h].each do |attribute|
            hidden_elements << self.hidden_field(:"#{attachment}_#{attribute}", id: "#{model_name}_#{attachment}_#{attribute}")
          end

          box =  @template.content_tag(:div, hidden_elements, style: "display:none")

          wrapper_attributes = {id: "#{model_name}_#{attachment}_cropbox_wrapper"}
          if(opts[:width] && opts[:height])
            wrapper_attributes.merge!(style: "width:#{opts[:width].round}px; height:#{opts[:height].round}px; overflow:hidden")
          end

          if opts[:version]
            img = self.object.send(attachment).url(opts[:version])
          else
            img = self.object.send(attachment).url
          end
          img_id = "#{model_name}_#{attachment}_cropbox"
          img_styles = {}
          if opts[:bg_color]
            crop_image = @template.image_tag(img, :id => img_id,style:"background-color:#{opts[:bg_color]}")
          else
            crop_image = @template.image_tag(img, :id => img_id)
          end

          box << @template.content_tag(:div, crop_image, wrapper_attributes)
          box << init_jcrop(img_id,attachment,object)
          box
        end
      end
# Form helper to render the actual cropping box of an attachment.
# Loads the actual image. Cropbox has no constraints on dimensions, image is renedred at full size.
# Box size can be restricted by setting the :width and :height option. If you override one of width/height you must override both.
# By default original image is rendered. Specific version can be specified by passing version option
#
#   cropbox :avatar
#   cropbox :avatar, width: 550, height: 600
#   cropbox :avatar, version: :medium
#
# @param attachment [Symbol] attachment name
# @param opts [Hash] specify version or width and height options
Form helper to render the actual cropping box of an attachment.
Loads the actual image. Cropbox has no constraints on dimensions, image is renedred at full size.
Box size can be restricted by setting the :width and :height option. If you override one of width/height you must override both.
By default original image is rendered. Specific version can be specified by passing version option


Form helper to render the actual cropping box of an attachment . Loads the actual image . Cropbox has no constraints on dimensions image is renedred at full size . Box size can be restricted by setting the : width and : height option . If you override one of width / height you must override both . By default original image is rendered . Specific version can be specified by passing version option
def cropbox(attachment, opts={})
        attachment = attachment.to_sym
        object = self.object
        attachment_instance = self.object.send(attachment)
        if(attachment_instance.class.ancestors.include?(CarrierWave::Uploader::Base) && object.send(attachment).present?)
          model_name = self.object.class.name.downcase.split("::").last
          hidden_elements  = self.hidden_field(:"#{attachment}_crop_x", id: "#{model_name}_#{attachment}_crop_x")
          [:crop_y, :crop_w, :crop_h].each do |attribute|
            hidden_elements << self.hidden_field(:"#{attachment}_#{attribute}", id: "#{model_name}_#{attachment}_#{attribute}")
          end
          box =  @template.content_tag(:div, hidden_elements, style: "display:none")
          wrapper_attributes = {id: "#{model_name}_#{attachment}_cropbox_wrapper"}
          if(opts[:width] && opts[:height])
            wrapper_attributes.merge!(style: "width:#{opts[:width].round}px; height:#{opts[:height].round}px; overflow:hidden")
          end
          if opts[:version]
            img = self.object.send(attachment).url(opts[:version])
          else
            img = self.object.send(attachment).url
          end
          img_id = "#{model_name}_#{attachment}_cropbox"
          img_styles = {}
          if opts[:bg_color]
            crop_image = @template.image_tag(img, :id => img_id,style:"background-color:#{opts[:bg_color]}")
          else
            crop_image = @template.image_tag(img, :id => img_id)
          end
          box << @template.content_tag(:div, crop_image, wrapper_attributes)
          box << init_jcrop(img_id,attachment,object)
          box
        end
      end
def cropbox ( attachment , opts = { } ) attachment = attachment . to_sym object = self . object attachment_instance = self . object . send ( attachment ) if ( attachment_instance . class . ancestors . include? ( CarrierWave :: Uploader :: Base ) && object . send ( attachment ) . present? ) model_name = self . object . class . name . downcase . split ( "::" ) . last hidden_elements = self . hidden_field ( :" #{ attachment } _crop_x " , id : "#{model_name}_#{attachment}_crop_x" ) [ :crop_y , :crop_w , :crop_h ] . each do | attribute | hidden_elements << self . hidden_field ( :" #{ attachment } _ #{ attribute } " , id : "#{model_name}_#{attachment}_#{attribute}" ) end box = @template . content_tag ( :div , hidden_elements , style : "display:none" ) wrapper_attributes = { id : "#{model_name}_#{attachment}_cropbox_wrapper" } if ( opts [ :width ] && opts [ :height ] ) wrapper_attributes . merge! ( style : "width:#{opts[:width].round}px; height:#{opts[:height].round}px; overflow:hidden" ) end if opts [ :version ] img = self . object . send ( attachment ) . url ( opts [ :version ] ) else img = self . object . send ( attachment ) . url end img_id = "#{model_name}_#{attachment}_cropbox" img_styles = { } if opts [ :bg_color ] crop_image = @template . image_tag ( img , :id => img_id , style : "background-color:#{opts[:bg_color]}" ) else crop_image = @template . image_tag ( img , :id => img_id ) end box << @template . content_tag ( :div , crop_image , wrapper_attributes ) box << init_jcrop ( img_id , attachment , object ) box end end
Form helper to render the actual cropping box of an attachment.
Form helper to render the actual cropping box of an attachment .
## Fixes Issue #1 : Colons in html id attributes with Namespaced Models
attachment
None
opts
specify version or width and height options
specify version or width and height options