From cb7594d9c1923554efc43215fd1b16b551dc73e9 Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Tue, 1 Sep 2015 11:02:28 +0200
Subject: reset
---
edit.js | 481 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 481 insertions(+)
create mode 100644 edit.js
(limited to 'edit.js')
diff --git a/edit.js b/edit.js
new file mode 100644
index 0000000..35ef20a
--- /dev/null
+++ b/edit.js
@@ -0,0 +1,481 @@
+/*
+ * global vars and data
+ *
+ */
+var shapes_by_id = {},
+ r,
+ curDrag = null,
+ curEd = null,
+ curEdShape = null,
+ shapes = [],
+ target_shapes = [],
+ texts = [],
+ connections = {},
+ margin = 30,
+ padding = margin/3,
+ xbegin = 80,
+ ybegin = 5,
+ box_height = 50,
+ line_margin = 150,
+ ysource = ybegin,
+ ytarget = ysource+line_margin;
+ font_size = 20,
+ font_width = -1,
+ id = 0,
+ connect_mode = false,
+ connect_mode_shape = null,
+ edit_mode = false,
+ rm_shape = null,
+ text_att = { 'fill': '#000', 'stroke': 'none', 'text-anchor': 'start', 'font-size': font_size, 'font-family': 'Times New Roman' },
+ shape_att = { fill: "#eee", stroke: "#000", "fill-opacity": 0, "stroke-width": 1 }
+ source = ["Das", "ist ein", "kleines", "Haus", "gewesen", "."], // data
+ target = ["This", "has been", "a", "small", "house", "."], // ^
+ align = [0, 1, 3, 4, 1, 5]; // ^
+
+/*
+ * connection
+ *
+ */
+Raphael.fn.connection = function (obj1, obj2, line, bg)
+{
+ if (obj1.line && obj1.from && obj1.to) {
+ line = obj1;
+ obj1 = line.from;
+ obj2 = line.to;
+ }
+ if (!obj1.getBBox() || !obj2.getBBox())
+ return;
+ var bb1 = obj1.getBBox(),
+ bb2 = obj2.getBBox(),
+ x1 = bb1.x+bb1.width/2,
+ y1 = bb1.y+bb1.height,
+ x2 = bb2.x+bb2.width/2,
+ y2 = bb2.y,
+ path = ["M", x1, y1, "L", x2, y2];
+ if (line && line.line) {
+ line.bg && line.bg.attr({path: path});
+ line.line.attr({path: path});
+ } else {
+ return {
+ bg: bg && bg.split && this.path(path).attr({stroke: bg.split("|")[0], fill: "none", "stroke-width": bg.split("|")[1] || 3}),
+ line: this.path(path).attr({stroke: "#000", fill: "none"}),
+ from: obj1,
+ to: obj2
+ };
+ }
+};
+var conn_str = function (obj1, obj2)
+{
+ return obj1["id_"]+"-"+obj2["id_"];
+}
+var make_conn = function(obj1, obj2)
+{
+ connections[conn_str(obj1,obj2)] = r.connection(obj1, obj2);
+},
+rm_conn = function(id1, id2)
+{
+ var b = false;
+ for (var i=0; i