Update layers panel on programatic call to createLayer.

Add class=“layer” to each layer element. This happens when calling
createLayer() or any call to identifyLayers(). This happens with new
drawings and when opening legacy drawings, so it’s fully backwards
compatible.
svg-editor.js elementChanged() looks for g.layer as an addition test
for calling populateLayers() which updates the layers panel.
Addition tests for class=“layer” added to draw_test.html.
Fixed Firefox exception in draw_test.html.
This commit is contained in:
Flint O'Brien
2016-04-29 16:13:35 -04:00
parent 3ef423e30a
commit ebcf3d9c47
4 changed files with 77 additions and 21 deletions

View File

@@ -1835,6 +1835,15 @@ TODOS
});
};
/**
* Test whether an element is a layer or not.
* @param {SVGGElement} elem - The SVGGElement to test.
* @returns {boolean} True if the element is a layer
*/
function isLayer(elem) {
return elem && elem.tagName === 'g' && svgedit.LAYER_CLASS_REGEX.test(elem.getAttribute('class'))
}
// called when any element has changed
var elementChanged = function(win, elems) {
var i,
@@ -1846,10 +1855,13 @@ TODOS
for (i = 0; i < elems.length; ++i) {
var elem = elems[i];
// if the element changed was the svg, then it could be a resolution change
if (elem && elem.tagName === 'svg') {
var isSvgElem = (elem && elem.tagName === 'svg');
if (isSvgElem || isLayer(elem)) {
populateLayers();
updateCanvas();
// if the element changed was the svg, then it could be a resolution change
if (isSvgElem) {
updateCanvas();
}
}
// Update selectedElement if element is no longer part of the image.
// This occurs for the text elements in Firefox