domo
domo copied to clipboard
Add support for events
/*
Event bindings are defined as mappings of event names to simple
objects which consist of the event callback, the context to bind
'this' to for the event and perhaps additional arguments relative to
the event that should be passed to the handler.
The callback signature would be function (eventName, element, eventArgs)
Maybe a mixin could be created that utilizes one of the many event
micro libraries on microjs.com could be used to make this an
optional extension, modular and also relieve the library of having
to worry about cross browser event support.
My reasoning is that since dom-o is creating the elements, it could
easily attach events as it is creating the elements as opposed to
doing some kind of CSS selector based lookup after the fact in order
to find the element again to attach the event that way. It also
helps keep the beauty of the DSL in tact by not requiring elements
that need events attached to them to be instantiated separately and
then composed into a broader dom-o statement.
*/
FORM({action: "post_here.py", method: "POST"},
LABEL({for: "name"}, "E-mail:"),
INPUT({id: "name", name: "name", type: "text"},
EVENTS({"keyup", {context: this, validateName}})),
INPUT({type: "button"},
EVENTS({"click": {context: this, function() { if (validateForm()) submitForm();}}}))
);
perhaps the best bet for an approach like this would be to differentiate attributes from properties, so that you could just use on<event-name>?
better yet, support a non-standard on attribute that takes an event name -> event handler map?
I like your second idea better, Would that look something like this?
INPUT({on: {"click": {context: this, handler: doThis, args: [1, "foo", bar]},
{"blur": {handler: doThat}}}
});
well, more likely to be just a generic on<event-name> property assignment. the binding you can do outside domo, no?
Oh ok.