Re: [webcomponents] Considering declarative event handlers

On 2/7/2012 11:41 AM, Dimitri Glazkov wrote:
> Folks,
>
> To make Web Components more usable, I would like to consider providing
> a way to declare event handlers in markup. As I look over the use

> <element name="x-tab-manager">
> <template>
> <div class="container">
> ...
> <div class="overflow">
>      <script event="click">
>          // "this" is the parent div element.
>          // "event" is the current event object.
>          if (event.target.className != 'more')
>              return;
>          if (this.moreOpened)
>              this.closeMore();
>         ...
>      </script>
> </div>
>
> ...
>
> </div>
> </template>
> </element>

> The cons are:
> * It's a new syntax
> * It doesn't allow to close over the event handler code, which is a
> common way to manage variable scoping in JS.
>
> I would appreciate any thoughts, ideas, or results of existing
> research on this. I am sure someone had thought about this harder and
> longer than I did.

How about setting it up as a different script type as well.
<script type="text/javascript+click">

That may be a horrible idea. So lets focus on the concern.
I'd like to be able to embed things like this in an HTML page and have 
them not break the page for browsers that don't support the template tag.

This script could pop up an error onload about how event doesn't have 
any attributes. Possibly, anyway.

-Charles

Received on Tuesday, 7 February 2012 20:46:27 UTC