File: getElementById.svg

package info (click to toggle)
batik 1.16%2Bdfsg-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 29,180 kB
  • sloc: java: 191,940; xml: 19,062; javascript: 1,276; sh: 85; makefile: 5
file content (184 lines) | stat: -rw-r--r-- 7,915 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">

<!--

   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

-->
<!-- ====================================================================== -->
<!-- Test of the getElementById method                                      -->
<!--                                                                        -->
<!-- @author deweese@apache.org                                             -->
<!-- @version $Id: getElementById.svg 1733420 2016-03-03 07:41:59Z gadams $ -->
<!-- ====================================================================== -->

<?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?>  

<svg id="body" width="450" height="500" viewBox="0 0 450 500"
     onload="doTest()"
     xmlns="http://www.w3.org/2000/svg" 
     xmlns:xlink="http://www.w3.org/1999/xlink">

   <title>Test of 'getElementById' method</title>

   <text x="50%" y="45" class="title">Test of 'getElementById' method</text>

   <script type="text/ecmascript">
      var svgns = "http://www.w3.org/2000/svg";

      function setText(id, text, color) {
         var tspan = document.getElementById(id);
         tspan.appendChild(document.createTextNode(text));
         tspan.setAttribute("fill", color);
      }
      function checkTest(e, base, id, tId) {
         if (e == base.getElementById(id)) 
            setText(tId, "success", "green");
         else
            setText(tId, "failed", "red");
      }
      function doTest() {
         var g   = document.getElementById("group");
         var id1 = g.firstChild;
         var id2 = id1.nextSibling;
         var id3 = id2.nextSibling;
         var id4 = id3.nextSibling;
         var svg1 = id4.nextSibling;
         var id5 = svg1.firstChild;
         var id6 = id5.nextSibling;
         var id7 = svg1.nextSibling;

         checkTest(id1, document, "id1", "t1");
         checkTest(id2, document, "id2", "t2");
         checkTest(null, document, "undefined", "t3");

         checkTest(svg1, document, "svg1", "t4");
         checkTest(svg1, svg1, "svg1", "t5");

         checkTest(id5, document, "id5", "t6");
         checkTest(id5, svg1, "id5", "t7");
         checkTest(id6, svg1, "id6", "t8");
         checkTest(id7, svg1, "id7", "t9");

         id2.setAttribute("id", "d1");
         checkTest(id2, document, "d1", "t10");

         var attr = document.createAttribute("id");
         attr.setValue("d2");
         id3.setAttributeNode(attr);
         checkTest(id3, document, "d2", "t11");
         checkTest(null, document, "id3", "t12");
         attr.setValue("d3");
         checkTest(id3, document, "d3", "t13");

         id4.removeAttribute("id");
         checkTest(null, document, "id4", "t14");

         svg1.parentNode.removeChild(svg1);
         checkTest(null, document, "id5", "t15");
         checkTest(id5, svg1, "id5", "t16");

         var svg2 = document.createElementNS(svgns, "svg");
         var id8  = document.createElementNS(svgns, "desc");
         svg2.appendChild(id8);
         id8.setAttribute("id", "id8");
         checkTest(null, document, "id8", "t17");
         checkTest(null, svg1, "id8", "t18");
         checkTest(id8,  svg2, "id8", "t19");

         var id9  = document.createElementNS(svgns, "desc");
         id9.setAttribute("id", "id9");
         svg2.appendChild(id9);
         checkTest(null, document, "id9", "t20");
         checkTest(null, svg1, "id9", "t21");
         checkTest(id9,  svg2, "id9", "t22");

         var id5_2 = id5.cloneNode(true);
         g.appendChild(id5_2);
         checkTest(id5_2, document, "id5", "t23");
      }
   </script>

   <g id="group"><rect id="id1" x="10" y="60" width="50" height="50"
            fill="gold" stroke="black"
      /><rect id="id2" x="70" y="60" width="50" height="50"
            fill="crimson" stroke="black"
      /><rect id="id3" x="130" y="60" width="50" height="50"
            fill="gold" stroke="black"
      /><rect id="id4" x="190" y="60" width="50" height="50"
            fill="crimson" stroke="black"
      /><svg id="svg1" x="0" y="0" width="450" height="500"
         ><rect id="id5" x="250" y="60" width="50" height="50"
               fill="gold" stroke="black"
         /><rect id="id6" x="310" y="60" width="50" height="50"
               fill="crimson" stroke="black"
      /></svg><rect id="id7" x="370" y="60" width="50" height="50"
                    fill="gold" stroke="black"/>

      <text x="60" y="140" text-anchor="end"
       >Test 1: <tspan id="t1" x="65" text-anchor="start"/></text>
      <text x="60" y="160" text-anchor="end"
       >Test 2: <tspan id="t2" x="65" text-anchor="start"/></text>
      <text x="60" y="180" text-anchor="end"
       >Test 3: <tspan id="t3" x="65" text-anchor="start"/></text>
      <text x="60" y="200" text-anchor="end"
       >Test 4: <tspan id="t4" x="65" text-anchor="start"/></text>
      <text x="60" y="220" text-anchor="end"
       >Test 5: <tspan id="t5" x="65" text-anchor="start"/></text>

      <text x="60" y="240" text-anchor="end"
       >Test 6: <tspan id="t6" x="65" text-anchor="start"/></text>
      <text x="60" y="260" text-anchor="end"
       >Test 7: <tspan id="t7" x="65" text-anchor="start"/></text>
      <text x="60" y="280" text-anchor="end"
       >Test 8: <tspan id="t8" x="65" text-anchor="start"/></text>
      <text x="60" y="300" text-anchor="end"
       >Test 9: <tspan id="t9" x="65" text-anchor="start"/></text>
      <text x="60" y="320" text-anchor="end"
       >Test 10: <tspan id="t10" x="65" text-anchor="start"/></text>

      <text x="60" y="340" text-anchor="end"
       >Test 11: <tspan id="t11" x="65" text-anchor="start"/></text>


      <text x="220" y="140" text-anchor="end"
       >Test 12: <tspan id="t12" x="225" text-anchor="start"/></text>
      <text x="220" y="160" text-anchor="end"
       >Test 13: <tspan id="t13" x="225" text-anchor="start"/></text>
      <text x="220" y="180" text-anchor="end"
       >Test 14: <tspan id="t14" x="225" text-anchor="start"/></text>
      <text x="220" y="200" text-anchor="end"
       >Test 15: <tspan id="t15" x="225" text-anchor="start"/></text>
      <text x="220" y="220" text-anchor="end"
       >Test 16: <tspan id="t16" x="225" text-anchor="start"/></text>
      <text x="220" y="240" text-anchor="end"
       >Test 17: <tspan id="t17" x="225" text-anchor="start"/></text>
      <text x="220" y="260" text-anchor="end"
       >Test 18: <tspan id="t18" x="225" text-anchor="start"/></text>
      <text x="220" y="280" text-anchor="end"
       >Test 19: <tspan id="t19" x="225" text-anchor="start"/></text>
      <text x="220" y="300" text-anchor="end"
       >Test 20: <tspan id="t20" x="225" text-anchor="start"/></text>
      <text x="220" y="320" text-anchor="end"
       >Test 21: <tspan id="t21" x="225" text-anchor="start"/></text>
      <text x="220" y="340" text-anchor="end"
       >Test 22: <tspan id="t22" x="225" text-anchor="start"/></text>
      <text x="220" y="360" text-anchor="end"
       >Test 23: <tspan id="t23" x="225" text-anchor="start"/></text>
   </g>
</svg>