Sha256: 9f71caacc64dc1dd009ae288d18312055eca36e06ab1de53d11c4e5a18d592e2

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

module FaceboxRender
  
  def render_to_facebox( options = {} )
    l = options.delete(:layout) { false }
    
    if options[:action]
      s = render_to_string(:action => options[:action], :layout => l)
    elsif options[:template]
      s = render_to_string(:template => options[:template], :layout => l)
    elsif !options[:partial] && !options[:html]
      s = render_to_string(:layout => l)
    end
    
    render :update do |page|
      if options[:action]
        page << "jQuery.facebox(#{s.to_json})"
      elsif options[:template]
        page << "jQuery.facebox(#{s.to_json})"
      elsif options[:partial]
        page << "jQuery.facebox(#{(render :partial => options[:partial]).to_json})"
      elsif options[:html]
        page << "jQuery.facebox(#{options[:html].to_json})"
      else
        page << "jQuery.facebox(#{s.to_json})"
      end
      
      if options[:msg]
        page << "jQuery('#facebox .content').prepend('<div class=\"message\">#{options[:msg]}</div>')"
      end
          
      yield(page) if block_given?
      
    end
  end
  
  # close an existed facebox, you can pass a block to update some messages
  def close_facebox
    render :update do |page|
      page << "jQuery.facebox.close();"
      yield(page) if block_given?
    end
  end

  # redirect_to other_path (i.e. reload page)
  def redirect_from_facebox(url)
    render :update do |page|
      page.redirect_to url
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facebox-render-0.9.9 lib/facebox_render.rb