From b10f0cef0e17f2fe1fbbef8b5020420fca9d6505 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 15 Apr 2016 08:31:22 +0800 Subject: [PATCH] Metamaps.Listeners.js.erb --- app/assets/javascripts/application.js | 1 + .../javascripts/src/Metamaps.Listeners.js.erb | 78 +++++++++++++++++++ app/assets/javascripts/src/Metamaps.js.erb | 76 ------------------ 3 files changed, 79 insertions(+), 76 deletions(-) create mode 100644 app/assets/javascripts/src/Metamaps.Listeners.js.erb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9df35932..b92b538a 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -25,6 +25,7 @@ //= require ./src/views/room //= require ./src/JIT //= require ./src/Metamaps +//= require ./src/Metamaps.Listeners //= require ./src/Metamaps.Organize //= require ./src/Metamaps.Topic //= require ./src/Metamaps.Synapse diff --git a/app/assets/javascripts/src/Metamaps.Listeners.js.erb b/app/assets/javascripts/src/Metamaps.Listeners.js.erb new file mode 100644 index 00000000..d5b3dc70 --- /dev/null +++ b/app/assets/javascripts/src/Metamaps.Listeners.js.erb @@ -0,0 +1,78 @@ +/* global Metamaps, $ */ + +/* + * Metamaps.Listeners.js.erb + * + * Dependencies: + * - Metamaps.Active + * - Metamaps.JIT + * - Metamaps.Control + * - Metamaps.Visualize + */ +Metamaps.Listeners = { + init: function () { + $(document).on('keydown', function (e) { + if (!(Metamaps.Active.Map || Metamaps.Active.Topic)) return + + switch (e.which) { + case 13: // if enter key is pressed + Metamaps.JIT.enterKeyHandler() + e.preventDefault() + break + case 27: // if esc key is pressed + Metamaps.JIT.escKeyHandler() + break + case 65: // if a or A is pressed + if (e.ctrlKey) { + Metamaps.Control.deselectAllNodes() + Metamaps.Control.deselectAllEdges() + + e.preventDefault() + Metamaps.Visualize.mGraph.graph.eachNode(function (n) { + Metamaps.Control.selectNode(n, e) + }) + + Metamaps.Visualize.mGraph.plot() + } + + break + case 69: // if e or E is pressed + if (e.ctrlKey) { + e.preventDefault() + if (Metamaps.Active.Map) { + Metamaps.JIT.zoomExtents(null, Metamaps.Visualize.mGraph.canvas) + } + } + break + case 77: // if m or M is pressed + if (e.ctrlKey) { + e.preventDefault() + Metamaps.Control.removeSelectedNodes() + Metamaps.Control.removeSelectedEdges() + } + break + case 68: // if d or D is pressed + if (e.ctrlKey) { + e.preventDefault() + Metamaps.Control.deleteSelected() + } + break + case 72: // if h or H is pressed + if (e.ctrlKey) { + e.preventDefault() + Metamaps.Control.hideSelectedNodes() + Metamaps.Control.hideSelectedEdges() + } + break + default: + break; // alert(e.which) + } + }) + + $(window).resize(function () { + if (Metamaps.Visualize && Metamaps.Visualize.mGraph) Metamaps.Visualize.mGraph.canvas.resize($(window).width(), $(window).height()) + if ((Metamaps.Active.Map || Metamaps.Active.Topic) && Metamaps.Famous && Metamaps.Famous.maps.surf) Metamaps.Famous.maps.reposition() + if (Metamaps.Active.Map && Metamaps.Realtime.inConversation) Metamaps.Realtime.positionVideos() + }) + } +}; // end Metamaps.Listeners diff --git a/app/assets/javascripts/src/Metamaps.js.erb b/app/assets/javascripts/src/Metamaps.js.erb index ec87022b..94c026d5 100644 --- a/app/assets/javascripts/src/Metamaps.js.erb +++ b/app/assets/javascripts/src/Metamaps.js.erb @@ -4022,79 +4022,3 @@ Metamaps.Filter = { }); } }; // end Metamaps.Filter - - -/* - * - * LISTENERS - * - */ -Metamaps.Listeners = { - - init: function () { - - $(document).on('keydown', function (e) { - if (!(Metamaps.Active.Map || Metamaps.Active.Topic)) return; - - switch (e.which) { - case 13: // if enter key is pressed - Metamaps.JIT.enterKeyHandler(); - e.preventDefault(); - break; - case 27: // if esc key is pressed - Metamaps.JIT.escKeyHandler(); - break; - case 65: //if a or A is pressed - if (e.ctrlKey){ - Metamaps.Control.deselectAllNodes(); - Metamaps.Control.deselectAllEdges(); - - e.preventDefault(); - Metamaps.Visualize.mGraph.graph.eachNode(function (n) { - Metamaps.Control.selectNode(n,e); - }); - - Metamaps.Visualize.mGraph.plot(); - } - - break; - case 69: //if e or E is pressed - if (e.ctrlKey){ - e.preventDefault(); - if (Metamaps.Active.Map) { - Metamaps.JIT.zoomExtents(null, Metamaps.Visualize.mGraph.canvas); - } - } - break; - case 77: //if m or M is pressed - if (e.ctrlKey){ - e.preventDefault(); - Metamaps.Control.removeSelectedNodes(); - Metamaps.Control.removeSelectedEdges(); - } - break; - case 68: //if d or D is pressed - if (e.ctrlKey){ - e.preventDefault(); - Metamaps.Control.deleteSelected(); - } - break; - case 72: //if h or H is pressed - if (e.ctrlKey){ - e.preventDefault(); - Metamaps.Control.hideSelectedNodes(); - Metamaps.Control.hideSelectedEdges(); - } - break; - default: - break; //alert(e.which); - } - }); - - $(window).resize(function () { - if (Metamaps.Visualize && Metamaps.Visualize.mGraph) Metamaps.Visualize.mGraph.canvas.resize($(window).width(), $(window).height()); - if ((Metamaps.Active.Map || Metamaps.Active.Topic) && Metamaps.Famous && Metamaps.Famous.maps.surf) Metamaps.Famous.maps.reposition(); - if (Metamaps.Active.Map && Metamaps.Realtime.inConversation) Metamaps.Realtime.positionVideos(); - }); - } -}; // end Metamaps.Listeners