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 !
Adam
November 5, 2009, November 05, 2009 16:37, permalink
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
hvillero
May 4, 2010, May 04, 2010 01:27, permalink
is that working? can i use the same javascripts libraries?
hvillero
May 4, 2010, May 04, 2010 01:28, permalink
is that working? can i use the same javascripts libraries?
Stephane Paul
December 16, 2010, December 16, 2010 22:23, permalink
yeah you can use it that works actually
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.