- Change forEach for each interator

- Fix issue deleting nodes with intermediate relationships
This commit is contained in:
Paulo Gustavo Veiga 2012-07-08 19:31:21 -03:00
parent 8175eea928
commit 39c2b37a1f
24 changed files with 521 additions and 508 deletions

View File

@ -73,7 +73,7 @@ mindplot.BrixActionDispatcher = new Class({
}, },
changeFontSizeToTopic : function(topicsIds, size) { changeFontSizeToTopic : function(topicsIds, size) {
topicsIds.forEach(function(topicId) { topicsIds.each(function(topicId) {
var framework = this._getFramework(); var framework = this._getFramework();
var topic = framework.getTopic(topicId); var topic = framework.getTopic(topicId);
topic.setFontSize(size, true); topic.setFontSize(size, true);
@ -81,7 +81,7 @@ mindplot.BrixActionDispatcher = new Class({
}, },
changeFontColorToTopic : function(topicsIds, color) { changeFontColorToTopic : function(topicsIds, color) {
topicsIds.forEach(function(topicId) { topicsIds.each(function(topicId) {
var framework = this._getFramework(); var framework = this._getFramework();
var topic = framework.getTopic(topicId); var topic = framework.getTopic(topicId);
topic.setFontColor(color, true); topic.setFontColor(color, true);
@ -89,7 +89,7 @@ mindplot.BrixActionDispatcher = new Class({
}, },
changeFontFamilyToTopic : function(topicsIds, family) { changeFontFamilyToTopic : function(topicsIds, family) {
topicsIds.forEach(function(topicId) { topicsIds.each(function(topicId) {
var framework = this._getFramework(); var framework = this._getFramework();
var topic = framework.getTopic(topicId); var topic = framework.getTopic(topicId);
topic.setFontFamily(family, true); topic.setFontFamily(family, true);
@ -97,7 +97,7 @@ mindplot.BrixActionDispatcher = new Class({
}, },
changeFontStyleToTopic : function(topicsIds) { changeFontStyleToTopic : function(topicsIds) {
topicsIds.forEach(function(topicId) { topicsIds.each(function(topicId) {
var framework = this._getFramework(); var framework = this._getFramework();
var topic = framework.getTopic(topicId); var topic = framework.getTopic(topicId);
var style = ( topic.getFontStyle() == "italic") ? "normal" : "italic"; var style = ( topic.getFontStyle() == "italic") ? "normal" : "italic";
@ -106,7 +106,7 @@ mindplot.BrixActionDispatcher = new Class({
}, },
changeShapeTypeToTopic : function(topicsIds, shapeType) { changeShapeTypeToTopic : function(topicsIds, shapeType) {
topicsIds.forEach(function(topicId) { topicsIds.each(function(topicId) {
var framework = this._getFramework(); var framework = this._getFramework();
var topic = framework.getTopic(topicId); var topic = framework.getTopic(topicId);
topic.setShapeType(shapeType); topic.setShapeType(shapeType);
@ -114,7 +114,7 @@ mindplot.BrixActionDispatcher = new Class({
}, },
changeFontWeightToTopic : function(topicsIds) { changeFontWeightToTopic : function(topicsIds) {
topicsIds.forEach(function(topicId) { topicsIds.each(function(topicId) {
var framework = this._getFramework(); var framework = this._getFramework();
var topic = framework.getTopic(topicId); var topic = framework.getTopic(topicId);
var weight = (topic.getFontWeight() == "bold") ? "normal" : "bold"; var weight = (topic.getFontWeight() == "bold") ? "normal" : "bold";
@ -123,7 +123,7 @@ mindplot.BrixActionDispatcher = new Class({
}, },
changeBackgroundColorToTopic : function(topicsIds, color) { changeBackgroundColorToTopic : function(topicsIds, color) {
topicsIds.forEach(function(topicId) { topicsIds.each(function(topicId) {
var framework = this._getFramework(); var framework = this._getFramework();
var topic = framework.getTopic(topicId); var topic = framework.getTopic(topicId);
topic.setBackgroundColor(color, true); topic.setBackgroundColor(color, true);
@ -132,7 +132,7 @@ mindplot.BrixActionDispatcher = new Class({
}, },
changeBorderColorToTopic : function(topicsIds, color) { changeBorderColorToTopic : function(topicsIds, color) {
topicsIds.forEach(function(topicId) { topicsIds.each(function(topicId) {
var framework = this._getFramework(); var framework = this._getFramework();
var topic = framework.getTopic(topicId); var topic = framework.getTopic(topicId);
topic.setBorderColor(color); topic.setBorderColor(color);
@ -144,7 +144,7 @@ mindplot.BrixActionDispatcher = new Class({
var framework = this._getFramework(); var framework = this._getFramework();
var mindmap = framework.getModel(); var mindmap = framework.getModel();
topicsIds.forEach(function(topicId) { topicsIds.each(function(topicId) {
var topic = framework.getTopic(topicId); var topic = framework.getTopic(topicId);
topic.deleteNode(); topic.deleteNode();
}); });

View File

@ -109,7 +109,7 @@ mindplot.Designer = new Class({
screenManager.addEvent('update', function () { screenManager.addEvent('update', function () {
// Topic must be set to his original state. All editors must be closed. // Topic must be set to his original state. All editors must be closed.
var topics = this.getModel().getTopics(); var topics = this.getModel().getTopics();
topics.forEach(function (object) { topics.each(function (object) {
object.closeEditors(); object.closeEditors();
}); });
@ -271,13 +271,13 @@ mindplot.Designer = new Class({
onObjectFocusEvent:function (currentObject, event) { onObjectFocusEvent:function (currentObject, event) {
// Close node editors .. // Close node editors ..
var topics = this.getModel().getTopics(); var topics = this.getModel().getTopics();
topics.forEach(function (topic) { topics.each(function (topic) {
topic.closeEditors(); topic.closeEditors();
}); });
var model = this.getModel(); var model = this.getModel();
var objects = model.getEntities(); var objects = model.getEntities();
objects.forEach(function (object) { objects.each(function (object) {
// Disable all nodes on focus but not the current if Ctrl key isn't being pressed // Disable all nodes on focus but not the current if Ctrl key isn't being pressed
if (!$defined(event) || (!event.control && !event.meta)) { if (!$defined(event) || (!event.control && !event.meta)) {
if (object.isOnFocus() && object != currentObject) { if (object.isOnFocus() && object != currentObject) {
@ -291,14 +291,14 @@ mindplot.Designer = new Class({
selectAll:function () { selectAll:function () {
var model = this.getModel(); var model = this.getModel();
var objects = model.getEntities(); var objects = model.getEntities();
objects.forEach(function (object) { objects.each(function (object) {
object.setOnFocus(true); object.setOnFocus(true);
}); });
}, },
deselectAll:function () { deselectAll:function () {
var objects = this.getModel().getEntities(); var objects = this.getModel().getEntities();
objects.forEach(function (object) { objects.each(function (object) {
object.setOnFocus(false); object.setOnFocus(false);
}); });
}, },

View File

@ -103,7 +103,7 @@ mindplot.IconGroup = new Class({
this._resize(this._icons.length); this._resize(this._icons.length);
// Add all again ... // Add all again ...
this._icons.forEach(function(elem, i) { this._icons.each(function(elem, i) {
this._positionIcon(elem, i); this._positionIcon(elem, i);
}.bind(this)); }.bind(this));
}, },

View File

@ -1,268 +1,268 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.MultilineTextEditor = new Class({ mindplot.MultilineTextEditor = new Class({
Extends: Events, Extends: Events,
initialize:function() { initialize:function() {
this._topic = null; this._topic = null;
}, },
_buildEditor : function() { _buildEditor : function() {
var result = new Element('div'); var result = new Element('div');
result.setStyles({ result.setStyles({
position:"absolute", position:"absolute",
display: "none", display: "none",
zIndex: "8", zIndex: "8",
overflow:"hidden", overflow:"hidden",
border: "0 none" border: "0 none"
} }
); );
var textareaElem = new Element('textarea', var textareaElem = new Element('textarea',
{ tabindex:'-1', { tabindex:'-1',
value:"", value:"",
wrap:'off' wrap:'off'
} }
); );
textareaElem.setStyles({ textareaElem.setStyles({
border: "1px gray dashed", border: "1px gray dashed",
background:"rgba(98, 135, 167, .3)", background:"rgba(98, 135, 167, .3)",
outline: '0 none', outline: '0 none',
resize: 'none', resize: 'none',
overflow:"hidden" overflow:"hidden"
}); });
textareaElem.inject(result); textareaElem.inject(result);
return result; return result;
}, },
_registerEvents : function(containerElem) { _registerEvents : function(containerElem) {
var textareaElem = this._getTextareaElem(); var textareaElem = this._getTextareaElem();
textareaElem.addEvent('keydown', function (event) { textareaElem.addEvent('keydown', function (event) {
switch (event.key) { switch (event.key) {
case 'esc': case 'esc':
this.close(false); this.close(false);
break; break;
case 'enter': case 'enter':
if (event.meta || event.control) { if (event.meta || event.control) {
// @todo: Enters must be in any place ... // @todo: Enters must be in any place ...
textareaElem.value = textareaElem.value + "\n"; textareaElem.value = textareaElem.value + "\n";
} }
else { else {
this.close(true); this.close(true);
} }
break; break;
} }
event.stopPropagation(); event.stopPropagation();
}.bind(this)); }.bind(this));
textareaElem.addEvent('keypress', function(event) { textareaElem.addEvent('keypress', function(event) {
event.stopPropagation(); event.stopPropagation();
}); });
textareaElem.addEvent('keyup', function(event) { textareaElem.addEvent('keyup', function(event) {
var text = this._getTextareaElem().value; var text = this._getTextareaElem().value;
this.fireEvent('input', [event, text]); this.fireEvent('input', [event, text]);
this._adjustEditorSize(); this._adjustEditorSize();
}.bind(this)); }.bind(this));
// If the user clicks on the input, all event must be ignored ... // If the user clicks on the input, all event must be ignored ...
containerElem.addEvent('click', function(event) { containerElem.addEvent('click', function(event) {
event.stopPropagation(); event.stopPropagation();
}); });
containerElem.addEvent('dblclick', function(event) { containerElem.addEvent('dblclick', function(event) {
event.stopPropagation(); event.stopPropagation();
}); });
containerElem.addEvent('mousedown', function(event) { containerElem.addEvent('mousedown', function(event) {
event.stopPropagation(); event.stopPropagation();
}); });
}, },
_adjustEditorSize : function() { _adjustEditorSize : function() {
if (this.isVisible()) { if (this.isVisible()) {
var textElem = this._getTextareaElem(); var textElem = this._getTextareaElem();
var lines = textElem.value.split('\n'); var lines = textElem.value.split('\n');
var maxLineLength = 1; var maxLineLength = 1;
lines.forEach(function(line) { lines.each(function(line) {
if (maxLineLength < line.length) if (maxLineLength < line.length)
maxLineLength = line.length; maxLineLength = line.length;
}); });
textElem.setAttribute('cols', maxLineLength); textElem.setAttribute('cols', maxLineLength);
textElem.setAttribute('rows', lines.length); textElem.setAttribute('rows', lines.length);
this._containerElem.setStyles({ this._containerElem.setStyles({
width: (maxLineLength + 3) + 'em', width: (maxLineLength + 3) + 'em',
height: textElem.getSize().height height: textElem.getSize().height
}); });
} }
}, },
isVisible : function () { isVisible : function () {
return $defined(this._containerElem) && this._containerElem.getStyle('display') == 'block'; return $defined(this._containerElem) && this._containerElem.getStyle('display') == 'block';
}, },
_updateModel : function () { _updateModel : function () {
if (this._topic.getText() != this._getText()) { if (this._topic.getText() != this._getText()) {
var text = this._getText(); var text = this._getText();
var topicId = this._topic.getId(); var topicId = this._topic.getId();
var actionDispatcher = mindplot.ActionDispatcher.getInstance(); var actionDispatcher = mindplot.ActionDispatcher.getInstance();
actionDispatcher.changeTextToTopic([topicId], text); actionDispatcher.changeTextToTopic([topicId], text);
} }
}, },
show : function (topic,text) { show : function (topic,text) {
this._topic = topic; this._topic = topic;
if (!this.isVisible()) { if (!this.isVisible()) {
//Create editor ui //Create editor ui
var containerElem = this._buildEditor(); var containerElem = this._buildEditor();
containerElem.inject($(document.body)); containerElem.inject($(document.body));
this._containerElem = containerElem; this._containerElem = containerElem;
this._registerEvents(containerElem); this._registerEvents(containerElem);
this._showEditor(text); this._showEditor(text);
} }
}, },
_showEditor : function (defaultText) { _showEditor : function (defaultText) {
var topic = this._topic; var topic = this._topic;
// Hide topic text ... // Hide topic text ...
topic.getTextShape().setVisibility(false); topic.getTextShape().setVisibility(false);
// Set Editor Style // Set Editor Style
var nodeText = topic.getTextShape(); var nodeText = topic.getTextShape();
var font = nodeText.getFont(); var font = nodeText.getFont();
font.size = nodeText.getHtmlFontSize(); font.size = nodeText.getHtmlFontSize();
font.color = nodeText.getColor(); font.color = nodeText.getColor();
this._setStyle(font); this._setStyle(font);
// Set editor's initial size // Set editor's initial size
var displayFunc = function() { var displayFunc = function() {
// Position the editor and set the size... // Position the editor and set the size...
var textShape = this._topic.getTextShape(); var textShape = this._topic.getTextShape();
textShape.positionRelativeTo(this._containerElem, { textShape.positionRelativeTo(this._containerElem, {
position: {x: 'left',y:'top'}, position: {x: 'left',y:'top'},
edge: {x: 'left', y: 'top'} edge: {x: 'left', y: 'top'}
}); });
this._containerElem.setStyle('display', 'block'); this._containerElem.setStyle('display', 'block');
// Set editor's initial text ... // Set editor's initial text ...
var text = $defined(defaultText) ? defaultText : topic.getText(); var text = $defined(defaultText) ? defaultText : topic.getText();
this._setText(text); this._setText(text);
// Set the element focus and select the current text ... // Set the element focus and select the current text ...
var inputElem = this._getTextareaElem(); var inputElem = this._getTextareaElem();
this._positionCursor(inputElem, !$defined(defaultText)); this._positionCursor(inputElem, !$defined(defaultText));
}.bind(this); }.bind(this);
displayFunc.delay(10); displayFunc.delay(10);
}, },
_setStyle : function (fontStyle) { _setStyle : function (fontStyle) {
var inputField = this._getTextareaElem(); var inputField = this._getTextareaElem();
if (!$defined(fontStyle.font)) { if (!$defined(fontStyle.font)) {
fontStyle.font = "Arial"; fontStyle.font = "Arial";
} }
if (!$defined(fontStyle.style)) { if (!$defined(fontStyle.style)) {
fontStyle.style = "normal"; fontStyle.style = "normal";
} }
if (!$defined(fontStyle.weight)) { if (!$defined(fontStyle.weight)) {
fontStyle.weight = "normal"; fontStyle.weight = "normal";
} }
if (!$defined(fontStyle.size)) { if (!$defined(fontStyle.size)) {
fontStyle.size = 12; fontStyle.size = 12;
} }
var style = { var style = {
fontSize : fontStyle.size + "px", fontSize : fontStyle.size + "px",
fontFamily : fontStyle.font, fontFamily : fontStyle.font,
fontStyle : fontStyle.style, fontStyle : fontStyle.style,
fontWeight : fontStyle.weight, fontWeight : fontStyle.weight,
color : fontStyle.color color : fontStyle.color
}; };
inputField.setStyles(style); inputField.setStyles(style);
this._containerElem.setStyles(style); this._containerElem.setStyles(style);
}, },
_setText : function(text) { _setText : function(text) {
var textareaElem = this._getTextareaElem(); var textareaElem = this._getTextareaElem();
textareaElem.value = text; textareaElem.value = text;
this._adjustEditorSize(); this._adjustEditorSize();
}, },
_getText : function() { _getText : function() {
return this._getTextareaElem().value; return this._getTextareaElem().value;
}, },
_getTextareaElem : function() { _getTextareaElem : function() {
return this._containerElem.getElement('textarea'); return this._containerElem.getElement('textarea');
}, },
_positionCursor : function(textareaElem, selectText) { _positionCursor : function(textareaElem, selectText) {
textareaElem.focus(); textareaElem.focus();
if (selectText) { if (selectText) {
// Mark text as selected ... // Mark text as selected ...
if (textareaElem.createTextRange) { if (textareaElem.createTextRange) {
var rang = textareaElem.createTextRange(); var rang = textareaElem.createTextRange();
rang.select(); rang.select();
rang.move("character", textareaElem.value.length); rang.move("character", textareaElem.value.length);
} }
else { else {
textareaElem.setSelectionRange(0, textareaElem.value.length); textareaElem.setSelectionRange(0, textareaElem.value.length);
} }
} else { } else {
// Move the cursor to the last character .. // Move the cursor to the last character ..
if (textareaElem.createTextRange) { if (textareaElem.createTextRange) {
var range = textareaElem.createTextRange(); var range = textareaElem.createTextRange();
range.move("character", textareaElem.value.length); range.move("character", textareaElem.value.length);
} else { } else {
textareaElem.selectionStart = textareaElem.value.length; textareaElem.selectionStart = textareaElem.value.length;
} }
} }
}, },
close : function(update) { close : function(update) {
if (this.isVisible()) { if (this.isVisible()) {
// Update changes ... // Update changes ...
if (!$defined(update) || update) { if (!$defined(update) || update) {
this._updateModel(); this._updateModel();
} }
// Let make the visible text in the node visible again ... // Let make the visible text in the node visible again ...
this._topic.getTextShape().setVisibility(true); this._topic.getTextShape().setVisibility(true);
// Remove it form the screen ... // Remove it form the screen ...
this._containerElem.dispose(); this._containerElem.dispose();
this._containerElem = null; this._containerElem = null;
this._topic = null; this._topic = null;
} }
} }
}); });

View File

@ -53,7 +53,7 @@ mindplot.RelationshipPivot = new Class({
// Register focus events on all topics ... // Register focus events on all topics ...
var model = this._designer.getModel(); var model = this._designer.getModel();
var topics = model.getTopics(); var topics = model.getTopics();
topics.forEach(function (topic) { topics.each(function (topic) {
topic.addEvent('ontfocus', this._onTopicClick); topic.addEvent('ontfocus', this._onTopicClick);
}.bind(this)); }.bind(this));
} }
@ -69,7 +69,7 @@ mindplot.RelationshipPivot = new Class({
var model = this._designer.getModel(); var model = this._designer.getModel();
var topics = model.getTopics(); var topics = model.getTopics();
topics.forEach(function (topic) { topics.each(function (topic) {
topic.removeEvent('ontfocus', this._onTopicClick); topic.removeEvent('ontfocus', this._onTopicClick);
}.bind(this)); }.bind(this));

View File

@ -1,147 +1,147 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.ScreenManager = new Class({ mindplot.ScreenManager = new Class({
initialize:function(divElement) { initialize:function(divElement) {
$assert(divElement, "can not be null"); $assert(divElement, "can not be null");
this._divContainer = divElement; this._divContainer = divElement;
this._padding = {x:0,y:0}; this._padding = {x:0,y:0};
// Ignore default click event propagation. Prevent 'click' event on drag. // Ignore default click event propagation. Prevent 'click' event on drag.
this._clickEvents = []; this._clickEvents = [];
this._divContainer.addEvent('click', function(event) { this._divContainer.addEvent('click', function(event) {
event.stopPropagation() event.stopPropagation()
}.bind(this)); }.bind(this));
this._divContainer.addEvent('dblclick', function(event) { this._divContainer.addEvent('dblclick', function(event) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
}); });
}, },
setScale : function(scale) { setScale : function(scale) {
$assert(scale, 'Screen scale can not be null'); $assert(scale, 'Screen scale can not be null');
this._scale = scale; this._scale = scale;
}, },
addEvent : function(event, listener) { addEvent : function(event, listener) {
if (event == 'click') if (event == 'click')
this._clickEvents.push(listener); this._clickEvents.push(listener);
else else
$(this._divContainer).addEvent(event, listener); $(this._divContainer).addEvent(event, listener);
}, },
removeEvent : function(event, listener) { removeEvent : function(event, listener) {
if (event == 'click') if (event == 'click')
this._clickEvents.remove(listener); this._clickEvents.remove(listener);
else else
$(this._divContainer).removeEvent(event, listener); $(this._divContainer).removeEvent(event, listener);
}, },
fireEvent : function(type, event) { fireEvent : function(type, event) {
if (type == 'click') { if (type == 'click') {
this._clickEvents.forEach(function(listener) { this._clickEvents.each(function(listener) {
listener(type, event); listener(type, event);
}); });
} }
else { else {
$(this._divContainer).fireEvent(type, event); $(this._divContainer).fireEvent(type, event);
} }
}, },
_getElementPosition : function(elem) { _getElementPosition : function(elem) {
// Retrieve current element position. // Retrieve current element position.
var elementPosition = elem.getPosition(); var elementPosition = elem.getPosition();
var x = elementPosition.x; var x = elementPosition.x;
var y = elementPosition.y; var y = elementPosition.y;
// Add workspace offset. // Add workspace offset.
x = x - this._padding.x; x = x - this._padding.x;
y = y - this._padding.y; y = y - this._padding.y;
// Scale coordinate in order to be relative to the workspace. That's coord/size; // Scale coordinate in order to be relative to the workspace. That's coord/size;
x = x / this._scale; x = x / this._scale;
y = y / this._scale; y = y / this._scale;
// Remove decimal part.. // Remove decimal part..
return {x:x,y:y}; return {x:x,y:y};
}, },
getWorkspaceIconPosition : function(e) { getWorkspaceIconPosition : function(e) {
// Retrieve current icon position. // Retrieve current icon position.
var image = e.getImage(); var image = e.getImage();
var elementPosition = image.getPosition(); var elementPosition = image.getPosition();
var imageSize = e.getSize(); var imageSize = e.getSize();
//Add group offset //Add group offset
var iconGroup = e.getGroup(); var iconGroup = e.getGroup();
var group = iconGroup.getNativeElement(); var group = iconGroup.getNativeElement();
var coordOrigin = group.getCoordOrigin(); var coordOrigin = group.getCoordOrigin();
var groupSize = group.getSize(); var groupSize = group.getSize();
var coordSize = group.getCoordSize(); var coordSize = group.getCoordSize();
var scale = {x:coordSize.width / parseInt(groupSize.width), y:coordSize.height / parseInt(groupSize.height)}; var scale = {x:coordSize.width / parseInt(groupSize.width), y:coordSize.height / parseInt(groupSize.height)};
var x = (elementPosition.x - coordOrigin.x - (parseInt(imageSize.width) / 2)) / scale.x; var x = (elementPosition.x - coordOrigin.x - (parseInt(imageSize.width) / 2)) / scale.x;
var y = (elementPosition.y - coordOrigin.y - (parseInt(imageSize.height) / 2)) / scale.y; var y = (elementPosition.y - coordOrigin.y - (parseInt(imageSize.height) / 2)) / scale.y;
//Retrieve iconGroup Position //Retrieve iconGroup Position
var groupPosition = iconGroup.getPosition(); var groupPosition = iconGroup.getPosition();
x = x + groupPosition.x; x = x + groupPosition.x;
y = y + groupPosition.y; y = y + groupPosition.y;
//Retrieve topic Position //Retrieve topic Position
var topic = iconGroup.getTopic(); var topic = iconGroup.getTopic();
var topicPosition = this._getElementPosition(topic); var topicPosition = this._getElementPosition(topic);
topicPosition.x = topicPosition.x - (parseInt(topic.getSize().width) / 2); topicPosition.x = topicPosition.x - (parseInt(topic.getSize().width) / 2);
// Remove decimal part.. // Remove decimal part..
return {x:x + topicPosition.x,y:y + topicPosition.y}; return {x:x + topicPosition.x,y:y + topicPosition.y};
}, },
getWorkspaceMousePosition : function(event) { getWorkspaceMousePosition : function(event) {
// Retrieve current mouse position. // Retrieve current mouse position.
var x = event.client.x; var x = event.client.x;
var y = event.client.y; var y = event.client.y;
// Subtract div position. // Subtract div position.
var containerPosition = this.getContainer().getPosition(); var containerPosition = this.getContainer().getPosition();
x = x - containerPosition.x; x = x - containerPosition.x;
y = y - containerPosition.y; y = y - containerPosition.y;
// Scale coordinate in order to be relative to the workspace. That's coordSize/size; // Scale coordinate in order to be relative to the workspace. That's coordSize/size;
x = x * this._scale; x = x * this._scale;
y = y * this._scale; y = y * this._scale;
// Add workspace offset. // Add workspace offset.
x = x + this._padding.x; x = x + this._padding.x;
y = y + this._padding.y; y = y + this._padding.y;
// Remove decimal part.. // Remove decimal part..
return new core.Point(x, y); return new core.Point(x, y);
}, },
getContainer : function() { getContainer : function() {
return this._divContainer; return this._divContainer;
}, },
setOffset : function(x, y) { setOffset : function(x, y) {
this._padding.x = x; this._padding.x = x;
this._padding.y = y; this._padding.y = y;
} }
}); });

View File

@ -875,7 +875,7 @@ mindplot.Topic = new Class({
}, },
_setRelationshipLinesVisibility:function (value) { _setRelationshipLinesVisibility:function (value) {
this._relationships.forEach(function (relationship) { this._relationships.each(function (relationship) {
relationship.setVisibility(value); relationship.setVisibility(value);
}); });
}, },

View File

@ -29,7 +29,7 @@ mindplot.commands.AddTopicCommand = new Class({
execute:function (commandContext) { execute:function (commandContext) {
this._models.forEach(function (model, index) { this._models.each(function (model, index) {
// Add a new topic ... // Add a new topic ...
var topic = commandContext.createTopic(model, false); var topic = commandContext.createTopic(model, false);
@ -56,7 +56,7 @@ mindplot.commands.AddTopicCommand = new Class({
undoExecute:function (commandContext) { undoExecute:function (commandContext) {
// Finally, delete the topic from the workspace ... // Finally, delete the topic from the workspace ...
this._models.forEach(function (model) { this._models.each(function (model) {
var topicId = model.getId(); var topicId = model.getId();
var topic = commandContext.findTopics(topicId)[0]; var topic = commandContext.findTopics(topicId)[0];

View File

@ -36,63 +36,61 @@ mindplot.commands.DeleteCommand = new Class({
if (topics.length > 0) { if (topics.length > 0) {
topics.forEach( topics.each(function (topic) {
function (topic) { var model = topic.getModel();
var model = topic.getModel();
// Delete relationships // Delete relationships
var relationships = topic.getRelationships(); var relationships = this._collectInDepthRelationships(topic);
while (relationships.length > 0) { this._deletedRelModel.append(relationships.map(function (rel) {
var relationship = relationships[0]; return rel.getModel().clone();
}));
this._deletedRelModel.push(relationship.getModel().clone()); relationships.each(function (relationship) {
commandContext.deleteRelationship(relationship); commandContext.deleteRelationship(relationship);
} });
// Store information for undo ... // Store information for undo ...
var clonedModel = model.clone(); var clonedModel = model.clone();
this._deletedTopicModels.push(clonedModel); this._deletedTopicModels.push(clonedModel);
var outTopic = topic.getOutgoingConnectedTopic(); var outTopic = topic.getOutgoingConnectedTopic();
var outTopicId = null; var outTopicId = null;
if (outTopic != null) { if (outTopic != null) {
outTopicId = outTopic.getId(); outTopicId = outTopic.getId();
} }
this._parentTopicIds.push(outTopicId); this._parentTopicIds.push(outTopicId);
// Finally, delete the topic from the workspace... // Finally, delete the topic from the workspace...
commandContext.deleteTopic(topic); commandContext.deleteTopic(topic);
}.bind(this) }, this);
);
} }
var rels = commandContext.findRelationships(this._relIds); var rels = commandContext.findRelationships(this._relIds);
if (rels.length > 0) { if (rels.length > 0) {
rels.forEach(function (rel) { rels.each(function (rel) {
this._deletedRelModel.push(rel.getModel().clone()); this._deletedRelModel.push(rel.getModel().clone());
commandContext.deleteRelationship(rel); commandContext.deleteRelationship(rel);
}.bind(this)); }, this);
} }
}, },
undoExecute:function (commandContext) { undoExecute:function (commandContext) {
var parent = commandContext.findTopics(this._parentTopicIds); var parent = commandContext.findTopics(this._parentTopicIds);
this._deletedTopicModels.forEach( this._deletedTopicModels.each(function (model, index) {
function (model, index) { var topic = commandContext.createTopic(model);
var topic = commandContext.createTopic(model);
// Was the topic connected? // Was the topic connected?
var parentTopic = parent[index]; var parentTopic = parent[index];
if (parentTopic != null) { if (parentTopic != null) {
commandContext.connect(topic, parentTopic); commandContext.connect(topic, parentTopic);
topic.setOnFocus(true); topic.setOnFocus(true);
} }
}.bind(this) }, this);
);
this._deletedRelModel.forEach(function (model) { this._deletedRelModel.each(function (model) {
commandContext.addRelationship(model); commandContext.addRelationship(model);
}.bind(this)); }.bind(this));
@ -105,7 +103,7 @@ mindplot.commands.DeleteCommand = new Class({
var topics = commandContext.findTopics(topicIds); var topics = commandContext.findTopics(topicIds);
var result = []; var result = [];
topics.forEach(function (topic) { topics.each(function (topic) {
var parent = topic.getParent(); var parent = topic.getParent();
var found = false; var found = false;
while (parent != null && !found) { while (parent != null && !found) {
@ -121,6 +119,21 @@ mindplot.commands.DeleteCommand = new Class({
} }
}); });
return result;
},
_collectInDepthRelationships:function (topic) {
var result = [];
var children = topic.getChildren();
if (children.length > 0) {
var rels = children.map(function (topic) {
return this._collectInDepthRelationships(topic);
}, this);
result.append(rels.flatten());
} else {
result.append(topic.getRelationships());
}
return result; return result;
} }
}); });

View File

@ -32,7 +32,7 @@ mindplot.commands.GenericFunctionCommand = new Class({
execute: function(commandContext) { execute: function(commandContext) {
if (!this.applied) { if (!this.applied) {
var topics = commandContext.findTopics(this._topicsIds); var topics = commandContext.findTopics(this._topicsIds);
topics.forEach(function(topic) { topics.each(function(topic) {
var oldValue = this._commandFunc(topic, this._value); var oldValue = this._commandFunc(topic, this._value);
this._oldValues.push(oldValue); this._oldValues.push(oldValue);
}.bind(this)); }.bind(this));
@ -46,7 +46,7 @@ mindplot.commands.GenericFunctionCommand = new Class({
undoExecute: function(commandContext) { undoExecute: function(commandContext) {
if (this.applied) { if (this.applied) {
var topics = commandContext.findTopics(this._topicsIds); var topics = commandContext.findTopics(this._topicsIds);
topics.forEach(function(topic, index) { topics.each(function(topic, index) {
this._commandFunc(topic, this._oldValues[index]); this._commandFunc(topic, this._oldValues[index]);
}.bind(this)); }.bind(this));

View File

@ -38,7 +38,7 @@ mindplot.layout.AbstractBasicSorter = new Class({
result = height; result = height;
} else { } else {
var childrenHeight = 0; var childrenHeight = 0;
children.forEach(function(child) { children.each(function(child) {
childrenHeight += this._computeChildrenHeight(treeSet, child, heightCache); childrenHeight += this._computeChildrenHeight(treeSet, child, heightCache);
}, this); }, this);

View File

@ -154,7 +154,7 @@ mindplot.layout.BalancedSorter = new Class({
var totalPHeight = 0; var totalPHeight = 0;
var totalNHeight = 0; var totalNHeight = 0;
heights.forEach(function (elem) { heights.each(function (elem) {
if (elem.order % 2 == 0) { if (elem.order % 2 == 0) {
totalPHeight += elem.height; totalPHeight += elem.height;
} else { } else {

View File

@ -143,7 +143,7 @@ mindplot.layout.LayoutManager = new Class({
}, },
_flushEvents: function() { _flushEvents: function() {
this._events.forEach(function(event) { this._events.each(function(event) {
this.fireEvent('change', event); this.fireEvent('change', event);
}, this); }, this);
this._events = []; this._events = [];
@ -153,7 +153,7 @@ mindplot.layout.LayoutManager = new Class({
if (!nodes) if (!nodes)
nodes = this._treeSet.getTreeRoots(); nodes = this._treeSet.getTreeRoots();
nodes.forEach(function(node) { nodes.each(function(node) {
if (node.hasOrderChanged() || node.hasPositionChanged()) { if (node.hasOrderChanged() || node.hasPositionChanged()) {
// Find or create a event ... // Find or create a event ...

View File

@ -70,7 +70,7 @@ mindplot.layout.OriginalLayout = new Class({
layout:function () { layout:function () {
var roots = this._treeSet.getTreeRoots(); var roots = this._treeSet.getTreeRoots();
roots.forEach(function (node) { roots.each(function (node) {
// Calculate all node heights ... // Calculate all node heights ...
var sorter = node.getSorter(); var sorter = node.getSorter();
@ -108,7 +108,7 @@ mindplot.layout.OriginalLayout = new Class({
var offsetById = sorter.computeOffsets(this._treeSet, node); var offsetById = sorter.computeOffsets(this._treeSet, node);
var parentPosition = node.getPosition(); var parentPosition = node.getPosition();
children.forEach(function (child) { children.each(function (child) {
var offset = offsetById[child.getId()]; var offset = offsetById[child.getId()];
var childFreeDisplacement = child.getFreeDisplacement(); var childFreeDisplacement = child.getFreeDisplacement();
@ -133,7 +133,7 @@ mindplot.layout.OriginalLayout = new Class({
} }
// Continue reordering the children nodes ... // Continue reordering the children nodes ...
children.forEach(function (child) { children.each(function (child) {
this._layoutChildren(child, heightById); this._layoutChildren(child, heightById);
}, this); }, this);
}, },
@ -183,7 +183,7 @@ mindplot.layout.OriginalLayout = new Class({
this._shiftBranches(node, heightById); this._shiftBranches(node, heightById);
} }
children.forEach(function (child) { children.each(function (child) {
this._fixOverlapping(child, heightById); this._fixOverlapping(child, heightById);
}, this); }, this);
}, },
@ -193,7 +193,7 @@ mindplot.layout.OriginalLayout = new Class({
var siblingsToShift = this._treeSet.getSiblingsInVerticalDirection(node, node.getFreeDisplacement().y); var siblingsToShift = this._treeSet.getSiblingsInVerticalDirection(node, node.getFreeDisplacement().y);
var last = node; var last = node;
siblingsToShift.forEach(function (sibling) { siblingsToShift.each(function (sibling) {
var overlappingOccurs = shiftedBranches.some(function (shiftedBranch) { var overlappingOccurs = shiftedBranches.some(function (shiftedBranch) {
return this._branchesOverlap(shiftedBranch, sibling, heightById); return this._branchesOverlap(shiftedBranch, sibling, heightById);
}, this); }, this);
@ -209,7 +209,7 @@ mindplot.layout.OriginalLayout = new Class({
return !shiftedBranches.contains(branch); return !shiftedBranches.contains(branch);
}); });
branchesToShift.forEach(function (branch) { branchesToShift.each(function (branch) {
var bAmount = node.getFreeDisplacement().y; var bAmount = node.getFreeDisplacement().y;
this._treeSet.shiftBranchPosition(branch, 0, bAmount); this._treeSet.shiftBranchPosition(branch, 0, bAmount);
shiftedBranches.push(branch); shiftedBranches.push(branch);

View File

@ -240,7 +240,7 @@ mindplot.layout.RootedTreeSet = new Class({
var yOffset = oldPos.y - position.y; var yOffset = oldPos.y - position.y;
var children = this.getChildren(node); var children = this.getChildren(node);
children.forEach(function (child) { children.each(function (child) {
this.shiftBranchPosition(child, xOffset, yOffset); this.shiftBranchPosition(child, xOffset, yOffset);
}.bind(this)); }.bind(this));
@ -251,7 +251,7 @@ mindplot.layout.RootedTreeSet = new Class({
node.setPosition({x:position.x + xOffset, y:position.y + yOffset}); node.setPosition({x:position.x + xOffset, y:position.y + yOffset});
var children = this.getChildren(node); var children = this.getChildren(node);
children.forEach(function (child) { children.each(function (child) {
this.shiftBranchPosition(child, xOffset, yOffset); this.shiftBranchPosition(child, xOffset, yOffset);
}.bind(this)); }.bind(this));
}, },

View File

@ -133,7 +133,7 @@ mindplot.layout.SymmetricSorter = new Class({
// Compute the center of the branch ... // Compute the center of the branch ...
var totalHeight = 0; var totalHeight = 0;
heights.forEach(function(elem) { heights.each(function(elem) {
totalHeight += elem.height; totalHeight += elem.height;
}); });
var ysum = totalHeight / 2; var ysum = totalHeight / 2;

View File

@ -135,7 +135,7 @@ mindplot.model.IMindmap = new Class({
// Then the rest of the branches ... // Then the rest of the branches ...
var sbranchs = source.getBranches(); var sbranchs = source.getBranches();
sbranchs.forEach(function(snode) { sbranchs.each(function(snode) {
var tnode = target.createNode(snode.getType(), snode.getId()); var tnode = target.createNode(snode.getType(), snode.getId());
snode.copyTo(tnode); snode.copyTo(tnode);
target.addBranch(tnode); target.addBranch(tnode);

View File

@ -213,7 +213,7 @@ mindplot.model.INodeModel = new Class({
var source = this; var source = this;
// Copy properties ... // Copy properties ...
var keys = source.getPropertiesKeys(); var keys = source.getPropertiesKeys();
keys.forEach(function(key) { keys.each(function(key) {
var value = source.getProperty(key); var value = source.getProperty(key);
target.putProperty(key, value); target.putProperty(key, value);
}); });
@ -222,7 +222,7 @@ mindplot.model.INodeModel = new Class({
var children = this.getChildren(); var children = this.getChildren();
var tmindmap = target.getMindmap(); var tmindmap = target.getMindmap();
children.forEach(function(snode) { children.each(function(snode) {
var tnode = tmindmap.createNode(snode.getType(), snode.getId()); var tnode = tmindmap.createNode(snode.getType(), snode.getId());
snode.copyTo(tnode); snode.copyTo(tnode);
target.appendChild(tnode); target.appendChild(tnode);
@ -278,10 +278,10 @@ mindplot.model.INodeModel = new Class({
var children = this.getChildren(); var children = this.getChildren();
if (children.length > 0) { if (children.length > 0) {
result = result + ", children: {(size:" + children.length; result = result + ", children: {(size:" + children.length;
children.forEach(function(node) { children.each(function(node) {
result = result + "=> ("; result = result + "=> (";
var keys = node.getPropertiesKeys(); var keys = node.getPropertiesKeys();
keys.forEach(function(key) { keys.each(function(key) {
var value = node.getProperty(key); var value = node.getProperty(key);
result = result + key + ":" + value + ","; result = result + key + ":" + value + ",";
}); });

View File

@ -25,7 +25,7 @@ mindplot.util.FadeEffect = new Class({
this.addEvent('complete', function() { this.addEvent('complete', function() {
this._element.forEach(function(elem) { this._element.each(function(elem) {
if(elem){ if(elem){
elem.setVisibility(isVisible); elem.setVisibility(isVisible);
} }
@ -39,7 +39,7 @@ mindplot.util.FadeEffect = new Class({
}, },
set: function(now) { set: function(now) {
this._element.forEach(function(elem) { this._element.each(function(elem) {
if(elem){ if(elem){
elem.setOpacity(now); elem.setOpacity(now);
} }

View File

@ -63,7 +63,7 @@ mindplot.widget.ColorPalettePanel = new Class({
// Register on toolbar elements ... // Register on toolbar elements ...
var colorCells = content.getElements('div[class=palette-colorswatch]'); var colorCells = content.getElements('div[class=palette-colorswatch]');
var model = this.getModel(); var model = this.getModel();
colorCells.forEach(function(elem) { colorCells.each(function(elem) {
elem.addEvent('click', function() { elem.addEvent('click', function() {
var color = elem.getStyle("background-color"); var color = elem.getStyle("background-color");
model.setValue(color); model.setValue(color);
@ -79,7 +79,7 @@ mindplot.widget.ColorPalettePanel = new Class({
// Clear selected cell based on the color ... // Clear selected cell based on the color ...
var tdCells = panelElem.getElements("td[class='palette-cell palette-cell-selected']"); var tdCells = panelElem.getElements("td[class='palette-cell palette-cell-selected']");
tdCells.forEach(function(elem) { tdCells.each(function(elem) {
elem.className = 'palette-cell'; elem.className = 'palette-cell';
}); });
@ -87,7 +87,7 @@ mindplot.widget.ColorPalettePanel = new Class({
var colorCells = panelElem.getElements('div[class=palette-colorswatch]'); var colorCells = panelElem.getElements('div[class=palette-colorswatch]');
var model = this.getModel(); var model = this.getModel();
var modelValue = model.getValue(); var modelValue = model.getValue();
colorCells.forEach(function(elem) { colorCells.each(function(elem) {
var color = elem.getStyle("background-color"); var color = elem.getStyle("background-color");
if (modelValue == color) { if (modelValue == color) {
elem.parentNode.className = 'palette-cell palette-cell-selected'; elem.parentNode.className = 'palette-cell palette-cell-selected';

View File

@ -29,7 +29,7 @@ mindplot.widget.IMenu = new Class({
}, },
clear:function () { clear:function () {
this._toolbarElems.forEach(function (item) { this._toolbarElems.each(function (item) {
item.hide(); item.hide();
}); });
}, },

View File

@ -26,7 +26,7 @@ mindplot.widget.ListToolbarPanel = new Class({
_initPanel: function () { _initPanel: function () {
// Register on toolbar elements ... // Register on toolbar elements ...
var menuElems = this.getPanelElem().getElements('div'); var menuElems = this.getPanelElem().getElements('div');
menuElems.forEach(function(elem) { menuElems.each(function(elem) {
elem.addEvent('click', function(event) { elem.addEvent('click', function(event) {
event.stopPropagation(); event.stopPropagation();
this.hide(); this.hide();
@ -41,7 +41,7 @@ mindplot.widget.ListToolbarPanel = new Class({
var panelElem = this.getPanelElem(); var panelElem = this.getPanelElem();
var menuElems = panelElem.getElements('div'); var menuElems = panelElem.getElements('div');
var value = this.getModel().getValue(); var value = this.getModel().getValue();
menuElems.forEach(function(elem) { menuElems.each(function(elem) {
var elemValue = $defined(elem.getAttribute('model')) ? elem.getAttribute('model') : elem.id; var elemValue = $defined(elem.getAttribute('model')) ? elem.getAttribute('model') : elem.id;
$assert(elemValue,"elemValue can not be null"); $assert(elemValue,"elemValue can not be null");
if (elemValue == value) if (elemValue == value)

View File

@ -438,7 +438,7 @@ mindplot.widget.Menu = new Class({
_registerEvents:function (designer) { _registerEvents:function (designer) {
// Register on close events ... // Register on close events ...
this._toolbarElems.forEach(function (elem) { this._toolbarElems.each(function (elem) {
elem.addEvent('show', function () { elem.addEvent('show', function () {
this.clear() this.clear()
}.bind(this)); }.bind(this));
@ -448,7 +448,7 @@ mindplot.widget.Menu = new Class({
var topics = designer.getModel().filterSelectedTopics(); var topics = designer.getModel().filterSelectedTopics();
var rels = designer.getModel().filterSelectedRelationships(); var rels = designer.getModel().filterSelectedRelationships();
this._toolbarElems.forEach(function (button) { this._toolbarElems.each(function (button) {
var disable = false; var disable = false;
if (button.isTopicAction() && button.isRelAction()) { if (button.isTopicAction() && button.isRelAction()) {
disable = rels.length == 0 && topics.length == 0; disable = rels.length == 0 && topics.length == 0;
@ -474,7 +474,7 @@ mindplot.widget.Menu = new Class({
var topics = designer.getModel().filterSelectedTopics(); var topics = designer.getModel().filterSelectedTopics();
var rels = designer.getModel().filterSelectedRelationships(); var rels = designer.getModel().filterSelectedRelationships();
this._toolbarElems.forEach(function (button) { this._toolbarElems.each(function (button) {
if (button.isTopicAction() && topics.length > 0) { if (button.isTopicAction() && topics.length > 0) {
button.enable(); button.enable();
} }

View File

@ -443,7 +443,7 @@ mindplot.layout.FreeTestSuite = new Class({
} }
var treeSet = manager._treeSet; var treeSet = manager._treeSet;
treeSet._rootNodes.forEach(function(rootNode) { treeSet._rootNodes.each(function(rootNode) {
var heightById = rootNode.getSorter().computeChildrenIdByHeights(treeSet, rootNode); var heightById = rootNode.getSorter().computeChildrenIdByHeights(treeSet, rootNode);
this._assertBranchCollision(treeSet, rootNode, heightById); this._assertBranchCollision(treeSet, rootNode, heightById);
}, this); }, this);
@ -453,7 +453,7 @@ mindplot.layout.FreeTestSuite = new Class({
var children = treeSet.getChildren(node); var children = treeSet.getChildren(node);
var childOfRootNode = treeSet._rootNodes.contains(node); var childOfRootNode = treeSet._rootNodes.contains(node);
children.forEach(function(child) { children.each(function(child) {
var height = heightById[child.getId()]; var height = heightById[child.getId()];
var siblings = treeSet.getSiblings(child); var siblings = treeSet.getSiblings(child);
if (childOfRootNode) { if (childOfRootNode) {
@ -461,12 +461,12 @@ mindplot.layout.FreeTestSuite = new Class({
return (child.getOrder() % 2) == (sibling.getOrder() % 2); return (child.getOrder() % 2) == (sibling.getOrder() % 2);
}) })
} }
siblings.forEach(function(sibling) { siblings.each(function(sibling) {
this._branchesOverlap(child, sibling, heightById); this._branchesOverlap(child, sibling, heightById);
}, this); }, this);
}, this); }, this);
children.forEach(function(child) { children.each(function(child) {
this._assertBranchCollision(treeSet, child, heightById); this._assertBranchCollision(treeSet, child, heightById);
}, this) }, this)
}, },