Hi Mr. Yang,
Thank you very much for your suggestion. I tried but can't make it work.
Maybe I am wrong somewhere:
1. I created a text node in Batik Java
SVGOMTextElement text = (SVGOMTextElement)
doc.createElementNS(svgNs, "text");
text.setAttribute("id", "MyTextNode");
text.setAttribute("x", "0");
text.setAttribute("y", "0");
text.setAttribute("visibility", "hidden");
svgRoot.appendChild(text);
2. When I need to call the Javascript function, I fired the following event
Element textElement =
svgDocument.getElementById("MyTextNode");
DocumentEvent de = (DocumentEvent) svgDocument;
MutationEvent ev =
(MutationEvent)de.createEvent("MutationEvents");
ev.initMutationEvent("DOMCharacterDataModified",
true, // canBubbleArg
false, // cancelableArg
null, // relatedNodeArg
null, // prevValueArg
null, // newValueArg
null, // attrNameArg
ev.ADDITION);
EventTarget t = (EventTarget) textElement;
t.dispatchEvent(ev);
3. In Javascript, my code is as follows:
var myTextNode = document.getElementById("MyTextNode");
myTextNode.addEventListener("MutationEvent", Scroll(evt, elt), false)
Where Scroll(evt, elt) is my Javascript function.
It seems that the code does not work. Could you tell me what is wrong with
my code?
With best regards,
William
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, February 10, 2003 3:58 PM
Subject: RE: Can I call Javascript function from Batik Java code?
> Here's a method based on the standard (but optional) DOM Event type,
> MutationEvents. It took me a little while to come up with it, but I'll
give
> it to you for free :-).
>
> If your SVG processor supports the MutationEvents feature (you should test
> for this, especially if you intend to also run on non-Batik SVG engines),
> and has the right language bindings to the DOM (like Batik does) then you
> can use a <text> element (probably with visibility="hidden", and width and
> height="0") to which you dispatch mutation events from Java, and to which
> you can attach an ECMAScript listener. The new text content specified in
> the event data can be used to carry any kind of message you want. You can
> use the same technique to go from ECMAScript to Java, too.
>
> Note that:
>
> (1) Using dispatchEvent() is more efficient that actually changing the
> content of the <text> element.
> (2) The <text> element should not have display="none", since then it is
not
> supposed to receive any events. [However, Batik currently does allow the
> dispatchEvent() method to send events to a <text> element having the
> display="none" attribute. I believe this is a bug. Also, I noticed that
in
> Batik when you use the dispatchEvent() method to send a mutation event for
a
> <text> element, the text element does not change its actual content,
meaning
> that the dispatched event is lying about the new (and possibly also the
old)
> content of the element. This is probably acceptable behavior, since the
> spec doesn't seem to say this can't happen, and it is more efficient.
Just
> be sure that you don't accidentally treat the event data for such <text>
> elements as being real text event data.]
>
> Samuel C. Yang
> Echelon Corp. <http://www.echelon.com>
>
> email: <mailto:[EMAIL PROTECTED]>
> phone: 408-938-5314
> fax: 408-790-3430
>
> > -----Original Message-----
> > From: William Huang [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, February 10, 2003 11:44 AM
> > To: Batik Users
> > Subject: Can I call Javascript function from Batik Java code?
> >
> >
> > I changed the SVGImageElementBridge program to make the <a>
> > element work as my application needs. However, I need to call
> > one large Javascript function of mine at the end of my
> > createSVGImageNode() method call. I can rewrite the
> > Javascript function into Java, but that costs too much
> > efforts. Is there a way to call Javascript function from
> > Batik Java implementation? Thanks a lot.
> >
> > William
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]