Hi Olaf
I did something quite similar:
by construction, I set onclick event to any object. For a text box, it could be
<g id="textBox1" onclick='click("textBox","textBox1",evt);set_TextBox_Text(evt,"You've
clicked on me")'>
<rect x="..." .../>
<text x="..." ...>My init content</text>
</g>
function click(myType, myName, evt)
{
//according to the type of the last object I've clicked on, I call a specific
function to simulate a
//onLostFocus event
switch (myTypeOld)
{
case "textBox":
textBoxOnLostFocus(myNameOld)
...
}
// I memorize the name and the time of object on which I've clicked for the next
onLostFocus event
myTypeOld=myType
myNameOld=myName
//according to the new type of object, I call a specific function to simulate the
onFocus event on a object
switch (myTypeOld)
{
case "textBox":
textBoxOnFocus(myNameOld)
...
}
function textBoxOnLostFocus(myName)
{
// the textBox loose the focus
document.getElementById(myName).firstChild.setAttribute('fill','red')
}
function textBoxOnFocus(myName)
{
// the textBox get the focus
document.getElementById(myName).firstChild.setAttribute('fill','blue')
}
function set_TextBox_Text(evt,myText)
{
evt.childNodes.item(1).firstChild.data=myText
}
I've supposed that a textBox with the focus is blue and is red
otherwise, but you can do whatever you want
You can also change the two swicth by something like
eval(myTypeold+"onLostFocus(myName)")
That way, you can have many different types of objects with similar
interfaces
Hope it helps
J�r�me
Olaf Schnabel wrote:
>Hi Andr�
>
>I will use this listener for a textbox. If I click on the textbox, an 2
>event listeners are added (keypress and click) to the svg root element.
>If I click somewhere else in the document, I want to remove the event
>listeners.
>As Antoine mentioned, an onclick-event and a event listener "click" are
>2 different shoes.
>Here is my code example:
>
>if (evt.type == "click")
>{// does not work!!! - eventlistener cannot be checked
>if (evt.currentTarget.nodeName == "svg" &&
>document.documentElement.eventListener == "keypress")
>{// remove event listeners
>document.documentElement.removeEventListener("keypress",this,false);
>document.documentElement.removeEventListener("click",this,false);
>}
>if (evt.currentTarget.nodeName == "g")
>{// set event listeners
>document.documentElement.addEventListener("keypress",this,false);
>document.documentElement.addEventListener("click",this,false);
>}
>}
>
>Olaf
>
>andr� m. winter wrote:
>
>
>
>>hi olaf,
>>
>>you could check the event attribute's value and decide on that what to
>>do next. if the eventhandler (eg. "click") is not definded the according
>>attribute (eg. "onclick") should be empty. or am i missing something here?
>>
>>btw i stopped playing around with eventlisteners and use only the
>>according attributes. it's not cleaner but sometimes safer (on asv3).
>>
>>andr�
>>
>>
>>
>
>
>
--
J�r�me Tricand de la Goutte
Soci�t� Logatique
50 rue Marcel Dassault
92100 Boulogne-Billancourt
01 46 21 59 59
------------------------ Yahoo! Groups Sponsor --------------------~-->
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/1U_rlB/TM
--------------------------------------------------------------------~->
-----
To unsubscribe send a message to: [EMAIL PROTECTED]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my membership"
----
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/svg-developers/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/