diff --git a/mindplot/src/main/javascript/CollabActionDispatcher.js b/mindplot/src/main/javascript/CollabActionDispatcher.js index 9509cd9e..e68e5cc9 100644 --- a/mindplot/src/main/javascript/CollabActionDispatcher.js +++ b/mindplot/src/main/javascript/CollabActionDispatcher.js @@ -73,7 +73,7 @@ mindplot.BrixActionDispatcher = new Class({ }, changeFontSizeToTopic : function(topicsIds, size) { - topicsIds.forEach(function(topicId) { + topicsIds.each(function(topicId) { var framework = this._getFramework(); var topic = framework.getTopic(topicId); topic.setFontSize(size, true); @@ -81,7 +81,7 @@ mindplot.BrixActionDispatcher = new Class({ }, changeFontColorToTopic : function(topicsIds, color) { - topicsIds.forEach(function(topicId) { + topicsIds.each(function(topicId) { var framework = this._getFramework(); var topic = framework.getTopic(topicId); topic.setFontColor(color, true); @@ -89,7 +89,7 @@ mindplot.BrixActionDispatcher = new Class({ }, changeFontFamilyToTopic : function(topicsIds, family) { - topicsIds.forEach(function(topicId) { + topicsIds.each(function(topicId) { var framework = this._getFramework(); var topic = framework.getTopic(topicId); topic.setFontFamily(family, true); @@ -97,7 +97,7 @@ mindplot.BrixActionDispatcher = new Class({ }, changeFontStyleToTopic : function(topicsIds) { - topicsIds.forEach(function(topicId) { + topicsIds.each(function(topicId) { var framework = this._getFramework(); var topic = framework.getTopic(topicId); var style = ( topic.getFontStyle() == "italic") ? "normal" : "italic"; @@ -106,7 +106,7 @@ mindplot.BrixActionDispatcher = new Class({ }, changeShapeTypeToTopic : function(topicsIds, shapeType) { - topicsIds.forEach(function(topicId) { + topicsIds.each(function(topicId) { var framework = this._getFramework(); var topic = framework.getTopic(topicId); topic.setShapeType(shapeType); @@ -114,7 +114,7 @@ mindplot.BrixActionDispatcher = new Class({ }, changeFontWeightToTopic : function(topicsIds) { - topicsIds.forEach(function(topicId) { + topicsIds.each(function(topicId) { var framework = this._getFramework(); var topic = framework.getTopic(topicId); var weight = (topic.getFontWeight() == "bold") ? "normal" : "bold"; @@ -123,7 +123,7 @@ mindplot.BrixActionDispatcher = new Class({ }, changeBackgroundColorToTopic : function(topicsIds, color) { - topicsIds.forEach(function(topicId) { + topicsIds.each(function(topicId) { var framework = this._getFramework(); var topic = framework.getTopic(topicId); topic.setBackgroundColor(color, true); @@ -132,7 +132,7 @@ mindplot.BrixActionDispatcher = new Class({ }, changeBorderColorToTopic : function(topicsIds, color) { - topicsIds.forEach(function(topicId) { + topicsIds.each(function(topicId) { var framework = this._getFramework(); var topic = framework.getTopic(topicId); topic.setBorderColor(color); @@ -144,7 +144,7 @@ mindplot.BrixActionDispatcher = new Class({ var framework = this._getFramework(); var mindmap = framework.getModel(); - topicsIds.forEach(function(topicId) { + topicsIds.each(function(topicId) { var topic = framework.getTopic(topicId); topic.deleteNode(); }); diff --git a/mindplot/src/main/javascript/Designer.js b/mindplot/src/main/javascript/Designer.js index 419718c3..c9772417 100644 --- a/mindplot/src/main/javascript/Designer.js +++ b/mindplot/src/main/javascript/Designer.js @@ -109,7 +109,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.forEach(function (object) { + topics.each(function (object) { object.closeEditors(); }); @@ -271,13 +271,13 @@ mindplot.Designer = new Class({ onObjectFocusEvent:function (currentObject, event) { // Close node editors .. var topics = this.getModel().getTopics(); - topics.forEach(function (topic) { + topics.each(function (topic) { topic.closeEditors(); }); var model = this.getModel(); 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 if (!$defined(event) || (!event.control && !event.meta)) { if (object.isOnFocus() && object != currentObject) { @@ -291,14 +291,14 @@ mindplot.Designer = new Class({ selectAll:function () { var model = this.getModel(); var objects = model.getEntities(); - objects.forEach(function (object) { + objects.each(function (object) { object.setOnFocus(true); }); }, deselectAll:function () { var objects = this.getModel().getEntities(); - objects.forEach(function (object) { + objects.each(function (object) { object.setOnFocus(false); }); }, diff --git a/mindplot/src/main/javascript/IconGroup.js b/mindplot/src/main/javascript/IconGroup.js index 8931a34d..b1d4fd1e 100644 --- a/mindplot/src/main/javascript/IconGroup.js +++ b/mindplot/src/main/javascript/IconGroup.js @@ -103,7 +103,7 @@ mindplot.IconGroup = new Class({ this._resize(this._icons.length); // Add all again ... - this._icons.forEach(function(elem, i) { + this._icons.each(function(elem, i) { this._positionIcon(elem, i); }.bind(this)); }, diff --git a/mindplot/src/main/javascript/MultilineTextEditor.js b/mindplot/src/main/javascript/MultilineTextEditor.js index db883074..eb9031fb 100644 --- a/mindplot/src/main/javascript/MultilineTextEditor.js +++ b/mindplot/src/main/javascript/MultilineTextEditor.js @@ -1,268 +1,268 @@ -/* - * Copyright [2011] [wisemapping] - * - * Licensed under WiseMapping Public License, Version 1.0 (the "License"). - * It is basically the Apache License, Version 2.0 (the "License") plus the - * "powered by wisemapping" text requirement on every single page; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the license at - * - * http://www.wisemapping.org/license - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -mindplot.MultilineTextEditor = new Class({ - Extends: Events, - initialize:function() { - this._topic = null; - }, - - _buildEditor : function() { - - var result = new Element('div'); - result.setStyles({ - position:"absolute", - display: "none", - zIndex: "8", - overflow:"hidden", - border: "0 none" - } - ); - - var textareaElem = new Element('textarea', - { tabindex:'-1', - value:"", - wrap:'off' - } - ); - - textareaElem.setStyles({ - border: "1px gray dashed", - background:"rgba(98, 135, 167, .3)", - outline: '0 none', - resize: 'none', - overflow:"hidden" - }); - textareaElem.inject(result); - return result; - }, - - _registerEvents : function(containerElem) { - var textareaElem = this._getTextareaElem(); - - textareaElem.addEvent('keydown', function (event) { - switch (event.key) { - case 'esc': - this.close(false); - break; - case 'enter': - if (event.meta || event.control) { - - // @todo: Enters must be in any place ... - textareaElem.value = textareaElem.value + "\n"; - } - else { - this.close(true); - } - break; - } - event.stopPropagation(); - }.bind(this)); - - textareaElem.addEvent('keypress', function(event) { - event.stopPropagation(); - }); - - textareaElem.addEvent('keyup', function(event) { - var text = this._getTextareaElem().value; - this.fireEvent('input', [event, text]); - this._adjustEditorSize(); - }.bind(this)); - - // If the user clicks on the input, all event must be ignored ... - containerElem.addEvent('click', function(event) { - event.stopPropagation(); - }); - containerElem.addEvent('dblclick', function(event) { - event.stopPropagation(); - }); - containerElem.addEvent('mousedown', function(event) { - event.stopPropagation(); - }); - }, - - _adjustEditorSize : function() { - - if (this.isVisible()) { - var textElem = this._getTextareaElem(); - - var lines = textElem.value.split('\n'); - var maxLineLength = 1; - lines.forEach(function(line) { - if (maxLineLength < line.length) - maxLineLength = line.length; - }); - - textElem.setAttribute('cols', maxLineLength); - textElem.setAttribute('rows', lines.length); - - this._containerElem.setStyles({ - width: (maxLineLength + 3) + 'em', - height: textElem.getSize().height - }); - } - }, - - isVisible : function () { - return $defined(this._containerElem) && this._containerElem.getStyle('display') == 'block'; - }, - - _updateModel : function () { - - if (this._topic.getText() != this._getText()) { - var text = this._getText(); - var topicId = this._topic.getId(); - - var actionDispatcher = mindplot.ActionDispatcher.getInstance(); - actionDispatcher.changeTextToTopic([topicId], text); - } - }, - - show : function (topic,text) { - - this._topic = topic; - if (!this.isVisible()) { - //Create editor ui - var containerElem = this._buildEditor(); - containerElem.inject($(document.body)); - - this._containerElem = containerElem; - this._registerEvents(containerElem); - this._showEditor(text); - } - }, - - _showEditor : function (defaultText) { - - var topic = this._topic; - - // Hide topic text ... - topic.getTextShape().setVisibility(false); - - // Set Editor Style - var nodeText = topic.getTextShape(); - var font = nodeText.getFont(); - font.size = nodeText.getHtmlFontSize(); - font.color = nodeText.getColor(); - this._setStyle(font); - - // Set editor's initial size - var displayFunc = function() { - // Position the editor and set the size... - var textShape = this._topic.getTextShape(); - textShape.positionRelativeTo(this._containerElem, { - position: {x: 'left',y:'top'}, - edge: {x: 'left', y: 'top'} - }); - this._containerElem.setStyle('display', 'block'); - - // Set editor's initial text ... - var text = $defined(defaultText) ? defaultText : topic.getText(); - this._setText(text); - - // Set the element focus and select the current text ... - var inputElem = this._getTextareaElem(); - this._positionCursor(inputElem, !$defined(defaultText)); - - }.bind(this); - - displayFunc.delay(10); - }, - - _setStyle : function (fontStyle) { - var inputField = this._getTextareaElem(); - if (!$defined(fontStyle.font)) { - fontStyle.font = "Arial"; - } - if (!$defined(fontStyle.style)) { - fontStyle.style = "normal"; - } - if (!$defined(fontStyle.weight)) { - fontStyle.weight = "normal"; - } - if (!$defined(fontStyle.size)) { - fontStyle.size = 12; - } - var style = { - fontSize : fontStyle.size + "px", - fontFamily : fontStyle.font, - fontStyle : fontStyle.style, - fontWeight : fontStyle.weight, - color : fontStyle.color - }; - inputField.setStyles(style); - this._containerElem.setStyles(style); - }, - - _setText : function(text) { - var textareaElem = this._getTextareaElem(); - textareaElem.value = text; - this._adjustEditorSize(); - }, - - _getText : function() { - return this._getTextareaElem().value; - }, - - _getTextareaElem : function() { - return this._containerElem.getElement('textarea'); - }, - - _positionCursor : function(textareaElem, selectText) { - textareaElem.focus(); - if (selectText) { - // Mark text as selected ... - if (textareaElem.createTextRange) { - var rang = textareaElem.createTextRange(); - rang.select(); - rang.move("character", textareaElem.value.length); - } - else { - textareaElem.setSelectionRange(0, textareaElem.value.length); - } - - } else { - // Move the cursor to the last character .. - if (textareaElem.createTextRange) { - var range = textareaElem.createTextRange(); - range.move("character", textareaElem.value.length); - } else { - textareaElem.selectionStart = textareaElem.value.length; - } - } - - }, - - close : function(update) { - if (this.isVisible()) { - // Update changes ... - if (!$defined(update) || update) { - this._updateModel(); - } - - // Let make the visible text in the node visible again ... - this._topic.getTextShape().setVisibility(true); - - // Remove it form the screen ... - this._containerElem.dispose(); - this._containerElem = null; - this._topic = null; - } - } -}); - +/* + * Copyright [2011] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +mindplot.MultilineTextEditor = new Class({ + Extends: Events, + initialize:function() { + this._topic = null; + }, + + _buildEditor : function() { + + var result = new Element('div'); + result.setStyles({ + position:"absolute", + display: "none", + zIndex: "8", + overflow:"hidden", + border: "0 none" + } + ); + + var textareaElem = new Element('textarea', + { tabindex:'-1', + value:"", + wrap:'off' + } + ); + + textareaElem.setStyles({ + border: "1px gray dashed", + background:"rgba(98, 135, 167, .3)", + outline: '0 none', + resize: 'none', + overflow:"hidden" + }); + textareaElem.inject(result); + return result; + }, + + _registerEvents : function(containerElem) { + var textareaElem = this._getTextareaElem(); + + textareaElem.addEvent('keydown', function (event) { + switch (event.key) { + case 'esc': + this.close(false); + break; + case 'enter': + if (event.meta || event.control) { + + // @todo: Enters must be in any place ... + textareaElem.value = textareaElem.value + "\n"; + } + else { + this.close(true); + } + break; + } + event.stopPropagation(); + }.bind(this)); + + textareaElem.addEvent('keypress', function(event) { + event.stopPropagation(); + }); + + textareaElem.addEvent('keyup', function(event) { + var text = this._getTextareaElem().value; + this.fireEvent('input', [event, text]); + this._adjustEditorSize(); + }.bind(this)); + + // If the user clicks on the input, all event must be ignored ... + containerElem.addEvent('click', function(event) { + event.stopPropagation(); + }); + containerElem.addEvent('dblclick', function(event) { + event.stopPropagation(); + }); + containerElem.addEvent('mousedown', function(event) { + event.stopPropagation(); + }); + }, + + _adjustEditorSize : function() { + + if (this.isVisible()) { + var textElem = this._getTextareaElem(); + + var lines = textElem.value.split('\n'); + var maxLineLength = 1; + lines.each(function(line) { + if (maxLineLength < line.length) + maxLineLength = line.length; + }); + + textElem.setAttribute('cols', maxLineLength); + textElem.setAttribute('rows', lines.length); + + this._containerElem.setStyles({ + width: (maxLineLength + 3) + 'em', + height: textElem.getSize().height + }); + } + }, + + isVisible : function () { + return $defined(this._containerElem) && this._containerElem.getStyle('display') == 'block'; + }, + + _updateModel : function () { + + if (this._topic.getText() != this._getText()) { + var text = this._getText(); + var topicId = this._topic.getId(); + + var actionDispatcher = mindplot.ActionDispatcher.getInstance(); + actionDispatcher.changeTextToTopic([topicId], text); + } + }, + + show : function (topic,text) { + + this._topic = topic; + if (!this.isVisible()) { + //Create editor ui + var containerElem = this._buildEditor(); + containerElem.inject($(document.body)); + + this._containerElem = containerElem; + this._registerEvents(containerElem); + this._showEditor(text); + } + }, + + _showEditor : function (defaultText) { + + var topic = this._topic; + + // Hide topic text ... + topic.getTextShape().setVisibility(false); + + // Set Editor Style + var nodeText = topic.getTextShape(); + var font = nodeText.getFont(); + font.size = nodeText.getHtmlFontSize(); + font.color = nodeText.getColor(); + this._setStyle(font); + + // Set editor's initial size + var displayFunc = function() { + // Position the editor and set the size... + var textShape = this._topic.getTextShape(); + textShape.positionRelativeTo(this._containerElem, { + position: {x: 'left',y:'top'}, + edge: {x: 'left', y: 'top'} + }); + this._containerElem.setStyle('display', 'block'); + + // Set editor's initial text ... + var text = $defined(defaultText) ? defaultText : topic.getText(); + this._setText(text); + + // Set the element focus and select the current text ... + var inputElem = this._getTextareaElem(); + this._positionCursor(inputElem, !$defined(defaultText)); + + }.bind(this); + + displayFunc.delay(10); + }, + + _setStyle : function (fontStyle) { + var inputField = this._getTextareaElem(); + if (!$defined(fontStyle.font)) { + fontStyle.font = "Arial"; + } + if (!$defined(fontStyle.style)) { + fontStyle.style = "normal"; + } + if (!$defined(fontStyle.weight)) { + fontStyle.weight = "normal"; + } + if (!$defined(fontStyle.size)) { + fontStyle.size = 12; + } + var style = { + fontSize : fontStyle.size + "px", + fontFamily : fontStyle.font, + fontStyle : fontStyle.style, + fontWeight : fontStyle.weight, + color : fontStyle.color + }; + inputField.setStyles(style); + this._containerElem.setStyles(style); + }, + + _setText : function(text) { + var textareaElem = this._getTextareaElem(); + textareaElem.value = text; + this._adjustEditorSize(); + }, + + _getText : function() { + return this._getTextareaElem().value; + }, + + _getTextareaElem : function() { + return this._containerElem.getElement('textarea'); + }, + + _positionCursor : function(textareaElem, selectText) { + textareaElem.focus(); + if (selectText) { + // Mark text as selected ... + if (textareaElem.createTextRange) { + var rang = textareaElem.createTextRange(); + rang.select(); + rang.move("character", textareaElem.value.length); + } + else { + textareaElem.setSelectionRange(0, textareaElem.value.length); + } + + } else { + // Move the cursor to the last character .. + if (textareaElem.createTextRange) { + var range = textareaElem.createTextRange(); + range.move("character", textareaElem.value.length); + } else { + textareaElem.selectionStart = textareaElem.value.length; + } + } + + }, + + close : function(update) { + if (this.isVisible()) { + // Update changes ... + if (!$defined(update) || update) { + this._updateModel(); + } + + // Let make the visible text in the node visible again ... + this._topic.getTextShape().setVisibility(true); + + // Remove it form the screen ... + this._containerElem.dispose(); + this._containerElem = null; + this._topic = null; + } + } +}); + diff --git a/mindplot/src/main/javascript/RelationshipPivot.js b/mindplot/src/main/javascript/RelationshipPivot.js index 739c3fd7..933f485a 100644 --- a/mindplot/src/main/javascript/RelationshipPivot.js +++ b/mindplot/src/main/javascript/RelationshipPivot.js @@ -53,7 +53,7 @@ mindplot.RelationshipPivot = new Class({ // Register focus events on all topics ... var model = this._designer.getModel(); var topics = model.getTopics(); - topics.forEach(function (topic) { + topics.each(function (topic) { topic.addEvent('ontfocus', this._onTopicClick); }.bind(this)); } @@ -69,7 +69,7 @@ mindplot.RelationshipPivot = new Class({ var model = this._designer.getModel(); var topics = model.getTopics(); - topics.forEach(function (topic) { + topics.each(function (topic) { topic.removeEvent('ontfocus', this._onTopicClick); }.bind(this)); diff --git a/mindplot/src/main/javascript/ScreenManager.js b/mindplot/src/main/javascript/ScreenManager.js index 384edb5e..5b7d943a 100644 --- a/mindplot/src/main/javascript/ScreenManager.js +++ b/mindplot/src/main/javascript/ScreenManager.js @@ -1,147 +1,147 @@ -/* - * Copyright [2011] [wisemapping] - * - * Licensed under WiseMapping Public License, Version 1.0 (the "License"). - * It is basically the Apache License, Version 2.0 (the "License") plus the - * "powered by wisemapping" text requirement on every single page; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the license at - * - * http://www.wisemapping.org/license - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -mindplot.ScreenManager = new Class({ - initialize:function(divElement) { - $assert(divElement, "can not be null"); - this._divContainer = divElement; - this._padding = {x:0,y:0}; - - // Ignore default click event propagation. Prevent 'click' event on drag. - this._clickEvents = []; - this._divContainer.addEvent('click', function(event) { - event.stopPropagation() - }.bind(this)); - - this._divContainer.addEvent('dblclick', function(event) { - event.stopPropagation(); - event.preventDefault(); - }); - }, - - setScale : function(scale) { - $assert(scale, 'Screen scale can not be null'); - this._scale = scale; - }, - - addEvent : function(event, listener) { - if (event == 'click') - this._clickEvents.push(listener); - else - $(this._divContainer).addEvent(event, listener); - }, - - removeEvent : function(event, listener) { - if (event == 'click') - this._clickEvents.remove(listener); - else - $(this._divContainer).removeEvent(event, listener); - }, - - fireEvent : function(type, event) { - if (type == 'click') { - this._clickEvents.forEach(function(listener) { - listener(type, event); - }); - } - else { - $(this._divContainer).fireEvent(type, event); - } - }, - - _getElementPosition : function(elem) { - // Retrieve current element position. - var elementPosition = elem.getPosition(); - var x = elementPosition.x; - var y = elementPosition.y; - - // Add workspace offset. - x = x - this._padding.x; - y = y - this._padding.y; - - // Scale coordinate in order to be relative to the workspace. That's coord/size; - x = x / this._scale; - y = y / this._scale; - - // Remove decimal part.. - return {x:x,y:y}; - }, - - getWorkspaceIconPosition : function(e) { - // Retrieve current icon position. - var image = e.getImage(); - var elementPosition = image.getPosition(); - var imageSize = e.getSize(); - - //Add group offset - var iconGroup = e.getGroup(); - var group = iconGroup.getNativeElement(); - var coordOrigin = group.getCoordOrigin(); - var groupSize = group.getSize(); - var coordSize = group.getCoordSize(); - - 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 y = (elementPosition.y - coordOrigin.y - (parseInt(imageSize.height) / 2)) / scale.y; - - //Retrieve iconGroup Position - var groupPosition = iconGroup.getPosition(); - x = x + groupPosition.x; - y = y + groupPosition.y; - - //Retrieve topic Position - var topic = iconGroup.getTopic(); - var topicPosition = this._getElementPosition(topic); - topicPosition.x = topicPosition.x - (parseInt(topic.getSize().width) / 2); - - // Remove decimal part.. - return {x:x + topicPosition.x,y:y + topicPosition.y}; - }, - - getWorkspaceMousePosition : function(event) { - // Retrieve current mouse position. - var x = event.client.x; - var y = event.client.y; - - // Subtract div position. - var containerPosition = this.getContainer().getPosition(); - x = x - containerPosition.x; - y = y - containerPosition.y; - - // Scale coordinate in order to be relative to the workspace. That's coordSize/size; - x = x * this._scale; - y = y * this._scale; - - // Add workspace offset. - x = x + this._padding.x; - y = y + this._padding.y; - - // Remove decimal part.. - return new core.Point(x, y); - }, - - getContainer : function() { - return this._divContainer; - }, - - setOffset : function(x, y) { - this._padding.x = x; - this._padding.y = y; - } -}); +/* + * Copyright [2011] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +mindplot.ScreenManager = new Class({ + initialize:function(divElement) { + $assert(divElement, "can not be null"); + this._divContainer = divElement; + this._padding = {x:0,y:0}; + + // Ignore default click event propagation. Prevent 'click' event on drag. + this._clickEvents = []; + this._divContainer.addEvent('click', function(event) { + event.stopPropagation() + }.bind(this)); + + this._divContainer.addEvent('dblclick', function(event) { + event.stopPropagation(); + event.preventDefault(); + }); + }, + + setScale : function(scale) { + $assert(scale, 'Screen scale can not be null'); + this._scale = scale; + }, + + addEvent : function(event, listener) { + if (event == 'click') + this._clickEvents.push(listener); + else + $(this._divContainer).addEvent(event, listener); + }, + + removeEvent : function(event, listener) { + if (event == 'click') + this._clickEvents.remove(listener); + else + $(this._divContainer).removeEvent(event, listener); + }, + + fireEvent : function(type, event) { + if (type == 'click') { + this._clickEvents.each(function(listener) { + listener(type, event); + }); + } + else { + $(this._divContainer).fireEvent(type, event); + } + }, + + _getElementPosition : function(elem) { + // Retrieve current element position. + var elementPosition = elem.getPosition(); + var x = elementPosition.x; + var y = elementPosition.y; + + // Add workspace offset. + x = x - this._padding.x; + y = y - this._padding.y; + + // Scale coordinate in order to be relative to the workspace. That's coord/size; + x = x / this._scale; + y = y / this._scale; + + // Remove decimal part.. + return {x:x,y:y}; + }, + + getWorkspaceIconPosition : function(e) { + // Retrieve current icon position. + var image = e.getImage(); + var elementPosition = image.getPosition(); + var imageSize = e.getSize(); + + //Add group offset + var iconGroup = e.getGroup(); + var group = iconGroup.getNativeElement(); + var coordOrigin = group.getCoordOrigin(); + var groupSize = group.getSize(); + var coordSize = group.getCoordSize(); + + 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 y = (elementPosition.y - coordOrigin.y - (parseInt(imageSize.height) / 2)) / scale.y; + + //Retrieve iconGroup Position + var groupPosition = iconGroup.getPosition(); + x = x + groupPosition.x; + y = y + groupPosition.y; + + //Retrieve topic Position + var topic = iconGroup.getTopic(); + var topicPosition = this._getElementPosition(topic); + topicPosition.x = topicPosition.x - (parseInt(topic.getSize().width) / 2); + + // Remove decimal part.. + return {x:x + topicPosition.x,y:y + topicPosition.y}; + }, + + getWorkspaceMousePosition : function(event) { + // Retrieve current mouse position. + var x = event.client.x; + var y = event.client.y; + + // Subtract div position. + var containerPosition = this.getContainer().getPosition(); + x = x - containerPosition.x; + y = y - containerPosition.y; + + // Scale coordinate in order to be relative to the workspace. That's coordSize/size; + x = x * this._scale; + y = y * this._scale; + + // Add workspace offset. + x = x + this._padding.x; + y = y + this._padding.y; + + // Remove decimal part.. + return new core.Point(x, y); + }, + + getContainer : function() { + return this._divContainer; + }, + + setOffset : function(x, y) { + this._padding.x = x; + this._padding.y = y; + } +}); diff --git a/mindplot/src/main/javascript/Topic.js b/mindplot/src/main/javascript/Topic.js index 79d7b7e3..cf8b51e5 100644 --- a/mindplot/src/main/javascript/Topic.js +++ b/mindplot/src/main/javascript/Topic.js @@ -875,7 +875,7 @@ mindplot.Topic = new Class({ }, _setRelationshipLinesVisibility:function (value) { - this._relationships.forEach(function (relationship) { + this._relationships.each(function (relationship) { relationship.setVisibility(value); }); }, diff --git a/mindplot/src/main/javascript/commands/AddTopicCommand.js b/mindplot/src/main/javascript/commands/AddTopicCommand.js index 62e01ac9..30e673a3 100644 --- a/mindplot/src/main/javascript/commands/AddTopicCommand.js +++ b/mindplot/src/main/javascript/commands/AddTopicCommand.js @@ -29,7 +29,7 @@ mindplot.commands.AddTopicCommand = new Class({ execute:function (commandContext) { - this._models.forEach(function (model, index) { + this._models.each(function (model, index) { // Add a new topic ... var topic = commandContext.createTopic(model, false); @@ -56,7 +56,7 @@ mindplot.commands.AddTopicCommand = new Class({ undoExecute:function (commandContext) { // Finally, delete the topic from the workspace ... - this._models.forEach(function (model) { + this._models.each(function (model) { var topicId = model.getId(); var topic = commandContext.findTopics(topicId)[0]; diff --git a/mindplot/src/main/javascript/commands/DeleteCommand.js b/mindplot/src/main/javascript/commands/DeleteCommand.js index b9498dc1..77a859f8 100644 --- a/mindplot/src/main/javascript/commands/DeleteCommand.js +++ b/mindplot/src/main/javascript/commands/DeleteCommand.js @@ -36,63 +36,61 @@ mindplot.commands.DeleteCommand = new Class({ if (topics.length > 0) { - topics.forEach( - function (topic) { - var model = topic.getModel(); + topics.each(function (topic) { + var model = topic.getModel(); - // Delete relationships - var relationships = topic.getRelationships(); - while (relationships.length > 0) { - var relationship = relationships[0]; + // Delete relationships + var relationships = this._collectInDepthRelationships(topic); + this._deletedRelModel.append(relationships.map(function (rel) { + return rel.getModel().clone(); + })); - this._deletedRelModel.push(relationship.getModel().clone()); - commandContext.deleteRelationship(relationship); - } + relationships.each(function (relationship) { + commandContext.deleteRelationship(relationship); + }); - // Store information for undo ... - var clonedModel = model.clone(); - this._deletedTopicModels.push(clonedModel); - var outTopic = topic.getOutgoingConnectedTopic(); - var outTopicId = null; - if (outTopic != null) { - outTopicId = outTopic.getId(); - } - this._parentTopicIds.push(outTopicId); + // Store information for undo ... + var clonedModel = model.clone(); + this._deletedTopicModels.push(clonedModel); + var outTopic = topic.getOutgoingConnectedTopic(); + var outTopicId = null; + if (outTopic != null) { + outTopicId = outTopic.getId(); + } + this._parentTopicIds.push(outTopicId); - // Finally, delete the topic from the workspace... - commandContext.deleteTopic(topic); + // Finally, delete the topic from the workspace... + commandContext.deleteTopic(topic); - }.bind(this) - ); + }, this); } + var rels = commandContext.findRelationships(this._relIds); if (rels.length > 0) { - rels.forEach(function (rel) { + rels.each(function (rel) { this._deletedRelModel.push(rel.getModel().clone()); commandContext.deleteRelationship(rel); - }.bind(this)); + }, this); } }, undoExecute:function (commandContext) { var parent = commandContext.findTopics(this._parentTopicIds); - this._deletedTopicModels.forEach( - function (model, index) { - var topic = commandContext.createTopic(model); + this._deletedTopicModels.each(function (model, index) { + var topic = commandContext.createTopic(model); - // Was the topic connected? - var parentTopic = parent[index]; - if (parentTopic != null) { - commandContext.connect(topic, parentTopic); - topic.setOnFocus(true); - } + // Was the topic connected? + var parentTopic = parent[index]; + if (parentTopic != null) { + commandContext.connect(topic, parentTopic); + topic.setOnFocus(true); + } - }.bind(this) - ); + }, this); - this._deletedRelModel.forEach(function (model) { + this._deletedRelModel.each(function (model) { commandContext.addRelationship(model); }.bind(this)); @@ -105,7 +103,7 @@ mindplot.commands.DeleteCommand = new Class({ var topics = commandContext.findTopics(topicIds); var result = []; - topics.forEach(function (topic) { + topics.each(function (topic) { var parent = topic.getParent(); var found = false; 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; } + }); \ No newline at end of file diff --git a/mindplot/src/main/javascript/commands/GenericFunctionCommand.js b/mindplot/src/main/javascript/commands/GenericFunctionCommand.js index f8dd4eb2..22742c91 100644 --- a/mindplot/src/main/javascript/commands/GenericFunctionCommand.js +++ b/mindplot/src/main/javascript/commands/GenericFunctionCommand.js @@ -32,7 +32,7 @@ mindplot.commands.GenericFunctionCommand = new Class({ execute: function(commandContext) { if (!this.applied) { var topics = commandContext.findTopics(this._topicsIds); - topics.forEach(function(topic) { + topics.each(function(topic) { var oldValue = this._commandFunc(topic, this._value); this._oldValues.push(oldValue); }.bind(this)); @@ -46,7 +46,7 @@ mindplot.commands.GenericFunctionCommand = new Class({ undoExecute: function(commandContext) { if (this.applied) { var topics = commandContext.findTopics(this._topicsIds); - topics.forEach(function(topic, index) { + topics.each(function(topic, index) { this._commandFunc(topic, this._oldValues[index]); }.bind(this)); diff --git a/mindplot/src/main/javascript/layout/AbstractBasicSorter.js b/mindplot/src/main/javascript/layout/AbstractBasicSorter.js index e78d6af7..02a85969 100644 --- a/mindplot/src/main/javascript/layout/AbstractBasicSorter.js +++ b/mindplot/src/main/javascript/layout/AbstractBasicSorter.js @@ -38,7 +38,7 @@ mindplot.layout.AbstractBasicSorter = new Class({ result = height; } else { var childrenHeight = 0; - children.forEach(function(child) { + children.each(function(child) { childrenHeight += this._computeChildrenHeight(treeSet, child, heightCache); }, this); diff --git a/mindplot/src/main/javascript/layout/BalancedSorter.js b/mindplot/src/main/javascript/layout/BalancedSorter.js index 40d5043e..ebc90e63 100644 --- a/mindplot/src/main/javascript/layout/BalancedSorter.js +++ b/mindplot/src/main/javascript/layout/BalancedSorter.js @@ -154,7 +154,7 @@ mindplot.layout.BalancedSorter = new Class({ var totalPHeight = 0; var totalNHeight = 0; - heights.forEach(function (elem) { + heights.each(function (elem) { if (elem.order % 2 == 0) { totalPHeight += elem.height; } else { diff --git a/mindplot/src/main/javascript/layout/LayoutManager.js b/mindplot/src/main/javascript/layout/LayoutManager.js index 63ec1e9e..2c93bbd8 100644 --- a/mindplot/src/main/javascript/layout/LayoutManager.js +++ b/mindplot/src/main/javascript/layout/LayoutManager.js @@ -143,7 +143,7 @@ mindplot.layout.LayoutManager = new Class({ }, _flushEvents: function() { - this._events.forEach(function(event) { + this._events.each(function(event) { this.fireEvent('change', event); }, this); this._events = []; @@ -153,7 +153,7 @@ mindplot.layout.LayoutManager = new Class({ if (!nodes) nodes = this._treeSet.getTreeRoots(); - nodes.forEach(function(node) { + nodes.each(function(node) { if (node.hasOrderChanged() || node.hasPositionChanged()) { // Find or create a event ... diff --git a/mindplot/src/main/javascript/layout/OriginalLayout.js b/mindplot/src/main/javascript/layout/OriginalLayout.js index 2347cc93..b8b1a55d 100644 --- a/mindplot/src/main/javascript/layout/OriginalLayout.js +++ b/mindplot/src/main/javascript/layout/OriginalLayout.js @@ -70,7 +70,7 @@ mindplot.layout.OriginalLayout = new Class({ layout:function () { var roots = this._treeSet.getTreeRoots(); - roots.forEach(function (node) { + roots.each(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.forEach(function (child) { + children.each(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.forEach(function (child) { + children.each(function (child) { this._layoutChildren(child, heightById); }, this); }, @@ -183,7 +183,7 @@ mindplot.layout.OriginalLayout = new Class({ this._shiftBranches(node, heightById); } - children.forEach(function (child) { + children.each(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.forEach(function (sibling) { + siblingsToShift.each(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.forEach(function (branch) { + branchesToShift.each(function (branch) { var bAmount = node.getFreeDisplacement().y; this._treeSet.shiftBranchPosition(branch, 0, bAmount); shiftedBranches.push(branch); diff --git a/mindplot/src/main/javascript/layout/RootedTreeSet.js b/mindplot/src/main/javascript/layout/RootedTreeSet.js index 9750eb40..f0b89741 100644 --- a/mindplot/src/main/javascript/layout/RootedTreeSet.js +++ b/mindplot/src/main/javascript/layout/RootedTreeSet.js @@ -240,7 +240,7 @@ mindplot.layout.RootedTreeSet = new Class({ var yOffset = oldPos.y - position.y; var children = this.getChildren(node); - children.forEach(function (child) { + children.each(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.forEach(function (child) { + children.each(function (child) { this.shiftBranchPosition(child, xOffset, yOffset); }.bind(this)); }, diff --git a/mindplot/src/main/javascript/layout/SymmetricSorter.js b/mindplot/src/main/javascript/layout/SymmetricSorter.js index b611b79f..bb694ca8 100644 --- a/mindplot/src/main/javascript/layout/SymmetricSorter.js +++ b/mindplot/src/main/javascript/layout/SymmetricSorter.js @@ -133,7 +133,7 @@ mindplot.layout.SymmetricSorter = new Class({ // Compute the center of the branch ... var totalHeight = 0; - heights.forEach(function(elem) { + heights.each(function(elem) { totalHeight += elem.height; }); var ysum = totalHeight / 2; diff --git a/mindplot/src/main/javascript/model/IMindmap.js b/mindplot/src/main/javascript/model/IMindmap.js index 8b09c5fe..3b3f0855 100644 --- a/mindplot/src/main/javascript/model/IMindmap.js +++ b/mindplot/src/main/javascript/model/IMindmap.js @@ -135,7 +135,7 @@ mindplot.model.IMindmap = new Class({ // Then the rest of the branches ... var sbranchs = source.getBranches(); - sbranchs.forEach(function(snode) { + sbranchs.each(function(snode) { var tnode = target.createNode(snode.getType(), snode.getId()); snode.copyTo(tnode); target.addBranch(tnode); diff --git a/mindplot/src/main/javascript/model/INodeModel.js b/mindplot/src/main/javascript/model/INodeModel.js index 9151c118..2a8cbcd2 100644 --- a/mindplot/src/main/javascript/model/INodeModel.js +++ b/mindplot/src/main/javascript/model/INodeModel.js @@ -213,7 +213,7 @@ mindplot.model.INodeModel = new Class({ var source = this; // Copy properties ... var keys = source.getPropertiesKeys(); - keys.forEach(function(key) { + keys.each(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.forEach(function(snode) { + children.each(function(snode) { var tnode = tmindmap.createNode(snode.getType(), snode.getId()); snode.copyTo(tnode); target.appendChild(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.forEach(function(node) { + children.each(function(node) { result = result + "=> ("; var keys = node.getPropertiesKeys(); - keys.forEach(function(key) { + keys.each(function(key) { var value = node.getProperty(key); result = result + key + ":" + value + ","; }); diff --git a/mindplot/src/main/javascript/util/FadeEffect.js b/mindplot/src/main/javascript/util/FadeEffect.js index efd99e5e..7d9c0616 100644 --- a/mindplot/src/main/javascript/util/FadeEffect.js +++ b/mindplot/src/main/javascript/util/FadeEffect.js @@ -25,7 +25,7 @@ mindplot.util.FadeEffect = new Class({ this.addEvent('complete', function() { - this._element.forEach(function(elem) { + this._element.each(function(elem) { if(elem){ elem.setVisibility(isVisible); } @@ -39,7 +39,7 @@ mindplot.util.FadeEffect = new Class({ }, set: function(now) { - this._element.forEach(function(elem) { + this._element.each(function(elem) { if(elem){ elem.setOpacity(now); } diff --git a/mindplot/src/main/javascript/widget/ColorPalettePanel.js b/mindplot/src/main/javascript/widget/ColorPalettePanel.js index 0765c688..4ce2e92e 100644 --- a/mindplot/src/main/javascript/widget/ColorPalettePanel.js +++ b/mindplot/src/main/javascript/widget/ColorPalettePanel.js @@ -63,7 +63,7 @@ mindplot.widget.ColorPalettePanel = new Class({ // Register on toolbar elements ... var colorCells = content.getElements('div[class=palette-colorswatch]'); var model = this.getModel(); - colorCells.forEach(function(elem) { + colorCells.each(function(elem) { elem.addEvent('click', function() { var color = elem.getStyle("background-color"); model.setValue(color); @@ -79,7 +79,7 @@ mindplot.widget.ColorPalettePanel = new Class({ // Clear selected cell based on the color ... var tdCells = panelElem.getElements("td[class='palette-cell palette-cell-selected']"); - tdCells.forEach(function(elem) { + tdCells.each(function(elem) { elem.className = 'palette-cell'; }); @@ -87,7 +87,7 @@ mindplot.widget.ColorPalettePanel = new Class({ var colorCells = panelElem.getElements('div[class=palette-colorswatch]'); var model = this.getModel(); var modelValue = model.getValue(); - colorCells.forEach(function(elem) { + colorCells.each(function(elem) { var color = elem.getStyle("background-color"); if (modelValue == color) { elem.parentNode.className = 'palette-cell palette-cell-selected'; diff --git a/mindplot/src/main/javascript/widget/IMenu.js b/mindplot/src/main/javascript/widget/IMenu.js index 59281e7c..18ad4b93 100644 --- a/mindplot/src/main/javascript/widget/IMenu.js +++ b/mindplot/src/main/javascript/widget/IMenu.js @@ -29,7 +29,7 @@ mindplot.widget.IMenu = new Class({ }, clear:function () { - this._toolbarElems.forEach(function (item) { + this._toolbarElems.each(function (item) { item.hide(); }); }, diff --git a/mindplot/src/main/javascript/widget/ListToolbarPanel.js b/mindplot/src/main/javascript/widget/ListToolbarPanel.js index 850bff20..7d744ff6 100644 --- a/mindplot/src/main/javascript/widget/ListToolbarPanel.js +++ b/mindplot/src/main/javascript/widget/ListToolbarPanel.js @@ -26,7 +26,7 @@ mindplot.widget.ListToolbarPanel = new Class({ _initPanel: function () { // Register on toolbar elements ... var menuElems = this.getPanelElem().getElements('div'); - menuElems.forEach(function(elem) { + menuElems.each(function(elem) { elem.addEvent('click', function(event) { event.stopPropagation(); this.hide(); @@ -41,7 +41,7 @@ mindplot.widget.ListToolbarPanel = new Class({ var panelElem = this.getPanelElem(); var menuElems = panelElem.getElements('div'); var value = this.getModel().getValue(); - menuElems.forEach(function(elem) { + menuElems.each(function(elem) { var elemValue = $defined(elem.getAttribute('model')) ? elem.getAttribute('model') : elem.id; $assert(elemValue,"elemValue can not be null"); if (elemValue == value) diff --git a/mindplot/src/main/javascript/widget/Menu.js b/mindplot/src/main/javascript/widget/Menu.js index 8941f2bb..92ffed62 100644 --- a/mindplot/src/main/javascript/widget/Menu.js +++ b/mindplot/src/main/javascript/widget/Menu.js @@ -438,7 +438,7 @@ mindplot.widget.Menu = new Class({ _registerEvents:function (designer) { // Register on close events ... - this._toolbarElems.forEach(function (elem) { + this._toolbarElems.each(function (elem) { elem.addEvent('show', function () { this.clear() }.bind(this)); @@ -448,7 +448,7 @@ mindplot.widget.Menu = new Class({ var topics = designer.getModel().filterSelectedTopics(); var rels = designer.getModel().filterSelectedRelationships(); - this._toolbarElems.forEach(function (button) { + this._toolbarElems.each(function (button) { var disable = false; if (button.isTopicAction() && button.isRelAction()) { disable = rels.length == 0 && topics.length == 0; @@ -474,7 +474,7 @@ mindplot.widget.Menu = new Class({ var topics = designer.getModel().filterSelectedTopics(); var rels = designer.getModel().filterSelectedRelationships(); - this._toolbarElems.forEach(function (button) { + this._toolbarElems.each(function (button) { if (button.isTopicAction() && topics.length > 0) { button.enable(); } diff --git a/mindplot/src/test/javascript/static/test/FreeTestSuite.js b/mindplot/src/test/javascript/static/test/FreeTestSuite.js index bdb0d2c8..a17926f3 100644 --- a/mindplot/src/test/javascript/static/test/FreeTestSuite.js +++ b/mindplot/src/test/javascript/static/test/FreeTestSuite.js @@ -443,7 +443,7 @@ mindplot.layout.FreeTestSuite = new Class({ } var treeSet = manager._treeSet; - treeSet._rootNodes.forEach(function(rootNode) { + treeSet._rootNodes.each(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.forEach(function(child) { + children.each(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.forEach(function(sibling) { + siblings.each(function(sibling) { this._branchesOverlap(child, sibling, heightById); }, this); }, this); - children.forEach(function(child) { + children.each(function(child) { this._assertBranchCollision(treeSet, child, heightById); }, this) },