[Prototype-core] Prototype-Base Overlay and Best Practices

2009-06-04 Thread Luisgo

Hi,

I am working on a little class to create prototype-based overlays that
has gotten me thinking about prototype best practices. I am not trying
to ask questions regarding this particular implementation but use this
as an example to aid in discussing and answering the questions below.

First, here is the file I'm working with:

http://github.com/lgomez/Prototype-based-Overlay/blob/f9978e260e5830c025214ed66d649246aa81a20e/overlay.js

What I am trying to figure out is:

1. Is there a better way to handle callback definition? See lines
7-11.
2. Is there a better way of referring to body? See line 33.
3. Is there a better way of injecting callbacks into functions so I
don't have to clutter methods like on and off? See lines 81, 91,
98, 108.
4. Is there a way to use prototype classes that take an element as
extensions to such element? Meaning, I would like to be able apply a
click observer to the instance of the class directly. Something
like:

  `modal.observe(click, someHandler)`

and have that passed to the element to which the class is applied to.
In the class: `this.element` or in this example `modal.element`

Please let me know if my questions are not clear and I'll try to
expand on them. Also, feel free to fork and do your magic with the
code. I added some preliminary comments to guide you. I will fully
document this class after it's done.

Thank you!

PS: Note that I am using RC2.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: Prototype-Base Overlay and Best Practices

2009-06-04 Thread Andrew Dupont


On Jun 4, 2009, at 8:36 PM, Luisgo wrote:

 1. Is there a better way to handle callback definition? See lines
 7-11.

You've got the right idea here. I'd use `Prototype.emptyFunction`  
instead because there's no reason to define more than one empty  
function, but this is of negligible importance.

 2. Is there a better way of referring to body? See line 33.

`$(document.body)` would be more concise. Works in all browsers I'm  
aware of.

 3. Is there a better way of injecting callbacks into functions so I
 don't have to clutter methods like on and off? See lines 81, 91,
 98, 108.

You seem reluctant to keep them on the `settings` object — why? Only  
difference is that you'd call `this.settings.onBeforeOpen()` instead.  
Scope would be preserved.

A _different_ approach to callbacks would be to use custom events — to  
fire modal:opened:before and modal:opened:after (etc.) — but there  
are pros and cons for each.

 4. Is there a way to use prototype classes that take an element as
 extensions to such element? Meaning, I would like to be able apply a
 click observer to the instance of the class directly. Something
 like:

  `modal.observe(click, someHandler)`

 and have that passed to the element to which the class is applied to.
 In the class: `this.element` or in this example `modal.element`

No, but if you wanted that sort of thing, you could write your own  
`observe` method which passed all its arguments to  
`modal.element.observe`.

Cheers,
Andrew
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---