onclick on an svg element

1,737 views
Skip to first unread message

zamek

unread,
Apr 30, 2012, 12:39:29 PM4/30/12
to lib-gwt-svg
Hi All,

Is there any method to catch a mouse click from inside svg?
I made a javascript function in svg :

<script type="text/javascript"><![CDATA[>
function rmP1Click(evt)
{
alert("RMP1 clicked");
}
< ]]> ></script>

and in an svg element:

<g onclick="rmP1Click(evt)">
<use height="1052.4" id="RM_P1_OFF"
style="visibility:visible;display:inline"
transform="matrix(-0.22574251,0,0,0.22574251,472.3526,483.18581)"
visibility="visible"
width="744.09003" x="0" xlink:href="#pump_off" y="0"/>
</g>

If I open it with firefox directly it works well, but when I load it
from my gwt app. ff. said: unknown function rmP1Click.

I would like to identify an object as sender from svg in my gwt
application.

thx
Zamek



Lukas Laag

unread,
May 5, 2012, 11:51:43 AM5/5/12
to lib-g...@googlegroups.com
Hi,

Interesting problem, I can reproduce it also. It seems to be specific
to firefox. I have filed a bug for this
https://bugzilla.mozilla.org/show_bug.cgi?id=752231

Regards

Lukas

zamek42

unread,
May 7, 2012, 2:05:34 AM5/7/12
to lib-g...@googlegroups.com
Hi All,

05/05/2012 05:51 PM keltezéssel, Lukas Laag írta:
> Hi,
>
> Interesting problem, I can reproduce it also. It seems to be specific
> to firefox. I have filed a bug for this
> https://bugzilla.mozilla.org/show_bug.cgi?id=752231
Thx Lukas, I tested it with FF12 which camed out at the last week, but
it cannot works :(
> Regards
>
> Lukas
>
> On Mon, Apr 30, 2012 at 6:39 PM, zamek<zam...@gmail.com> wrote:
>> Hi All,
>>
>> Is there any method to catch a mouse click from inside svg?
>> I made a javascript function in svg :
>>
>> <script type="text/javascript"><![CDATA[>
>> function rmP1Click(evt)
>> {
>> alert("RMP1 clicked");
>> }
>> < ]]> ></script>
>>
>> and in an svg element:
>>
>> <g onclick="rmP1Click(evt)">
>> <use height="1052.4" id="RM_P1_OFF"
>> style="visibility:visible;display:inline"
>> transform="matrix(-0.22574251,0,0,0.22574251,472.3526,483.18581)"
>> visibility="visible"
>> width="744.09003" x="0" xlink:href="#pump_off" y="0"/>
>> </g>
>>
>> If I open it with firefox directly it works well, but when I load it
>> from my gwt app. ff. said: unknown function rmP1Click.
>>
>> I would like to identify an object as sender from svg in my gwt
>> application.
>>
>> thx
>> Zamek
>>
>>
>>


--
thx
Zoltan (Zamek) Zidarics
programmer
email:zam...@gmail.com
skype:zamek_z

Lukas Laag

unread,
May 12, 2012, 5:48:56 PM5/12/12
to lib-g...@googlegroups.com
Hi,

I have not yet had an answer from Mozilla for this problem:
https://bugzilla.mozilla.org/show_bug.cgi?id=752231

I have found a workaround thought and have integrated the fix and
pushed in here:
https://github.com/laaglu/lib-gwt-svg/commit/28d220bc9d7c1a5e5e84db6c101d57f57595aa52

Let me know if this fixes your problem when you get a chance.

Regards

Lukas

zamek42

unread,
May 14, 2012, 2:59:42 AM5/14/12
to lib-g...@googlegroups.com
hello,

05/12/2012 11:48 PM keltezéssel, Lukas Laag írta:
> Hi,
>
> I have not yet had an answer from Mozilla for this problem:
> https://bugzilla.mozilla.org/show_bug.cgi?id=752231
>
> I have found a workaround thought and have integrated the fix and
> pushed in here:
> https://github.com/laaglu/lib-gwt-svg/commit/28d220bc9d7c1a5e5e84db6c101d57f57595aa52
>
> Let me know if this fixes your problem when you get a chance.
>
>
It works well :)
Thx a lot for good job!

Lukas Laag

unread,
May 14, 2012, 3:52:29 PM5/14/12
to lib-g...@googlegroups.com
Hi again,

I got an answer from Mozilla and it turns out the firefox behavior is
the only correct one (a browser is supposed to disable the scripts
parsed from DOMParser.parserString, which is the function I use). So
mozilla has filed a bug report to webkit, and I have filed one for
Opera. (see: https://bugzilla.mozilla.org/show_bug.cgi?id=752231).

With regards to lib-gwt-svg, what I plan to do in the next release
(0.5.7), is to add the following method overload to OMSVGParser.

/**
* Calls OMSVGSVGElement(String, boolean) with parseScripts set to true
*/
public static final OMSVGSVGElement parse(String rawSvg)
/**
* Parses the supplied SVG text into a document
* @param rawSvg
* raw xml to be parsed
* @param parseScripts
* activate the scripts embedded in the svg if set, deactivates them otherwise.
* @return
* the document resulting from the parse
* @throws ParserException
* if the document is not well-formed or is not SVG
*/
public static final OMSVGSVGElement parse(String rawSvg, boolean parseScripts)

This way your code will keep on working when Opera and Webkit fix
their bugs, and it will still be possible to have the official
'script-less' behavior by valuating the parseScripts flags to false.

Regards

Lukas

zamek42

unread,
May 22, 2012, 3:52:53 PM5/22/12
to lib-g...@googlegroups.com
Hi Lukas,

Thx for your answer, I use your snapshot version.
I found a differrent way to getting an click event from svg:
I can add a clickEvent to the selected element after the svg is loaded.

thx a lot,
Reply all
Reply to author
Forward
0 new messages