<?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.

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

<svg xmlns="http://www.w3.org/2000/svg" 
     xmlns:xlink="http://www.w3.org/1999/xlink"
     xmlns:cb="http://www.example.org/gui/checkbox"
     id="body" width="450" height="500" viewBox="0 0 450 500">

  <title>Dynamic test of CSS selectors</title>
  <text x="50%" y="45" class="title">Dynamic test of CSS selectors</text>

  <style type="text/css"><![CDATA[
    text.button {
    fill: #00F;
    }

    text + text.button {
    fill: #888;
    }

    text + g > text {
      fill: #F00;
    }

    g > text {
      fill: #0F0;
    }

    g.xxx > text { fill: #F0F; }

    [id=test4] > text { fill: #80F; }

    g + [id=foo] > text { fill: #808; }

    .checkbox > path { fill: none; stroke: black; stroke-width: 2; }
    .checkbox > rect { fill: white; stroke: black; stroke-width: 1; }
    .checkbox[selected=true] > path { visibility: visible;}
    .checkbox[selected=false] > path { visibility: hidden; }

    .a { fill: red; }
    .b { fill: orange; }
    rect.a + .b { fill: blue; }

    ]]></style>

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

    function insertTextEvt(evt, x, y) {
       insertText(evt.currentTarget, x, y);
    }

    function removeTargetEvt(evt) {
       removeTarget(evt.currentTarget);
    }

    function setAttributeEvt(evt, attr, val) {
      evt.currentTarget.setAttribute(attr, val);
    }

    function removeTarget(e) {
       e.parentNode.removeChild(e);
    }

    function insertText(e, x, y) {
       var t = document.createElementNS(svgns, "text");
       t.setAttribute("x", x);
       t.setAttribute("y", y);
       t.appendChild(document.createTextNode("Inserted"));
       e.parentNode.insertBefore(t, e);
    }

    function toggleSelectedEvt(evt) {
      toggleSelected(evt.currentTarget);
    }
    function toggleSelected(e) {
       var sel = e.getAttribute("selected");
       if (sel == "true") {
         e.setAttribute("selected", "false");
       } else {
         e.setAttribute("selected", "true");
       }
    }


    function regardStart() {
      var e;
      removeTarget(document.getElementById("rm1"))
      insertText(document.getElementById("in1"), '10', '75');

      removeTarget(document.getElementById("rm2"))
      insertText(document.getElementById("in2"), '10', '125');

      document.getElementById("test3").setAttribute("class", "xxx");
      document.getElementById("test4").setAttribute("class", "");
      document.getElementById("test5").setAttribute("id", "foo");
      toggleSelected(document.getElementById("cb"));

      document.getElementById("a").setAttribute("class", "");

      regardTestInstance.scriptDone();
    }
  ]]></script>

  <g/>
  <text id="rm1" x="10" y="100" onclick="removeTargetEvt(evt)">Click me</text>
  <text x="100" y="100" class="button">Do I change?</text>

  <g/>
  <text id="in1" x="100" y="125" class="button" 
        onclick="insertTextEvt(evt, '10', '125')">Click Me!</text>

  <g/>
  <text id="rm2" x="10" y="150" onclick="removeTargetEvt(evt)">Click me</text>
  <g id="test1">
    <text id="ct" x="100" y="150">Child Text</text>
  </g>

  <g/>
  <g id="in2" onclick="insertTextEvt(evt, '10', '175')">
    <text id="ct2" x="100" y="175">Click me</text>
  </g>

  <g id="test3" onclick="setAttributeEvt(evt, 'class', 'xxx')">
    <text id="ct3" x="10" y="200">Click me</text>
  </g>

  <g id="test4" class="xxx" onclick="setAttributeEvt(evt, 'class', '')">
    <text id="ct4" x="100" y="200">Click me</text>
  </g>

  <g id="test5" class="xxx" onclick="setAttributeEvt(evt, 'id', 'foo')">
    <text id="ct5" x="200" y="200">Click me</text>
  </g>

  <g id="cb" class="checkbox" selected="true" transform="translate(10, 225)"
     onclick="toggleSelectedEvt(evt)">
    <rect width="15" height="15" fill="white" stroke="black"/>
    <path d="M3,3 L12,12 M12,3 L3,12"/>
  </g>

  <g fill="white" stroke="black">
    <rect id="a" class="a" x="10"  y="275" width="100" height="50"
      onclick="setAttributeEvt(evt, 'class', '')"/>
    <rect id="b" class="b" x="150" y="275" width="100" height="50"/>
    <g/>
    <text x="25" y="300" pointer-events="none" 
      style="fill: black; stroke: none">Click Me</text>
  </g>
</svg>
