From 88522be80c04c6dcb6b4cde43d99a178c65c8980 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 22 Feb 2013 18:27:11 -0500 Subject: [PATCH] now if you double click 'inCanvas' nodes they will be added to the map. TODO they don't have a mapping yet --- .../Jit/graphsettings-event-handlers.js | 37 ++++++++++++++++--- app/views/main/search.js.erb | 2 +- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/Jit/graphsettings-event-handlers.js b/app/assets/javascripts/Jit/graphsettings-event-handlers.js index 4be5f134..32e1a1d5 100644 --- a/app/assets/javascripts/Jit/graphsettings-event-handlers.js +++ b/app/assets/javascripts/Jit/graphsettings-event-handlers.js @@ -28,9 +28,38 @@ function selectEdgeOnClickHandler(adj, e) { Mconsole.plot(); }//selectEdgeOnClickHandler -function selectNodeOnClickHandler(node, e) { +function nodeDoubleClickHandler(node, e) { + node.setData('onCanvas', true); + node.setData('inCommons', false); + console.log("Here's the node you clicked:"); + console.log(node); + //if ($('.maps.onMap').length > 0 && node.getData('mappingid')) { + // //TODO + // var mappingId = createAMapping(alert('unimp')); + // node.setData('mappingid', mappingId); + //} +}//doubleClickNodeHandler +function nodeWasDoubleClicked() { + //grab the timestamp of the click + var storedTime = MetamapsModel.lastNodeClick; + var now = Date.now(); //not compatible with IE8 FYI + MetamapsModel.lastNodeClick = now; + + if (now - storedTime < MetamapsModel.DOUBLE_CLICK_TOLERANCE) { + return true; + } else { + return false; + } +}//nodeWasDoubleClicked; + +function selectNodeOnClickHandler(node, e) { if (Mconsole.busy) return; + + if (nodeWasDoubleClicked()) { + nodeDoubleClickHandler(node, e); + return; + } if (gType != "centered") { //set final styles @@ -70,13 +99,12 @@ function selectNodeOnClickHandler(node, e) { }//selectNodeOnClickHandler function canvasDoubleClickHandler(canvasLoc,e) { - var DOUBLE_CLICK_TOLERANCE = 300; //0.3 seconds - //grab the location and timestamp of the click var storedTime = MetamapsModel.lastCanvasClick; var now = Date.now(); //not compatible with IE8 FYI + MetamapsModel.lastCanvasClick = now; - if (now - storedTime < DOUBLE_CLICK_TOLERANCE) { + if (now - storedTime < MetamapsModel.DOUBLE_CLICK_TOLERANCE) { //pop up node creation :) $('#topic_grabTopic').val("null"); $('#topic_addSynapse').val("false"); @@ -89,7 +117,6 @@ function canvasDoubleClickHandler(canvasLoc,e) { addMetacode(); $('#topic_name').focus(); } else { - MetamapsModel.lastCanvasClick = now; $('#new_topic').fadeOut('fast'); $('#new_synapse').fadeOut('fast'); tempInit = false; diff --git a/app/views/main/search.js.erb b/app/views/main/search.js.erb index f3df1b9c..78cd8f2b 100644 --- a/app/views/main/search.js.erb +++ b/app/views/main/search.js.erb @@ -66,7 +66,7 @@ var even = true; var temp1 = null, temp2 = null; temp1 = Mconsole.graph.getNode(<%= synapse.topic1.id %>); temp2 = Mconsole.graph.getNode(<%= synapse.topic2.id %>); - if (!(temp1 == undefined || temp2 == undefined)) { + if (temp1 != undefined && temp2 != undefined) { Mconsole.graph.addAdjacence(temp1, temp2, {}); temp = Mconsole.graph.getAdjacence(temp1.id, temp2.id); temp.setDataset('start', {