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 Otasyn <ot...@gmail.com> on 2007/05/24 17:39:53 UTC
onclick within defs
Here is what I have:
<?xml version="1.0" encoding="UTF-8" ?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="101" height="101">
<script type="text/ecmascript" >
function changeRect(rectName) {
var useElem = document.getElementById('useElem');
if (useElem.getAttribute('href') != null) {
document.getElementById('useElem').setAttribute('href','#' +
rectName);
}
else if (useElem.getAttribute('xlink:href') != null) {
document.getElementById('useElem').setAttribute('xlink:href','#'
+ rectName);
}
}
</script>
<defs>
<rect id="rect1" x="1" y="1" width="50" height="50" stroke="green"
fill="green" onclick="changeRect('rect2')" />
<rect id="rect2" x="1" y="1" width="50" height="50" stroke="red"
fill="red" onclick="changeRect('rect1')" />
</defs>
<use id="useElem" xlink:href="#rect1" />
</svg>
This works in FireFox and Opera. IE is and always will be pure crap, so
that doesn't matter. In fact, the reason I even care to use Batik is that I
want to ensure that I can use this in every browser through an applet.
However, this SVG doesn't work in Squiggle. I played around and found that
I can put JS calls into the <use> element, but any of the JS calls within
the defs won't be run. I need different objects to produce unique results.
Such as this example: both do call changeRect(), but each supplies a
different name to be used in the function. If I can only make the call from
the <use> element, then I cannot specify what to feed the parameters such
that it relates to the currently displayed object. If there is a work
around for, I would like to know. If not, this renders Batik/Squiggle
completely useless for me.
--
View this message in context: http://www.nabble.com/onclick-within-defs-tf3810944.html#a10786685
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: onclick within defs
Posted by th...@kodak.com.
Hi Otasyn,
Otasyn <ot...@gmail.com> wrote on 05/24/2007 11:39:53 AM:
> <script type="text/ecmascript" >
> function changeRect(rectName) {
> var useElem = document.getElementById('useElem');
> if (useElem.getAttribute('href') != null) {
> document.getElementById('useElem').setAttribute('href','#' +
> rectName);
> }
> else if (useElem.getAttribute('xlink:href') != null) {
> document.getElementById('useElem').setAttribute('xlink:href','#'
> + rectName);
> }
If you are trying to set the 'href' attribute in the
xlink namespace (and you are) this is wrong according to the DOM spec.
You want to use something like:
var xlinkns = "http://www.w3.org/1999/xlink";
document.getElementById('useElem').setAttributeNS(xlinkns, "xlink:href",
"#"+rectName);
> This works in FireFox and Opera.
The above should work in FF and Opera otherwise they are totally
broken and I don't think they are.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org