Created
June 14, 2010 19:12
-
-
Save coryschires/438135 to your computer and use it in GitHub Desktop.
link_to_lightbox helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# builds an href for an iframe using prettyPhoto.js plugin | |
def link_to_lightbox(*args, &block) | |
if block_given? | |
options = args.first || {} | |
html_options = args.second | |
concat(link_to(capture(&block), options, html_options)) | |
else | |
name = args.first | |
options = args.second || {} | |
html_options = args.third | |
# automatically pass params[:lightbox] of true - useful for rendering layouts conditionally | |
options.include?("?") ? options << "&lightbox=true" : options << "?lightbox=true" | |
url = url_for(options) | |
if html_options | |
html_options[:rel] = "prettyPhoto" if html_options[:rel].blank? | |
# grab width/height attrs and remove from html options | |
lightbox_width = html_options.delete(:width) | |
lightbox_height = html_options.delete(:height) | |
html_options = html_options.stringify_keys | |
href = html_options['href'] | |
convert_options_to_javascript!(html_options, url) | |
tag_options = tag_options(html_options) | |
else | |
tag_options = nil | |
end | |
href_attr = "href=\"#{url}?iframe=true&width=#{lightbox_width}&height=#{lightbox_height}\"" unless href | |
"<a #{href_attr}#{tag_options}>#{name || url}</a>" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment