From 00ab985b296b8a41f782be9766faa7e6320f4198 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Fri, 6 Nov 2015 11:59:21 +0100 Subject: fixed edit mode --- README | 8 +- demo.html | 3 +- derivation-editor.js | 8 +- raphael.inline_text_editing.js | 193 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 205 insertions(+), 7 deletions(-) create mode 100644 raphael.inline_text_editing.js diff --git a/README b/README index cd066f1..c193e38 100644 --- a/README +++ b/README @@ -1,7 +1,9 @@ Visualize and edit machine translation derivations using raphaeljs. +Took raphael.inline_text_editing.js from [1]. +Partially adapted from [3] and [2]. Resources: - * http://grokbase.com/p/gg/raphaeljs/135twn41fq/how-to-move-text-and-rect-together-using-raphaeljs - * https://github.com/marmelab/Raphael.InlineTextEditing - * http://raphaeljs.com/graffle.html + [1] https://github.com/marmelab/Raphael.InlineTextEditing + [2] http://grokbase.com/p/gg/raphaeljs/135twn41fq/how-to-move-text-and-rect-together-using-raphaeljs + [3] http://raphaeljs.com/graffle.html diff --git a/demo.html b/demo.html index 9033d55..8a19348 100644 --- a/demo.html +++ b/demo.html @@ -6,7 +6,8 @@ derivation editor - + + diff --git a/derivation-editor.js b/derivation-editor.js index 08b97fc..641a478 100644 --- a/derivation-editor.js +++ b/derivation-editor.js @@ -369,7 +369,7 @@ var DE_make_obj = function (x, text, type) } else if(e.ctrlKey) { // add var x = DE_shapes_by_id[this["id_"]].attr("x")+DE_shapes_by_id[this["id_"]].attr("width") +2*DE_ui_padding; - var new_obj = DE_make_obj(x, "test", "target"); + var new_obj = DE_make_obj(x, "", "target"); var new_grid = this["grid_"]+1; new_obj["grid_"] = new_grid; new_obj.pair["grid_"] = new_grid; @@ -391,6 +391,8 @@ var DE_make_obj = function (x, text, type) if (DE_edit_mode) return; DE_edit_mode = true; this.pair.toFront(); + this.toBack(); + //this.animate({"opacity":0}, 250); DE_cur_ed = this.pair; DE_cur_ed_shape = this; var input = DE_cur_ed.inlineTextEditing.startEditing(); @@ -505,10 +507,10 @@ var DE_add_object = function() } } if (!DE_shapes[max_idx]) { - DE_make_obj(DE_ui_xbegin+DE_ui_padding, "X", "target"); + DE_make_obj(DE_ui_xbegin+DE_ui_padding, "", "target"); } else { DE_make_obj(DE_shapes[max_idx].getBBox().x2+(DE_ui_margin-DE_ui_padding), - "X", + "", "target"); } DE_paper.setSize(DE_paper.width+DE_target_shapes[DE_target_shapes.length-1].getBBox().width+DE_ui_margin, DE_paper.height); diff --git a/raphael.inline_text_editing.js b/raphael.inline_text_editing.js new file mode 100644 index 0000000..ccc37ed --- /dev/null +++ b/raphael.inline_text_editing.js @@ -0,0 +1,193 @@ +/* + * Inline text editing tool for Raphaël 2.0 & compatible with Raphaël Free transform. + * Source: https://github.com/marmelab/Raphael.InlineTextEditing + * Licensed under the MIT license + */ +(function (root, factory) { + if (typeof define === "function" && define.amd) { + // AMD. Register as an anonymous module. + define(["raphael"], function(Raphael) { + // Use global variables if the locals are undefined. + return factory(Raphael || root.Raphael); + }); + } else { + // RequireJS isn't being used. Assume Raphael is loaded in