Move getLayerVisibility() and getLayerOpacity() into Drawing and some tests

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1942 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2011-01-28 06:45:34 +00:00
parent 3e9f1747ff
commit 4190990d69
3 changed files with 79 additions and 24 deletions

View File

@ -363,4 +363,49 @@ svgedit.draw.Drawing.prototype.createLayer = function(name) {
return new_layer;
};
// Function: svgedit.draw.Drawing.getLayerVisibility
// Returns whether the layer is visible. If the layer name is not valid, then this function
// returns false.
//
// Parameters:
// layername - the name of the layer which you want to query.
//
// Returns:
// The visibility state of the layer, or false if the layer name was invalid.
svgedit.draw.Drawing.prototype.getLayerVisibility = function(layername) {
// find the layer
var layer = null;
for (var i = 0; i < this.getNumLayers(); ++i) {
if (this.getLayerName(i) == layername) {
layer = this.all_layers[i][1];
break;
}
}
if (!layer) return false;
return (layer.getAttribute('display') != 'none');
};
// Function: svgedit.draw.Drawing.getLayerOpacity
// Returns the opacity of the given layer. If the input name is not a layer, null is returned.
//
// Parameters:
// layername - name of the layer on which to get the opacity
//
// Returns:
// The opacity value of the given layer. This will be a value between 0.0 and 1.0, or null
// if layername is not a valid layer
svgedit.draw.Drawing.prototype.getLayerOpacity = function(layername) {
for (var i = 0; i < this.getNumLayers(); ++i) {
if (this.getLayerName(i) == layername) {
var g = this.all_layers[i][1];
var opacity = g.getAttribute('opacity');
if (!opacity) {
opacity = '1.0';
}
return parseFloat(opacity);
}
}
return null;
};
})();

View File

@ -6994,8 +6994,9 @@ this.cloneLayer = function(name) {
var layer_title = svgdoc.createElementNS(svgns, "title");
layer_title.textContent = name;
new_layer.appendChild(layer_title);
$(current_drawing.current_layer).after(new_layer);
var childs = current_drawing.current_layer.childNodes;
var current_layer = getCurrentDrawing().getCurrentLayer();
$(current_layer).after(new_layer);
var childs = current_layer.childNodes;
for(var i = 0; i < childs.length; i++) {
var ch = childs[i];
if(ch.localName == 'title') continue;
@ -7160,16 +7161,7 @@ this.setCurrentLayerPosition = function(newpos) {
// Returns:
// The visibility state of the layer, or false if the layer name was invalid.
this.getLayerVisibility = function(layername) {
// find the layer
var layer = null;
for (var i = 0; i < current_drawing.getNumLayers(); ++i) {
if (current_drawing.getLayerName(i) == layername) {
layer = current_drawing.all_layers[i][1];
break;
}
}
if (!layer) return false;
return (layer.getAttribute("display") != "none");
return getCurrentDrawing().getLayerVisibility(layername);
};
// Function: setLayerVisibility
@ -7308,18 +7300,7 @@ this.mergeAllLayers = function() {
// The opacity value of the given layer. This will be a value between 0.0 and 1.0, or null
// if layername is not a valid layer
this.getLayerOpacity = function(layername) {
for (var i = 0; i < current_drawing.getNumLayers(); ++i) {
if (current_drawing.getLayerName(i) == layername) {
var g = current_drawing.all_layers[i][1];
var opacity = g.getAttribute("opacity");
if (!opacity) {
opacity = "1.0";
}
return parseFloat(opacity);
}
}
return null;
return getCurrentDrawing().getLayerOpacity(layername);
};
// Function: setLayerOpacity

View File

@ -364,6 +364,7 @@
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.createLayer);
equals(typeof drawing.createLayer, typeof function(){});
@ -377,6 +378,34 @@
cleanupSvg(svg);
});
test('Test getLayerVisibility()', function() {
expect(5);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.getLayerVisibility);
equals(typeof drawing.getLayerVisibility, typeof function(){});
ok(drawing.getLayerVisibility(LAYER1));
ok(drawing.getLayerVisibility(LAYER2));
ok(drawing.getLayerVisibility(LAYER3));
});
test('Test getLayerOpacity()', function() {
expect(5);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.getLayerOpacity);
equals(typeof drawing.getLayerOpacity, typeof function(){});
ok(drawing.getLayerOpacity(LAYER1) == 1.0);
ok(drawing.getLayerOpacity(LAYER2) == 1.0);
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
});
});
</script>