Add tests for MoveElementCommand, InsertElementCommand and RemoveElementCommand
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1867 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
deb5e4a2fa
commit
d5ae56ea8e
|
@ -74,14 +74,30 @@ svgedit.history.MoveElementCommand.prototype.getText = function() {
|
||||||
|
|
||||||
// Function: svgedit.history.MoveElementCommand.apply
|
// Function: svgedit.history.MoveElementCommand.apply
|
||||||
// Re-positions the element
|
// Re-positions the element
|
||||||
svgedit.history.MoveElementCommand.prototype.apply = function() {
|
svgedit.history.MoveElementCommand.prototype.apply = function(handler) {
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_APPLY, this);
|
||||||
|
}
|
||||||
|
|
||||||
this.elem = this.newParent.insertBefore(this.elem, this.newNextSibling);
|
this.elem = this.newParent.insertBefore(this.elem, this.newNextSibling);
|
||||||
|
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.AFTER_APPLY, this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: svgedit.history.MoveElementCommand.unapply
|
// Function: svgedit.history.MoveElementCommand.unapply
|
||||||
// Positions the element back to its original location
|
// Positions the element back to its original location
|
||||||
svgedit.history.MoveElementCommand.prototype.unapply = function() {
|
svgedit.history.MoveElementCommand.prototype.unapply = function(handler) {
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_UNAPPLY, this);
|
||||||
|
}
|
||||||
|
|
||||||
this.elem = this.oldParent.insertBefore(this.elem, this.oldNextSibling);
|
this.elem = this.oldParent.insertBefore(this.elem, this.oldNextSibling);
|
||||||
|
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.AFTER_UNAPPLY, this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: svgedit.history.MoveElementCommand.elements
|
// Function: svgedit.history.MoveElementCommand.elements
|
||||||
|
@ -102,6 +118,7 @@ svgedit.history.InsertElementCommand = function(elem, text) {
|
||||||
this.elem = elem;
|
this.elem = elem;
|
||||||
this.text = text || ("Create " + elem.tagName);
|
this.text = text || ("Create " + elem.tagName);
|
||||||
this.parent = elem.parentNode;
|
this.parent = elem.parentNode;
|
||||||
|
this.nextSibling = this.elem.nextSibling;
|
||||||
};
|
};
|
||||||
svgedit.history.InsertElementCommand.type = function() { return 'svgedit.history.InsertElementCommand'; }
|
svgedit.history.InsertElementCommand.type = function() { return 'svgedit.history.InsertElementCommand'; }
|
||||||
svgedit.history.InsertElementCommand.prototype.type = svgedit.history.InsertElementCommand.type;
|
svgedit.history.InsertElementCommand.prototype.type = svgedit.history.InsertElementCommand.type;
|
||||||
|
@ -113,15 +130,31 @@ svgedit.history.InsertElementCommand.prototype.getText = function() {
|
||||||
|
|
||||||
// Function: svgedit.history.InsertElementCommand.apply
|
// Function: svgedit.history.InsertElementCommand.apply
|
||||||
// Re-Inserts the new element
|
// Re-Inserts the new element
|
||||||
svgedit.history.InsertElementCommand.prototype.apply = function() {
|
svgedit.history.InsertElementCommand.prototype.apply = function(handler) {
|
||||||
this.elem = this.parent.insertBefore(this.elem, this.elem.nextSibling);
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_APPLY, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.elem = this.parent.insertBefore(this.elem, this.nextSibling);
|
||||||
|
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.AFTER_APPLY, this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: svgedit.history.InsertElementCommand.unapply
|
// Function: svgedit.history.InsertElementCommand.unapply
|
||||||
// Removes the element
|
// Removes the element
|
||||||
svgedit.history.InsertElementCommand.prototype.unapply = function() {
|
svgedit.history.InsertElementCommand.prototype.unapply = function(handler) {
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_UNAPPLY, this);
|
||||||
|
}
|
||||||
|
|
||||||
this.parent = this.elem.parentNode;
|
this.parent = this.elem.parentNode;
|
||||||
this.elem = this.elem.parentNode.removeChild(this.elem);
|
this.elem = this.elem.parentNode.removeChild(this.elem);
|
||||||
|
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.AFTER_UNAPPLY, this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: svgedit.history.InsertElementCommand.elements
|
// Function: svgedit.history.InsertElementCommand.elements
|
||||||
|
@ -137,12 +170,14 @@ svgedit.history.InsertElementCommand.prototype.elements = function() {
|
||||||
//
|
//
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// elem - The removed DOM element
|
// elem - The removed DOM element
|
||||||
// parent - The DOM element's parent
|
// oldNextSibling - the DOM element's nextSibling when it was in the DOM
|
||||||
|
// oldParent - The DOM element's parent
|
||||||
// text - An optional string visible to user related to this change
|
// text - An optional string visible to user related to this change
|
||||||
svgedit.history.RemoveElementCommand = function(elem, parent, text) {
|
svgedit.history.RemoveElementCommand = function(elem, oldNextSibling, oldParent, text) {
|
||||||
this.elem = elem;
|
this.elem = elem;
|
||||||
this.text = text || ("Delete " + elem.tagName);
|
this.text = text || ("Delete " + elem.tagName);
|
||||||
this.parent = parent;
|
this.nextSibling = oldNextSibling;
|
||||||
|
this.parent = oldParent;
|
||||||
|
|
||||||
// special hack for webkit: remove this element's entry in the svgTransformLists map
|
// special hack for webkit: remove this element's entry in the svgTransformLists map
|
||||||
svgedit.transformlist.removeElementFromListMap(elem);
|
svgedit.transformlist.removeElementFromListMap(elem);
|
||||||
|
@ -157,19 +192,33 @@ svgedit.history.RemoveElementCommand.prototype.getText = function() {
|
||||||
|
|
||||||
// Function: RemoveElementCommand.apply
|
// Function: RemoveElementCommand.apply
|
||||||
// Re-removes the new element
|
// Re-removes the new element
|
||||||
svgedit.history.RemoveElementCommand.prototype.apply = function() {
|
svgedit.history.RemoveElementCommand.prototype.apply = function(handler) {
|
||||||
svgedit.transformlist.removeElementFromListMap(this.elem);
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_APPLY, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
svgedit.transformlist.removeElementFromListMap(this.elem);
|
||||||
this.parent = this.elem.parentNode;
|
this.parent = this.elem.parentNode;
|
||||||
this.elem = this.parent.removeChild(this.elem);
|
this.elem = this.parent.removeChild(this.elem);
|
||||||
|
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.AFTER_APPLY, this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: RemoveElementCommand.unapply
|
// Function: RemoveElementCommand.unapply
|
||||||
// Re-adds the new element
|
// Re-adds the new element
|
||||||
svgedit.history.RemoveElementCommand.prototype.unapply = function() {
|
svgedit.history.RemoveElementCommand.prototype.unapply = function(handler) {
|
||||||
svgedit.transformlist.removeElementFromListMap(this.elem);
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_UNAPPLY, this);
|
||||||
|
}
|
||||||
|
|
||||||
this.parent.insertBefore(this.elem, this.elem.nextSibling);
|
svgedit.transformlist.removeElementFromListMap(this.elem);
|
||||||
|
this.parent.insertBefore(this.elem, this.nextSibling);
|
||||||
|
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.AFTER_UNAPPLY, this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: RemoveElementCommand.elements
|
// Function: RemoveElementCommand.elements
|
||||||
|
@ -209,7 +258,11 @@ svgedit.history.ChangeElementCommand.prototype.getText = function() {
|
||||||
|
|
||||||
// Function: svgedit.history.ChangeElementCommand.apply
|
// Function: svgedit.history.ChangeElementCommand.apply
|
||||||
// Performs the stored change action
|
// Performs the stored change action
|
||||||
svgedit.history.ChangeElementCommand.prototype.apply = function() {
|
svgedit.history.ChangeElementCommand.prototype.apply = function(handler) {
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_APPLY, this);
|
||||||
|
}
|
||||||
|
|
||||||
var bChangedTransform = false;
|
var bChangedTransform = false;
|
||||||
for(var attr in this.newValues ) {
|
for(var attr in this.newValues ) {
|
||||||
if (this.newValues[attr]) {
|
if (this.newValues[attr]) {
|
||||||
|
@ -241,12 +294,21 @@ svgedit.history.ChangeElementCommand.prototype.apply = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.AFTER_APPLY, this);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: svgedit.history.ChangeElementCommand.unapply
|
// Function: svgedit.history.ChangeElementCommand.unapply
|
||||||
// Reverses the stored change action
|
// Reverses the stored change action
|
||||||
svgedit.history.ChangeElementCommand.prototype.unapply = function() {
|
svgedit.history.ChangeElementCommand.prototype.unapply = function(handler) {
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_UNAPPLY, this);
|
||||||
|
}
|
||||||
|
|
||||||
var bChangedTransform = false;
|
var bChangedTransform = false;
|
||||||
for(var attr in this.oldValues ) {
|
for(var attr in this.oldValues ) {
|
||||||
if (this.oldValues[attr]) {
|
if (this.oldValues[attr]) {
|
||||||
|
@ -277,6 +339,10 @@ svgedit.history.ChangeElementCommand.prototype.unapply = function() {
|
||||||
// Remove transformlist to prevent confusion that causes bugs like 575.
|
// Remove transformlist to prevent confusion that causes bugs like 575.
|
||||||
svgedit.transformlist.removeElementFromListMap(this.elem);
|
svgedit.transformlist.removeElementFromListMap(this.elem);
|
||||||
|
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.AFTER_UNAPPLY, this);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -312,18 +378,34 @@ svgedit.history.BatchCommand.prototype.getText = function() {
|
||||||
|
|
||||||
// Function: svgedit.history.BatchCommand.apply
|
// Function: svgedit.history.BatchCommand.apply
|
||||||
// Runs "apply" on all subcommands
|
// Runs "apply" on all subcommands
|
||||||
svgedit.history.BatchCommand.prototype.apply = function() {
|
svgedit.history.BatchCommand.prototype.apply = function(handler) {
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_APPLY, this);
|
||||||
|
}
|
||||||
|
|
||||||
var len = this.stack.length;
|
var len = this.stack.length;
|
||||||
for (var i = 0; i < len; ++i) {
|
for (var i = 0; i < len; ++i) {
|
||||||
this.stack[i].apply();
|
this.stack[i].apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.AFTER_APPLY, this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: svgedit.history.BatchCommand.unapply
|
// Function: svgedit.history.BatchCommand.unapply
|
||||||
// Runs "unapply" on all subcommands
|
// Runs "unapply" on all subcommands
|
||||||
svgedit.history.BatchCommand.prototype.unapply = function() {
|
svgedit.history.BatchCommand.prototype.unapply = function(handler) {
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_UNAPPLY, this);
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = this.stack.length-1; i >= 0; i--) {
|
for (var i = this.stack.length-1; i >= 0; i--) {
|
||||||
this.stack[i].unapply();
|
this.stack[i].unapply(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handler) {
|
||||||
|
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.AFTER_UNAPPLY, this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -425,16 +507,7 @@ svgedit.history.UndoManager.prototype.getNextRedoCommandText = function() {
|
||||||
svgedit.history.UndoManager.prototype.undo = function() {
|
svgedit.history.UndoManager.prototype.undo = function() {
|
||||||
if (this.undoStackPointer > 0) {
|
if (this.undoStackPointer > 0) {
|
||||||
var cmd = this.undoStack[--this.undoStackPointer];
|
var cmd = this.undoStack[--this.undoStackPointer];
|
||||||
|
cmd.unapply(this.handler_);
|
||||||
if (this.handler_ != null) {
|
|
||||||
this.handler_.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_UNAPPLY, cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.unapply();
|
|
||||||
|
|
||||||
if (this.handler_ != null) {
|
|
||||||
this.handler_.handleHistoryEvent(svgedit.history.HistoryEventTypes.AFTER_UNAPPLY, cmd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -443,16 +516,7 @@ svgedit.history.UndoManager.prototype.undo = function() {
|
||||||
svgedit.history.UndoManager.prototype.redo = function() {
|
svgedit.history.UndoManager.prototype.redo = function() {
|
||||||
if (this.undoStackPointer < this.undoStack.length && this.undoStack.length > 0) {
|
if (this.undoStackPointer < this.undoStack.length && this.undoStack.length > 0) {
|
||||||
var cmd = this.undoStack[this.undoStackPointer++];
|
var cmd = this.undoStack[this.undoStackPointer++];
|
||||||
|
cmd.apply(this.handler_);
|
||||||
if (this.handler_ != null) {
|
|
||||||
this.handler_.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_APPLY, cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.apply();
|
|
||||||
|
|
||||||
if (this.handler_ != null) {
|
|
||||||
this.handler_.handleHistoryEvent(svgedit.history.HistoryEventTypes.AFTER_APPLY, cmd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6950,7 +6950,7 @@ var convertToGroup = this.convertToGroup = function(elem) {
|
||||||
var prev = $elem.prev();
|
var prev = $elem.prev();
|
||||||
|
|
||||||
// Remove <use> element
|
// Remove <use> element
|
||||||
batchCmd.addSubCommand(new RemoveElementCommand($elem[0], $elem[0].parentNode));
|
batchCmd.addSubCommand(new RemoveElementCommand($elem[0], $elem[0].nextSibling, $elem[0].parentNode));
|
||||||
$elem.remove();
|
$elem.remove();
|
||||||
|
|
||||||
// See if other elements reference this symbol
|
// See if other elements reference this symbol
|
||||||
|
@ -6980,8 +6980,9 @@ var convertToGroup = this.convertToGroup = function(elem) {
|
||||||
if(parent) {
|
if(parent) {
|
||||||
if(!has_more) {
|
if(!has_more) {
|
||||||
// remove symbol/svg element
|
// remove symbol/svg element
|
||||||
|
var nextSibling = elem.nextSibling;
|
||||||
parent.removeChild(elem);
|
parent.removeChild(elem);
|
||||||
batchCmd.addSubCommand(new RemoveElementCommand(elem, parent));
|
batchCmd.addSubCommand(new RemoveElementCommand(elem, nextSibling, parent));
|
||||||
}
|
}
|
||||||
batchCmd.addSubCommand(new InsertElementCommand(g));
|
batchCmd.addSubCommand(new InsertElementCommand(g));
|
||||||
}
|
}
|
||||||
|
@ -7027,8 +7028,9 @@ this.setSvgString = function(xmlString) {
|
||||||
var batchCmd = new BatchCommand("Change Source");
|
var batchCmd = new BatchCommand("Change Source");
|
||||||
|
|
||||||
// remove old svg document
|
// remove old svg document
|
||||||
|
var nextSibling = svgcontent.nextSibling;
|
||||||
var oldzoom = svgroot.removeChild(svgcontent);
|
var oldzoom = svgroot.removeChild(svgcontent);
|
||||||
batchCmd.addSubCommand(new RemoveElementCommand(oldzoom, svgroot));
|
batchCmd.addSubCommand(new RemoveElementCommand(oldzoom, nextSibling, svgroot));
|
||||||
|
|
||||||
// set new svg document
|
// set new svg document
|
||||||
svgcontent = svgroot.appendChild(svgdoc.importNode(newDoc.documentElement, true));
|
svgcontent = svgroot.appendChild(svgdoc.importNode(newDoc.documentElement, true));
|
||||||
|
@ -7407,7 +7409,8 @@ this.deleteCurrentLayer = function() {
|
||||||
var batchCmd = new BatchCommand("Delete Layer");
|
var batchCmd = new BatchCommand("Delete Layer");
|
||||||
// actually delete from the DOM and store in our Undo History
|
// actually delete from the DOM and store in our Undo History
|
||||||
var parent = current_layer.parentNode;
|
var parent = current_layer.parentNode;
|
||||||
batchCmd.addSubCommand(new RemoveElementCommand(current_layer, parent));
|
var nextSibling = current_layer.nextSibling;
|
||||||
|
batchCmd.addSubCommand(new RemoveElementCommand(current_layer, nextSibling, parent));
|
||||||
parent.removeChild(current_layer);
|
parent.removeChild(current_layer);
|
||||||
addCommandToHistory(batchCmd);
|
addCommandToHistory(batchCmd);
|
||||||
clearSelection();
|
clearSelection();
|
||||||
|
@ -7685,12 +7688,14 @@ this.mergeLayer = function(skipHistory) {
|
||||||
if(!prev) return;
|
if(!prev) return;
|
||||||
var childs = current_layer.childNodes;
|
var childs = current_layer.childNodes;
|
||||||
var len = childs.length;
|
var len = childs.length;
|
||||||
batchCmd.addSubCommand(new RemoveElementCommand(current_layer, svgcontent));
|
var layerNextSibling = current_layer.nextSibling;
|
||||||
|
batchCmd.addSubCommand(new RemoveElementCommand(current_layer, layerNextSibling, svgcontent));
|
||||||
|
|
||||||
while(current_layer.firstChild) {
|
while(current_layer.firstChild) {
|
||||||
var ch = current_layer.firstChild;
|
var ch = current_layer.firstChild;
|
||||||
if(ch.localName == 'title') {
|
if(ch.localName == 'title') {
|
||||||
batchCmd.addSubCommand(new RemoveElementCommand(ch, current_layer));
|
var chNextSibling = ch.nextSibling;
|
||||||
|
batchCmd.addSubCommand(new RemoveElementCommand(ch, chNextSibling, current_layer));
|
||||||
current_layer.removeChild(ch);
|
current_layer.removeChild(ch);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -7942,7 +7947,8 @@ this.setGroupTitle = function(val) {
|
||||||
|
|
||||||
if(!val.length) {
|
if(!val.length) {
|
||||||
// Remove title element
|
// Remove title element
|
||||||
batchCmd.addSubCommand(new RemoveElementCommand(ts[0], elem));
|
var tsNextSibling = ts.nextSibling;
|
||||||
|
batchCmd.addSubCommand(new RemoveElementCommand(ts[0], tsNextSibling, elem));
|
||||||
ts.remove();
|
ts.remove();
|
||||||
} else if(ts.length) {
|
} else if(ts.length) {
|
||||||
// Change title contents
|
// Change title contents
|
||||||
|
@ -9016,7 +9022,8 @@ this.convertToPath = function(elem, getBBox) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
batchCmd.addSubCommand(new RemoveElementCommand(elem, parent));
|
var nextSibling = elem.nextSibling;
|
||||||
|
batchCmd.addSubCommand(new RemoveElementCommand(elem, nextSibling, parent));
|
||||||
batchCmd.addSubCommand(new InsertElementCommand(path));
|
batchCmd.addSubCommand(new InsertElementCommand(path));
|
||||||
|
|
||||||
clearSelection();
|
clearSelection();
|
||||||
|
@ -9197,10 +9204,11 @@ this.deleteSelectedElements = function() {
|
||||||
var t = selected;
|
var t = selected;
|
||||||
// this will unselect the element and remove the selectedOutline
|
// this will unselect the element and remove the selectedOutline
|
||||||
selectorManager.releaseSelector(t);
|
selectorManager.releaseSelector(t);
|
||||||
|
var nextSibling = t.nextSibling;
|
||||||
var elem = parent.removeChild(t);
|
var elem = parent.removeChild(t);
|
||||||
selectedCopy.push(selected) //for the copy
|
selectedCopy.push(selected); //for the copy
|
||||||
selectedElements[i] = null;
|
selectedElements[i] = null;
|
||||||
batchCmd.addSubCommand(new RemoveElementCommand(elem, parent));
|
batchCmd.addSubCommand(new RemoveElementCommand(elem, nextSibling, parent));
|
||||||
}
|
}
|
||||||
if (!batchCmd.isEmpty()) addCommandToHistory(batchCmd);
|
if (!batchCmd.isEmpty()) addCommandToHistory(batchCmd);
|
||||||
call("changed", selectedCopy);
|
call("changed", selectedCopy);
|
||||||
|
@ -9224,10 +9232,11 @@ this.cutSelectedElements = function() {
|
||||||
var t = selected;
|
var t = selected;
|
||||||
// this will unselect the element and remove the selectedOutline
|
// this will unselect the element and remove the selectedOutline
|
||||||
selectorManager.releaseSelector(t);
|
selectorManager.releaseSelector(t);
|
||||||
|
var nextSibling = t.nextSibling;
|
||||||
var elem = parent.removeChild(t);
|
var elem = parent.removeChild(t);
|
||||||
selectedCopy.push(selected) //for the copy
|
selectedCopy.push(selected); //for the copy
|
||||||
selectedElements[i] = null;
|
selectedElements[i] = null;
|
||||||
batchCmd.addSubCommand(new RemoveElementCommand(elem, parent));
|
batchCmd.addSubCommand(new RemoveElementCommand(elem, nextSibling, parent));
|
||||||
}
|
}
|
||||||
if (!batchCmd.isEmpty()) addCommandToHistory(batchCmd);
|
if (!batchCmd.isEmpty()) addCommandToHistory(batchCmd);
|
||||||
call("changed", selectedCopy);
|
call("changed", selectedCopy);
|
||||||
|
@ -9534,7 +9543,8 @@ this.ungroupSelectedElement = function() {
|
||||||
|
|
||||||
// Remove child title elements
|
// Remove child title elements
|
||||||
if(elem.tagName === 'title') {
|
if(elem.tagName === 'title') {
|
||||||
batchCmd.addSubCommand(new RemoveElementCommand(elem, oldParent));
|
var nextSibling = elem.nextSibling;
|
||||||
|
batchCmd.addSubCommand(new RemoveElementCommand(elem, nextSibling, oldParent));
|
||||||
oldParent.removeChild(elem);
|
oldParent.removeChild(elem);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -9547,8 +9557,9 @@ this.ungroupSelectedElement = function() {
|
||||||
clearSelection();
|
clearSelection();
|
||||||
|
|
||||||
// delete the group element (but make undo-able)
|
// delete the group element (but make undo-able)
|
||||||
|
var gNextSibling = g.nextSibling;
|
||||||
g = parent.removeChild(g);
|
g = parent.removeChild(g);
|
||||||
batchCmd.addSubCommand(new RemoveElementCommand(g, parent));
|
batchCmd.addSubCommand(new RemoveElementCommand(g, gNextSibling, parent));
|
||||||
|
|
||||||
if (!batchCmd.isEmpty()) addCommandToHistory(batchCmd);
|
if (!batchCmd.isEmpty()) addCommandToHistory(batchCmd);
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,16 @@
|
||||||
<head>
|
<head>
|
||||||
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
|
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
|
||||||
<script src='../editor/jquery.js'></script>
|
<script src='../editor/jquery.js'></script>
|
||||||
<script type='text/javascript' src='../editor/svgtransformlist.js'></script>
|
|
||||||
<script type='text/javascript' src='../editor/history.js'></script>
|
|
||||||
<script type='text/javascript' src='../editor/svgutils.js'></script>
|
<script type='text/javascript' src='../editor/svgutils.js'></script>
|
||||||
|
<script type='text/javascript' src='../editor/history.js'></script>
|
||||||
<script type='text/javascript' src='qunit/qunit.js'></script>
|
<script type='text/javascript' src='qunit/qunit.js'></script>
|
||||||
<script type='text/javascript'>
|
<script type='text/javascript'>
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
|
// Mocked out method.
|
||||||
|
svgedit.transformlist = {};
|
||||||
|
svgedit.transformlist.removeElementFromListMap = function(elem) {};
|
||||||
|
|
||||||
// log function
|
// log function
|
||||||
QUnit.log = function(result, message) {
|
QUnit.log = function(result, message) {
|
||||||
if (window.console && window.console.log) {
|
if (window.console && window.console.log) {
|
||||||
|
@ -19,8 +23,14 @@
|
||||||
var svgns = 'http://www.w3.org/2000/svg';
|
var svgns = 'http://www.w3.org/2000/svg';
|
||||||
var svg = document.createElementNS(svgns, 'svg');
|
var svg = document.createElementNS(svgns, 'svg');
|
||||||
var undoMgr = null;
|
var undoMgr = null;
|
||||||
|
var divparent = document.getElementById('divparent');
|
||||||
|
var div1 = document.getElementById('div1');
|
||||||
|
var div2 = document.getElementById('div2');
|
||||||
|
var div3 = document.getElementById('div3');
|
||||||
|
var div4 = document.getElementById('div4');
|
||||||
|
var div5 = document.getElementById('div5');
|
||||||
|
|
||||||
module('svgedit.history Module');
|
module('svgedit.history');
|
||||||
|
|
||||||
var MockCommand = function(opt_text) {
|
var MockCommand = function(opt_text) {
|
||||||
this.text_ = opt_text;
|
this.text_ = opt_text;
|
||||||
|
@ -297,6 +307,143 @@
|
||||||
tearDown();
|
tearDown();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Test MoveElementCommand', function() {
|
||||||
|
expect(26);
|
||||||
|
|
||||||
|
setUp();
|
||||||
|
|
||||||
|
var move = new svgedit.history.MoveElementCommand(div3, div1, divparent);
|
||||||
|
ok(move.unapply);
|
||||||
|
ok(move.apply);
|
||||||
|
equals(typeof move.unapply, typeof function(){});
|
||||||
|
equals(typeof move.apply, typeof function(){});
|
||||||
|
|
||||||
|
move.unapply();
|
||||||
|
equals(divparent.firstElementChild, div3);
|
||||||
|
equals(divparent.firstElementChild.nextElementSibling, div1);
|
||||||
|
equals(divparent.lastElementChild, div2);
|
||||||
|
|
||||||
|
move.apply();
|
||||||
|
equals(divparent.firstElementChild, div1);
|
||||||
|
equals(divparent.firstElementChild.nextElementSibling, div2);
|
||||||
|
equals(divparent.lastElementChild, div3);
|
||||||
|
|
||||||
|
move = new svgedit.history.MoveElementCommand(div1, null, divparent);
|
||||||
|
|
||||||
|
move.unapply();
|
||||||
|
equals(divparent.firstElementChild, div2);
|
||||||
|
equals(divparent.firstElementChild.nextElementSibling, div3);
|
||||||
|
equals(divparent.lastElementChild, div1);
|
||||||
|
|
||||||
|
move.apply();
|
||||||
|
equals(divparent.firstElementChild, div1);
|
||||||
|
equals(divparent.firstElementChild.nextElementSibling, div2);
|
||||||
|
equals(divparent.lastElementChild, div3);
|
||||||
|
|
||||||
|
move = new svgedit.history.MoveElementCommand(div2, div5, div4);
|
||||||
|
|
||||||
|
move.unapply();
|
||||||
|
equals(divparent.firstElementChild, div1);
|
||||||
|
equals(divparent.firstElementChild.nextElementSibling, div3);
|
||||||
|
equals(divparent.lastElementChild, div3);
|
||||||
|
equals(div4.firstElementChild, div2);
|
||||||
|
equals(div4.firstElementChild.nextElementSibling, div5);
|
||||||
|
|
||||||
|
move.apply();
|
||||||
|
equals(divparent.firstElementChild, div1);
|
||||||
|
equals(divparent.firstElementChild.nextElementSibling, div2);
|
||||||
|
equals(divparent.lastElementChild, div3);
|
||||||
|
equals(div4.firstElementChild, div5);
|
||||||
|
equals(div4.lastElementChild, div5);
|
||||||
|
|
||||||
|
tearDown();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Test InsertElementCommand', function() {
|
||||||
|
expect(20);
|
||||||
|
|
||||||
|
setUp();
|
||||||
|
|
||||||
|
var insert = new svgedit.history.InsertElementCommand(div3);
|
||||||
|
ok(insert.unapply);
|
||||||
|
ok(insert.apply);
|
||||||
|
equals(typeof insert.unapply, typeof function(){});
|
||||||
|
equals(typeof insert.apply, typeof function(){});
|
||||||
|
|
||||||
|
insert.unapply();
|
||||||
|
equals(divparent.childElementCount, 2);
|
||||||
|
equals(divparent.firstElementChild, div1);
|
||||||
|
equals(div1.nextElementSibling, div2);
|
||||||
|
equals(divparent.lastElementChild, div2);
|
||||||
|
|
||||||
|
insert.apply();
|
||||||
|
equals(divparent.childElementCount, 3);
|
||||||
|
equals(divparent.firstElementChild, div1);
|
||||||
|
equals(div1.nextElementSibling, div2);
|
||||||
|
equals(div2.nextElementSibling, div3);
|
||||||
|
|
||||||
|
insert = new svgedit.history.InsertElementCommand(div2);
|
||||||
|
|
||||||
|
insert.unapply();
|
||||||
|
equals(divparent.childElementCount, 2);
|
||||||
|
equals(divparent.firstElementChild, div1);
|
||||||
|
equals(div1.nextElementSibling, div3);
|
||||||
|
equals(divparent.lastElementChild, div3);
|
||||||
|
|
||||||
|
insert.apply();
|
||||||
|
equals(divparent.childElementCount, 3);
|
||||||
|
equals(divparent.firstElementChild, div1);
|
||||||
|
equals(div1.nextElementSibling, div2);
|
||||||
|
equals(div2.nextElementSibling, div3);
|
||||||
|
|
||||||
|
tearDown();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Test RemoveElementCommand', function() {
|
||||||
|
expect(22);
|
||||||
|
|
||||||
|
setUp();
|
||||||
|
|
||||||
|
var div6 = document.createElement('div');
|
||||||
|
div6.id = 'div6';
|
||||||
|
|
||||||
|
var remove = new svgedit.history.RemoveElementCommand(div6, null, divparent);
|
||||||
|
ok(remove.unapply);
|
||||||
|
ok(remove.apply);
|
||||||
|
equals(typeof remove.unapply, typeof function(){});
|
||||||
|
equals(typeof remove.apply, typeof function(){});
|
||||||
|
|
||||||
|
remove.unapply();
|
||||||
|
equals(divparent.childElementCount, 4);
|
||||||
|
equals(divparent.firstElementChild, div1);
|
||||||
|
equals(div1.nextElementSibling, div2);
|
||||||
|
equals(div2.nextElementSibling, div3);
|
||||||
|
equals(div3.nextElementSibling, div6);
|
||||||
|
|
||||||
|
remove.apply();
|
||||||
|
equals(divparent.childElementCount, 3);
|
||||||
|
equals(divparent.firstElementChild, div1);
|
||||||
|
equals(div1.nextElementSibling, div2);
|
||||||
|
equals(div2.nextElementSibling, div3);
|
||||||
|
|
||||||
|
remove = new svgedit.history.RemoveElementCommand(div6, div2, divparent);
|
||||||
|
|
||||||
|
remove.unapply();
|
||||||
|
equals(divparent.childElementCount, 4);
|
||||||
|
equals(divparent.firstElementChild, div1);
|
||||||
|
equals(div1.nextElementSibling, div6);
|
||||||
|
equals(div6.nextElementSibling, div2);
|
||||||
|
equals(div2.nextElementSibling, div3);
|
||||||
|
|
||||||
|
remove.apply();
|
||||||
|
equals(divparent.childElementCount, 3);
|
||||||
|
equals(divparent.firstElementChild, div1);
|
||||||
|
equals(div1.nextElementSibling, div2);
|
||||||
|
equals(div2.nextElementSibling, div3);
|
||||||
|
|
||||||
|
tearDown();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
@ -306,5 +453,13 @@
|
||||||
<h2 id='qunit-userAgent'></h2>
|
<h2 id='qunit-userAgent'></h2>
|
||||||
<ol id='qunit-tests'>
|
<ol id='qunit-tests'>
|
||||||
</ol>
|
</ol>
|
||||||
|
<div id='divparent' style='visibility:hidden'>
|
||||||
|
<div id='div1'></div>
|
||||||
|
<div id='div2'></div>
|
||||||
|
<div id='div3'></div>
|
||||||
|
</div>
|
||||||
|
<div id='div4' style='visibility:hidden'>
|
||||||
|
<div id='div5'></div>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
var svgns = 'http://www.w3.org/2000/svg';
|
var svgns = 'http://www.w3.org/2000/svg';
|
||||||
var svg = document.createElementNS(svgns, 'svg');
|
var svg = document.createElementNS(svgns, 'svg');
|
||||||
|
|
||||||
module('svgedit.math Module');
|
module('svgedit.math');
|
||||||
|
|
||||||
test('Test svgedit.math package', function() {
|
test('Test svgedit.math package', function() {
|
||||||
expect(7);
|
expect(7);
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module('svgedit.svgtransformlist Module');
|
module('svgedit.svgtransformlist');
|
||||||
|
|
||||||
test('Test svgedit.transformlist package', function() {
|
test('Test svgedit.transformlist package', function() {
|
||||||
expect(2);
|
expect(2);
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
var svgns = 'http://www.w3.org/2000/svg';
|
var svgns = 'http://www.w3.org/2000/svg';
|
||||||
var svg = document.createElementNS(svgns, 'svg');
|
var svg = document.createElementNS(svgns, 'svg');
|
||||||
|
|
||||||
module('svgedit.utilities Module');
|
module('svgedit.utilities');
|
||||||
|
|
||||||
test('Test svgedit.utilities package', function() {
|
test('Test svgedit.utilities package', function() {
|
||||||
expect(3);
|
expect(3);
|
||||||
|
|
Loading…
Reference in New Issue