From 9469b08ffa890fd4675d010230a6d0731396f6bd Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 12 Feb 2016 11:21:22 +0800 Subject: [PATCH] cancel synapse creation with esc, backspace, or delete --- app/assets/javascripts/src/Metamaps.js.erb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.js.erb b/app/assets/javascripts/src/Metamaps.js.erb index fb636f11..82b033ca 100644 --- a/app/assets/javascripts/src/Metamaps.js.erb +++ b/app/assets/javascripts/src/Metamaps.js.erb @@ -791,16 +791,22 @@ Metamaps.Create = { }] ); - $('#synapse_desc').keyup(function () { + $('#synapse_desc').keyup(function (e) { + var ESC = 27, BACKSPACE = 8, DELETE = 46; + if (e.keyCode === BACKSPACE && $(this).val() === "" || + e.keyCode === DELETE && $(this).val() === "" || + e.keyCode === ESC) { + Metamaps.Create.newSynapse.hide(); + }//if Metamaps.Create.newSynapse.description = $(this).val(); }); $('#synapse_desc').focusout(function() { - // Metamaps.Create.newSynapse.description = $(this).val(); - Metamaps.Synapse.createSynapseLocally(); + if (Metamaps.Create.newSynapse.beingCreated) { + Metamaps.Synapse.createSynapseLocally(); + } }); - $('#synapse_desc').bind('typeahead:select', function (event, datum, dataset) { if (datum.id) { // if they clicked on an existing synapse get it Metamaps.Synapse.getSynapseFromAutocomplete(datum.id);