You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Nirmesh Desai <nd...@cardiff.com> on 2008/07/16 22:45:37 UTC

svg event on text value change


Is there an event for 'text' node's value change?


I had managed to use DOMAttrModified event to get updates relayed to
other elements

However I do not want to add attribute just to use the listener, is a
direct event on text content change?

Thanks,
Nirmesh.



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: svg event on text value change

Posted by Nirmesh Desai <nd...@cardiff.com>.
Thanks Cameron,

The onload for svg element is working so I will use it to add DOMCharacterDataModified listeners to other elements.

The other elements have variable ids so I need to follow this approach
to wait till svg is loaded.


Nirmesh.


-----Original Message-----
From: Cameron McCormack [mailto:cam@mcc.id.au] 
Sent: Wednesday, July 16, 2008 4:21 PM
To: batik-users@xmlgraphics.apache.org
Subject: Re: svg event on text value change

Hi Nirmesh.

Nirmesh Desai:
> Is there a place where I can add this listener to appropriate nodes?
> 
> Currently onload throws error in batik saying the function not found.

Here’s an example:

<svg xmlns='http://www.w3.org/2000/svg' width='400' height='300' font-size='18'>
  <title id='title'>Initial title</title>
  <text x='20' y='30'>Document title: “<tspan id='t'> </tspan>”</text>
  <rect x='20' y='60' width='30' height='30'
        onclick='title.firstChild.nodeValue = "Hello!"'/>
  <text x='60' y='80'>← click to change title</text>
  <script>
    var title = document.getElementById('title');
    var t = document.getElementById('t');
    function update(evt) {
      t.firstChild.nodeValue = title.firstChild.nodeValue;
    }
    title.addEventListener('DOMCharacterDataModified', update, false);
    update();
  </script>
</svg>

-- 
Cameron McCormack ≝ http://mcc.id.au/

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org



Re: svg event on text value change

Posted by Cameron McCormack <ca...@mcc.id.au>.
Hi Nirmesh.

Nirmesh Desai:
> Is there a place where I can add this listener to appropriate nodes?
> 
> Currently onload throws error in batik saying the function not found.

Here’s an example:

<svg xmlns='http://www.w3.org/2000/svg' width='400' height='300' font-size='18'>
  <title id='title'>Initial title</title>
  <text x='20' y='30'>Document title: “<tspan id='t'> </tspan>”</text>
  <rect x='20' y='60' width='30' height='30'
        onclick='title.firstChild.nodeValue = "Hello!"'/>
  <text x='60' y='80'>← click to change title</text>
  <script>
    var title = document.getElementById('title');
    var t = document.getElementById('t');
    function update(evt) {
      t.firstChild.nodeValue = title.firstChild.nodeValue;
    }
    title.addEventListener('DOMCharacterDataModified', update, false);
    update();
  </script>
</svg>

-- 
Cameron McCormack ≝ http://mcc.id.au/

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: svg event on text value change

Posted by Nirmesh Desai <nd...@cardiff.com>.
Thanks.

Is there a place where I can add this listener to appropriate nodes?

Currently onload throws error in batik saying the function not found.


Where can I add this line without using ui (mouse/keyboard) events..

node.addEventListener('DOMCharacterDataModified', doSomething, false);

Thanks again in advance.
Nirmesh.

-----Original Message-----
From: Cameron McCormack [mailto:cam@mcc.id.au] 
Sent: Wednesday, July 16, 2008 3:55 PM
To: batik-users@xmlgraphics.apache.org
Subject: Re: svg event on text value change

Nirmesh Desai:
> Is there an event for 'text' node's value change?

Yes, you can listen for a DOMCharacterDataModified event:

  http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MutationEvent

-- 
Cameron McCormack ≝ http://mcc.id.au/

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org



Re: svg event on text value change

Posted by Cameron McCormack <ca...@mcc.id.au>.
Nirmesh Desai:
> Is there an event for 'text' node's value change?

Yes, you can listen for a DOMCharacterDataModified event:

  http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MutationEvent

-- 
Cameron McCormack ≝ http://mcc.id.au/

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org