replacing old .each mootools' method by _.each

This commit is contained in:
Ezequiel Bergamaschi 2014-03-17 00:36:29 -03:00
parent 2f29dfe203
commit e9f4b0c7d8
26 changed files with 63 additions and 62 deletions

View File

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

View File

@ -26,7 +26,7 @@ mindplot.Events = new Class({
var events = this.$events[type];
if (!events) return this;
args = Array.from(args);
events.each(function(fn){
_.each(events, function(fn){
if (delay) fn.delay(delay, this, args);
else fn.apply(this, args);
}, this);

View File

@ -72,7 +72,7 @@ mindplot.IconGroup = new Class({
_findIconFromModel:function (iconModel) {
var result = null;
this._icons.each(function (icon) {
_.each(this._icons, function (icon) {
var elModel = icon.getModel();
if (elModel.getId() == iconModel.getId()) {
result = icon;
@ -103,7 +103,7 @@ mindplot.IconGroup = new Class({
this._resize(this._icons.length);
// Add all again ...
this._icons.each(function (elem, i) {
_.each(this._icons, function (elem, i) {
this._positionIcon(elem, i);
}.bind(this));
},

View File

@ -126,7 +126,7 @@ mindplot.MultilineTextEditor = new Class({
var lines = textElem.value.split('\n');
var maxLineLength = 1;
lines.each(function (line) {
_.each(lines, function (line) {
if (maxLineLength < line.length)
maxLineLength = line.length;
});

View File

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

View File

@ -57,7 +57,7 @@ mindplot.ScreenManager = new Class({
fireEvent : function(type, event) {
if (type == 'click') {
this._clickEvents.each(function(listener) {
_.each(this._clickEvents, function(listener) {
listener(type, event);
});
}

View File

@ -887,7 +887,7 @@ mindplot.Topic = new Class({
},
_setRelationshipLinesVisibility:function (value) {
this._relationships.each(function (relationship) {
_.each(this._relationships, function (relationship) {
var sourceTopic = relationship.getSourceTopic();
var targetTopic = relationship.getTargetTopic();

View File

@ -29,7 +29,7 @@ mindplot.commands.AddTopicCommand = new Class({
execute:function (commandContext) {
this._models.each(function (model, index) {
_.each(this._models, function (model, index) {
// Add a new topic ...
var topic = commandContext.createTopic(model);
@ -59,12 +59,12 @@ mindplot.commands.AddTopicCommand = new Class({
undoExecute:function (commandContext) {
// Delete disconnected the nodes. Create a copy of the topics ...
var clonedModel = [];
this._models.each(function (model) {
_.each(this._models, function (model) {
clonedModel.push(model.clone());
});
// Finally, remove the nodes ...
this._models.each(function (model) {
_.each(this._models, function (model) {
var topicId = model.getId();
var topic = commandContext.findTopics(topicId)[0];

View File

@ -35,7 +35,7 @@ mindplot.commands.DeleteCommand = new Class({
var topics = this._filterChildren(this._topicIds, commandContext);
if (topics.length > 0) {
topics.each(function (topic) {
_.each(topics, function (topic) {
// In case that it's editing text node, force close without update ...
topic.closeEditors();
@ -47,7 +47,7 @@ mindplot.commands.DeleteCommand = new Class({
return rel.getModel().clone();
}));
relationships.each(function (relationship) {
_.each(relationships, function (relationship) {
commandContext.deleteRelationship(relationship);
});
@ -69,7 +69,7 @@ mindplot.commands.DeleteCommand = new Class({
var rels = commandContext.findRelationships(this._relIds);
if (rels.length > 0) {
rels.each(function (rel) {
_.each(rels, function (rel) {
this._deletedRelModel.push(rel.getModel().clone());
commandContext.deleteRelationship(rel);
}, this);
@ -79,12 +79,12 @@ mindplot.commands.DeleteCommand = new Class({
undoExecute:function (commandContext) {
// Add all the topics ...
this._deletedTopicModels.each(function (model) {
_.each(this._deletedTopicModels, function (model) {
commandContext.createTopic(model);
}, this);
// Do they need to be connected ?
this._deletedTopicModels.each(function (topicModel, index) {
_.each(this._deletedTopicModels, function (topicModel, index) {
var topics = commandContext.findTopics(topicModel.getId());
var parentId = this._parentTopicIds[index];
@ -95,12 +95,12 @@ mindplot.commands.DeleteCommand = new Class({
}, this);
// Add rebuild relationships ...
this._deletedRelModel.each(function (model) {
_.each(this._deletedRelModel, function (model) {
commandContext.addRelationship(model);
}.bind(this));
// Finally display the topics ...
this._deletedTopicModels.each(function (topicModel) {
_.each(this._deletedTopicModels, function (topicModel) {
var topics = commandContext.findTopics(topicModel.getId());
topics[0].setBranchVisibility(true);
}, this);
@ -121,7 +121,7 @@ mindplot.commands.DeleteCommand = new Class({
var topics = commandContext.findTopics(topicIds);
var result = [];
topics.each(function (topic) {
_.each(topics, function (topic) {
var parent = topic.getParent();
var found = false;
while (parent != null && !found) {

View File

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

View File

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

View File

@ -77,7 +77,7 @@ mindplot.layout.BalancedSorter = new Class({
var result = null;
var last = children.getLast();
position = position || {x:last.getPosition().x, y:last.getPosition().y + 1};
children.each(function (child, index) {
_.each(children, function (child, index) {
var cpos = child.getPosition();
if (position.y > cpos.y) {
yOffset = child == last ?
@ -129,7 +129,7 @@ mindplot.layout.BalancedSorter = new Class({
// Filter nodes on one side..
var children = this._getChildrenForOrder(parent, treeSet, node.getOrder());
children.each(function (child, index) {
_.each(children, function (child, index) {
if (child.getOrder() > node.getOrder()) {
child.setOrder(child.getOrder() - 2);
}
@ -154,7 +154,7 @@ mindplot.layout.BalancedSorter = new Class({
var totalPHeight = 0;
var totalNHeight = 0;
heights.each(function (elem) {
_.each(heights, function (elem) {
if (elem.order % 2 == 0) {
totalPHeight += elem.height;
} else {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -32,7 +32,7 @@ mindplot.persistence.Beta2PelaMigrator = new Class({
// Beta does not set position on second level nodes ...
var branches = mindmap.getBranches();
branches.each(function (model) {
_.each(branches, function (model) {
this._fixPosition(model);
}.bind(this));
@ -42,7 +42,7 @@ mindplot.persistence.Beta2PelaMigrator = new Class({
_fixPosition:function (parentModel) {
var parentPos = parentModel.getPosition();
var isRight = parentPos.x > 0;
parentModel.getChildren().each(function (child) {
_.each(parentModel.getChildren(), function (child) {
if (!child.getPosition()) {
child.setPosition(parentPos.x + (50 * isRight ? 1 : -1), parentPos.y);
}

View File

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

View File

@ -64,7 +64,7 @@ mindplot.widget.ColorPalettePanel = new Class({
// Register on toolbar elements ...
var colorCells = content.find('div[class=palette-colorswatch]');
var model = this.getModel();
colorCells.each(function (elem) {
_.each(colorCells, function (elem) {
$(elem).on('click', function () {
var color = elem.css("background-color");
model.setValue(color);
@ -80,7 +80,7 @@ mindplot.widget.ColorPalettePanel = new Class({
// Clear selected cell based on the color ...
var tdCells = panelElem.find("td[class='palette-cell palette-cell-selected']");
tdCells.each(function (elem) {
_.each(tdCells, function (elem) {
elem.className = 'palette-cell';
});
@ -88,7 +88,7 @@ mindplot.widget.ColorPalettePanel = new Class({
var colorCells = panelElem.find('div[class=palette-colorswatch]');
var model = this.getModel();
var modelValue = model.getValue();
colorCells.each(function (elem) {
_.each(colorCells, function (elem) {
var color = elem.css("background-color");
if (modelValue != null && modelValue[0] == 'r') {
modelValue = modelValue.rgbToHex();

View File

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

View File

@ -37,7 +37,7 @@ mindplot.widget.ListToolbarPanel = new Class({
var panelElem = this.getPanelElem();
var menuElems = panelElem.getElements('div');
var value = this.getModel().getValue();
menuElems.each(function (elem) {
_.each(menuElems, function (elem) {
var elemValue = $defined(elem.getAttribute('model')) ? elem.getAttribute('model') : elem.id;
$assert(elemValue, "elemValue can not be null");
if (elemValue == value)

View File

@ -452,7 +452,7 @@ mindplot.widget.Menu = new Class({
_registerEvents: function (designer) {
// Register on close events ...
this._toolbarElems.each(function (elem) {
_.each(this._toolbarElems, function (elem) {
elem.addEvent('show', function () {
this.clear()
}.bind(this));
@ -462,7 +462,7 @@ mindplot.widget.Menu = new Class({
var topics = designer.getModel().filterSelectedTopics();
var rels = designer.getModel().filterSelectedRelationships();
this._toolbarElems.each(function (button) {
_.each(this._toolbarElems, function (button) {
var isTopicAction = button.isTopicAction();
var isRelAction = button.isRelAction();
@ -480,7 +480,7 @@ mindplot.widget.Menu = new Class({
var topics = designer.getModel().filterSelectedTopics();
var rels = designer.getModel().filterSelectedRelationships();
this._toolbarElems.each(function (button) {
_.each(this._toolbarElems, function (button) {
var isTopicAction = button.isTopicAction();
var isRelAction = button.isRelAction();

View File

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

View File

@ -13,6 +13,7 @@
<script type='text/javascript' src='js/jquery.js'></script>
<script type='text/javascript' src='js/hotkeys.js'></script>
<script type='text/javascript' src='js/underscorejs.js'></script>
<script type="text/javascript" language="javascript" src="bootstrap/js/bootstrap.js"></script>
<script src="js/less.js" type="text/javascript"></script>