The first problem has us wanting to run the applyStrokes() function when the dropdown item is selected.
The change function at line 163 is what gets triggered when an item is selected. The end of that change function is at line 194, and we find some code there that can be removed.
The code from 191-193 copies the SVG element stroke-width to the input field. That was to fix a problem that we later on fixed by making a change to the fieldsToClear array, so the code on lines 191-193 can now be deleted.
Where you deleted those lines, add a call to the applyStrokes(); function. That will make sure that the selected item gets the active width applied to it.
applyStrokes();
So in summary there are two changes to make that are best expressed as: replace lines 191-193 with a call to the applyStrokes() function.
I’ve just been notified that there might be a 1000 post limit. Yes, I have a halo for telling you that.
If that becomes a problem we’ll continue on from a new topic.
What happens to the line width when you test it by selecting a line from the dropdown box?
Problem #2 is best experienced by selecting a line, and then clicking back and forth between Active and one of the Line fields. You’ll see that the active line goes away when clicking on one of the Line fields.
The code that shows the SVG code is where that problem occurs, which we’ll find in the showSVGCode function.
Here’s the problem function:
function showSVGCode() {
getActiveShape().removeAttribute("stroke-width");
var code = document.querySelector("svg").innerHTML;
document.getElementById("result").innerHTML = escapeHTML(code);
getActiveShape().setAttribute("stroke-width", document.getElementById("active"));
}
What’s going wrong is that it looks like instructions from earlier haven’t been followed.
What should be there is a separate var statement that gets the active element. That would have allowed us to more easily see what the problem is.
Here’s code with that update.
function showSVGCode() {
getActiveShape().removeAttribute("stroke-width");
var code = document.querySelector("svg").innerHTML;
document.getElementById("result").innerHTML = escapeHTML(code);
var active = document.getElementById("active");
getActiveShape().setAttribute("stroke-width", active);
}
Note: The above code still doesn’t work, but is an important step to understanding how to get it working.
Now we can more easily see what the problem is. We need to assign to stroke-width the value of the active field. Not the active field itself.
So only one simple change is needed to fix that problem, and that is at the very end, changing active to active.value instead.
function showSVGCode() {
getActiveShape().removeAttribute("stroke-width");
var code = document.querySelector("svg").innerHTML;
document.getElementById("result").innerHTML = escapeHTML(code);
var active = document.getElementById("active");
getActiveShape().setAttribute("stroke-width", active.value);
}