<script> as handler for XML events

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

<script> as handler for XML events

Chris Cross-4
Jonas,

I'm developing a Mozilla extension implementing XHTML+Voice, or X+V (see
http://www.w3.org/TR/xhtml+voice/ and
http://www.voicexml.org/specs/multimodal/x+v/12/) The X+V profile pulls
in VoiceXML <form> and makes it a handler for XML events. However, to
make a multimodal application truly interesting, the document author
needs the ability to respond to the XML events emitted by VoiceXML.
Opera and NetFront have implemented <script> as a handler by allowing it
to be specified in the XML events <listener> element, without otherwise
affecting the behavior of <script> (it still executes on page load, for
example.) This approach is used in examples in the XML spec but is not
normative. There was some discussion of including it in the Mozilla XML
events implementation
(https://bugzilla.mozilla.org/show_bug.cgi?id=164482) .

What are the options to implement this behavior in Mozilla?

chris
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: <script> as handler for XML events

SmauG-2
Chris Cross wrote:

> Jonas,
>
> I'm developing a Mozilla extension implementing XHTML+Voice, or X+V (see
> http://www.w3.org/TR/xhtml+voice/ and
> http://www.voicexml.org/specs/multimodal/x+v/12/) The X+V profile pulls
> in VoiceXML <form> and makes it a handler for XML events. However, to
> make a multimodal application truly interesting, the document author
> needs the ability to respond to the XML events emitted by VoiceXML.
> Opera and NetFront have implemented <script> as a handler by allowing it
> to be specified in the XML events <listener> element, without otherwise
> affecting the behavior of <script> (it still executes on page load, for
> example.) This approach is used in examples in the XML spec but is not
> normative. There was some discussion of including it in the Mozilla XML
> events implementation
> (https://bugzilla.mozilla.org/show_bug.cgi?id=164482) .
>
> What are the options to implement this behavior in Mozilla?
>
> chris

It would be great if W3C had a specification for script elements as XML
Events handlers.
(Still waiting to see the "companion specification",
http://www.w3.org/TR/xml-events/Overview.html#section-eventhandlers)

Do Opera and NetFront handle <script> in the same way? For example, is
the event object accessible from the script (probably using |event| )
and what is the |this| object in the script? How, or based on what is
the script execution deferred when the element is a handler (i.e. where
did the "declare" attribute come ;) that is not HTML4. XHTML2 Object
module has that attribute...)?
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: <script> as handler for XML events

mccobb
> It would be great if W3C had a specification for script elements as XML
> Events handlers.
> (Still waiting to see the "companion specification",
> http://www.w3.org/TR/xml-events/Overview.html#section-eventhandlers)
>
Agreed!

> Do Opera and NetFront handle <script> in the same way? For example, is
> the event object accessible from the script (probably using |event| )
> and what is the |this| object in the script?
>From the DOM Level 2 Events specification, "The Event interface is used
to provide contextual information about an event to the handler
processing the event. An object which implements the Event interface is
generally passed as the first parameter to an event handler."  As a way
to allow the author access to the event parameter, both Opera and
NetFront support an implicit object "event" that is scoped to the the
<script> handler.
Here is an example which works the same in both Opera and NetFront.
You can
try it with a copy of Opera 8.5:
<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml"
  xml:lang="en"
  xmlns:ev="http://www.w3.org/2001/xml-events">
<head><title>Mouse Click Event</title>

  <script type="text/javascript">
        var isDocLoaded = false;
  </script>

  <script id="proxy" type="text/javascript"
           ev:event="click" ev:observer="para">
  if (isDocLoaded) {
   alert("X="+event.screenX+" Y="+event.screenY);
  }
  </script>

  <script type="text/javascript">
    isDocLoaded = true;
  </script>
<body>
   <h4>Mouse Click Event</h4>
   <p id="para">Click anywhere in this paragraph.
An alert should pop up with the X and Y location
where you clicked.  Twinkle, twinkle little star,
how I wonder what you are.  Up above the world
so high like a diamond in the sky.  Twinkle,
twinkle little star, how I wonder what you are.
</p>
</body>
</html>

> How, or based on what is
> the script execution deferred when the element is a handler (i.e. where
> did the "declare" attribute come ;) that is not HTML4. XHTML2 Object
> module has that attribute...)?
Unfortunately 'declare="declare"' was dropped by the latest version of
the XHTML 2 WD when <script> was replaced by <handler> (but the latest
XHTML 2 WD is still incomplete -- the specification of the supported
XML Events types is missing, for example). Both Opera and NetFront
support 'declare="declare"', but the only truly portable and backwards
compatible solution is to declare a variable "isDocLoaded" and set it
to false before using a condition for execution of the event handler
scripts, and then setting to true when done loading.

smaug wrote:

> Chris Cross wrote:
> > Jonas,
> >
> > I'm developing a Mozilla extension implementing XHTML+Voice, or X+V (see
> > http://www.w3.org/TR/xhtml+voice/ and
> > http://www.voicexml.org/specs/multimodal/x+v/12/) The X+V profile pulls
> > in VoiceXML <form> and makes it a handler for XML events. However, to
> > make a multimodal application truly interesting, the document author
> > needs the ability to respond to the XML events emitted by VoiceXML.
> > Opera and NetFront have implemented <script> as a handler by allowing it
> > to be specified in the XML events <listener> element, without otherwise
> > affecting the behavior of <script> (it still executes on page load, for
> > example.) This approach is used in examples in the XML spec but is not
> > normative. There was some discussion of including it in the Mozilla XML
> > events implementation
> > (https://bugzilla.mozilla.org/show_bug.cgi?id=164482) .
> >
> > What are the options to implement this behavior in Mozilla?
> >
> > chris
>
> It would be great if W3C had a specification for script elements as XML
> Events handlers.
> (Still waiting to see the "companion specification",
> http://www.w3.org/TR/xml-events/Overview.html#section-eventhandlers)
>
> Do Opera and NetFront handle <script> in the same way? For example, is
> the event object accessible from the script (probably using |event| )
> and what is the |this| object in the script? How, or based on what is
> the script execution deferred when the element is a handler (i.e. where
> did the "declare" attribute come ;) that is not HTML4. XHTML2 Object
> module has that attribute...)?

_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: <script> as handler for XML events

SmauG-2
[hidden email] wrote:

>> It would be great if W3C had a specification for script elements as XML
>> Events handlers.
>> (Still waiting to see the "companion specification",
>> http://www.w3.org/TR/xml-events/Overview.html#section-eventhandlers)
>>
> Agreed!
>
>> Do Opera and NetFront handle <script> in the same way? For example, is
>> the event object accessible from the script (probably using |event| )
>> and what is the |this| object in the script?
>>From the DOM Level 2 Events specification, "The Event interface is used
> to provide contextual information about an event to the handler
> processing the event. An object which implements the Event interface is
> generally passed as the first parameter to an event handler."  As a way
> to allow the author access to the event parameter, both Opera and
> NetFront support an implicit object "event" that is scoped to the the
> <script> handler.
> Here is an example which works the same in both Opera and NetFront.
> You can
> try it with a copy of Opera 8.5:
> <?xml version="1.0"?>
> <html xmlns="http://www.w3.org/1999/xhtml"
>   xml:lang="en"
>   xmlns:ev="http://www.w3.org/2001/xml-events">
> <head><title>Mouse Click Event</title>
>
>   <script type="text/javascript">
> var isDocLoaded = false;
>   </script>
>
>   <script id="proxy" type="text/javascript"
>            ev:event="click" ev:observer="para">
>   if (isDocLoaded) {
>    alert("X="+event.screenX+" Y="+event.screenY);
>   }
>   </script>


So what is |this| in the <script> ? Is it |window|, |HTMLScriptElement|
or the currentTarget of the |event| or what?

>
>   <script type="text/javascript">
>     isDocLoaded = true;
>   </script>
> <body>
>    <h4>Mouse Click Event</h4>
>    <p id="para">Click anywhere in this paragraph.
> An alert should pop up with the X and Y location
> where you clicked.  Twinkle, twinkle little star,
> how I wonder what you are.  Up above the world
> so high like a diamond in the sky.  Twinkle,
> twinkle little star, how I wonder what you are.
> </p>
> </body>
> </html>
>
>> How, or based on what is
>> the script execution deferred when the element is a handler (i.e. where
>> did the "declare" attribute come ;) that is not HTML4. XHTML2 Object
>> module has that attribute...)?
> Unfortunately 'declare="declare"' was dropped by the latest version of
> the XHTML 2 WD when <script> was replaced by <handler> (but the latest
> XHTML 2 WD is still incomplete -- the specification of the supported
> XML Events types is missing, for example). Both Opera and NetFront
> support 'declare="declare"', but the only truly portable and backwards
> compatible solution is to declare a variable "isDocLoaded" and set it
> to false before using a condition for execution of the event handler
> scripts, and then setting to true when done loading.
>
> smaug wrote:
>> Chris Cross wrote:
>>> Jonas,
>>>
>>> I'm developing a Mozilla extension implementing XHTML+Voice, or X+V (see
>>> http://www.w3.org/TR/xhtml+voice/ and
>>> http://www.voicexml.org/specs/multimodal/x+v/12/) The X+V profile pulls
>>> in VoiceXML <form> and makes it a handler for XML events. However, to
>>> make a multimodal application truly interesting, the document author
>>> needs the ability to respond to the XML events emitted by VoiceXML.
>>> Opera and NetFront have implemented <script> as a handler by allowing it
>>> to be specified in the XML events <listener> element, without otherwise
>>> affecting the behavior of <script> (it still executes on page load, for
>>> example.) This approach is used in examples in the XML spec but is not
>>> normative. There was some discussion of including it in the Mozilla XML
>>> events implementation
>>> (https://bugzilla.mozilla.org/show_bug.cgi?id=164482) .
>>>
>>> What are the options to implement this behavior in Mozilla?
>>>
>>> chris
>> It would be great if W3C had a specification for script elements as XML
>> Events handlers.
>> (Still waiting to see the "companion specification",
>> http://www.w3.org/TR/xml-events/Overview.html#section-eventhandlers)
>>
>> Do Opera and NetFront handle <script> in the same way? For example, is
>> the event object accessible from the script (probably using |event| )
>> and what is the |this| object in the script? How, or based on what is
>> the script execution deferred when the element is a handler (i.e. where
>> did the "declare" attribute come ;) that is not HTML4. XHTML2 Object
>> module has that attribute...)?
>
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: <script> as handler for XML events

Chris Cross-4
smaug wrote:
> So what is |this| in the <script> ? Is it |window|, |HTMLScriptElement|
> or the currentTarget of the |event| or what?
>

A <script> with this line of code in Opera 8.5 returned true

        alert(this == window.top);

so it looks like |this| is the main browser window in Opera.

A similar test in NetFront reveals that |this| is the target of the
event. Nothing like choice in the market, eh? ;-)

What do you think |this| *should* be?

chris
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: <script> as handler for XML events

SmauG-2
Chris Cross wrote:

> smaug wrote:
>> So what is |this| in the <script> ? Is it |window|,
>> |HTMLScriptElement| or the currentTarget of the |event| or what?
>>
>
> A <script> with this line of code in Opera 8.5 returned true
>
>     alert(this == window.top);
>
> so it looks like |this| is the main browser window in Opera.
>
> A similar test in NetFront reveals that |this| is the target of the
> event. Nothing like choice in the market, eh? ;-)
>
> What do you think |this| *should* be?

I *think* it should be |window|. That way it would be the same for
normal <script> elements and XML Events handlers. Though, normal
even handlers have .currentTarget as |this|...

>
> chris
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: <script> as handler for XML events

Jonas Sicking
In reply to this post by Chris Cross-4
Hi Chris,

Sorry for taking so long to get back to you. I had a big backlog of NG
postings to read.

The problem with reusing <script> is that the semantics of <script> and
what you want is slightly different. For example if you have something like:

   <script id="proxy" type="text/javascript"
            ev:event="click" ev:observer="para">
   alert("hello");
   </script>

You'll not only see an alert every time "para" is clicked, but also
during loading of the document. To work around this ugly hacks like the
one in mccobbs mail.

So I suggest that we add a new element, <handler> that can be used as
EventHandler. This would solve the problem of handlers executing during
load.

Additionally, we could require such elements to implement the
EventListener interface which means that they can be used as
event-handlers even when using the addEventListener function.

/ Jonas

Chris Cross wrote:

> Jonas,
>
> I'm developing a Mozilla extension implementing XHTML+Voice, or X+V (see
> http://www.w3.org/TR/xhtml+voice/ and
> http://www.voicexml.org/specs/multimodal/x+v/12/) The X+V profile pulls
> in VoiceXML <form> and makes it a handler for XML events. However, to
> make a multimodal application truly interesting, the document author
> needs the ability to respond to the XML events emitted by VoiceXML.
> Opera and NetFront have implemented <script> as a handler by allowing it
> to be specified in the XML events <listener> element, without otherwise
> affecting the behavior of <script> (it still executes on page load, for
> example.) This approach is used in examples in the XML spec but is not
> normative. There was some discussion of including it in the Mozilla XML
> events implementation
> (https://bugzilla.mozilla.org/show_bug.cgi?id=164482) .
>
> What are the options to implement this behavior in Mozilla?
>
> chris
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: <script> as handler for XML events

Chris Cross-4
Jonas Sicking wrote:

>
> So I suggest that we add a new element, <handler> that can be used as
> EventHandler. This would solve the problem of handlers executing during
> load.
>
> Additionally, we could require such elements to implement the
> EventListener interface which means that they can be used as
> event-handlers even when using the addEventListener function.
>
> / Jonas
>

Hi Jonas,
<handler> seems to be a reasonable way to go and I would be interested
in working on it. Presumably it could inherit much of its behavior from
<script>. Can you provide some high level directions for a newbie?

chirs
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: <script> as handler for XML events

Jonas Sicking
Chris Cross wrote:
> <handler> seems to be a reasonable way to go and I would be interested
> in working on it. Presumably it could inherit much of its behavior from
> <script>. Can you provide some high level directions for a newbie?

I would suggest looking at nsSVGScriptElement to start off with.
nsHTMLScriptElement has a lot of the same code, but it also has a bunch
of cruft you are not interested in.

Though you're going to have to modify it quite a bit since it interacts
with the script engine in such a way that the script is automatically
loaded and executed, whereas you just want to do the former.

But at least it'll point you towards the right APIs.

/ Jonas
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml