Greetings all,
I've written an object to create a lightbox-like dialog on-screen (I
posted about it earlier; search for "dialogish" within the group and
you'll find that thread). I then ran into the Control.Modal window
which did much of what I wanted, but was also much more complex. I
didn't understand all of what the developer of Control.Modal was doing
so I tried to take what I did understand from his class and apply it to
mine. If you're unfamiliar with Control.Modal, you can find it here:
http://livepipe.net/projects/control_modal/.
The problem I'm facing as that the functions that are called to respond
to different dialog-centric events (like beforeLoad, beforeOpen, etc.)
have a scope that's not that of the dialog object. Code time:
var dialog = new Dialog("test.php", {
beforeLoad: function() { return { window_id: $F("window_id") } }
}); dialog.activate();
The above snippet shows the basics of how the dialog object is started.
You pass the URL of the information to be loaded
via Ajax.Updater as well as any custom functions which need to respond
to one of four different events within the dialog code: before the
information is loaded, before the content is shown, before the content
is hidden, and before the dialog container is actually removed from the
DOM. The above snippet would work fine, but I can imagine a time when I
might want to do something like this:
var dialog = new Dialog("test.php", {
beforeClose: function() {
$(this.dialog_id).getElementsByTagName("input").each(function(input)
{ /* ... */ })
}
}); dialog.activate();
The above snippet doesn't work, clearly because the this keyword refers
to the scope of the anonymous function, unless I misunderstand something
crucial. So, I tried to do something like this:
Dialog.prototype = {
initialize: function(href, custom_responders) {
/* ... do other setup stuff ... */
if(custom_responders)
for(responder in custom_responders)
this.responders[responder] = custom_responder[responder];
*for(responder in this.responders)
this.responders[responder].bind(this)*
I thought that the above use of the bind() function would tell the the
responder functions which are passed within the custom_responders object
to use the scope of the dialog object as their scope but that doesn't
seem to be the case. Simply uses of this binding like the following
still fail:
var dialog = new Dialog("test.php", { beforeLoad: function() {
alert(this.dialog_id) } });
For what it's worth, it alerts undefined. Here's the code:
http://pastie.caboo.se/52614
Note that the usage of bind() mentioned in this post is not in the
pastie. My bad.
-- Dash --
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---