Skip to content

Commit

Permalink
updated readme and added some argument checking to the helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jadehopepunk committed Mar 27, 2007
1 parent 12cf844 commit dec3e37
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
43 changes: 40 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ This library should be considered to be a derivative work of Thickbox, and is al

http://jquery.com/demo/thickbox/

Redbox Rails plugin development by Craig Ambrose from Tinbox
Redbox Rails plugin development by Craig Ambrose

http://www.craigambrose.com
http://www.tinboxsoftware.com

Additional code submissions, testing and bugfixes by:
- Brandon Keepers
- Niko Dittmann
- Randy Parker
- Julien Coupard
- Erin Staniland

(and many more)

Licence
=======
Expand All @@ -50,3 +49,41 @@ Usage
=====

Examine the public methods of redbox_helper.rb. They will all look familiar, much like the existing link helpers, except that they work with redboxes. You should not need to interact with the javascript directly.

Redbox provides three helpers which are used instead of a regular “link_to” helper when linking to a redbox.

link_to_redbox(name, id, html_options = {})

This is used if you already have an HTML element in your page (presumably hidden, but it doesn’t have to be) and you wish to use it for your redbox. Specify it by it’s id, and you’re in business.

link_to_component_redbox(name, url_options = {}, html_options = {})

This serves essentially the same purpose, but it uses the url_options supplied to load another page from your app into a hidden div on page load. This saves you having to do it yourself, but beware that there are definite performance implications to using components.

link_to_remote_redbox(name, link_to_remote_options = {}, html_options = {})

This waits until the link is clicked on to load the redbox using ajax, and displays loading graphics while it’s waiting.

link_to_close_redbox(name, html_options = {})

Allows you to put a link (presumably inside the redbox) to close it. Other way to close it is to refresh the entire page, but obviously closing it with javascript is spiffier.

More Info
=========

A static page is maintained for this plugin at:

http://www.craigambrose.com/projects/redbox

Updates are always posted at:

http://blog.craigambrose.com

Bugs, once you have tracked down the exact problem and can reproduce a failure case, can be reported to:

[email protected]

If you find this plugin useful, you can give something back to the community by examining your own code and seeing
what bits of functionality are generic enough to be useful as a rails plugin. Releasing rails plugins is dead
simple, and helps us all do better work.

16 changes: 14 additions & 2 deletions lib/redbox_helper.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
module RedboxHelper

def link_to_redbox(name, id, html_options = {})
@uses_redbox = true
link_to_function name, "RedBox.showInline('#{id.to_s}')", html_options
end

def link_to_component_redbox(name, url_options = {}, html_options = {})
@uses_redbox = true
id = id_from_url(url_options, html_options[:id])
link_to_redbox(name, id, html_options) + content_tag("span", render_component(url_options), :id => id, :style => 'display: none;')
end

def link_to_remote_redbox(name, link_to_remote_options = {}, html_options = {})
@uses_redbox = true
id = id_from_url(link_to_remote_options[:url], html_options[:id])
hidden_content_id = "hidden_content_#{id}"
link_to_remote_options = redbox_remote_options(link_to_remote_options, hidden_content_id)
Expand All @@ -18,14 +21,17 @@ def link_to_remote_redbox(name, link_to_remote_options = {}, html_options = {})
end

def link_to_close_redbox(name, html_options = {})
@uses_redbox = true
link_to_function name, 'RedBox.close()', html_options
end

def button_to_close_redbox(name, html_options = {})
@uses_redbox = true
button_to_function name, 'RedBox.close()', html_options
end

def launch_remote_redbox(link_to_remote_options = {}, html_options = {})
@uses_redbox = true
id = id_from_url(link_to_remote_options[:url], html_options[:id])
hidden_content_id = "hidden_content_#{id}"
hidden_content = build_hidden_content(hidden_content_id)
Expand All @@ -40,12 +46,18 @@ def id_from_url(url_options, link_id)
result = ''
result = link_id.to_s + '_' unless link_id.nil?

if url_options.is_a? String
if url_options.nil?
raise ArgumentError, 'You are trying to create a RedBox link without specifying a valid url.'
elsif url_options.is_a? String
result + url_options.delete(":/")
else
result + url_options.values.join('_')
result + url_to_id_string(url_options.values.join('_'))
end
end

def url_to_id_string(value)
value.sub(/[?=&]/, '')
end

def build_hidden_content(hidden_content_id)
content_tag("div", '', :id => hidden_content_id, :style => 'display: none;')
Expand Down

0 comments on commit dec3e37

Please sign in to comment.