Re: Should events be preferably sent to the Window or the nearest object?

On Thu, Mar 20, 2014 at 8:33 AM, Ian Hickson <ian@hixie.ch> wrote:
> On Fri, 21 Mar 2014, Mounir Lamouri wrote:
>> I would love to gather the opinion of public-webapps on a discussion
>> Hixie and I had for two different APIs recently: if an array |foo| can
>> change, should the change event be fired on its parent or the window
>> (its grandparent)? The two cases we discussed with Hixie were
>> navigator.languages and screen.orientation for which Hixie thinks the
>> change events should be fired on the window so developers can do <body
>> onlanguagechange="..." onorientationchange="..."> but I feel that having
>> the change event sent on the parent would make things more
>> self-contained.
>>
>> I would love to hear people's opinion on this.
>>
>> (Note: sending an orientationchange event to the window object would
>> have other implications because there is a proprietary API that does
>> that but this is entirely orthogonal.)
>
> To be clear, my opinion is just that we should be consistent. If the event
> is related to the Document, then we should fire it at the Document. If
> it's related to the <html>, we should fire on the <html>. Some objects are
> already EventTargets, including many new objects. I'm just saying that for
> existing objects that aren't EventTargets, and for which events have
> historically been sent to the Window, we should continue to send events to
> the Window, so that we don't end up sending some events to the object and
> some to the Window. In the case of Navigation, "online" and "offline"
> events go to the Window. In the case of Screen, "resize" and "scroll"
> events go to the Window. So it makes sense to put new events there too.

Agreed.  The exact target isn't very important here, and so being
consistent with legacy event firing for the same system is probably a
good idea.

~TJ

Received on Thursday, 20 March 2014 16:57:57 UTC