Yes, thats true. It is more straight forward, but you could also use
bind() for it.
Assuming you want to create a new dialog like so: new Dialog(..), it
makes sense to create a random ID for each dialog. I think a class is
ment to handle multiple instances of something. Since you are
currently using a static ID "dialog" you can never handle more then
one dialog. If you want to achive this, a internal close method is the
way to do it. But then you would have to create all elements with the
Template class on demand, rather then having them sitting empty in the
DOM all the time.
initialize: function() {
this.randomID = 'dialog'+ Math.floor(Math.random()*6000)
}
showDialog: function(xhr) {
var dialogObj = {randomID: this.randomID, content: xhr.responseText};
new Insertion.after('overlay', new Template('<div
id="#{randomID}" class="dialog">#{content}</div>').evaluate(dialogObj)
);
// After this its available and you can use $(randomID) to bind
your events along.
$(this.randomID).getElementsBySelector("[action=deactivate]").each(function(e){
e.observe('click', function(){ this.closeDialog() }.bind(this) )
});
}
And closeDialog could look like this:
closeDialog: function() {
if($('overlay').visible()) { // overlay is always present.
$('overlay').hide() // we just hide and show on demand next time.
}
$(this.randomID).remove(); // generic, so we remove it
}
I hope this helps.. Of course this would need you to rewrite the whole
class (use Ajax.Request over Update), but thats the way i would do it,
and your internal close function would serve some purpose since it
uses the value of the instance that you create for each Dialog.
On 3/24/07, David Dashifen Kees <[EMAIL PROTECTED]> wrote:
>
> Interesting. I like it. I was more focused on trying to get the the
> deactivating elements to call a method of the dialog object, but then the
> dialog method would probably only end up performing the same actions as you
> described. Thanks!
> -- Dash --
>
>
> Kjell Bublitz wrote:
> On 3/24/07, David Dashifen Kees <[EMAIL PROTECTED]> wrote:
>
>
> So, one of the things I've always wanted to do was expand upon the
> simplicity of the Lightbox Gone Wild! object that the coders at
> www.particletree.com put together months ago. I used it on an
> application I wrote to organize my own picture albums on my localhost
> web server, but I had to hack it apart to get it to do the things I
> wanted it to do. I looked at the Prototype Window class, thick box,
> grey box, etc. and all of them didn't seem to be quite what I was
> looking for. So, this afternoon I decided to try and write one myself.
> I've gotten about 95% of the way completed (at least for the first go)
> but I can't get the dialog, after it is shown, to disappear.
>
> Here's a pastie: http://pastie.caboo.se/49182
> Here's a demo: http://www.dashifen.com/.temp/
>
> You can see at line #19 within the pastie that I'm trying to get
> anything within the newly loaded div#dialog element which an action
> attribute equal to "deactivate" and then capture click events to close
> the dialog. If I change line #20 to include an anonymous function
> (element.observe("click", function() { alert("hello world"); }); for
> example), the anonymous function works fine. I suspect I'm still hazy
> on the exact usage (and purpose) of the bindAsEventListener() method of
> the Function object.
>
> Anyone got any ideas about how to get the darned things to close when
> they're opened?
>
> $("dialog").getElementsBySelector("[action=deactivate]").each(function(e){
> e.observe('click', function(){
> $("dialog").remove(); $('overlay').remove()
> })
> });
>
>
>
>
> Also, for what it's worth, I'm not even worrying about anything other
> than Firefox at this point. The first step is to get it working. I'll
> worry about getting working in other browsers as phase 2!! Also, FYI,
> I'm using prototype.js version 1.5.1 release candidate 2.
>
> Thanks All,
> -- Dash --
>
>
>
>
>
> >
>
--
Regards, Kjell
www.m3nt0r.de
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---