dynamic-use-01.svg 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!--
  2. Any copyright is dedicated to the Public Domain.
  3. http://creativecommons.org/publicdomain/zero/1.0/
  4. -->
  5. <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
  6. xmlns:xlink="http://www.w3.org/1999/xlink">
  7. <title>Testing that dynamic changes to the element for a given ID are reflected in 'use'</title>
  8. <use id="u1" x="10%" xlink:href="#r1"/>
  9. <script>
  10. // force frame construction; test that parsing "r1" after frame construction
  11. // is still bound to "u1" eventually
  12. var rect = document.getElementById("u1").getBoundingClientRect();
  13. </script>
  14. <rect width="11%" height="100%" fill="lime" id="r1"/>
  15. <rect width="11%" height="100%" fill="lime" id="x"/>
  16. <use id="u2" x="20%" xlink:href="#r2"/>
  17. <script>
  18. var rect = document.getElementById("u2").getBoundingClientRect();
  19. // check that changing an id to "r2" lets u2 find it
  20. var r2 = document.getElementById("x");
  21. r2.setAttribute("id", "r2");
  22. </script>
  23. <rect width="10%" height="100%" fill="red" id="r3"/>
  24. <rect width="11%" height="100%" fill="lime" id="r3"/>
  25. <use id="u3" x="30%" xlink:href="#r3"/>
  26. <script>
  27. var rect = document.getElementById("u3").getBoundingClientRect();
  28. // check that removing the bad r3 lets u3 find the good one
  29. var r3 = document.getElementById("r3");
  30. r3.parentNode.removeChild(r3);
  31. </script>
  32. <rect width="10%" height="100%" fill="red" id="r4"/>
  33. <rect width="11%" height="100%" fill="lime" id="r4"/>
  34. <use id="u4" x="40%" xlink:href="#r4"/>
  35. <script>
  36. var rect = document.getElementById("u4").getBoundingClientRect();
  37. // check that renaming the bad r4 lets u4 find the good one
  38. var r4 = document.getElementById("r4");
  39. r4.removeAttribute("id");
  40. </script>
  41. <rect width="10%" height="100%" fill="red" id="r5"/>
  42. <use id="u5" x="50%" xlink:href="#r5"/>
  43. <script>
  44. var rect = document.getElementById("u5").getBoundingClientRect();
  45. // check that changing u5's reference works
  46. var u5 = document.getElementById("u5");
  47. u5.setAttributeNS("http://www.w3.org/1999/xlink", "href", "#r1");
  48. </script>
  49. <rect width="10%" height="100%" fill="red" id="r6"/>
  50. <rect width="11%" height="100%" fill="lime" id="r6-2"/>
  51. <use id="u6" x="60%" xlink:href="#r6"/>
  52. <script>
  53. var rect = document.getElementById("u6").getBoundingClientRect();
  54. // check that inserting a good element before the bad r6 works
  55. var r6 = document.getElementById("r6-2");
  56. r6.parentNode.removeChild(r6);
  57. r6.setAttribute("id", "r6");
  58. document.documentElement.insertBefore(r6, document.documentElement.firstChild);
  59. </script>
  60. <rect width="11%" height="100%" fill="lime" id="r7"/>
  61. <rect width="10%" height="100%" fill="red" id="r7-2"/>
  62. <use id="u7" x="70%" xlink:href="#r7"/>
  63. <script>
  64. var rect = document.getElementById("u7").getBoundingClientRect();
  65. // check that inserting a bad element after a good one doesn't break anything
  66. var r7 = document.getElementById("r7-2");
  67. r7.parentNode.removeChild(r7);
  68. r7.setAttribute("id", "r7");
  69. document.documentElement.appendChild(r7);
  70. </script>
  71. <rect width="11%" height="100%" fill="lime" id="r8-2"/>
  72. <rect width="10%" height="100%" fill="red" id="r8"/>
  73. <use id="u8" x="80%" xlink:href="#r8"/>
  74. <script>
  75. var rect = document.getElementById("u8").getBoundingClientRect();
  76. // check that renaming a good element to r8 works
  77. var r8 = document.getElementById("r8-2");
  78. r8.setAttribute("id", "r8");
  79. </script>
  80. <rect width="11%" height="100%" fill="lime"/>
  81. <rect x="90%" width="11%" height="100%" fill="lime"/>
  82. </svg>