SVG – Learning by Coding
1: <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
2: <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
3: "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
4: <!ATTLIST svg xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink">
5: ]>
6:
7: <!-- SVG - Learning by Coding - http://www.datenverdrahten.de/svglbc/ -->
8: <!-- Author: Dr. Thomas Meinike 08/04 - thomas@handmadecode.de -->
9:
10: <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
11:
12: <title>SVG - Learning by Coding</title>
13: <desc>SVG-Spezifikation in Beispielen</desc>
14:
15: <defs>
16:
17: <script type="text/javascript">
18: <![CDATA[
19:
20: function SplitNorm(evt)
21: {
22: var svgdoc,txtobj;
23: svgdoc=evt.target.ownerDocument;
24: txtobj=svgdoc.getElementById("txt");
25:
26: alert("- Ausgangszustand\n\n"+
27: "Anzahl der Kindknoten von txtobj: "+txtobj.childNodes.length+
28: "\ntxtobj.firstChild.nodeValue: "+txtobj.firstChild.nodeValue);
29:
30: // Textinhalt ab dem 5. Zeichen als neuen Textknoten abspalten
31: txtobj.firstChild.splitText(4); // Ergebnis = neuer Textknoten
32: alert("- nach txtobj.firstChild.splitText(4)\n\n"+
33: "Anzahl der Kindknoten von txtobj: "+txtobj.childNodes.length+
34: "\ntxtobj.firstChild.nodeValue: "+txtobj.firstChild.nodeValue+
35: "\ntxtobj.lastChild.nodeValue: "+txtobj.lastChild.nodeValue);
36:
37: // Geschwister-Textknoten (siblings) zusammenfassen
38: txtobj.normalize();
39: alert("- nach textobj.normalize()\n\n"+
40: "Anzahl der Kindknoten von txtobj: "+txtobj.childNodes.length+
41: "\ntxtobj.firstChild.nodeValue: "+txtobj.firstChild.nodeValue);
42: }
43:
44: ]]>
45: </script>
46:
47: </defs>
48:
49: <text x="20" y="30" style="fill: #000; font-size: 24px">
50: DOM-Methoden splitText() und normalize()</text>
51:
52: <text id="txt" x="20" y="60" style="fill: #00C; font-size: 14px">TestText</text>
53:
54: <a xlink:href="" cursor="pointer" onclick="return false">
55: <text x="20" y="80" onclick="SplitNorm(evt)">Methoden aufrufen</text>
56: <set attributeName="fill" attributeType="CSS" to="#F00" begin="mouseover"/>
57: <set attributeName="fill" attributeType="CSS" to="#000" begin="mouseout"/>
58: </a>
59:
60: </svg>
[zum Anfang]