= Kenny Dialoggins
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
== Helpful Links
* Repository: http://github.com/coroutine/kenny_dialoggins
* Gem: http://rubygems.org/gems/kenny_dialoggins
* Authors: http://coroutine.com
== Prerequisites
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: http://prototypejs.org
* Scriptaculous: http://script.aculo.us
== Installation & Generators
Install me from RubyGems.org and add a gem dependency in the appropriate file.
$ 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
== IE6 Support
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.
== License
Copyright (c) 2010 {Coroutine LLC}[http://coroutine.com].
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.