Hey, there.
I’m Kenny Dialoggins. A lot of people confuse me with the singer who rose to fame in the 1980s, but I’m a different guy altogether.
Don’t get me wrong, that Kenny and I are into a lot of the same things, like manly beards and Miami Vice- inspired attire. But while that Kenny spent his career focused on synth beats and lyrics that cut to the bone, I only care about one thing.
Freakin’ Dialogs.
If you’re a Rails developer who wants to use dialogs but doesn’t want to mess with Javascript, you might want to prep your best friend for some bad news. We’re about to become tight.
Let me lay it out for you. If you want my dialog in one of your views, here’s what you do:
# Create the dialog <%= render_dialog :danger_zone_dialog, :partial => "danger_zone", :locals => { :pilot => current_user } %> # Invoke the dialog <%= link_to_function "Take Me to the Danger Zone", show_dialog(:danger_zone_dialog) %>
That’s pretty much it. Did you notice how render_dialog
takes the same options as render
? The content for your dialog can just be a regular old partial.
You like that. I can tell. Don’t fight it.
What’s that, you want more details? You got it, buddy.
render_dialog
always needs a unique id for its first argument. After that, it will take the same options as ActionController::Base#render
. It’ll also take a few more, namely:
-
:before_show
- a Javascript function that will be invoked before the dialog is shown -
:after_show
- a Javascript function that will be invoked after the dialog has become visible -
:before_hide
- a Javascript function that will be invoked before the dialog is hidden -
:after_hide
- a Javascript function that will be invoked after the dialog has been hidden
Here’s an example using the before_show
option:
# Create the dialog with a callback <%= render_dialog :footloose_dialog, :partial => "footloose", :before_show => "function() { alert('Everybody get footloose!'); }" %> # Invoke the dialog <%= link_to_function "Dance party!", show_dialog(:footloose_dialog) %>
If you need more help than that, maybe you should just look at the source code. There are a ton of comments in there.
Your pal,
Kenny Dialoggins
-
Repository: github.com/coroutine/kenny_dialoggins
-
Authors: coroutine.com
To take you to the danger zone, I need my kick ass backup singers Prototype and Scriptaculous.
But since I was designed as a Rails extension, chances are you already have my boys in the mix.
-
Prototype: prototypejs.org
-
Scriptaculous: script.aculo.us
Install me from RubyGems.org and add a gem dependency in your configuration file.
$ sudo gem install kenny_dialoggins
Or install me as a plugin.
$ script/plugin install git://github.com/coroutine/kenny_dialoggins.git
Either way, then generate the stylesheet and javascript files I need.
$ script/generate kenny_dialoggins_assets
I’m not what you’d call a huge fan of IE6, so I don’t provide a blocking iframe for my dialogs by default. But I can. You just need to ask nicely.
At the top of the generated javascript file, just change the obviously-named property hanging right off of the Kenny D namespace. Like this.
KennyDialoggins.SUPPORT_IE6_BULLSHIT = true;
That’s it. I do the rest.
Copyright © 2010 Coroutine LLC.