Formatting changes.
This commit is contained in:
150
editor/layer.js
150
editor/layer.js
@@ -17,7 +17,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
if (!svgedit.draw) {
|
if (!svgedit.draw) {
|
||||||
svgedit.draw = {};
|
svgedit.draw = {};
|
||||||
}
|
}
|
||||||
var NS = svgedit.NS;
|
var NS = svgedit.NS;
|
||||||
|
|
||||||
@@ -27,9 +27,9 @@ var NS = svgedit.NS;
|
|||||||
* an existing group element or, with three parameters, will create a new layer group element.
|
* an existing group element or, with three parameters, will create a new layer group element.
|
||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
* new Layer( 'name', group) // Use the existing group for this layer.
|
* new Layer'name', group) // Use the existing group for this layer.
|
||||||
* new Layer( 'name', group, svgElem) // Create a new group and add it to the DOM after group.
|
* new Layer('name', group, svgElem) // Create a new group and add it to the DOM after group.
|
||||||
* new Layer( 'name', null, svgElem) // Create a new group and add it to the DOM as the last layer.
|
* new Layer('name', null, svgElem) // Create a new group and add it to the DOM as the last layer.
|
||||||
*
|
*
|
||||||
* @param {string} name - Layer name
|
* @param {string} name - Layer name
|
||||||
* @param {SVGGElement|null} group - An existing SVG group element or null.
|
* @param {SVGGElement|null} group - An existing SVG group element or null.
|
||||||
@@ -40,27 +40,27 @@ var NS = svgedit.NS;
|
|||||||
* a new layer to the document.
|
* a new layer to the document.
|
||||||
*/
|
*/
|
||||||
var Layer = svgedit.draw.Layer = function(name, group, svgElem) {
|
var Layer = svgedit.draw.Layer = function(name, group, svgElem) {
|
||||||
this.name_ = name;
|
this.name_ = name;
|
||||||
this.group_ = svgElem ? null : group;
|
this.group_ = svgElem ? null : group;
|
||||||
|
|
||||||
if (svgElem) {
|
if (svgElem) {
|
||||||
// Create a group element with title and add it to the DOM.
|
// Create a group element with title and add it to the DOM.
|
||||||
var svgdoc = svgElem.ownerDocument;
|
var svgdoc = svgElem.ownerDocument;
|
||||||
this.group_ = svgdoc.createElementNS(NS.SVG, "g");
|
this.group_ = svgdoc.createElementNS(NS.SVG, "g");
|
||||||
var layer_title = svgdoc.createElementNS(NS.SVG, "title");
|
var layer_title = svgdoc.createElementNS(NS.SVG, "title");
|
||||||
layer_title.textContent = name;
|
layer_title.textContent = name;
|
||||||
this.group_.appendChild(layer_title);
|
this.group_.appendChild(layer_title);
|
||||||
if( group) {
|
if (group) {
|
||||||
$(group).after(this.group_);
|
$(group).after(this.group_);
|
||||||
} else {
|
} else {
|
||||||
svgElem.appendChild(this.group_);
|
svgElem.appendChild(this.group_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addLayerClass(this.group_);
|
addLayerClass(this.group_);
|
||||||
svgedit.utilities.walkTree(this.group_, function(e){e.setAttribute("style", "pointer-events:inherit");});
|
svgedit.utilities.walkTree(this.group_, function(e){e.setAttribute("style", "pointer-events:inherit");});
|
||||||
|
|
||||||
this.group_.setAttribute("style", svgElem ? "pointer-events:all" : "pointer-events:none");
|
this.group_.setAttribute("style", svgElem ? "pointer-events:all" : "pointer-events:none");
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,7 +79,7 @@ Layer.CLASS_REGEX = new RegExp('(\\s|^)' + Layer.CLASS_NAME + '(\\s|$)');
|
|||||||
* @returns {string} The layer name
|
* @returns {string} The layer name
|
||||||
*/
|
*/
|
||||||
Layer.prototype.getName = function() {
|
Layer.prototype.getName = function() {
|
||||||
return this.name_;
|
return this.name_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,21 +87,21 @@ Layer.prototype.getName = function() {
|
|||||||
* @returns {SVGGElement} The layer SVG group
|
* @returns {SVGGElement} The layer SVG group
|
||||||
*/
|
*/
|
||||||
Layer.prototype.getGroup = function() {
|
Layer.prototype.getGroup = function() {
|
||||||
return this.group_;
|
return this.group_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Active this layer so it takes pointer events.
|
* Active this layer so it takes pointer events.
|
||||||
*/
|
*/
|
||||||
Layer.prototype.activate = function() {
|
Layer.prototype.activate = function() {
|
||||||
this.group_.setAttribute("style", "pointer-events:all");
|
this.group_.setAttribute("style", "pointer-events:all");
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deactive this layer so it does NOT take pointer events.
|
* Deactive this layer so it does NOT take pointer events.
|
||||||
*/
|
*/
|
||||||
Layer.prototype.deactivate = function() {
|
Layer.prototype.deactivate = function() {
|
||||||
this.group_.setAttribute("style", "pointer-events:none");
|
this.group_.setAttribute("style", "pointer-events:none");
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,11 +109,11 @@ Layer.prototype.deactivate = function() {
|
|||||||
* @param {boolean} visible - If true, make visible; otherwise, hide it.
|
* @param {boolean} visible - If true, make visible; otherwise, hide it.
|
||||||
*/
|
*/
|
||||||
Layer.prototype.setVisible = function(visible) {
|
Layer.prototype.setVisible = function(visible) {
|
||||||
var expected = visible === undefined || visible ? "inline" : "none";
|
var expected = visible === undefined || visible ? "inline" : "none";
|
||||||
var oldDisplay = this.group_.getAttribute("display");
|
var oldDisplay = this.group_.getAttribute("display");
|
||||||
if (oldDisplay !== expected) {
|
if (oldDisplay !== expected) {
|
||||||
this.group_.setAttribute("display", expected);
|
this.group_.setAttribute("display", expected);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,7 +121,7 @@ Layer.prototype.setVisible = function(visible) {
|
|||||||
* @returns {boolean} True if visible.
|
* @returns {boolean} True if visible.
|
||||||
*/
|
*/
|
||||||
Layer.prototype.isVisible = function() {
|
Layer.prototype.isVisible = function() {
|
||||||
return this.group_.getAttribute('display') !== 'none';
|
return this.group_.getAttribute('display') !== 'none';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,11 +129,11 @@ Layer.prototype.isVisible = function() {
|
|||||||
* @returns {number} Opacity value.
|
* @returns {number} Opacity value.
|
||||||
*/
|
*/
|
||||||
Layer.prototype.getOpacity = function() {
|
Layer.prototype.getOpacity = function() {
|
||||||
var opacity = this.group_.getAttribute('opacity');
|
var opacity = this.group_.getAttribute('opacity');
|
||||||
if (opacity === null || opacity === undefined) {
|
if (opacity === null || opacity === undefined) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return parseFloat(opacity);
|
return parseFloat(opacity);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,9 +142,9 @@ Layer.prototype.getOpacity = function() {
|
|||||||
* @param {number} opacity - A float value in the range 0.0-1.0
|
* @param {number} opacity - A float value in the range 0.0-1.0
|
||||||
*/
|
*/
|
||||||
Layer.prototype.setOpacity = function(opacity) {
|
Layer.prototype.setOpacity = function(opacity) {
|
||||||
if (typeof opacity === 'number' && opacity >= 0.0 && opacity <= 1.0) {
|
if (typeof opacity === 'number' && opacity >= 0.0 && opacity <= 1.0) {
|
||||||
this.group_.setAttribute('opacity', opacity);
|
this.group_.setAttribute('opacity', opacity);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,20 +152,20 @@ Layer.prototype.setOpacity = function(opacity) {
|
|||||||
* @param {SVGGElement} children - The children to append to this layer.
|
* @param {SVGGElement} children - The children to append to this layer.
|
||||||
*/
|
*/
|
||||||
Layer.prototype.appendChildren = function(children) {
|
Layer.prototype.appendChildren = function(children) {
|
||||||
for (var i = 0; i < children.length; ++i) {
|
for (var i = 0; i < children.length; ++i) {
|
||||||
this.group_.appendChild(children[i]);
|
this.group_.appendChild(children[i]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Layer.prototype.getTitleElement = function() {
|
Layer.prototype.getTitleElement = function() {
|
||||||
var len = this.group_.childNodes.length;
|
var len = this.group_.childNodes.length;
|
||||||
for (var i = 0; i < len; ++i) {
|
for (var i = 0; i < len; ++i) {
|
||||||
var child = this.group_.childNodes.item(i);
|
var child = this.group_.childNodes.item(i);
|
||||||
if (child && child.tagName === 'title') {
|
if (child && child.tagName === 'title') {
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -175,20 +175,20 @@ Layer.prototype.getTitleElement = function() {
|
|||||||
* @returns {string|null} The new name if changed; otherwise, null.
|
* @returns {string|null} The new name if changed; otherwise, null.
|
||||||
*/
|
*/
|
||||||
Layer.prototype.setName = function(name, hrService) {
|
Layer.prototype.setName = function(name, hrService) {
|
||||||
var previousName = this.name_;
|
var previousName = this.name_;
|
||||||
name = svgedit.utilities.toXml(name);
|
name = svgedit.utilities.toXml(name);
|
||||||
// now change the underlying title element contents
|
// now change the underlying title element contents
|
||||||
var title = this.getTitleElement();
|
var title = this.getTitleElement();
|
||||||
if (title) {
|
if (title) {
|
||||||
while (title.firstChild) { title.removeChild(title.firstChild); }
|
while (title.firstChild) { title.removeChild(title.firstChild); }
|
||||||
title.textContent = name;
|
title.textContent = name;
|
||||||
this.name_ = name;
|
this.name_ = name;
|
||||||
if( hrService) {
|
if (hrService) {
|
||||||
hrService.changeElement(title, {'#text':previousName});
|
hrService.changeElement(title, {'#text':previousName});
|
||||||
}
|
}
|
||||||
return this.name_;
|
return this.name_;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -197,10 +197,10 @@ Layer.prototype.setName = function(name, hrService) {
|
|||||||
* @returns {SVGGElement} The layer SVG group that was just removed.
|
* @returns {SVGGElement} The layer SVG group that was just removed.
|
||||||
*/
|
*/
|
||||||
Layer.prototype.removeGroup = function() {
|
Layer.prototype.removeGroup = function() {
|
||||||
var parent = this.group_.parentNode;
|
var parent = this.group_.parentNode;
|
||||||
var group = parent.removeChild(this.group_);
|
var group = parent.removeChild(this.group_);
|
||||||
this.group_ = undefined;
|
this.group_ = undefined;
|
||||||
return group;
|
return group;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -211,12 +211,12 @@ Layer.prototype.removeGroup = function() {
|
|||||||
* @param {SVGGElement} elem - The SVG element to update
|
* @param {SVGGElement} elem - The SVG element to update
|
||||||
*/
|
*/
|
||||||
function addLayerClass(elem) {
|
function addLayerClass(elem) {
|
||||||
var classes = elem.getAttribute('class');
|
var classes = elem.getAttribute('class');
|
||||||
if (classes === null || classes === undefined || classes.length === 0) {
|
if (classes === null || classes === undefined || classes.length === 0) {
|
||||||
elem.setAttribute('class', Layer.CLASS_NAME);
|
elem.setAttribute('class', Layer.CLASS_NAME);
|
||||||
} else if (! Layer.CLASS_REGEX.test(classes)) {
|
} else if (! Layer.CLASS_REGEX.test(classes)) {
|
||||||
elem.setAttribute('class', classes + ' ' + Layer.CLASS_NAME);
|
elem.setAttribute('class', classes + ' ' + Layer.CLASS_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ var addCommandToHistory = function(cmd) {
|
|||||||
* @param {svgedit.history.HistoryRecordingService=} hrService - if exists, return it instead of creating a new service.
|
* @param {svgedit.history.HistoryRecordingService=} hrService - if exists, return it instead of creating a new service.
|
||||||
* @returns {svgedit.history.HistoryRecordingService}
|
* @returns {svgedit.history.HistoryRecordingService}
|
||||||
*/
|
*/
|
||||||
function historyRecordingService( hrService) {
|
function historyRecordingService(hrService) {
|
||||||
return hrService ? hrService : new svgedit.history.HistoryRecordingService(canvas.undoMgr);
|
return hrService ? hrService : new svgedit.history.HistoryRecordingService(canvas.undoMgr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7174,7 +7174,7 @@ this.getPrivateMethods = function() {
|
|||||||
BatchCommand: BatchCommand,
|
BatchCommand: BatchCommand,
|
||||||
call: call,
|
call: call,
|
||||||
ChangeElementCommand: ChangeElementCommand,
|
ChangeElementCommand: ChangeElementCommand,
|
||||||
copyElem: function( elem) {return getCurrentDrawing().copyElem(elem)},
|
copyElem: function(elem) {return getCurrentDrawing().copyElem(elem)},
|
||||||
ffClone: ffClone,
|
ffClone: ffClone,
|
||||||
findDefs: findDefs,
|
findDefs: findDefs,
|
||||||
findDuplicateGradient: findDuplicateGradient,
|
findDuplicateGradient: findDuplicateGradient,
|
||||||
|
|||||||
@@ -1211,10 +1211,10 @@ function pathDSegment(letter, points, morePoints, lastPoint) {
|
|||||||
points[i] = svgedit.units.shortFloat(pnt);
|
points[i] = svgedit.units.shortFloat(pnt);
|
||||||
});
|
});
|
||||||
var segment = letter + points.join(' ');
|
var segment = letter + points.join(' ');
|
||||||
if( morePoints) {
|
if (morePoints) {
|
||||||
segment += ' ' + morePoints.join(' ');
|
segment += ' ' + morePoints.join(' ');
|
||||||
}
|
}
|
||||||
if( lastPoint) {
|
if (lastPoint) {
|
||||||
segment += ' ' + svgedit.units.shortFloat(lastPoint);
|
segment += ' ' + svgedit.units.shortFloat(lastPoint);
|
||||||
}
|
}
|
||||||
return segment;
|
return segment;
|
||||||
|
|||||||
@@ -465,18 +465,18 @@
|
|||||||
|
|
||||||
var oldName = drawing.getCurrentLayerName();
|
var oldName = drawing.getCurrentLayerName();
|
||||||
var newName = 'New Name'
|
var newName = 'New Name'
|
||||||
ok( drawing.layer_map[oldName]);
|
ok(drawing.layer_map[oldName]);
|
||||||
equals( drawing.layer_map[newName], undefined); // newName shouldn't exist.
|
equals(drawing.layer_map[newName], undefined); // newName shouldn't exist.
|
||||||
var result = drawing.setCurrentLayerName(newName, mockHrService);
|
var result = drawing.setCurrentLayerName(newName, mockHrService);
|
||||||
equals(result, newName);
|
equals(result, newName);
|
||||||
equals(drawing.getCurrentLayerName(), newName);
|
equals(drawing.getCurrentLayerName(), newName);
|
||||||
// Was the map updated?
|
// Was the map updated?
|
||||||
equals( drawing.layer_map[oldName], undefined);
|
equals(drawing.layer_map[oldName], undefined);
|
||||||
equals( drawing.layer_map[newName], drawing.current_layer);
|
equals(drawing.layer_map[newName], drawing.current_layer);
|
||||||
// Was mockHrService called?
|
// Was mockHrService called?
|
||||||
ok( mockHrService.changeElement.calledOnce);
|
ok(mockHrService.changeElement.calledOnce);
|
||||||
equals( oldName, mockHrService.changeElement.getCall(0).args[1]['#text']);
|
equals(oldName, mockHrService.changeElement.getCall(0).args[1]['#text']);
|
||||||
equals( newName, mockHrService.changeElement.getCall(0).args[0].textContent);
|
equals(newName, mockHrService.changeElement.getCall(0).args[0].textContent);
|
||||||
|
|
||||||
cleanupSvg(svg);
|
cleanupSvg(svg);
|
||||||
});
|
});
|
||||||
@@ -506,8 +506,8 @@
|
|||||||
equals(NEW_LAYER_NAME, drawing.getLayerName(3));
|
equals(NEW_LAYER_NAME, drawing.getLayerName(3));
|
||||||
|
|
||||||
equals(layer_g, mockHrService.insertElement.getCall(0).args[0]);
|
equals(layer_g, mockHrService.insertElement.getCall(0).args[0]);
|
||||||
ok( mockHrService.startBatchCommand.calledOnce);
|
ok(mockHrService.startBatchCommand.calledOnce);
|
||||||
ok( mockHrService.endBatchCommand.calledOnce);
|
ok(mockHrService.endBatchCommand.calledOnce);
|
||||||
|
|
||||||
cleanupSvg(svg);
|
cleanupSvg(svg);
|
||||||
});
|
});
|
||||||
@@ -540,8 +540,8 @@
|
|||||||
|
|
||||||
|
|
||||||
// check history record
|
// check history record
|
||||||
ok( mockHrService.startBatchCommand.calledOnce);
|
ok(mockHrService.startBatchCommand.calledOnce);
|
||||||
ok( mockHrService.endBatchCommand.calledOnce);
|
ok(mockHrService.endBatchCommand.calledOnce);
|
||||||
equals(mockHrService.startBatchCommand.getCall(0).args[0], 'Merge Layer');
|
equals(mockHrService.startBatchCommand.getCall(0).args[0], 'Merge Layer');
|
||||||
equals(mockHrService.moveElement.callCount, elementCount - 1); // -1 because the title was not moved.
|
equals(mockHrService.moveElement.callCount, elementCount - 1); // -1 because the title was not moved.
|
||||||
equals(mockHrService.removeElement.callCount, 2); // remove group and title.
|
equals(mockHrService.removeElement.callCount, 2); // remove group and title.
|
||||||
@@ -611,8 +611,8 @@
|
|||||||
equals(layers[0].childElementCount, elementCount * 3 - 2); // -2 because two titles were deleted.
|
equals(layers[0].childElementCount, elementCount * 3 - 2); // -2 because two titles were deleted.
|
||||||
|
|
||||||
// check history record
|
// check history record
|
||||||
equals( mockHrService.startBatchCommand.callCount, 3); // mergeAllLayers + 2 * mergeLayer
|
equals(mockHrService.startBatchCommand.callCount, 3); // mergeAllLayers + 2 * mergeLayer
|
||||||
equals( mockHrService.endBatchCommand.callCount, 3);
|
equals(mockHrService.endBatchCommand.callCount, 3);
|
||||||
equals(mockHrService.startBatchCommand.getCall(0).args[0], 'Merge all Layers');
|
equals(mockHrService.startBatchCommand.getCall(0).args[0], 'Merge all Layers');
|
||||||
equals(mockHrService.startBatchCommand.getCall(1).args[0], 'Merge Layer');
|
equals(mockHrService.startBatchCommand.getCall(1).args[0], 'Merge Layer');
|
||||||
equals(mockHrService.startBatchCommand.getCall(2).args[0], 'Merge Layer');
|
equals(mockHrService.startBatchCommand.getCall(2).args[0], 'Merge Layer');
|
||||||
@@ -649,8 +649,8 @@
|
|||||||
equals(clone.childElementCount, elementCount);
|
equals(clone.childElementCount, elementCount);
|
||||||
|
|
||||||
// check history record
|
// check history record
|
||||||
ok( mockHrService.startBatchCommand.calledOnce); // mergeAllLayers + 2 * mergeLayer
|
ok(mockHrService.startBatchCommand.calledOnce); // mergeAllLayers + 2 * mergeLayer
|
||||||
ok( mockHrService.endBatchCommand.calledOnce);
|
ok(mockHrService.endBatchCommand.calledOnce);
|
||||||
equals(mockHrService.startBatchCommand.getCall(0).args[0], 'Duplicate Layer');
|
equals(mockHrService.startBatchCommand.getCall(0).args[0], 'Duplicate Layer');
|
||||||
equals(mockHrService.insertElement.callCount, 1);
|
equals(mockHrService.insertElement.callCount, 1);
|
||||||
equals(mockHrService.insertElement.getCall(0).args[0], clone);
|
equals(mockHrService.insertElement.getCall(0).args[0], clone);
|
||||||
|
|||||||
Reference in New Issue
Block a user