Re: <script> as handler for XML events

[email protected] 19 Jun 2006 13:36:41 -0700
Newsgroups gmane.comp.mozilla.devel.xml
Organization http://groups.google.com
Message-ID <[email protected]>
> 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...)?