Commit 750c81af authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

make convertToRelativePosition public and use it when adding an element.

parent 2f52679d
...@@ -216,16 +216,18 @@ ...@@ -216,16 +216,18 @@
stop: function (tool) { stop: function (tool) {
var box_top, box_left, _class; var box_top, box_left, _class;
var offset = $("#render").offset(); var offset = $("#render").offset();
box_top = (tool.clientY - offset.top) / $('#main').height(); box_top = tool.clientY - offset.top + "px";
box_left = (tool.clientX - offset.left) / $('#main').width(); box_left = tool.clientX - offset.left + "px";
var relative_position = dream_instance.convertToRelativePosition(
box_left, box_top);
id_container[tool.target.id] = (id_container[tool.target.id] || 0) + id_container[tool.target.id] = (id_container[tool.target.id] || 0) +
1; 1;
_class = tool.target.id.replace('-', '.'); // XXX - vs . _class = tool.target.id.replace('-', '.'); // XXX - vs .
dream_instance.newElement({ dream_instance.newElement({
id: tool.target.id + "_" + id_container[tool.target.id], id: tool.target.id + "_" + id_container[tool.target.id],
coordinate: { coordinate: {
top: box_top, top: relative_position[1],
left: box_left left: relative_position[0]
}, },
_class: _class _class: _class
}); });
......
...@@ -112,7 +112,7 @@ ...@@ -112,7 +112,7 @@
if (coordinate === undefined) { if (coordinate === undefined) {
coordinate = {}; coordinate = {};
element = $("#" + element_id); element = $("#" + element_id);
var relative_position = priv.convertToRelativePosition( var relative_position = that.convertToRelativePosition(
element.css('left'), element.css('top')); element.css('left'), element.css('top'));
coordinate.top = relative_position[1]; coordinate.top = relative_position[1];
coordinate.left = relative_position[0]; coordinate.left = relative_position[0];
...@@ -148,7 +148,7 @@ ...@@ -148,7 +148,7 @@
return [left, top]; return [left, top];
}; };
priv.convertToRelativePosition = function(x, y) { that.convertToRelativePosition = function(x, y) {
var canvas_size_x = $('#main').width(); var canvas_size_x = $('#main').width();
var canvas_size_y = $('#main').height(); var canvas_size_y = $('#main').height();
var size_x = $('.window').width(); var size_x = $('.window').width();
...@@ -169,9 +169,8 @@ ...@@ -169,9 +169,8 @@
priv.draggable = function () { priv.draggable = function () {
// make all the window divs draggable // make all the window divs draggable
var stop = function (el) { var stop = function (element) {
var element_id = el.target.id; priv.updateElementCoordinate(element.target.id);
priv.updateElementCoordinate(element_id);
}; };
jsPlumb.draggable(jsPlumb.getSelector(".window"), { jsPlumb.draggable(jsPlumb.getSelector(".window"), {
grid: [10, 10], grid: [10, 10],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment