Created
March 6, 2009 17:50
-
-
Save kblake/74990 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#Examples: | |
# modalbox_spawn(:link_text=>"content", :content=>"Content for light box", :width=>1000) | |
# modalbox_spawn(:link_text=>"partial render", :partial=>"partials/education_component", :locals=>{:key=>"value"}) | |
# modalbox_spawn(:link_image=>"icons/pedigree_button1.gif", :content=>"<h2>COMING SOON: Pedigree Viewer. w00t!</h2>") | |
# modalbox_spawn(:link_text=>"View Pedigree", :classes=>"black_link other1 other2", :content=>"<h2>COMING SOON: Pedigree Viewer. w00t!</h2>") | |
# modalbox_spawn(:link_text=>"View Pedigree", :id=> person_being_viewed, :content=>"some content") | |
def modalbox_spawn(options={}) | |
link_path = options[:link_path] || root_path | |
link_display = options[:link_text] || image_tag(options[:link_image]) | |
content = options[:content] || render(:partial=>options[:partial], :locals=>options[:locals]) | |
unique_number = options[:id].try(:id) || rand(100) | |
unique_div_id = "content_for_modal#{unique_number}" | |
unique_link_class = "modal_link#{unique_number}" | |
width = options[:width] || 500 | |
output = link_to(link_display, link_path, :class => unique_link_class + " #{options[:classes]}", :title=>options[:link_text]) | |
output << %{ | |
<div id="#{unique_div_id}" style="display:none">#{content}</div> | |
<script type="text/javascript" charset="utf-8"> | |
$(document).ready(function(){ | |
$('.#{unique_link_class}').modalBox('#{unique_div_id}', #{width}); | |
}); | |
</script> | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment