Jorge Godoy wrote:
> I'd like seeing your code. :-) You could post it here to the list.
>
> Getting something like that with map() wouldn't be all that hard (but why
> reinventing the wheel if you have already done the hard part? ;-))...
>
> --
> Jorge Godoy <[EMAIL PROTECTED]>
Well, its not beautiful but it works.
It would be better if the selection of elements to be connected were
done using a function as parameter (so its decoupled, and extensible):
function connectEventMap(eventMap, parent)
{
parent = parent || document.body;
forEach(eventMap, partial(connectEventMapItem, parent));
}
function connectEventMapItem(parent, eventSpec)
{
var items;
var selector;
if(eventSpec.name) {
items = base.filter(
partial(hasParent, parent),
document.getElementsByName(eventSpec.name)
);
selector = 'name';
}
else if(eventSpec.id) {
items = [getElement(eventSpec.id)];
selector = 'id';
}
else if(eventSpec.tag) {
items = getElementsByTagAndClassName(eventSpec.tag, null,
parent);
selector = 'tag';
}
forEach(items, function(item) {
if(item) {
for(var eventName in eventSpec) {
if(eventName != selector) {
connect(item, eventName,
eventSpec[eventName]);
}
}
}
})
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" 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/mochikit
-~----------~----~----~----~------~----~------~--~---