Permalink
Browse files

import from facebox-render

  • Loading branch information...
0 parents commit 383bc03ba446e04a515048a359276f38d2030ca0 @ihower committed Jun 11, 2008
Showing with 102 additions and 0 deletions.
  1. +55 −0 README.txt
  2. +1 −0 init.rb
  3. +39 −0 lib/facebox_render.rb
  4. +7 −0 lib/facebox_render_helper.rb
@@ -0,0 +1,55 @@
+Author:: Wen-Tien Chang(mailto:ihower@handlino.com)
+Copyright:: Copyright (c) 2008 Handlino Inc.
+Licensed under the MIT: http://www.opensource.org/licenses/mit-license.php
+
+== Description ==
+FaceboxRender plugin let you use lightbox seamlessly using Facebox library.
+http://handlino.com/blog/2008/02/26/57/
+
+== Install ==
+ * download from http://github.com/ihower/facebox-render/
+ * uncompress to /vendor/plugins/facebox_render
+
+ Note that you must install Facebox first(see http://famspam.com/facebox/).
+
+ 1.Download jQuery (or you can try to install http://ennerchi.com/projects/jrails to replace Prototype library totally)
+ 2.Download facebox
+ 3.Copy facebox js file to /public/javascripts/
+ 4.Copy facebox css file to /public/styleshees/
+ 5.Copy facebox all image files to /public/facebox/
+ 6.Config your layout (stylesheet_link_tag and javascript_include_tag) to add these js,css files
+
+= USAGE =
+
+== Helper ==
+We have facebox_link_to helper (it's will launch loading facebox first, send ajax request second)
+or you can use link_to_remote, form_remote_tag...etc Ajax helper.
+Don't use <a href="somelink" ref="facebox">
+
+== Controller ==
+Add "include FaceboxRender" to your controller,
+or simply put it at /app/controllers/application.rb
+
+Then in your action:
+
+respond_to do |format|
+ format.html
+ format.js { render_to_facebox }
+end
+
+By Default render the html without layout,
+otherwise you can pass options[:template], options[:action], options[:partial] or options[:html] string.
+Passing options[:msg] will pulsate a message.
+
+If block given, it will yield after facebox script, eg:
+
+render_to_facebox do |page|
+ page << "alert('test')"
+end
+
+Besides render_facebox, we have close_facebox, redirect_from_facebox.
+
+respond_to do |format|
+ format.html
+ format.js { close_facebox }
+end
@@ -0,0 +1 @@
+ActionController::Base.helper FaceboxRenderHelper
@@ -0,0 +1,39 @@
+module FaceboxRender
+
+ def render_to_facebox( options = {} )
+ options[:template] = "#{default_template_name}.html.erb" if options.empty?
+
+ 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 << "jQuery.facebox(#{action_string.to_json})" if options[:action]
+ page << "jQuery.facebox(#{template_string.to_json})" if options[:template]
+ page << "jQuery.facebox(#{(render :partial => options[:partial]).to_json})" if options[:partial]
+ page << "jQuery.facebox(#{options[:html].to_json})" if options[:html]
+
+ 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
@@ -0,0 +1,7 @@
+module FaceboxRenderHelper
+
+ def facebox_link_to(name, options = {}, html_options = nil)
+ link_to_function(name, "jQuery.facebox(function(){ #{remote_function(options)} })", html_options || options.delete(:html))
+ end
+
+end

0 comments on commit 383bc03

Please sign in to comment.