Greg
2006-04-19 22:22:00 UTC
This code is the start of a prototype for a time controller. Click on the
chain icon to toggle it on/off and click on the grey areas to add a
marker. Only, it doesn't show! The alerts seem to indicate the marker is
appended correctly! What's wrong with this code?(see below)
When I save the generated source code from 'Firefox/tools/Web
Developer/View Source/View Generated Source' and reopen it in Firefox 1.5,
I see the results I'm after but never directly from the code.
Cheers,
Greg
ps I hope the text wrapping hasn't made it too unintelligible
======================================================
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- Created with
Inkscape (http://www.inkscape.org/) --> <svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="660pt"
height="250pt"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.43"
sodipodi:docbase="C:\Documents and
Settings\Administrator\Desktop\HeatingController"
sodipodi:docname="timeLineObj.svg"
version="1.0">
<script
type="text/ecmascript"
id="script3">
boldStyle =
"fill:none;stroke:#000000;stroke-width:2.0000000;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-opacity:1.0000000";
greyStyle =
"fill:none;stroke:#888888;stroke-width:2.0000000;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-opacity:1.0000000";
redBox =
"fill:#ff0000;fill-opacity:1;stroke:#0000ff;stroke-width:2.0000000;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-opacity:1.0000000;visibility:'visible';";
//redBox = "fill:#ff00ff;";
function toggleLinkColour(evt) {
var thisLink = evt.target;
var thisLinkParent = thisLink.parentNode; //can't see where the
intervening nodes are that make it 1,3 & 5, rather than 0,1 & 2?
var link1 = thisLinkParent.childNodes[1]; var link2 =
thisLinkParent.childNodes[3]; var link3 = thisLinkParent.childNodes[5];
if (thisLink.parentNode.getAttribute("tog") == 0){
thisLinkParent.setAttribute("tog",1) ;
link1.setAttribute("style", boldStyle); link2.setAttribute("style",
boldStyle); link3.setAttribute("style", boldStyle);
}
else{
thisLinkParent.setAttribute("tog",0) ;
link1.setAttribute("style", greyStyle); link2.setAttribute("style",
greyStyle); link3.setAttribute("style", greyStyle);
}
}
function switchEvent(evt) {
var targetObj = evt.target; //The object that received the event var
targetDoc = targetObj.ownerDocument; //Owner document var targetGrp =
targetObj.parentNode; //The group containing the target object (so that
the new objects can be appended as siblings to the target object)
var targetX = evt.pageX - targetObj.getAttribute("x"); var targetY =
evt.pageY - targetObj.getAttribute("y"); //alert(evt.target.id + " " +
targetX + " " + targetY);
periodIndicator = targetDoc.createElement("rect");
//alert(periodIndicator);
periodIndicator.setAttribute("id", "startmark");
periodIndicator.setAttribute("style", redBox);
periodIndicator.setAttribute("x", targetX);
periodIndicator.setAttribute("y", targetY);
periodIndicator.setAttribute("width", 6);
periodIndicator.setAttribute("height", 6);
targetGrp.appendChild(periodIndicator); //Add it to the group
containing the appropriate timeline target //targetDoc.forceRedraw();
//Can't find any documentation on this, so don't know if it's called
correctly - doesn't work as far as I can tell
alert(targetGrp.getAttribute("id"));
alert(targetObj.getAttribute("id"));
alert(periodIndicator.getAttribute("id"));
// periodIndicator SEEMS to be there but can't view it - maybe appended
it in the wrong place?
}
}
</script>
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.304619"
inkscape:cx="395.13338"
inkscape:cy="728.43129"
inkscape:document-units="px"
inkscape:current-layer="layer1"
inkscape:window-width="1142"
inkscape:window-height="755"
inkscape:window-x="0"
inkscape:window-y="46"
showguides="true"
inkscape:guide-bbox="true" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 120,28 L 770,28"
id="Timeline" />
<g
id="HWtimelineGroup">
<rect
ry="0"
rx="0"
y="14"
x="120"
height="12"
width="650"
id="HWtimelineTarget"
onmouseup="switchEvent(evt)"
style="fill:#000000;fill-opacity:0.05;stroke:#dddddd;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
/>
</g>
<g
id="CHtimelineGroup">
<rect
ry="0"
rx="0"
y="30"
x="120"
height="12"
width="650"
id="CHtimelineTarget"
onmouseup="switchEvent(evt)"
style="fill:#000000;fill-opacity:0.05;stroke:#dddddd;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
/>
</g>
<g
id="LabelGroup"
transform="translate(67.6447,-78.45772)">
<text
id="HotWaterLabel"
y="102.61897"
x="10.540583"
style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream
Vera Sans" xml:space="preserve"><tspan
y="102.61897"
x="10.540583"
id="tspan2597"
sodipodi:role="line">HW</tspan></text>
<text
id="CentralHeatingLabel"
y="119.70714"
x="12.922419"
style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream
Vera Sans" xml:space="preserve"><tspan
y="119.70714"
x="12.922419"
id="tspan2601"
sodipodi:role="line">CH</tspan></text>
</g>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream
Vera Sans" x="22.510159"
y="32.710236"
id="timelineLabel"><tspan
sodipodi:role="line"
id="tspan3348"
x="22.510159"
y="32.710236"><Label></tspan></text>
<g
id="linkHW-CH"
transform="translate(65.0269,-81.40793)"
onclick="toggleLinkColour(evt)"
tog="0">
<path
sodipodi:type="arc"
id="L1"
sodipodi:cx="88.588737"
sodipodi:cy="175.01889"
sodipodi:rx="4.9465795"
sodipodi:ry="9.44347"
d="M 93.535317 175.01889 A 4.9465795 9.44347 0 1 1
83.642158,175.01889 A 4.9465795 9.44347 0 1 1 93.535317
175.01889 z"
style="fill:none;stroke:#888888;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
transform="matrix(0.571439,0,0,0.421008,-6.05958,31.51435)" />
<path
sodipodi:type="arc"
id="L2"
sodipodi:cx="88.588737"
sodipodi:cy="175.01889"
sodipodi:rx="4.9465795"
sodipodi:ry="9.44347"
d="M 93.535317 175.01889 A 4.9465795 9.44347 0 1 1
83.642158,175.01889 A 4.9465795 9.44347 0 1 1 93.535317
175.01889 z"
style="fill:none;stroke:#888888;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
transform="matrix(0.571439,0,0,0.421008,-6.05958,35.76649)" />
<path
sodipodi:type="arc"
id="L3"
sodipodi:cx="88.588737"
sodipodi:cy="175.01889"
sodipodi:rx="4.9465795"
sodipodi:ry="9.44347"
d="M 93.535317 175.01889 A 4.9465795 9.44347 0 1 1
83.642158,175.01889 A 4.9465795 9.44347 0 1 1 93.535317
175.01889 z"
style="fill:none;stroke:#888888;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
transform="matrix(0.571439,0,0,0.421008,-6.05958,40.76534)" />
<rect
ry="0"
rx="0"
y="99.906265"
x="39.988377"
height="19.668055"
width="8.8506336"
id="linkTarget"
style="fill:#000000;fill-opacity:0;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0"
/>
</g>
</g>
</svg>
chain icon to toggle it on/off and click on the grey areas to add a
marker. Only, it doesn't show! The alerts seem to indicate the marker is
appended correctly! What's wrong with this code?(see below)
When I save the generated source code from 'Firefox/tools/Web
Developer/View Source/View Generated Source' and reopen it in Firefox 1.5,
I see the results I'm after but never directly from the code.
Cheers,
Greg
ps I hope the text wrapping hasn't made it too unintelligible
======================================================
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- Created with
Inkscape (http://www.inkscape.org/) --> <svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="660pt"
height="250pt"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.43"
sodipodi:docbase="C:\Documents and
Settings\Administrator\Desktop\HeatingController"
sodipodi:docname="timeLineObj.svg"
version="1.0">
<script
type="text/ecmascript"
id="script3">
boldStyle =
"fill:none;stroke:#000000;stroke-width:2.0000000;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-opacity:1.0000000";
greyStyle =
"fill:none;stroke:#888888;stroke-width:2.0000000;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-opacity:1.0000000";
redBox =
"fill:#ff0000;fill-opacity:1;stroke:#0000ff;stroke-width:2.0000000;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-opacity:1.0000000;visibility:'visible';";
//redBox = "fill:#ff00ff;";
function toggleLinkColour(evt) {
var thisLink = evt.target;
var thisLinkParent = thisLink.parentNode; //can't see where the
intervening nodes are that make it 1,3 & 5, rather than 0,1 & 2?
var link1 = thisLinkParent.childNodes[1]; var link2 =
thisLinkParent.childNodes[3]; var link3 = thisLinkParent.childNodes[5];
if (thisLink.parentNode.getAttribute("tog") == 0){
thisLinkParent.setAttribute("tog",1) ;
link1.setAttribute("style", boldStyle); link2.setAttribute("style",
boldStyle); link3.setAttribute("style", boldStyle);
}
else{
thisLinkParent.setAttribute("tog",0) ;
link1.setAttribute("style", greyStyle); link2.setAttribute("style",
greyStyle); link3.setAttribute("style", greyStyle);
}
}
function switchEvent(evt) {
var targetObj = evt.target; //The object that received the event var
targetDoc = targetObj.ownerDocument; //Owner document var targetGrp =
targetObj.parentNode; //The group containing the target object (so that
the new objects can be appended as siblings to the target object)
var targetX = evt.pageX - targetObj.getAttribute("x"); var targetY =
evt.pageY - targetObj.getAttribute("y"); //alert(evt.target.id + " " +
targetX + " " + targetY);
periodIndicator = targetDoc.createElement("rect");
//alert(periodIndicator);
periodIndicator.setAttribute("id", "startmark");
periodIndicator.setAttribute("style", redBox);
periodIndicator.setAttribute("x", targetX);
periodIndicator.setAttribute("y", targetY);
periodIndicator.setAttribute("width", 6);
periodIndicator.setAttribute("height", 6);
targetGrp.appendChild(periodIndicator); //Add it to the group
containing the appropriate timeline target //targetDoc.forceRedraw();
//Can't find any documentation on this, so don't know if it's called
correctly - doesn't work as far as I can tell
alert(targetGrp.getAttribute("id"));
alert(targetObj.getAttribute("id"));
alert(periodIndicator.getAttribute("id"));
// periodIndicator SEEMS to be there but can't view it - maybe appended
it in the wrong place?
}
}
</script>
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.304619"
inkscape:cx="395.13338"
inkscape:cy="728.43129"
inkscape:document-units="px"
inkscape:current-layer="layer1"
inkscape:window-width="1142"
inkscape:window-height="755"
inkscape:window-x="0"
inkscape:window-y="46"
showguides="true"
inkscape:guide-bbox="true" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 120,28 L 770,28"
id="Timeline" />
<g
id="HWtimelineGroup">
<rect
ry="0"
rx="0"
y="14"
x="120"
height="12"
width="650"
id="HWtimelineTarget"
onmouseup="switchEvent(evt)"
style="fill:#000000;fill-opacity:0.05;stroke:#dddddd;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
/>
</g>
<g
id="CHtimelineGroup">
<rect
ry="0"
rx="0"
y="30"
x="120"
height="12"
width="650"
id="CHtimelineTarget"
onmouseup="switchEvent(evt)"
style="fill:#000000;fill-opacity:0.05;stroke:#dddddd;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
/>
</g>
<g
id="LabelGroup"
transform="translate(67.6447,-78.45772)">
<text
id="HotWaterLabel"
y="102.61897"
x="10.540583"
style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream
Vera Sans" xml:space="preserve"><tspan
y="102.61897"
x="10.540583"
id="tspan2597"
sodipodi:role="line">HW</tspan></text>
<text
id="CentralHeatingLabel"
y="119.70714"
x="12.922419"
style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream
Vera Sans" xml:space="preserve"><tspan
y="119.70714"
x="12.922419"
id="tspan2601"
sodipodi:role="line">CH</tspan></text>
</g>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream
Vera Sans" x="22.510159"
y="32.710236"
id="timelineLabel"><tspan
sodipodi:role="line"
id="tspan3348"
x="22.510159"
y="32.710236"><Label></tspan></text>
<g
id="linkHW-CH"
transform="translate(65.0269,-81.40793)"
onclick="toggleLinkColour(evt)"
tog="0">
<path
sodipodi:type="arc"
id="L1"
sodipodi:cx="88.588737"
sodipodi:cy="175.01889"
sodipodi:rx="4.9465795"
sodipodi:ry="9.44347"
d="M 93.535317 175.01889 A 4.9465795 9.44347 0 1 1
83.642158,175.01889 A 4.9465795 9.44347 0 1 1 93.535317
175.01889 z"
style="fill:none;stroke:#888888;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
transform="matrix(0.571439,0,0,0.421008,-6.05958,31.51435)" />
<path
sodipodi:type="arc"
id="L2"
sodipodi:cx="88.588737"
sodipodi:cy="175.01889"
sodipodi:rx="4.9465795"
sodipodi:ry="9.44347"
d="M 93.535317 175.01889 A 4.9465795 9.44347 0 1 1
83.642158,175.01889 A 4.9465795 9.44347 0 1 1 93.535317
175.01889 z"
style="fill:none;stroke:#888888;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
transform="matrix(0.571439,0,0,0.421008,-6.05958,35.76649)" />
<path
sodipodi:type="arc"
id="L3"
sodipodi:cx="88.588737"
sodipodi:cy="175.01889"
sodipodi:rx="4.9465795"
sodipodi:ry="9.44347"
d="M 93.535317 175.01889 A 4.9465795 9.44347 0 1 1
83.642158,175.01889 A 4.9465795 9.44347 0 1 1 93.535317
175.01889 z"
style="fill:none;stroke:#888888;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
transform="matrix(0.571439,0,0,0.421008,-6.05958,40.76534)" />
<rect
ry="0"
rx="0"
y="99.906265"
x="39.988377"
height="19.668055"
width="8.8506336"
id="linkTarget"
style="fill:#000000;fill-opacity:0;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0"
/>
</g>
</g>
</svg>