2016-09-22 10:31:56 +00:00
|
|
|
/* global $ */
|
|
|
|
|
|
|
|
import Active from './Active'
|
2017-03-07 03:49:46 +00:00
|
|
|
import Create from './Create'
|
2016-09-22 10:31:56 +00:00
|
|
|
import Control from './Control'
|
2016-12-11 21:21:36 +00:00
|
|
|
import DataModel from './DataModel'
|
2016-09-22 10:31:56 +00:00
|
|
|
import JIT from './JIT'
|
|
|
|
import Mobile from './Mobile'
|
|
|
|
import Realtime from './Realtime'
|
|
|
|
import Selected from './Selected'
|
|
|
|
import Topic from './Topic'
|
2016-10-07 00:33:16 +00:00
|
|
|
import Util from './Util'
|
2016-09-22 10:31:56 +00:00
|
|
|
import Visualize from './Visualize'
|
2016-09-30 03:33:39 +00:00
|
|
|
import { Search } from './GlobalUI'
|
2016-04-15 00:31:22 +00:00
|
|
|
|
2016-09-22 07:21:59 +00:00
|
|
|
const Listeners = {
|
2016-11-07 20:25:08 +00:00
|
|
|
init: function() {
|
2016-08-08 13:46:05 +00:00
|
|
|
var self = this
|
2016-11-07 20:25:08 +00:00
|
|
|
$(document).on('keydown', function(e) {
|
2016-09-22 10:31:56 +00:00
|
|
|
if (!(Active.Map || Active.Topic)) return
|
2016-04-15 00:31:22 +00:00
|
|
|
|
2016-10-23 10:02:59 +00:00
|
|
|
const onCanvas = e.target.tagName === 'BODY'
|
2017-02-03 19:23:04 +00:00
|
|
|
|
2016-04-15 00:31:22 +00:00
|
|
|
switch (e.which) {
|
|
|
|
case 13: // if enter key is pressed
|
2016-10-06 02:17:04 +00:00
|
|
|
// prevent topic creation if sending a message
|
|
|
|
if (e.target.className !== 'chat-input') {
|
|
|
|
JIT.enterKeyHandler()
|
|
|
|
}
|
2016-04-15 00:31:22 +00:00
|
|
|
break
|
|
|
|
case 27: // if esc key is pressed
|
2016-09-22 10:31:56 +00:00
|
|
|
JIT.escKeyHandler()
|
2016-04-15 00:31:22 +00:00
|
|
|
break
|
2017-02-03 19:23:04 +00:00
|
|
|
case 46: // if DEL is pressed
|
2017-03-07 03:49:46 +00:00
|
|
|
if(e.target.tagName !== "INPUT" && e.target.tagName !== "TEXTAREA" && (Selected.Nodes.length + Selected.Edges.length) > 0){
|
|
|
|
e.preventDefault()
|
|
|
|
Control.removeSelectedNodes()
|
|
|
|
Control.removeSelectedEdges()
|
|
|
|
}
|
2017-02-03 19:23:04 +00:00
|
|
|
break
|
2016-04-15 00:31:22 +00:00
|
|
|
case 65: // if a or A is pressed
|
2017-03-07 03:49:46 +00:00
|
|
|
if (Create.isSwitchingSet && e.ctrlKey || e.metaKey) {
|
|
|
|
Create.metacodeSelectorToggleSelectAll()
|
|
|
|
e.preventDefault()
|
|
|
|
break
|
|
|
|
} else if ((e.ctrlKey || e.metaKey) && onCanvas) {
|
2016-12-11 21:21:36 +00:00
|
|
|
const nodesCount = Object.keys(Visualize.mGraph.graph.nodes).length
|
|
|
|
const selectedNodesCount = Selected.Nodes.length
|
2016-04-15 00:31:22 +00:00
|
|
|
e.preventDefault()
|
2016-12-11 21:21:36 +00:00
|
|
|
|
|
|
|
// Hit Ctrl+A once to select all nodes
|
|
|
|
Control.deselectAllNodes()
|
|
|
|
Visualize.mGraph.graph.eachNode(node => {
|
|
|
|
Control.selectNode(node, e)
|
2016-04-15 00:31:22 +00:00
|
|
|
})
|
|
|
|
|
2016-12-11 21:21:36 +00:00
|
|
|
// Hitting Ctrl+A a second time will select all edges too
|
|
|
|
Control.deselectAllEdges()
|
|
|
|
if (nodesCount === selectedNodesCount) {
|
|
|
|
DataModel.Synapses.models.forEach(synapse => {
|
|
|
|
const topic1id = synapse.get('topic1_id')
|
|
|
|
const topic2id = synapse.get('topic2_id')
|
|
|
|
const edge = Visualize.mGraph.graph.edges[topic1id][topic2id]
|
|
|
|
Control.selectEdge(edge, e)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-09-22 10:31:56 +00:00
|
|
|
Visualize.mGraph.plot()
|
2016-04-15 00:31:22 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 13:46:05 +00:00
|
|
|
break
|
|
|
|
case 68: // if d or D is pressed
|
2016-10-07 06:03:48 +00:00
|
|
|
if (e.ctrlKey || e.metaKey) {
|
2016-08-08 13:46:05 +00:00
|
|
|
e.preventDefault()
|
2016-09-22 10:31:56 +00:00
|
|
|
Control.deleteSelected()
|
2016-08-08 13:46:05 +00:00
|
|
|
}
|
2016-04-15 00:31:22 +00:00
|
|
|
break
|
|
|
|
case 69: // if e or E is pressed
|
2016-10-07 06:03:48 +00:00
|
|
|
if ((e.ctrlKey || e.metaKey) && Active.Map) {
|
2016-08-09 15:53:50 +00:00
|
|
|
e.preventDefault()
|
2016-09-22 10:31:56 +00:00
|
|
|
JIT.zoomExtents(null, Visualize.mGraph.canvas)
|
2016-08-09 15:53:50 +00:00
|
|
|
break
|
|
|
|
}
|
2016-09-22 10:31:56 +00:00
|
|
|
if (e.altKey && Active.Topic) {
|
2016-04-15 00:31:22 +00:00
|
|
|
e.preventDefault()
|
2016-08-09 15:53:50 +00:00
|
|
|
|
2016-09-22 10:31:56 +00:00
|
|
|
if (Active.Topic) {
|
|
|
|
self.centerAndReveal(Selected.Nodes, {
|
2016-08-08 13:46:05 +00:00
|
|
|
center: true,
|
|
|
|
reveal: false
|
|
|
|
})
|
2016-04-15 00:31:22 +00:00
|
|
|
}
|
2016-08-09 15:53:50 +00:00
|
|
|
break
|
2016-04-15 00:31:22 +00:00
|
|
|
}
|
|
|
|
break
|
2016-08-08 13:46:05 +00:00
|
|
|
case 72: // if h or H is pressed
|
2016-10-07 06:03:48 +00:00
|
|
|
if (e.ctrlKey || e.metaKey) {
|
2016-08-08 13:46:05 +00:00
|
|
|
e.preventDefault()
|
2016-09-22 10:31:56 +00:00
|
|
|
Control.hideSelectedNodes()
|
|
|
|
Control.hideSelectedEdges()
|
2016-08-08 13:46:05 +00:00
|
|
|
}
|
|
|
|
break
|
2016-04-15 00:31:22 +00:00
|
|
|
case 77: // if m or M is pressed
|
2016-10-07 06:03:48 +00:00
|
|
|
if (e.ctrlKey || e.metaKey) {
|
2016-04-15 00:31:22 +00:00
|
|
|
e.preventDefault()
|
2016-09-22 10:31:56 +00:00
|
|
|
Control.removeSelectedNodes()
|
|
|
|
Control.removeSelectedEdges()
|
2016-04-15 00:31:22 +00:00
|
|
|
}
|
|
|
|
break
|
2016-08-08 13:46:05 +00:00
|
|
|
case 82: // if r or R is pressed
|
2016-09-22 10:31:56 +00:00
|
|
|
if (e.altKey && Active.Topic) {
|
2016-04-15 00:31:22 +00:00
|
|
|
e.preventDefault()
|
2016-09-22 10:31:56 +00:00
|
|
|
self.centerAndReveal(Selected.Nodes, {
|
2016-08-08 13:46:05 +00:00
|
|
|
center: false,
|
|
|
|
reveal: true
|
|
|
|
})
|
2016-04-15 00:31:22 +00:00
|
|
|
}
|
|
|
|
break
|
2016-08-08 13:46:05 +00:00
|
|
|
case 84: // if t or T is pressed
|
2016-09-22 10:31:56 +00:00
|
|
|
if (e.altKey && Active.Topic) {
|
2016-04-15 00:31:22 +00:00
|
|
|
e.preventDefault()
|
2016-09-22 10:31:56 +00:00
|
|
|
self.centerAndReveal(Selected.Nodes, {
|
2016-08-08 13:46:05 +00:00
|
|
|
center: true,
|
|
|
|
reveal: true
|
|
|
|
})
|
2016-04-15 00:31:22 +00:00
|
|
|
}
|
|
|
|
break
|
2016-09-30 03:33:39 +00:00
|
|
|
case 191: // if / is pressed
|
2016-10-07 06:03:48 +00:00
|
|
|
if (e.ctrlKey || e.metaKey) {
|
2016-09-30 03:33:39 +00:00
|
|
|
Search.focus()
|
|
|
|
}
|
|
|
|
break
|
2016-04-15 00:31:22 +00:00
|
|
|
default:
|
2016-08-08 13:46:05 +00:00
|
|
|
// console.log(e.which)
|
|
|
|
break
|
2016-04-15 00:31:22 +00:00
|
|
|
}
|
|
|
|
})
|
2016-11-07 20:25:08 +00:00
|
|
|
$(window).resize(function() {
|
2016-10-10 09:20:43 +00:00
|
|
|
if (Visualize && Visualize.mGraph) {
|
2016-10-22 05:50:31 +00:00
|
|
|
Util.resizeCanvas(Visualize.mGraph.canvas)
|
2016-10-07 00:51:52 +00:00
|
|
|
}
|
2016-10-10 09:20:43 +00:00
|
|
|
|
2016-09-22 10:31:56 +00:00
|
|
|
if (Active.Map && Realtime.inConversation) Realtime.positionVideos()
|
|
|
|
Mobile.resizeTitle()
|
2016-04-15 00:31:22 +00:00
|
|
|
})
|
2016-08-08 13:46:05 +00:00
|
|
|
},
|
2016-11-07 20:25:08 +00:00
|
|
|
centerAndReveal: function(nodes, opts) {
|
2016-08-08 13:46:05 +00:00
|
|
|
if (nodes.length < 1) return
|
|
|
|
var node = nodes[nodes.length - 1]
|
2016-08-09 15:53:50 +00:00
|
|
|
if (opts.center && opts.reveal) {
|
2016-11-07 20:25:08 +00:00
|
|
|
Topic.centerOn(node.id, function() {
|
2016-09-22 10:31:56 +00:00
|
|
|
Topic.fetchRelatives(nodes)
|
2016-08-09 15:53:50 +00:00
|
|
|
})
|
|
|
|
} else if (opts.center) {
|
2016-09-22 10:31:56 +00:00
|
|
|
Topic.centerOn(node.id)
|
2016-08-09 15:53:50 +00:00
|
|
|
} else if (opts.reveal) {
|
2016-09-22 10:31:56 +00:00
|
|
|
Topic.fetchRelatives(nodes)
|
2016-08-08 13:46:05 +00:00
|
|
|
}
|
2016-04-15 00:31:22 +00:00
|
|
|
}
|
2016-09-22 07:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Listeners
|