A486c31326dffba0cde8bade19108dc2

I didn't want to add jQuery and mix it up with prototype, so I moved the facebox jquery code to prototype and converted faceboxrender to use prototype instead.

module PrototypeFaceboxRender
  def render_to_facebox(options = {})
    options[:template] = "#{default_template_name}" if options.empty?

    logger.info(options[:template])
    
    action_string = render_to_string(:action => options[:action], :layout => false) if options[:action]
    template_string = render_to_string(:template => options[:template], :layout => false) if options[:template]
    
    render :update do |page|

      page << "facebox.reveal(#{action_string.to_json})" if options[:action]
      page << "facebox.reveal(#{template_string.to_json})" if options[:template]
      page << "facebox.reveal(#{(render :partial => options[:partial]).to_json})" if options[:partial]
      page << "facebox.reveal(#{options[:html].to_json})" if options[:html]
      
      if options[:msg]
        page << "if( !$('facebox_message')){"
        page << "$('facebox_content').insert({top: '<div id=facebox_message>#{options[:msg]}</div>'});"
        page << "}"
      end

      yield(page) if block_given?
    end
  end

  def close_facebox
    render :update do |page|
      page << 'facebox.close();'
      yield(page) if block_given?
    end
  end

  def redirect_from_facebox(url)
    render :update do |page|
      page.redirect_to url
    end
  end
end

Refactorings

No refactoring yet !

A8d3f35baafdaea851914b17dae9e1fc

Adam

November 5, 2009, November 05, 2009 16:37, permalink

No rating. Login to rate!

I would start by building your Javascript in Ruby and put your if logic in Javascript so that you can set your message in much the same way.

render :update do |page|
  page.facebox.reveal(action_string) if options[:action]
  page.facebox.reveal(template_string) if options[:action]

  # ...

  page.facebox.setMessage(options[:msg]) if options[:msg]
end
F69a7d839c6454c94d361a9d7b6de890

hvillero

May 4, 2010, May 04, 2010 01:27, permalink

No rating. Login to rate!

is that working? can i use the same javascripts libraries?

F69a7d839c6454c94d361a9d7b6de890

hvillero

May 4, 2010, May 04, 2010 01:28, permalink

No rating. Login to rate!

is that working? can i use the same javascripts libraries?

A486c31326dffba0cde8bade19108dc2

Stephane Paul

December 16, 2010, December 16, 2010 22:23, permalink

No rating. Login to rate!

yeah you can use it that works actually

Your refactoring





Format Copy from initial code

or Cancel