From a176cdf2312156fd3fd512bb80a2cc832039dc38 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 7 Nov 2016 15:25:08 -0500 Subject: [PATCH] eslint frontend folder (#923) --- .eslintrc.js | 1 + frontend/src/Metamaps/Account.js | 26 +- frontend/src/Metamaps/Admin.js | 21 +- frontend/src/Metamaps/AutoLayout.js | 23 +- frontend/src/Metamaps/Control.js | 117 ++--- frontend/src/Metamaps/Create.js | 108 ++-- frontend/src/Metamaps/DataModel/Map.js | 25 +- .../src/Metamaps/DataModel/MapCollection.js | 12 +- frontend/src/Metamaps/DataModel/Mapper.js | 4 +- frontend/src/Metamaps/DataModel/Mapping.js | 10 +- frontend/src/Metamaps/DataModel/Message.js | 2 +- frontend/src/Metamaps/DataModel/Metacode.js | 4 +- .../Metamaps/DataModel/MetacodeCollection.js | 2 +- frontend/src/Metamaps/DataModel/Synapse.js | 38 +- frontend/src/Metamaps/DataModel/Topic.js | 34 +- frontend/src/Metamaps/DataModel/index.js | 10 +- frontend/src/Metamaps/Filter.js | 143 +++--- frontend/src/Metamaps/GlobalUI/Account.js | 14 +- frontend/src/Metamaps/GlobalUI/CreateMap.js | 28 +- .../src/Metamaps/GlobalUI/ImportDialog.js | 6 +- frontend/src/Metamaps/GlobalUI/Search.js | 50 +- frontend/src/Metamaps/GlobalUI/index.js | 24 +- frontend/src/Metamaps/Import.js | 74 +-- frontend/src/Metamaps/JIT.js | 482 +++++++++--------- frontend/src/Metamaps/Listeners.js | 12 +- frontend/src/Metamaps/Loading.js | 6 +- frontend/src/Metamaps/Map/CheatSheet.js | 32 +- frontend/src/Metamaps/Map/InfoBox.js | 151 +++--- frontend/src/Metamaps/Map/index.js | 144 +++--- frontend/src/Metamaps/Mapper.js | 2 +- frontend/src/Metamaps/Mobile.js | 12 +- frontend/src/Metamaps/Organize.js | 82 ++- frontend/src/Metamaps/PasteInput.js | 22 +- frontend/src/Metamaps/Realtime/index.js | 203 ++++---- frontend/src/Metamaps/Realtime/receivable.js | 73 ++- frontend/src/Metamaps/Realtime/sendable.js | 6 +- frontend/src/Metamaps/Router.js | 30 +- frontend/src/Metamaps/Selected.js | 2 +- frontend/src/Metamaps/Synapse.js | 58 +-- frontend/src/Metamaps/SynapseCard.js | 88 ++-- frontend/src/Metamaps/Topic.js | 83 ++- frontend/src/Metamaps/TopicCard.js | 91 ++-- frontend/src/Metamaps/Util.js | 103 ++-- frontend/src/Metamaps/Views/ChatView.js | 90 ++-- frontend/src/Metamaps/Views/ExploreMaps.js | 39 +- frontend/src/Metamaps/Views/Room.js | 208 ++++---- frontend/src/Metamaps/Views/VideoView.js | 327 ++++++------ frontend/src/Metamaps/Views/index.js | 4 +- frontend/src/Metamaps/Visualize.js | 114 ++--- frontend/src/Metamaps/index.js | 14 +- frontend/src/components/ImportDialogBox.js | 2 +- frontend/src/components/Maps/MapCard.js | 4 - frontend/src/components/Maps/index.js | 10 +- frontend/test/Metamaps.Import.spec.js | 4 +- frontend/test/Metamaps.Util.spec.js | 72 +-- realtime/global.js | 15 +- realtime/junto.js | 23 +- realtime/map.js | 25 +- realtime/realtime-server.js | 13 +- realtime/reducer.js | 80 +-- realtime/signal.js | 30 +- 61 files changed, 1723 insertions(+), 1809 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 1222f4a1..949de95b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -20,6 +20,7 @@ module.exports = { "rules": { "react/jsx-uses-react": [2], "react/jsx-uses-vars": [2], + "space-before-function-paren": [2, "never"], "yoda": [2, "never", { "exceptRange": true }] } } diff --git a/frontend/src/Metamaps/Account.js b/frontend/src/Metamaps/Account.js index b7e1fe79..19785797 100644 --- a/frontend/src/Metamaps/Account.js +++ b/frontend/src/Metamaps/Account.js @@ -1,33 +1,33 @@ /* global $, CanvasLoader */ const Account = { - init: function (serverData) { + init: function(serverData) { Account.userIconUrl = serverData['user.png'] }, listenersInitialized: false, userIconUrl: null, - initListeners: function () { + initListeners: function() { var self = Account $('#user_image').change(self.showImagePreview) self.listenersInitialized = true }, - toggleChangePicture: function () { + toggleChangePicture: function() { var self = Account $('.userImageMenu').toggle() if (!self.listenersInitialized) self.initListeners() }, - openChangePicture: function () { + openChangePicture: function() { var self = Account $('.userImageMenu').show() if (!self.listenersInitialized) self.initListeners() }, - closeChangePicture: function () { + closeChangePicture: function() { $('.userImageMenu').hide() }, - showLoading: function () { + showLoading: function() { var loader = new CanvasLoader('accountPageLoading') loader.setColor('#4FC059') // default is '#000000' loader.setDiameter(28) // default is 40 @@ -36,12 +36,12 @@ const Account = { loader.show() // Hidden by default $('#accountPageLoading').show() }, - showImagePreview: function () { + showImagePreview: function() { var file = $('#user_image')[0].files[0] var reader = new window.FileReader() - reader.onload = function (e) { + reader.onload = function(e) { var $canvas = $('').attr({ width: 84, height: 84 @@ -49,7 +49,7 @@ const Account = { var context = $canvas[0].getContext('2d') var imageObj = new window.Image() - imageObj.onload = function () { + imageObj.onload = function() { $('.userImageDiv canvas').remove() $('.userImageDiv img').hide() @@ -80,7 +80,7 @@ const Account = { $('#remove_image').val('0') } }, - removePicture: function () { + removePicture: function() { var self = Account $('.userImageDiv canvas').remove() @@ -91,15 +91,15 @@ const Account = { input.replaceWith(input.val('').clone(true)) $('#remove_image').val('1') }, - changeName: function () { + changeName: function() { $('.accountName').hide() $('.changeName').show() }, - showPass: function () { + showPass: function() { $('.toHide').show() $('.changePass').hide() }, - hidePass: function () { + hidePass: function() { $('.toHide').hide() $('.changePass').show() diff --git a/frontend/src/Metamaps/Admin.js b/frontend/src/Metamaps/Admin.js index d78fcecb..9cb80750 100644 --- a/frontend/src/Metamaps/Admin.js +++ b/frontend/src/Metamaps/Admin.js @@ -3,44 +3,43 @@ const Admin = { selectMetacodes: [], allMetacodes: [], - init: function () { + init: function() { var self = Admin $('#metacodes_value').val(self.selectMetacodes.toString()) }, - selectAll: function () { + selectAll: function() { var self = Admin $('.editMetacodes li').removeClass('toggledOff') self.selectMetacodes = self.allMetacodes.slice(0) $('#metacodes_value').val(self.selectMetacodes.toString()) }, - deselectAll: function () { + deselectAll: function() { var self = Admin $('.editMetacodes li').addClass('toggledOff') self.selectMetacodes = [] $('#metacodes_value').val(0) }, - liClickHandler: function () { + liClickHandler: function() { var self = Admin - if ($(this).attr('class') != 'toggledOff') { + if ($(this).attr('class') !== 'toggledOff') { $(this).addClass('toggledOff') - var value_to_remove = $(this).attr('id') - self.selectMetacodes.splice(self.selectMetacodes.indexOf(value_to_remove), 1) + const valueToRemove = $(this).attr('id') + self.selectMetacodes.splice(self.selectMetacodes.indexOf(valueToRemove), 1) $('#metacodes_value').val(self.selectMetacodes.toString()) - } - else if ($(this).attr('class') == 'toggledOff') { + } else if ($(this).attr('class') === 'toggledOff') { $(this).removeClass('toggledOff') self.selectMetacodes.push($(this).attr('id')) $('#metacodes_value').val(self.selectMetacodes.toString()) } }, - validate: function () { + validate: function() { var self = Admin - if (self.selectMetacodes.length == 0) { + if (self.selectMetacodes.length === 0) { window.alert('Would you pretty please select at least one metacode for the set?') return false } diff --git a/frontend/src/Metamaps/AutoLayout.js b/frontend/src/Metamaps/AutoLayout.js index 1408ba62..acbca6ff 100644 --- a/frontend/src/Metamaps/AutoLayout.js +++ b/frontend/src/Metamaps/AutoLayout.js @@ -7,7 +7,7 @@ const AutoLayout = { nextYshift: 0, timeToTurn: 0, - getNextCoord: function (opts = {}) { + getNextCoord: function(opts = {}) { var self = AutoLayout var nextX = self.nextX var nextY = self.nextY @@ -28,22 +28,19 @@ const AutoLayout = { self.timeToTurn = 0 // going right? turn down - if (self.nextXshift == 1 && self.nextYshift == 0) { + if (self.nextXshift === 1 && self.nextYshift === 0) { self.nextXshift = 0 self.nextYshift = 1 - } - // going down? turn left - else if (self.nextXshift == 0 && self.nextYshift == 1) { + } else if (self.nextXshift === 0 && self.nextYshift === 1) { + // going down? turn left self.nextXshift = -1 self.nextYshift = 0 - } - // going left? turn up - else if (self.nextXshift == -1 && self.nextYshift == 0) { + } else if (self.nextXshift === -1 && self.nextYshift === 0) { + // going left? turn up self.nextXshift = 0 self.nextYshift = -1 - } - // going up? turn right - else if (self.nextXshift == 0 && self.nextYshift == -1) { + } else if (self.nextXshift === 0 && self.nextYshift === -1) { + // going up? turn right self.nextXshift = 1 self.nextYshift = 0 } @@ -59,14 +56,14 @@ const AutoLayout = { } } }, - coordsTaken: function (x, y, mappings) { + coordsTaken: function(x, y, mappings) { if (mappings.findWhere({ xloc: x, yloc: y })) { return true } else { return false } }, - resetSpiral: function () { + resetSpiral: function() { var self = AutoLayout self.nextX = 0 self.nextY = 0 diff --git a/frontend/src/Metamaps/Control.js b/frontend/src/Metamaps/Control.js index 8305e097..8f613b16 100644 --- a/frontend/src/Metamaps/Control.js +++ b/frontend/src/Metamaps/Control.js @@ -14,16 +14,16 @@ import Settings from './Settings' import Visualize from './Visualize' const Control = { - init: function () {}, - selectNode: function (node, e) { + init: function() {}, + selectNode: function(node, e) { var filtered = node.getData('alpha') === 0 - if (filtered || Selected.Nodes.indexOf(node) != -1) return + if (filtered || Selected.Nodes.indexOf(node) !== -1) return node.selected = true node.setData('dim', 30, 'current') Selected.Nodes.push(node) }, - deselectAllNodes: function () { + deselectAllNodes: function() { var l = Selected.Nodes.length for (var i = l - 1; i >= 0; i -= 1) { var node = Selected.Nodes[i] @@ -31,7 +31,7 @@ const Control = { } Visualize.mGraph.plot() }, - deselectNode: function (node) { + deselectNode: function(node) { delete node.selected node.setData('dim', 25, 'current') @@ -39,7 +39,7 @@ const Control = { Selected.Nodes.splice( Selected.Nodes.indexOf(node), 1) }, - deleteSelected: function () { + deleteSelected: function() { if (!Active.Map) return var n = Selected.Nodes.length @@ -67,7 +67,7 @@ const Control = { GlobalUI.showDiv('#instructions') } }, - deleteSelectedNodes: function () { // refers to deleting topics permanently + deleteSelectedNodes: function() { // refers to deleting topics permanently if (!Active.Map) return var authorized = Active.Map.authorizeToEdit(Active.Mapper) @@ -83,7 +83,7 @@ const Control = { Control.deleteNode(node.id) } }, - deleteNode: function (nodeid) { // refers to deleting topics permanently + deleteNode: function(nodeid) { // refers to deleting topics permanently if (!Active.Map) return var authorized = Active.Map.authorizeToEdit(Active.Mapper) @@ -110,7 +110,7 @@ const Control = { GlobalUI.notifyUser('Only topics you created can be deleted') } }, - removeSelectedNodes: function () { // refers to removing topics permanently from a map + removeSelectedNodes: function() { // refers to removing topics permanently from a map if (Active.Topic) { // hideNode will handle synapses as well var nodeids = _.map(Selected.Nodes, function(node) { @@ -126,22 +126,20 @@ const Control = { } if (!Active.Map) return - var l = Selected.Nodes.length, - i, - node, - authorized = Active.Map.authorizeToEdit(Active.Mapper) + const l = Selected.Nodes.length + const authorized = Active.Map.authorizeToEdit(Active.Mapper) if (!authorized) { GlobalUI.notifyUser('Cannot edit Public map.') return } - for (i = l - 1; i >= 0; i -= 1) { - node = Selected.Nodes[i] + for (let i = l - 1; i >= 0; i -= 1) { + const node = Selected.Nodes[i] Control.removeNode(node.id) } }, - removeNode: function (nodeid) { // refers to removing topics permanently from a map + removeNode: function(nodeid) { // refers to removing topics permanently from a map if (!Active.Map) return var authorized = Active.Map.authorizeToEdit(Active.Mapper) @@ -162,24 +160,21 @@ const Control = { }]) Control.hideNode(nodeid) }, - hideSelectedNodes: function () { - var l = Selected.Nodes.length, - i, - node - - for (i = l - 1; i >= 0; i -= 1) { - node = Selected.Nodes[i] + hideSelectedNodes: function() { + const l = Selected.Nodes.length + for (let i = l - 1; i >= 0; i -= 1) { + const node = Selected.Nodes[i] Control.hideNode(node.id) } }, - hideNode: function (nodeid) { + hideNode: function(nodeid) { var node = Visualize.mGraph.graph.getNode(nodeid) var graph = Visualize.mGraph Control.deselectNode(node) node.setData('alpha', 0, 'end') - node.eachAdjacency(function (adj) { + node.eachAdjacency(function(adj) { adj.setData('alpha', 0, 'end') }) Visualize.mGraph.fx.animate({ @@ -188,9 +183,9 @@ const Control = { ], duration: 500 }) - setTimeout(function () { + setTimeout(function() { if (nodeid === Visualize.mGraph.root) { // && Visualize.type === "RGraph" - var newroot = _.find(graph.graph.nodes, function (n) { return n.id !== nodeid; }) + var newroot = _.find(graph.graph.nodes, function(n) { return n.id !== nodeid }) graph.root = newroot ? newroot.id : null } Visualize.mGraph.graph.removeNode(nodeid) @@ -198,10 +193,10 @@ const Control = { Filter.checkMetacodes() Filter.checkMappers() }, - selectEdge: function (edge) { - var filtered = edge.getData('alpha') === 0; // don't select if the edge is filtered + selectEdge: function(edge) { + var filtered = edge.getData('alpha') === 0 // don't select if the edge is filtered - if (filtered || Selected.Edges.indexOf(edge) != -1) return + if (filtered || Selected.Edges.indexOf(edge) !== -1) return var width = Mouse.edgeHoveringOver === edge ? 4 : 2 edge.setDataset('current', { @@ -213,7 +208,7 @@ const Control = { Selected.Edges.push(edge) }, - deselectAllEdges: function () { + deselectAllEdges: function() { var l = Selected.Edges.length for (var i = l - 1; i >= 0; i -= 1) { var edge = Selected.Edges[i] @@ -221,7 +216,7 @@ const Control = { } Visualize.mGraph.plot() }, - deselectEdge: function (edge) { + deselectEdge: function(edge) { edge.setData('showDesc', false, 'current') edge.setDataset('current', { @@ -242,10 +237,7 @@ const Control = { Selected.Edges.splice( Selected.Edges.indexOf(edge), 1) }, - deleteSelectedEdges: function () { // refers to deleting topics permanently - var edge, - l = Selected.Edges.length - + deleteSelectedEdges: function() { // refers to deleting topics permanently if (!Active.Map) return var authorized = Active.Map.authorizeToEdit(Active.Mapper) @@ -255,12 +247,13 @@ const Control = { return } - for (var i = l - 1; i >= 0; i -= 1) { - edge = Selected.Edges[i] + const l = Selected.Edges.length + for (let i = l - 1; i >= 0; i -= 1) { + const edge = Selected.Edges[i] Control.deleteEdge(edge) } }, - deleteEdge: function (edge) { + deleteEdge: function(edge) { if (!Active.Map) return var authorized = Active.Map.authorizeToEdit(Active.Mapper) @@ -297,13 +290,11 @@ const Control = { GlobalUI.notifyUser('Only synapses you created can be deleted') } }, - removeSelectedEdges: function () { + removeSelectedEdges: function() { // Topic view is handled by removeSelectedNodes if (!Active.Map) return - var l = Selected.Edges.length, - i, - edge + const l = Selected.Edges.length var authorized = Active.Map.authorizeToEdit(Active.Mapper) @@ -312,13 +303,13 @@ const Control = { return } - for (i = l - 1; i >= 0; i -= 1) { - edge = Selected.Edges[i] + for (let i = l - 1; i >= 0; i -= 1) { + const edge = Selected.Edges[i] Control.removeEdge(edge) } Selected.Edges = [ ] }, - removeEdge: function (edge) { + removeEdge: function(edge) { if (!Active.Map) return var authorized = Active.Map.authorizeToEdit(Active.Mapper) @@ -350,17 +341,15 @@ const Control = { mappableid: mappableid }]) }, - hideSelectedEdges: function () { - var edge, - l = Selected.Edges.length, - i - for (i = l - 1; i >= 0; i -= 1) { - edge = Selected.Edges[i] + hideSelectedEdges: function() { + const l = Selected.Edges.length + for (let i = l - 1; i >= 0; i -= 1) { + const edge = Selected.Edges[i] Control.hideEdge(edge) } Selected.Edges = [ ] }, - hideEdge: function (edge) { + hideEdge: function(edge) { var from = edge.nodeFrom.id var to = edge.nodeTo.id edge.setData('alpha', 0, 'end') @@ -369,24 +358,24 @@ const Control = { modes: ['edge-property:alpha'], duration: 500 }) - setTimeout(function () { + setTimeout(function() { Visualize.mGraph.graph.removeAdjacence(from, to) }, 500) Filter.checkSynapses() Filter.checkMappers() }, - updateSelectedPermissions: function (permission) { + updateSelectedPermissions: function(permission) { var edge, synapse, node, topic GlobalUI.notifyUser('Working...') // variables to keep track of how many nodes and synapses you had the ability to change the permission of - var nCount = 0, - sCount = 0 + var nCount = 0 + var sCount = 0 // change the permission of the selected synapses, if logged in user is the original creator - var l = Selected.Edges.length - for (var i = l - 1; i >= 0; i -= 1) { + const edgesLength = Selected.Edges.length + for (let i = edgesLength - 1; i >= 0; i -= 1) { edge = Selected.Edges[i] synapse = edge.getData('synapses')[0] @@ -399,8 +388,8 @@ const Control = { } // change the permission of the selected topics, if logged in user is the original creator - var l = Selected.Nodes.length - for (var i = l - 1; i >= 0; i -= 1) { + const nodesLength = Selected.Nodes.length + for (let i = nodesLength - 1; i >= 0; i -= 1) { node = Selected.Nodes[i] topic = node.getData('topic') @@ -418,12 +407,12 @@ const Control = { var message = nString + sString + ' you created updated to ' + permission GlobalUI.notifyUser(message) }, - updateSelectedMetacodes: function (metacode_id) { + updateSelectedMetacodes: function(metacodeId) { var node, topic GlobalUI.notifyUser('Working...') - var metacode = DataModel.Metacodes.get(metacode_id) + var metacode = DataModel.Metacodes.get(metacodeId) // variables to keep track of how many nodes and synapses you had the ability to change the permission of var nCount = 0 @@ -436,7 +425,7 @@ const Control = { if (topic.authorizeToEdit(Active.Mapper)) { topic.save({ - 'metacode_id': metacode_id + 'metacode_id': metacodeId }) nCount++ } diff --git a/frontend/src/Metamaps/Create.js b/frontend/src/Metamaps/Create.js index d12a5de5..7c3c4ff3 100644 --- a/frontend/src/Metamaps/Create.js +++ b/frontend/src/Metamaps/Create.js @@ -16,7 +16,7 @@ const Create = { newSelectedMetacodeNames: [], selectedMetacodes: [], newSelectedMetacodes: [], - init: function () { + init: function() { var self = Create self.newTopic.init() self.newSynapse.init() @@ -29,23 +29,23 @@ const Create = { $('#metacodeSwitchTabs .ui-tabs-nav li').removeClass('ui-corner-top').addClass('ui-corner-left') $('.customMetacodeList li').click(self.toggleMetacodeSelected) // within the custom metacode set tab }, - toggleMetacodeSelected: function () { + toggleMetacodeSelected: function() { var self = Create - if ($(this).attr('class') != 'toggledOff') { + if ($(this).attr('class') !== 'toggledOff') { $(this).addClass('toggledOff') - var value_to_remove = $(this).attr('id') - var name_to_remove = $(this).attr('data-name') - self.newSelectedMetacodes.splice(self.newSelectedMetacodes.indexOf(value_to_remove), 1) - self.newSelectedMetacodeNames.splice(self.newSelectedMetacodeNames.indexOf(name_to_remove), 1) - } else if ($(this).attr('class') == 'toggledOff') { + var valueToRemove = $(this).attr('id') + var nameToRemove = $(this).attr('data-name') + self.newSelectedMetacodes.splice(self.newSelectedMetacodes.indexOf(valueToRemove), 1) + self.newSelectedMetacodeNames.splice(self.newSelectedMetacodeNames.indexOf(nameToRemove), 1) + } else if ($(this).attr('class') === 'toggledOff') { $(this).removeClass('toggledOff') self.newSelectedMetacodes.push($(this).attr('id')) self.newSelectedMetacodeNames.push($(this).attr('data-name')) } }, - updateMetacodeSet: function (set, index, custom) { - if (custom && Create.newSelectedMetacodes.length == 0) { + updateMetacodeSet: function(set, index, custom) { + if (custom && Create.newSelectedMetacodes.length === 0) { window.alert('Please select at least one metacode to use!') return false } @@ -62,8 +62,7 @@ const Create = { Create.selectedMetacodeNames = [] Create.newSelectedMetacodes = [] Create.newSelectedMetacodeNames = [] - } - else if (custom) { + } else if (custom) { // uses .slice to avoid setting the two arrays to the same actual array Create.selectedMetacodes = Create.newSelectedMetacodes.slice(0) Create.selectedMetacodeNames = Create.newSelectedMetacodeNames.slice(0) @@ -79,7 +78,7 @@ const Create = { $('#metacodeImg, #metacodeImgTitle').empty() $('#metacodeImg').removeData('cloudcarousel') var newMetacodes = '' - metacodeModels.each(function (metacode) { + metacodeModels.each(function(metacode) { newMetacodes += '' + metacode.get('name') + '' }) @@ -107,20 +106,20 @@ const Create = { dataType: 'json', url: '/user/updatemetacodes', data: mdata, - success: function (data) { + success: function(data) { console.log('selected metacodes saved') }, - error: function () { + error: function() { console.log('failed to save selected metacodes') } }) }, - cancelMetacodeSetSwitch: function () { + cancelMetacodeSetSwitch: function() { var self = Create self.isSwitchingSet = false - if (self.selectedMetacodeSet != 'metacodeset-custom') { + if (self.selectedMetacodeSet !== 'metacodeset-custom') { $('.customMetacodeList li').addClass('toggledOff') self.selectedMetacodes = [] self.selectedMetacodeNames = [] @@ -140,17 +139,16 @@ const Create = { $('#topic_name').focus() }, newTopic: { - init: function () { - $('#topic_name').keyup(function () { + init: function() { + $('#topic_name').keyup(function() { Create.newTopic.name = $(this).val() }) - + $('.pinCarousel').click(function() { if (Create.newTopic.pinned) { $('.pinCarousel').removeClass('isPinned') Create.newTopic.pinned = false - } - else { + } else { $('.pinCarousel').addClass('isPinned') Create.newTopic.pinned = true } @@ -174,18 +172,18 @@ const Create = { [{ name: 'topic_autocomplete', limit: 8, - display: function (s) { return s.label; }, + display: function(s) { return s.label }, templates: { - suggestion: function (s) { + suggestion: function(s) { return Hogan.compile($('#topicAutocompleteTemplate').html()).render(s) } }, - source: topicBloodhound, + source: topicBloodhound }] ) // tell the autocomplete to submit the form with the topic you clicked on if you pick from the autocomplete - $('#topic_name').bind('typeahead:select', function (event, datum, dataset) { + $('#topic_name').bind('typeahead:select', function(event, datum, dataset) { Create.newTopic.beingCreated = false if (datum.rtype === 'topic') { Topic.getTopicFromAutocomplete(datum.id) @@ -209,7 +207,7 @@ const Create = { bringToFront: true }) $('.new_topic').hide() - $('#new_topic').attr('oncontextmenu','return false') //prevents the mouse up event from opening the default context menu on this element + $('#new_topic').attr('oncontextmenu', 'return false') // prevents the mouse up event from opening the default context menu on this element }, name: null, newId: 1, @@ -219,15 +217,15 @@ const Create = { y: null, addSynapse: false, pinned: false, - open: function () { - $('#new_topic').fadeIn('fast', function () { + open: function() { + $('#new_topic').fadeIn('fast', function() { $('#topic_name').focus() }) Create.newTopic.beingCreated = true Create.newTopic.name = '' GlobalUI.hideDiv('#instructions') }, - hide: function (force) { + hide: function(force) { if (force || !Create.newTopic.pinned) { $('#new_topic').fadeOut('fast') } @@ -240,28 +238,26 @@ const Create = { } Create.newTopic.beingCreated = false }, - reset: function () { + reset: function() { $('#topic_name').typeahead('val', '') } }, newSynapse: { - init: function () { - var self = Create.newSynapse - + init: function() { var synapseBloodhound = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { url: '/search/synapses?term=%QUERY', - wildcard: '%QUERY', - }, + wildcard: '%QUERY' + } }) var existingSynapseBloodhound = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { url: '/search/synapses?topic1id=%TOPIC1&topic2id=%TOPIC2', - prepare: function (query, settings) { + prepare: function(query, settings) { var self = Create.newSynapse if (Selected.Nodes.length < 2 && self.topic1id && self.topic2id) { settings.url = settings.url.replace('%TOPIC1', self.topic1id).replace('%TOPIC2', self.topic2id) @@ -269,42 +265,44 @@ const Create = { } else { return null } - }, - }, + } + } }) // initialize the autocomplete results for synapse creation $('#synapse_desc').typeahead( { highlight: true, - minLength: 2, + minLength: 2 }, [{ name: 'synapse_autocomplete', - display: function (s) { return s.label; }, + display: function(s) { return s.label }, templates: { - suggestion: function (s) { + suggestion: function(s) { return Hogan.compile("
{{label}}
").render(s) - }, + } }, - source: synapseBloodhound, + source: synapseBloodhound }, { name: 'existing_synapses', limit: 50, - display: function (s) { return s.label; }, + display: function(s) { return s.label }, templates: { - suggestion: function (s) { + suggestion: function(s) { return Hogan.compile($('#synapseAutocompleteTemplate').html()).render(s) }, header: '

Existing synapses

' }, - source: existingSynapseBloodhound, + source: existingSynapseBloodhound }] ) - $('#synapse_desc').keyup(function (e) { - var ESC = 27, BACKSPACE = 8, DELETE = 46 + $('#synapse_desc').keyup(function(e) { + const ESC = 27 + const BACKSPACE = 8 + const DELETE = 46 if (e.keyCode === BACKSPACE && $(this).val() === '' || e.keyCode === DELETE && $(this).val() === '' || e.keyCode === ESC) { @@ -313,13 +311,13 @@ const Create = { Create.newSynapse.description = $(this).val() }) - $('#synapse_desc').focusout(function () { + $('#synapse_desc').focusout(function() { if (Create.newSynapse.beingCreated) { Synapse.createSynapseLocally() } }) - $('#synapse_desc').bind('typeahead:select', function (event, datum, dataset) { + $('#synapse_desc').bind('typeahead:select', function(event, datum, dataset) { if (datum.id) { // if they clicked on an existing synapse get it Synapse.getSynapseFromAutocomplete(datum.id) } else { @@ -333,13 +331,13 @@ const Create = { topic1id: null, topic2id: null, newSynapseId: null, - open: function () { - $('#new_synapse').fadeIn(100, function () { + open: function() { + $('#new_synapse').fadeIn(100, function() { $('#synapse_desc').focus() }) Create.newSynapse.beingCreated = true }, - hide: function () { + hide: function() { $('#new_synapse').fadeOut('fast') $('#synapse_desc').typeahead('val', '') Create.newSynapse.beingCreated = false @@ -348,7 +346,7 @@ const Create = { Create.newSynapse.topic2id = 0 Mouse.synapseStartCoordinates = [] if (Visualize.mGraph) Visualize.mGraph.plot() - }, + } } } diff --git a/frontend/src/Metamaps/DataModel/Map.js b/frontend/src/Metamaps/DataModel/Map.js index 2ab98575..17e9ad18 100644 --- a/frontend/src/Metamaps/DataModel/Map.js +++ b/frontend/src/Metamaps/DataModel/Map.js @@ -9,18 +9,13 @@ import InfoBox from '../Map/InfoBox' import Mapper from '../Mapper' import Realtime from '../Realtime' -import MapperCollection from './MapperCollection' -import TopicCollection from './TopicCollection' -import SynapseCollection from './SynapseCollection' -import MappingCollection from './MappingCollection' - const Map = Backbone.Model.extend({ urlRoot: '/maps', blacklist: ['created_at', 'updated_at', 'created_at_clean', 'updated_at_clean', 'user_name', 'contributor_count', 'topic_count', 'synapse_count', 'topics', 'synapses', 'mappings', 'mappers'], - toJSON: function (options) { + toJSON: function(options) { return _.omit(this.attributes, this.blacklist) }, - save: function (key, val, options) { + save: function(key, val, options) { var attrs // Handle both `"key", value` and `{key: value}` -style arguments. @@ -34,20 +29,20 @@ const Map = Backbone.Model.extend({ var newOptions = options || {} var s = newOptions.success - newOptions.success = function (model, response, opt) { + newOptions.success = function(model, response, opt) { if (s) s(model, response, opt) model.trigger('saved') } return Backbone.Model.prototype.save.call(this, attrs, newOptions) }, - initialize: function () { + initialize: function() { this.on('changeByOther', this.updateView) this.on('saved', this.savedEvent) }, - savedEvent: function () { + savedEvent: function() { Realtime.updateMap(this) }, - authorizeToEdit: function (mapper) { + authorizeToEdit: function(mapper) { if (mapper && ( this.get('permission') === 'commons' || (this.get('collaborator_ids') || []).includes(mapper.get('id')) || @@ -57,17 +52,17 @@ const Map = Backbone.Model.extend({ return false } }, - authorizePermissionChange: function (mapper) { + authorizePermissionChange: function(mapper) { if (mapper && this.get('user_id') === mapper.get('id')) { return true } else { return false } }, - getUser: function () { + getUser: function() { return Mapper.get(this.get('user_id')) }, - updateView: function () { + updateView: function() { var map = Active.Map var isActiveMap = this.id === map.id if (isActiveMap) { @@ -78,7 +73,7 @@ const Map = Backbone.Model.extend({ document.title = this.get('name') + ' | Metamaps' } }, - updateMapWrapper: function () { + updateMapWrapper: function() { var map = Active.Map var isActiveMap = this.id === map.id var authorized = map && map.authorizeToEdit(Active.Mapper) ? 'canEditMap' : '' diff --git a/frontend/src/Metamaps/DataModel/MapCollection.js b/frontend/src/Metamaps/DataModel/MapCollection.js index 22bbcf7b..b15a945f 100644 --- a/frontend/src/Metamaps/DataModel/MapCollection.js +++ b/frontend/src/Metamaps/DataModel/MapCollection.js @@ -7,7 +7,7 @@ import Map from './Map' const MapCollection = Backbone.Collection.extend({ model: Map, - initialize: function (models, options) { + initialize: function(models, options) { this.id = options.id this.sortBy = options.sortBy @@ -18,14 +18,14 @@ const MapCollection = Backbone.Collection.extend({ // this.page represents the NEXT page to fetch this.page = models.length > 0 ? (models.length < 20 ? 'loadedAll' : 2) : 1 }, - url: function () { + url: function() { if (!this.mapperId) { return '/explore/' + this.id + '.json' } else { return '/explore/mapper/' + this.mapperId + '.json' } }, - comparator: function (a, b) { + comparator: function(a, b) { a = a.get(this.sortBy) b = b.get(this.sortBy) var temp @@ -42,7 +42,7 @@ const MapCollection = Backbone.Collection.extend({ } return a > b ? 1 : a < b ? -1 : 0 }, - getMaps: function (cb) { + getMaps: function(cb) { var self = this Loading.show() @@ -53,7 +53,7 @@ const MapCollection = Backbone.Collection.extend({ remove: false, silent: true, data: { page: this.page }, - success: function (collection, response, options) { + success: function(collection, response, options) { // you can pass additional options to the event you trigger here as well if (collection.length - numBefore < 20) { self.page = 'loadedAll' @@ -62,7 +62,7 @@ const MapCollection = Backbone.Collection.extend({ } self.trigger('successOnFetch', cb) }, - error: function (collection, response, options) { + error: function(collection, response, options) { // you can pass additional options to the event you trigger here as well self.trigger('errorOnFetch') } diff --git a/frontend/src/Metamaps/DataModel/Mapper.js b/frontend/src/Metamaps/DataModel/Mapper.js index 39e83503..f772c288 100644 --- a/frontend/src/Metamaps/DataModel/Mapper.js +++ b/frontend/src/Metamaps/DataModel/Mapper.js @@ -6,10 +6,10 @@ import outdent from 'outdent' const Mapper = Backbone.Model.extend({ urlRoot: '/users', blacklist: ['created_at', 'updated_at'], - toJSON: function (options) { + toJSON: function(options) { return _.omit(this.attributes, this.blacklist) }, - prepareLiForFilter: function () { + prepareLiForFilter: function() { return outdent`
  • ${this.get('name')} diff --git a/frontend/src/Metamaps/DataModel/Mapping.js b/frontend/src/Metamaps/DataModel/Mapping.js index 282c419f..2cd2b0b8 100644 --- a/frontend/src/Metamaps/DataModel/Mapping.js +++ b/frontend/src/Metamaps/DataModel/Mapping.js @@ -10,10 +10,10 @@ import Topic from '../Topic' const Mapping = Backbone.Model.extend({ urlRoot: '/mappings', blacklist: ['created_at', 'updated_at'], - toJSON: function (options) { + toJSON: function(options) { return _.omit(this.attributes, this.blacklist) }, - initialize: function () { + initialize: function() { if (this.isNew()) { this.set({ 'user_id': Active.Mapper.id, @@ -21,14 +21,14 @@ const Mapping = Backbone.Model.extend({ }) } }, - getMap: function () { + getMap: function() { return Map.get(this.get('map_id')) }, - getTopic: function () { + getTopic: function() { if (this.get('mappable_type') !== 'Topic') return false return Topic.get(this.get('mappable_id')) }, - getSynapse: function () { + getSynapse: function() { if (this.get('mappable_type') !== 'Synapse') return false return Synapse.get(this.get('mappable_id')) } diff --git a/frontend/src/Metamaps/DataModel/Message.js b/frontend/src/Metamaps/DataModel/Message.js index 00f1cf4b..5def166f 100644 --- a/frontend/src/Metamaps/DataModel/Message.js +++ b/frontend/src/Metamaps/DataModel/Message.js @@ -5,7 +5,7 @@ try { Backbone.$ = window.$ } catch (err) {} const Message = Backbone.Model.extend({ urlRoot: '/messages', blacklist: ['created_at', 'updated_at'], - toJSON: function (options) { + toJSON: function(options) { return _.omit(this.attributes, this.blacklist) } }) diff --git a/frontend/src/Metamaps/DataModel/Metacode.js b/frontend/src/Metamaps/DataModel/Metacode.js index fbd13755..e7ee5a31 100644 --- a/frontend/src/Metamaps/DataModel/Metacode.js +++ b/frontend/src/Metamaps/DataModel/Metacode.js @@ -3,13 +3,13 @@ try { Backbone.$ = window.$ } catch (err) {} import outdent from 'outdent' const Metacode = Backbone.Model.extend({ - initialize: function () { + initialize: function() { var image = new window.Image() image.crossOrigin = 'Anonymous' image.src = this.get('icon') this.set('image', image) }, - prepareLiForFilter: function () { + prepareLiForFilter: function() { return outdent`
  • ${this.get('name')} diff --git a/frontend/src/Metamaps/DataModel/MetacodeCollection.js b/frontend/src/Metamaps/DataModel/MetacodeCollection.js index 03c41613..80022780 100644 --- a/frontend/src/Metamaps/DataModel/MetacodeCollection.js +++ b/frontend/src/Metamaps/DataModel/MetacodeCollection.js @@ -6,7 +6,7 @@ import Metacode from './Metacode' const MetacodeCollection = Backbone.Collection.extend({ model: Metacode, url: '/metacodes', - comparator: function (a, b) { + comparator: function(a, b) { a = a.get('name').toLowerCase() b = b.get('name').toLowerCase() return a > b ? 1 : a < b ? -1 : 0 diff --git a/frontend/src/Metamaps/DataModel/Synapse.js b/frontend/src/Metamaps/DataModel/Synapse.js index a60611a3..e5002824 100644 --- a/frontend/src/Metamaps/DataModel/Synapse.js +++ b/frontend/src/Metamaps/DataModel/Synapse.js @@ -17,10 +17,10 @@ import DataModel from './index' const Synapse = Backbone.Model.extend({ urlRoot: '/synapses', blacklist: ['edge', 'created_at', 'updated_at'], - toJSON: function (options) { + toJSON: function(options) { return _.omit(this.attributes, this.blacklist) }, - save: function (key, val, options) { + save: function(key, val, options) { var attrs // Handle both `"key", value` and `{key: value}` -style arguments. @@ -36,7 +36,7 @@ const Synapse = Backbone.Model.extend({ var permBefore = this.get('permission') - newOptions.success = function (model, response, opt) { + newOptions.success = function(model, response, opt) { if (s) s(model, response, opt) model.trigger('saved') @@ -48,7 +48,7 @@ const Synapse = Backbone.Model.extend({ } return Backbone.Model.prototype.save.call(this, attrs, newOptions) }, - initialize: function () { + initialize: function() { if (this.isNew()) { this.set({ 'user_id': Active.Mapper.id, @@ -60,7 +60,7 @@ const Synapse = Backbone.Model.extend({ this.on('changeByOther', this.updateCardView) this.on('change', this.updateEdgeView) this.on('saved', this.savedEvent) - this.on('noLongerPrivate', function () { + this.on('noLongerPrivate', function() { var newSynapseData = { mappingid: this.getMapping().id, mappableid: this.id @@ -68,7 +68,7 @@ const Synapse = Backbone.Model.extend({ $(document).trigger(JIT.events.newSynapse, [newSynapseData]) }) - this.on('nowPrivate', function () { + this.on('nowPrivate', function() { $(document).trigger(JIT.events.removeSynapse, [{ mappableid: this.id }]) @@ -76,28 +76,28 @@ const Synapse = Backbone.Model.extend({ this.on('change:desc', Filter.checkSynapses, this) }, - prepareLiForFilter: function () { + prepareLiForFilter: function() { return outdent`
  • synapse icon

    ${this.get('desc')}

  • ` }, - authorizeToEdit: function (mapper) { + authorizeToEdit: function(mapper) { if (mapper && (this.get('calculated_permission') === 'commons' || this.get('collaborator_ids').includes(mapper.get('id')) || this.get('user_id') === mapper.get('id'))) return true else return false }, - authorizePermissionChange: function (mapper) { + authorizePermissionChange: function(mapper) { if (mapper && this.get('user_id') === mapper.get('id')) return true else return false }, - getTopic1: function () { + getTopic1: function() { return DataModel.Topics.get(this.get('topic1_id')) }, - getTopic2: function () { + getTopic2: function() { return DataModel.Topics.get(this.get('topic2_id')) }, - getDirection: function () { + getDirection: function() { var t1 = this.getTopic1() var t2 = this.getTopic2() @@ -106,7 +106,7 @@ const Synapse = Backbone.Model.extend({ t2.get('node').id ] : false }, - getMapping: function () { + getMapping: function() { if (!Active.Map) return false return DataModel.Mappings.findWhere({ @@ -115,7 +115,7 @@ const Synapse = Backbone.Model.extend({ mappable_id: this.isNew() ? this.cid : this.id }) }, - createEdge: function (providedMapping) { + createEdge: function(providedMapping) { var mapping, mappingID var synapseID = this.isNew() ? this.cid : this.id @@ -137,7 +137,7 @@ const Synapse = Backbone.Model.extend({ return edge }, - updateEdge: function () { + updateEdge: function() { var mapping var edge = this.get('edge') edge.getData('synapses').push(this) @@ -149,14 +149,14 @@ const Synapse = Backbone.Model.extend({ return edge }, - savedEvent: function () { + savedEvent: function() { Realtime.updateSynapse(this) }, - updateViews: function () { + updateViews: function() { this.updateCardView() this.updateEdgeView() }, - updateCardView: function () { + updateCardView: function() { var onPageWithSynapseCard = Active.Map || Active.Topic var edge = this.get('edge') @@ -165,7 +165,7 @@ const Synapse = Backbone.Model.extend({ SynapseCard.showCard(edge) } }, - updateEdgeView: function () { + updateEdgeView: function() { var onPageWithSynapseCard = Active.Map || Active.Topic var edge = this.get('edge') diff --git a/frontend/src/Metamaps/DataModel/Topic.js b/frontend/src/Metamaps/DataModel/Topic.js index d8426c92..1e27d138 100644 --- a/frontend/src/Metamaps/DataModel/Topic.js +++ b/frontend/src/Metamaps/DataModel/Topic.js @@ -16,10 +16,10 @@ import DataModel from './index' const Topic = Backbone.Model.extend({ urlRoot: '/topics', blacklist: ['node', 'created_at', 'updated_at', 'user_name', 'user_image', 'map_count', 'synapse_count'], - toJSON: function (options) { + toJSON: function(options) { return _.omit(this.attributes, this.blacklist) }, - save: function (key, val, options) { + save: function(key, val, options) { var attrs // Handle both `"key", value` and `{key: value}` -style arguments. @@ -35,7 +35,7 @@ const Topic = Backbone.Model.extend({ var permBefore = this.get('permission') - newOptions.success = function (model, response, opt) { + newOptions.success = function(model, response, opt) { if (s) s(model, response, opt) model.trigger('saved') model.set('calculated_permission', model.get('permission')) @@ -48,7 +48,7 @@ const Topic = Backbone.Model.extend({ } return Backbone.Model.prototype.save.call(this, attrs, newOptions) }, - initialize: function () { + initialize: function() { if (this.isNew()) { this.set({ 'user_id': Active.Mapper.id, @@ -61,14 +61,14 @@ const Topic = Backbone.Model.extend({ this.on('changeByOther', this.updateCardView) this.on('change', this.updateNodeView) this.on('saved', this.savedEvent) - this.on('nowPrivate', function () { + this.on('nowPrivate', function() { var removeTopicData = { mappableid: this.id } $(document).trigger(JIT.events.removeTopic, [removeTopicData]) }) - this.on('noLongerPrivate', function () { + this.on('noLongerPrivate', function() { var newTopicData = { mappingid: this.getMapping().id, mappableid: this.id @@ -79,7 +79,7 @@ const Topic = Backbone.Model.extend({ this.on('change:metacode_id', Filter.checkMetacodes, this) }, - authorizeToEdit: function (mapper) { + authorizeToEdit: function(mapper) { if (mapper && (this.get('user_id') === mapper.get('id') || this.get('calculated_permission') === 'commons' || @@ -89,15 +89,15 @@ const Topic = Backbone.Model.extend({ return false } }, - authorizePermissionChange: function (mapper) { + authorizePermissionChange: function(mapper) { if (mapper && this.get('user_id') === mapper.get('id')) return true else return false }, - getDate: function () {}, - getMetacode: function () { + getDate: function() {}, + getMetacode: function() { return DataModel.Metacodes.get(this.get('metacode_id')) }, - getMapping: function () { + getMapping: function() { if (!Active.Map) return false return DataModel.Mappings.findWhere({ @@ -106,7 +106,7 @@ const Topic = Backbone.Model.extend({ mappable_id: this.isNew() ? this.cid : this.id }) }, - createNode: function () { + createNode: function() { var mapping var node = { adjacencies: [], @@ -124,7 +124,7 @@ const Topic = Backbone.Model.extend({ return node }, - updateNode: function () { + updateNode: function() { var mapping var node = this.get('node') node.setData('topic', this) @@ -136,10 +136,10 @@ const Topic = Backbone.Model.extend({ return node }, - savedEvent: function () { + savedEvent: function() { Realtime.updateTopic(this) }, - updateViews: function () { + updateViews: function() { var onPageWithTopicCard = Active.Map || Active.Topic var node = this.get('node') // update topic card, if this topic is the one open there @@ -153,7 +153,7 @@ const Topic = Backbone.Model.extend({ Visualize.mGraph.plot() } }, - updateCardView: function () { + updateCardView: function() { var onPageWithTopicCard = Active.Map || Active.Topic var node = this.get('node') // update topic card, if this topic is the one open there @@ -161,7 +161,7 @@ const Topic = Backbone.Model.extend({ TopicCard.showCard(node) } }, - updateNodeView: function () { + updateNodeView: function() { var onPageWithTopicCard = Active.Map || Active.Topic var node = this.get('node') diff --git a/frontend/src/Metamaps/DataModel/index.js b/frontend/src/Metamaps/DataModel/index.js index 4e62113d..6235b879 100644 --- a/frontend/src/Metamaps/DataModel/index.js +++ b/frontend/src/Metamaps/DataModel/index.js @@ -54,7 +54,7 @@ const DataModel = { Synapses: new SynapseCollection(), Topics: new TopicCollection(), - init: function (serverData) { + init: function(serverData) { var self = DataModel // workaround circular import problem @@ -101,18 +101,18 @@ const DataModel = { self.attachCollectionEvents() }, - attachCollectionEvents: function () { - DataModel.Topics.on('add remove', function (topic) { + attachCollectionEvents: function() { + DataModel.Topics.on('add remove', function(topic) { InfoBox.updateNumbers() Filter.checkMetacodes() Filter.checkMappers() }) - DataModel.Synapses.on('add remove', function (synapse) { + DataModel.Synapses.on('add remove', function(synapse) { InfoBox.updateNumbers() Filter.checkSynapses() Filter.checkMappers() }) - DataModel.Mappings.on('add remove', function (mapping) { + DataModel.Mappings.on('add remove', function(mapping) { InfoBox.updateNumbers() Filter.checkSynapses() Filter.checkMetacodes() diff --git a/frontend/src/Metamaps/Filter.js b/frontend/src/Metamaps/Filter.js index 271e5758..8f45423e 100644 --- a/frontend/src/Metamaps/Filter.js +++ b/frontend/src/Metamaps/Filter.js @@ -23,7 +23,7 @@ const Filter = { }, isOpen: false, changing: false, - init: function () { + init: function() { var self = Filter $('.sidebarFilterIcon').click(self.toggleBox) @@ -38,7 +38,7 @@ const Filter = { self.bindLiClicks() self.getFilterData() }, - toggleBox: function (event) { + toggleBox: function(event) { var self = Filter if (self.isOpen) self.close() @@ -46,7 +46,7 @@ const Filter = { event.stopPropagation() }, - open: function () { + open: function() { var self = Filter GlobalUI.Account.close() @@ -56,26 +56,26 @@ const Filter = { self.changing = true var height = $(document).height() - 108 - $('.sidebarFilterBox').css('max-height', height + 'px').fadeIn(200, function () { + $('.sidebarFilterBox').css('max-height', height + 'px').fadeIn(200, function() { self.changing = false self.isOpen = true }) } }, - close: function () { + close: function() { var self = Filter $('.sidebarFilterIcon div').removeClass('hide') if (!self.changing) { self.changing = true - $('.sidebarFilterBox').fadeOut(200, function () { + $('.sidebarFilterBox').fadeOut(200, function() { self.changing = false self.isOpen = false }) } }, - reset: function () { + reset: function() { var self = Filter self.filters.metacodes = [] @@ -95,30 +95,30 @@ const Filter = { Most of this data essentially depends on the ruby function which are happening for filter inside view filterBox But what these function do is load this data into three accessible array within java : metacodes, mappers and synapses */ - getFilterData: function () { + getFilterData: function() { var self = Filter var metacode, mapper, synapse - $('#filter_by_metacode li').each(function () { + $('#filter_by_metacode li').each(function() { metacode = $(this).attr('data-id') self.filters.metacodes.push(metacode) self.visible.metacodes.push(metacode) }) - $('#filter_by_mapper li').each(function () { + $('#filter_by_mapper li').each(function() { mapper = ($(this).attr('data-id')) self.filters.mappers.push(mapper) self.visible.mappers.push(mapper) }) - $('#filter_by_synapse li').each(function () { + $('#filter_by_synapse li').each(function() { synapse = ($(this).attr('data-id')) self.filters.synapses.push(synapse) self.visible.synapses.push(synapse) }) }, - bindLiClicks: function () { + bindLiClicks: function() { var self = Filter $('#filter_by_metacode ul li').unbind().click(self.toggleMetacode) $('#filter_by_mapper ul li').unbind().click(self.toggleMapper) @@ -129,7 +129,7 @@ const Filter = { /* @param */ - updateFilters: function (collection, propertyToCheck, correlatedModel, filtersToUse, listToModify) { + updateFilters: function(collection, propertyToCheck, correlatedModel, filtersToUse, listToModify) { var self = Filter var newList = [] @@ -139,7 +139,7 @@ const Filter = { // the first option enables us to accept // ['Topics', 'Synapses'] as 'collection' if (typeof collection === 'object') { - DataModel[collection[0]].each(function (model) { + DataModel[collection[0]].each(function(model) { var prop = model.get(propertyToCheck) if (prop !== null) { prop = prop.toString() @@ -148,7 +148,7 @@ const Filter = { } } }) - DataModel[collection[1]].each(function (model) { + DataModel[collection[1]].each(function(model) { var prop = model.get(propertyToCheck) if (prop !== null) { prop = prop.toString() @@ -158,7 +158,7 @@ const Filter = { } }) } else if (typeof collection === 'string') { - DataModel[collection].each(function (model) { + DataModel[collection].each(function(model) { var prop = model.get(propertyToCheck) if (prop !== null) { prop = prop.toString() @@ -173,8 +173,8 @@ const Filter = { added = _.difference(newList, self.filters[filtersToUse]) // remove the list items for things no longer present on the map - _.each(removed, function (identifier) { - $('#filter_by_' + listToModify + ' li[data-id="' + identifier + '"]').fadeOut('fast', function () { + _.each(removed, function(identifier) { + $('#filter_by_' + listToModify + ' li[data-id="' + identifier + '"]').fadeOut('fast', function() { $(this).remove() }) const index = self.visible[filtersToUse].indexOf(identifier) @@ -182,13 +182,13 @@ const Filter = { }) var model, li, jQueryLi - function sortAlpha (a, b) { + function sortAlpha(a, b) { return a.childNodes[1].innerHTML.toLowerCase() > b.childNodes[1].innerHTML.toLowerCase() ? 1 : -1 } // for each new filter to be added, create a list item for it and fade it in - _.each(added, function (identifier) { + _.each(added, function(identifier) { model = DataModel[correlatedModel].get(identifier) || - DataModel[correlatedModel].find(function (model) { + DataModel[correlatedModel].find(function(model) { return model.get(propertyToCheck) === identifier }) li = model.prepareLiForFilter() @@ -204,25 +204,24 @@ const Filter = { // make sure clicks on list items still trigger the right events self.bindLiClicks() }, - checkMetacodes: function () { + checkMetacodes: function() { var self = Filter self.updateFilters('Topics', 'metacode_id', 'Metacodes', 'metacodes', 'metacode') }, - checkMappers: function () { + checkMappers: function() { var self = Filter - var onMap = Active.Map ? true : false - if (onMap) { + if (Active.Map) { self.updateFilters('Mappings', 'user_id', 'Mappers', 'mappers', 'mapper') } else { // on topic view self.updateFilters(['Topics', 'Synapses'], 'user_id', 'Creators', 'mappers', 'mapper') } }, - checkSynapses: function () { + checkSynapses: function() { var self = Filter self.updateFilters('Synapses', 'desc', 'Synapses', 'synapses', 'synapse') }, - filterAllMetacodes: function (e) { + filterAllMetacodes: function(e) { var self = Filter $('#filter_by_metacode ul li').addClass('toggledOff') $('.showAllMetacodes').removeClass('active') @@ -230,7 +229,7 @@ const Filter = { self.visible.metacodes = [] self.passFilters() }, - filterNoMetacodes: function (e) { + filterNoMetacodes: function(e) { var self = Filter $('#filter_by_metacode ul li').removeClass('toggledOff') $('.showAllMetacodes').addClass('active') @@ -238,7 +237,7 @@ const Filter = { self.visible.metacodes = self.filters.metacodes.slice() self.passFilters() }, - filterAllMappers: function (e) { + filterAllMappers: function(e) { var self = Filter $('#filter_by_mapper ul li').addClass('toggledOff') $('.showAllMappers').removeClass('active') @@ -246,7 +245,7 @@ const Filter = { self.visible.mappers = [] self.passFilters() }, - filterNoMappers: function (e) { + filterNoMappers: function(e) { var self = Filter $('#filter_by_mapper ul li').removeClass('toggledOff') $('.showAllMappers').addClass('active') @@ -254,7 +253,7 @@ const Filter = { self.visible.mappers = self.filters.mappers.slice() self.passFilters() }, - filterAllSynapses: function (e) { + filterAllSynapses: function(e) { var self = Filter $('#filter_by_synapse ul li').addClass('toggledOff') $('.showAllSynapses').removeClass('active') @@ -262,7 +261,7 @@ const Filter = { self.visible.synapses = [] self.passFilters() }, - filterNoSynapses: function (e) { + filterNoSynapses: function(e) { var self = Filter $('#filter_by_synapse ul li').removeClass('toggledOff') $('.showAllSynapses').addClass('active') @@ -273,28 +272,27 @@ const Filter = { // an abstraction function for toggleMetacode, toggleMapper, toggleSynapse // to reduce code redundancy // gets called in the context of a list item in a filter box - toggleLi: function (whichToFilter) { - var self = Filter, index + toggleLi: function(whichToFilter) { + var self = Filter var id = $(this).attr('data-id') - if (self.visible[whichToFilter].indexOf(id) == -1) { + if (self.visible[whichToFilter].indexOf(id) === -1) { self.visible[whichToFilter].push(id) $(this).removeClass('toggledOff') } else { - index = self.visible[whichToFilter].indexOf(id) + const index = self.visible[whichToFilter].indexOf(id) self.visible[whichToFilter].splice(index, 1) $(this).addClass('toggledOff') } self.passFilters() }, - toggleMetacode: function () { + toggleMetacode: function() { var self = Filter self.toggleLi.call(this, 'metacodes') if (self.visible.metacodes.length === self.filters.metacodes.length) { $('.showAllMetacodes').addClass('active') $('.hideAllMetacodes').removeClass('active') - } - else if (self.visible.metacodes.length === 0) { + } else if (self.visible.metacodes.length === 0) { $('.showAllMetacodes').removeClass('active') $('.hideAllMetacodes').addClass('active') } else { @@ -302,15 +300,14 @@ const Filter = { $('.hideAllMetacodes').removeClass('active') } }, - toggleMapper: function () { + toggleMapper: function() { var self = Filter self.toggleLi.call(this, 'mappers') if (self.visible.mappers.length === self.filters.mappers.length) { $('.showAllMappers').addClass('active') $('.hideAllMappers').removeClass('active') - } - else if (self.visible.mappers.length === 0) { + } else if (self.visible.mappers.length === 0) { $('.showAllMappers').removeClass('active') $('.hideAllMappers').addClass('active') } else { @@ -318,15 +315,14 @@ const Filter = { $('.hideAllMappers').removeClass('active') } }, - toggleSynapse: function () { + toggleSynapse: function() { var self = Filter self.toggleLi.call(this, 'synapses') if (self.visible.synapses.length === self.filters.synapses.length) { $('.showAllSynapses').addClass('active') $('.hideAllSynapses').removeClass('active') - } - else if (self.visible.synapses.length === 0) { + } else if (self.visible.synapses.length === 0) { $('.showAllSynapses').removeClass('active') $('.hideAllSynapses').addClass('active') } else { @@ -334,71 +330,65 @@ const Filter = { $('.hideAllSynapses').removeClass('active') } }, - passFilters: function () { + passFilters: function() { var self = Filter var visible = self.visible var passesMetacode, passesMapper, passesSynapse - var onMap - if (Active.Map) { - onMap = true - } - else if (Active.Topic) { - onMap = false - } + var opacityForFilter = Active.Map ? 0 : 0.4 - var opacityForFilter = onMap ? 0 : 0.4 - - DataModel.Topics.each(function (topic) { + DataModel.Topics.each(function(topic) { var n = topic.get('node') - var metacode_id = topic.get('metacode_id').toString() + var metacodeId = topic.get('metacode_id').toString() - if (visible.metacodes.indexOf(metacode_id) == -1) passesMetacode = false + if (visible.metacodes.indexOf(metacodeId) === -1) passesMetacode = false else passesMetacode = true - if (onMap) { + if (Active.Map) { // when on a map, // we filter by mapper according to the person who added the // topic or synapse to the map - var user_id = topic.getMapping().get('user_id').toString() - if (visible.mappers.indexOf(user_id) == -1) passesMapper = false + let userId = topic.getMapping().get('user_id').toString() + if (visible.mappers.indexOf(userId) === -1) passesMapper = false else passesMapper = true } else { // when on a topic view, // we filter by mapper according to the person who created the // topic or synapse - var user_id = topic.get('user_id').toString() - if (visible.mappers.indexOf(user_id) == -1) passesMapper = false + let userId = topic.get('user_id').toString() + if (visible.mappers.indexOf(userId) === -1) passesMapper = false else passesMapper = true } if (passesMetacode && passesMapper) { if (n) { n.setData('alpha', 1, 'end') + } else { + console.log(topic) } - else console.log(topic) } else { if (n) { Control.deselectNode(n, true) n.setData('alpha', opacityForFilter, 'end') - n.eachAdjacency(function (e) { + n.eachAdjacency(function(e) { Control.deselectEdge(e, true) }) + } else { + console.log(topic) } - else console.log(topic) } }) // flag all the edges back to 'untouched' - DataModel.Synapses.each(function (synapse) { + DataModel.Synapses.each(function(synapse) { var e = synapse.get('edge') e.setData('touched', false) }) - DataModel.Synapses.each(function (synapse) { + DataModel.Synapses.each(function(synapse) { var e = synapse.get('edge') var desc - var user_id = synapse.get('user_id').toString() + var userId = synapse.get('user_id').toString() if (e && !e.getData('touched')) { var synapses = e.getData('synapses') @@ -406,7 +396,7 @@ const Filter = { // if any of the synapses represent by the edge are still unfiltered // leave the edge visible passesSynapse = false - for (var i = 0; i < synapses.length; i++) { + for (let i = 0; i < synapses.length; i++) { desc = synapses[i].get('desc') if (visible.synapses.indexOf(desc) > -1) passesSynapse = true } @@ -416,9 +406,9 @@ const Filter = { var displayIndex = e.getData('displayIndex') ? e.getData('displayIndex') : 0 var displayedSynapse = synapses[displayIndex] desc = displayedSynapse.get('desc') - if (passesSynapse && visible.synapses.indexOf(desc) == -1) { + if (passesSynapse && visible.synapses.indexOf(desc) === -1) { // iterate and find an unfiltered one - for (var i = 0; i < synapses.length; i++) { + for (let i = 0; i < synapses.length; i++) { desc = synapses[i].get('desc') if (visible.synapses.indexOf(desc) > -1) { e.setData('displayIndex', i) @@ -427,13 +417,13 @@ const Filter = { } } - if (onMap) { + if (Active.Map) { // when on a map, // we filter by mapper according to the person who added the // topic or synapse to the map - user_id = synapse.getMapping().get('user_id').toString() + userId = synapse.getMapping().get('user_id').toString() } - if (visible.mappers.indexOf(user_id) == -1) passesMapper = false + if (visible.mappers.indexOf(userId) === -1) passesMapper = false else passesMapper = true var color = Settings.colors.synapses.normal @@ -446,8 +436,9 @@ const Filter = { } e.setData('touched', true) + } else if (!e) { + console.log(synapse) } - else if (!e) console.log(synapse) }) // run the animation diff --git a/frontend/src/Metamaps/GlobalUI/Account.js b/frontend/src/Metamaps/GlobalUI/Account.js index 210627ff..a2823ef5 100644 --- a/frontend/src/Metamaps/GlobalUI/Account.js +++ b/frontend/src/Metamaps/GlobalUI/Account.js @@ -5,16 +5,16 @@ import Filter from '../Filter' const Account = { isOpen: false, changing: false, - init: function () { + init: function() { var self = Account $('.sidebarAccountIcon').click(self.toggleBox) - $('.sidebarAccountBox').click(function (event) { + $('.sidebarAccountBox').click(function(event) { event.stopPropagation() }) $('body').click(self.close) }, - toggleBox: function (event) { + toggleBox: function(event) { var self = Account if (self.isOpen) self.close() @@ -22,7 +22,7 @@ const Account = { event.stopPropagation() }, - open: function () { + open: function() { var self = Account Filter.close() @@ -30,21 +30,21 @@ const Account = { if (!self.isOpen && !self.changing) { self.changing = true - $('.sidebarAccountBox').fadeIn(200, function () { + $('.sidebarAccountBox').fadeIn(200, function() { self.changing = false self.isOpen = true $('.sidebarAccountBox #user_email').focus() }) } }, - close: function () { + close: function() { var self = Account $('.sidebarAccountIcon .tooltipsUnder').removeClass('hide') if (!self.changing) { self.changing = true $('.sidebarAccountBox #user_email').blur() - $('.sidebarAccountBox').fadeOut(200, function () { + $('.sidebarAccountBox').fadeOut(200, function() { self.changing = false self.isOpen = false }) diff --git a/frontend/src/Metamaps/GlobalUI/CreateMap.js b/frontend/src/Metamaps/GlobalUI/CreateMap.js index 11c8deb9..9a4d8770 100644 --- a/frontend/src/Metamaps/GlobalUI/CreateMap.js +++ b/frontend/src/Metamaps/GlobalUI/CreateMap.js @@ -13,7 +13,7 @@ const CreateMap = { emptyForkMapForm: '', topicsToMap: [], synapsesToMap: [], - init: function () { + init: function() { var self = CreateMap self.newMap = new DataModelMap({ permission: 'commons' }) @@ -22,14 +22,14 @@ const CreateMap = { self.emptyMapForm = $('#new_map').html() }, - bindFormEvents: function () { + bindFormEvents: function() { var self = CreateMap - $('.new_map input, .new_map div').unbind('keypress').bind('keypress', function (event) { + $('.new_map input, .new_map div').unbind('keypress').bind('keypress', function(event) { if (event.keyCode === 13) self.submit() }) - $('.new_map button.cancel').unbind().bind('click', function (event) { + $('.new_map button.cancel').unbind().bind('click', function(event) { event.preventDefault() GlobalUI.closeLightbox() }) @@ -38,12 +38,12 @@ const CreateMap = { // bind permission changer events on the createMap form $('.permIcon').unbind().bind('click', self.switchPermission) }, - closeSuccess: function () { - $('#mapCreatedSuccess').fadeOut(300, function () { + closeSuccess: function() { + $('#mapCreatedSuccess').fadeOut(300, function() { $(this).remove() }) }, - switchPermission: function () { + switchPermission: function() { var self = CreateMap self.newMap.set('permission', $(this).attr('data-permission')) @@ -53,7 +53,7 @@ const CreateMap = { var permText = $(this).find('.tip').html() $(this).parents('.new_map').find('.permText').html(permText) }, - submit: function (event) { + submit: function(event) { if (event) event.preventDefault() var self = CreateMap @@ -82,22 +82,20 @@ const CreateMap = { GlobalUI.closeLightbox() GlobalUI.notifyUser('Working...') }, - throwMapNameError: function () { - + throwMapNameError: function() { var formId = GlobalUI.lightbox === 'forkmap' ? '#fork_map' : '#new_map' var $form = $(formId) var message = $("") $form.find('#map_name').after(message) - setTimeout(function () { - message.fadeOut('fast', function () { + setTimeout(function() { + message.fadeOut('fast', function() { message.remove() }) }, 5000) }, - success: function (model) { - var self = CreateMap + success: function(model) { // push the new map onto the collection of 'my maps' DataModel.Maps.Mine.add(model) @@ -117,7 +115,7 @@ const CreateMap = { return false }) }, - reset: function (id) { + reset: function(id) { var self = CreateMap var form = $('#' + id) diff --git a/frontend/src/Metamaps/GlobalUI/ImportDialog.js b/frontend/src/Metamaps/GlobalUI/ImportDialog.js index 96f9524f..dfc319b7 100644 --- a/frontend/src/Metamaps/GlobalUI/ImportDialog.js +++ b/frontend/src/Metamaps/GlobalUI/ImportDialog.js @@ -12,7 +12,7 @@ const ImportDialog = { openLightbox: null, closeLightbox: null, - init: function (serverData, openLightbox, closeLightbox) { + init: function(serverData, openLightbox, closeLightbox) { const self = ImportDialog self.openLightbox = openLightbox self.closeLightbox = closeLightbox @@ -27,10 +27,10 @@ const ImportDialog = { exampleImageUrl: serverData['import-example.png'] }), $('.importDialogWrapper').get(0)) }, - show: function () { + show: function() { ImportDialog.openLightbox('import-dialog') }, - hide: function () { + hide: function() { ImportDialog.closeLightbox('import-dialog') } } diff --git a/frontend/src/Metamaps/GlobalUI/Search.js b/frontend/src/Metamaps/GlobalUI/Search.js index 0859b941..a37b62a8 100644 --- a/frontend/src/Metamaps/GlobalUI/Search.js +++ b/frontend/src/Metamaps/GlobalUI/Search.js @@ -10,7 +10,7 @@ const Search = { limitMapsToMe: false, changing: false, optionsInitialized: false, - init: function (serverData) { + init: function(serverData) { var self = Search self.wildcardIconUrl = serverData['icons/wildcard.png'] @@ -24,10 +24,10 @@ const Search = { loader.setRange(0.9) // default is 1.3 loader.show() // Hidden by default - $('.sidebarSearchIcon').click(function (e) { + $('.sidebarSearchIcon').click(function(e) { $('.sidebarSearchField').focus() }) - $('.sidebarSearch').click(function (e) { + $('.sidebarSearch').click(function(e) { e.stopPropagation() }) @@ -36,7 +36,7 @@ const Search = { focus: function() { $('.sidebarSearchField').focus() }, - startTypeahead: function () { + startTypeahead: function() { var self = Search var mapheader = Active.Mapper ? '

    Maps

    ' : '

    Maps

    ' @@ -49,7 +49,7 @@ const Search = { display: s => s.label, templates: { - notFound: function (s) { + notFound: function(s) { return Hogan.compile(topicheader + $('#topicSearchTemplate').html()).render({ value: 'No results', label: 'No results', @@ -58,7 +58,7 @@ const Search = { }) }, header: topicheader, - suggestion: function (s) { + suggestion: function(s) { return Hogan.compile($('#topicSearchTemplate').html()).render(s) } }, @@ -67,7 +67,7 @@ const Search = { queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { url: '/search/topics', - prepare: function (query, settings) { + prepare: function(query, settings) { settings.url += '?term=' + query if (Active.Mapper && self.limitTopicsToMe) { settings.url += '&user=' + Active.Mapper.id.toString() @@ -83,7 +83,7 @@ const Search = { limit: 9999, display: s => s.label, templates: { - notFound: function (s) { + notFound: function(s) { return Hogan.compile(mapheader + $('#mapSearchTemplate').html()).render({ value: 'No results', label: 'No results', @@ -91,7 +91,7 @@ const Search = { }) }, header: mapheader, - suggestion: function (s) { + suggestion: function(s) { return Hogan.compile($('#mapSearchTemplate').html()).render(s) } }, @@ -100,7 +100,7 @@ const Search = { queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { url: '/search/maps', - prepare: function (query, settings) { + prepare: function(query, settings) { settings.url += '?term=' + query if (Active.Mapper && self.limitMapsToMe) { settings.url += '&user=' + Active.Mapper.id.toString() @@ -116,7 +116,7 @@ const Search = { limit: 9999, display: s => s.label, templates: { - notFound: function (s) { + notFound: function(s) { return Hogan.compile(mapperheader + $('#mapperSearchTemplate').html()).render({ value: 'No results', label: 'No results', @@ -125,7 +125,7 @@ const Search = { }) }, header: mapperheader, - suggestion: function (s) { + suggestion: function(s) { return Hogan.compile($('#mapperSearchTemplate').html()).render(s) } }, @@ -148,7 +148,7 @@ const Search = { ) // Set max height of the search results box to prevent it from covering bottom left footer - $('.sidebarSearchField').bind('typeahead:render', function (event) { + $('.sidebarSearchField').bind('typeahead:render', function(event) { self.initSearchOptions() self.hideLoader() var h = $(window).height() @@ -160,7 +160,7 @@ const Search = { $('#limitMapsToMe').prop('checked', true) } }) - $(window).resize(function () { + $(window).resize(function() { var h = $(window).height() $('.tt-dropdown-menu').css('max-height', h - 100) }) @@ -169,12 +169,12 @@ const Search = { $('.sidebarSearchField').bind('typeahead:select', self.handleResultClick) // don't do it, if they clicked on a 'addToMap' button - $('.sidebarSearch button.addToMap').click(function (event) { + $('.sidebarSearch button.addToMap').click(function(event) { event.stopPropagation() }) // make sure that when you click on 'limit to me' or 'toggle section' it works - $('.sidebarSearchField.tt-input').keyup(function () { + $('.sidebarSearchField.tt-input').keyup(function() { if ($('.sidebarSearchField.tt-input').val() === '') { self.hideLoader() } else { @@ -182,7 +182,7 @@ const Search = { } }) }, - handleResultClick: function (event, datum, dataset) { + handleResultClick: function(event, datum, dataset) { var self = Search self.hideLoader() @@ -197,10 +197,10 @@ const Search = { } } }, - initSearchOptions: function () { + initSearchOptions: function() { var self = Search - function toggleResultSet (set) { + function toggleResultSet(set) { var s = $('.tt-dataset-' + set + ' .tt-suggestion, .tt-dataset-' + set + ' .resultnoresult') if (s.is(':visible')) { s.hide() @@ -211,7 +211,7 @@ const Search = { } } - $('.limitToMe').unbind().bind('change', function (e) { + $('.limitToMe').unbind().bind('change', function(e) { if ($(this).attr('id') === 'limitTopicsToMe') { self.limitTopicsToMe = !self.limitTopicsToMe } @@ -227,20 +227,20 @@ const Search = { }) // when the user clicks minimize section, hide the results for that section - $('.minimizeMapperResults').unbind().click(function (e) { + $('.minimizeMapperResults').unbind().click(function(e) { toggleResultSet.call(this, 'mappers') }) - $('.minimizeTopicResults').unbind().click(function (e) { + $('.minimizeTopicResults').unbind().click(function(e) { toggleResultSet.call(this, 'topics') }) - $('.minimizeMapResults').unbind().click(function (e) { + $('.minimizeMapResults').unbind().click(function(e) { toggleResultSet.call(this, 'maps') }) }, - hideLoader: function () { + hideLoader: function() { $('#searchLoading').hide() }, - showLoader: function () { + showLoader: function() { $('#searchLoading').show() } } diff --git a/frontend/src/Metamaps/GlobalUI/index.js b/frontend/src/Metamaps/GlobalUI/index.js index d1a0b6ba..95e484f8 100644 --- a/frontend/src/Metamaps/GlobalUI/index.js +++ b/frontend/src/Metamaps/GlobalUI/index.js @@ -12,7 +12,7 @@ import ImportDialog from './ImportDialog' const GlobalUI = { notifyTimeout: null, lightbox: null, - init: function (serverData) { + init: function(serverData) { var self = GlobalUI self.Search.init(serverData) @@ -23,7 +23,7 @@ const GlobalUI = { if ($('#toast').html().trim()) self.notifyUser($('#toast').html()) // bind lightbox clicks - $('.openLightbox').click(function (event) { + $('.openLightbox').click(function(event) { self.openLightbox($(this).attr('data-open')) event.preventDefault() return false @@ -31,18 +31,18 @@ const GlobalUI = { $('#lightbox_screen, #lightbox_close').click(self.closeLightbox) }, - showDiv: function (selector) { + showDiv: function(selector) { $(selector).show() $(selector).animate({ opacity: 1 }, 200, 'easeOutCubic') }, - hideDiv: function (selector) { + hideDiv: function(selector) { $(selector).animate({ opacity: 0 - }, 200, 'easeInCubic', function () { $(this).hide() }) + }, 200, 'easeInCubic', function() { $(this).hide() }) }, - openLightbox: function (which) { + openLightbox: function(which) { var self = GlobalUI $('.lightboxContent').hide() @@ -69,7 +69,7 @@ const GlobalUI = { } }, - closeLightbox: function (event) { + closeLightbox: function(event) { var self = GlobalUI if (event) event.preventDefault() @@ -83,7 +83,7 @@ const GlobalUI = { // fade the black overlay out $('#lightbox_screen').animate({ 'opacity': '0.0' - }, 200, function () { + }, 200, function() { $('#lightbox_overlay').hide() }) @@ -94,25 +94,25 @@ const GlobalUI = { } self.lightbox = null }, - notifyUser: function (message, leaveOpen) { + notifyUser: function(message, leaveOpen) { var self = GlobalUI $('#toast').html(message) self.showDiv('#toast') clearTimeout(self.notifyTimeOut) if (!leaveOpen) { - self.notifyTimeOut = setTimeout(function () { + self.notifyTimeOut = setTimeout(function() { self.hideDiv('#toast') }, 8000) } }, - clearNotify: function () { + clearNotify: function() { var self = GlobalUI clearTimeout(self.notifyTimeOut) self.hideDiv('#toast') }, - shareInvite: function (inviteLink) { + shareInvite: function(inviteLink) { clipboard.copy({ 'text/plain': inviteLink }).then(() => { diff --git a/frontend/src/Metamaps/Import.js b/frontend/src/Metamaps/Import.js index 8436c148..cde37a73 100644 --- a/frontend/src/Metamaps/Import.js +++ b/frontend/src/Metamaps/Import.js @@ -19,14 +19,14 @@ const Import = { synapseWhitelist: [ 'topic1', 'topic2', 'category', 'direction', 'desc', 'description', 'permission' ], - cidMappings: {}, // to be filled by import_id => cid mappings + cidMappings: {}, // to be filled by importId => cid mappings - handleTSV: function (text) { + handleTSV: function(text) { const results = Import.parseTabbedString(text) Import.handle(results) }, - handleCSV: function (text, parserOpts = {}) { + handleCSV: function(text, parserOpts = {}) { const self = Import const topicsRegex = /("?Topics"?)([\s\S]*)/mi @@ -37,14 +37,14 @@ const Import = { if (synapsesText) synapsesText = synapsesText[2].replace(topicsRegex, '') // merge default options and extra options passed in parserOpts argument - const csv_parser_options = Object.assign({ + const csvParserOptions = Object.assign({ columns: true, // get headers relax_column_count: true, skip_empty_lines: true }, parserOpts) const topicsPromise = $.Deferred() - parse(topicsText, csv_parser_options, (err, data) => { + parse(topicsText, csvParserOptions, (err, data) => { if (err) { console.warn(err) return topicsPromise.resolve([]) @@ -53,7 +53,7 @@ const Import = { }) const synapsesPromise = $.Deferred() - parse(synapsesText, csv_parser_options, (err, data) => { + parse(synapsesText, csvParserOptions, (err, data) => { if (err) { console.warn(err) return synapsesPromise.resolve([]) @@ -62,11 +62,11 @@ const Import = { }) $.when(topicsPromise, synapsesPromise).done((topics, synapses) => { - self.handle({ topics, synapses}) + self.handle({ topics, synapses }) }) }, - handleJSON: function (text) { + handleJSON: function(text) { const results = JSON.parse(text) Import.handle(results) }, @@ -80,13 +80,13 @@ const Import = { if (window.confirm('Are you sure you want to create ' + topics.length + ' new topics and ' + synapses.length + ' new synapses?')) { self.importTopics(topics) - //window.setTimeout(() => self.importSynapses(synapses), 5000) + // window.setTimeout(() => self.importSynapses(synapses), 5000) self.importSynapses(synapses) } // if } // if }, - parseTabbedString: function (text) { + parseTabbedString: function(text) { var self = Import // determine line ending and split lines @@ -113,9 +113,9 @@ const Import = { var topicHeaders = [] var synapseHeaders = [] - lines.forEach(function (line_raw, index) { - var line = line_raw.split('\t') - var noblanks = line.filter(function (elt) { + lines.forEach(function(lineRaw, index) { + const line = lineRaw.split('\t') + var noblanks = line.filter(function(elt) { return elt !== '' }) switch (state) { @@ -139,7 +139,7 @@ const Import = { self.abort('Not enough topic headers on line ' + index) state = STATES.ABORT } - topicHeaders = line.map(function (header, index) { + topicHeaders = line.map(function(header, index) { return self.normalizeKey(header) }) state = STATES.TOPICS @@ -150,7 +150,7 @@ const Import = { self.abort('Not enough synapse headers on line ' + index) state = STATES.ABORT } - synapseHeaders = line.map(function (header, index) { + synapseHeaders = line.map(function(header, index) { return self.normalizeKey(header) }) state = STATES.SYNAPSES @@ -165,7 +165,7 @@ const Import = { state = STATES.SYNAPSES_NEED_HEADERS } else { var topic = {} - line.forEach(function (field, index) { + line.forEach(function(field, index) { var header = topicHeaders[index] if (self.topicWhitelist.indexOf(header) === -1) return topic[header] = field @@ -186,7 +186,7 @@ const Import = { state = STATES.SYNAPSES_NEED_HEADERS } else { var synapse = {} - line.forEach(function (field, index) { + line.forEach(function(field, index) { var header = synapseHeaders[index] if (self.synapseWhitelist.indexOf(header) === -1) return synapse[header] = field @@ -212,7 +212,7 @@ const Import = { } }, - importTopics: function (parsedTopics) { + importTopics: function(parsedTopics) { var self = Import parsedTopics.forEach(topic => { @@ -227,7 +227,7 @@ const Import = { coords, name: topic.name, permission: topic.permission, - import_id: topic.id + importId: topic.id }) return // "continue" } @@ -239,10 +239,10 @@ const Import = { }) }, - importSynapses: function (parsedSynapses) { + importSynapses: function(parsedSynapses) { var self = Import - parsedSynapses.forEach(function (synapse) { + parsedSynapses.forEach(function(synapse) { // only createSynapseWithParameters once both topics are persisted // if there isn't a cidMapping, check by topic name instead var topic1 = DataModel.Topics.get(self.cidMappings[synapse.topic1]) @@ -277,31 +277,31 @@ const Import = { }) }, - createTopicWithParameters: function (name, metacode_name, permission, desc, - link, xloc, yloc, import_id, opts = {}) { + createTopicWithParameters: function(name, metacodeName, permission, desc, + link, xloc, yloc, importId, opts = {}) { var self = Import $(document).trigger(Map.events.editedByActiveMapper) - var metacode = DataModel.Metacodes.where({name: metacode_name})[0] || null + var metacode = DataModel.Metacodes.where({name: metacodeName})[0] || null if (metacode === null) { metacode = DataModel.Metacodes.where({ name: 'Wildcard' })[0] - console.warn("Couldn't find metacode " + metacode_name + ' so used Wildcard instead.') + console.warn("Couldn't find metacode " + metacodeName + ' so used Wildcard instead.') } - var topic_permission = permission || Active.Map.get('permission') - var defer_to_map_id = permission === topic_permission ? Active.Map.get('id') : null + const topicPermision = permission || Active.Map.get('permission') + var deferToMapId = permission === topicPermision ? Active.Map.get('id') : null var topic = new DataModel.Topic({ name: name, metacode_id: metacode.id, - permission: topic_permission, - defer_to_map_id: defer_to_map_id, + permission: topicPermision, + defer_to_map_id: deferToMapId, desc: desc || '', link: link || '', calculated_permission: Active.Map.get('permission') }) DataModel.Topics.add(topic) - if (import_id !== null && import_id !== undefined) { - self.cidMappings[import_id] = topic.cid + if (importId !== null && importId !== undefined) { + self.cidMappings[importId] = topic.cid } var mapping = new DataModel.Mapping({ @@ -320,7 +320,7 @@ const Import = { GlobalUI.hideDiv('#instructions') }, - createSynapseWithParameters: function (desc, category, permission, + createSynapseWithParameters: function(desc, category, permission, topic1, topic2) { var node1 = topic1.get('node') var node2 = topic2.get('node') @@ -348,7 +348,7 @@ const Import = { Synapse.renderSynapse(mapping, synapse, node1, node2, true) }, - handleURL: function (url, opts = {}) { + handleURL: function(url, opts = {}) { let coords = opts.coords if (!coords || coords.x === undefined || coords.y === undefined) { coords = AutoLayout.getNextCoord({ mappings: DataModel.Mappings }) @@ -356,7 +356,7 @@ const Import = { const name = opts.name || 'Link' const metacode = opts.metacode || 'Reference' - const import_id = opts.import_id || null // don't store a cidMapping + const importId = opts.importId || null // don't store a cidMapping const permission = opts.permission || null // use default const desc = opts.desc || url @@ -368,7 +368,7 @@ const Import = { url, coords.x, coords.y, - import_id, + importId, { success: function(topic) { if (topic.get('name') !== 'Link') return @@ -393,12 +393,12 @@ const Import = { * helper functions */ - abort: function (message) { + abort: function(message) { console.error(message) }, // TODO investigate replacing with es6 (?) trim() - simplify: function (string) { + simplify: function(string) { return string .replace(/(^\s*|\s*$)/g, '') .toLowerCase() diff --git a/frontend/src/Metamaps/JIT.js b/frontend/src/Metamaps/JIT.js index 7cbce927..0f21f70b 100644 --- a/frontend/src/Metamaps/JIT.js +++ b/frontend/src/Metamaps/JIT.js @@ -13,7 +13,6 @@ import Filter from './Filter' import GlobalUI from './GlobalUI' import Map from './Map' import Mouse from './Mouse' -import Realtime from './Realtime' import Selected from './Selected' import Settings from './Settings' import Synapse from './Synapse' @@ -31,7 +30,7 @@ const JIT = { tempNode: null, tempNode2: null, mouseDownPix: {}, - dragFlag : 0, + dragFlag: 0, dragTolerance: 0, virtualPointer: {}, @@ -51,13 +50,13 @@ const JIT = { /** * This method will bind the event handlers it is interested and initialize the class. */ - init: function (serverData) { + init: function(serverData) { const self = JIT $('.zoomIn').click(self.zoomIn) $('.zoomOut').click(self.zoomOut) - const zoomExtents = function (event) { + const zoomExtents = function(event) { self.zoomExtents(event, Visualize.mGraph.canvas) } $('.zoomExtents').click(zoomExtents) @@ -73,7 +72,7 @@ const JIT = { /** * convert our topic JSON into something JIT can use */ - convertModelsToJIT: function (topics, synapses) { + convertModelsToJIT: function(topics, synapses) { const jitReady = [] const synapsesToRemove = [] @@ -84,11 +83,11 @@ const JIT = { let edge const edges = [] - topics.each(function (t) { + topics.each(function(t) { node = t.createNode() nodes[node.id] = node }) - synapses.each(function (s) { + synapses.each(function(s) { edge = s.createEdge() if (topics.get(s.get('topic1_id')) === undefined || topics.get(s.get('topic2_id')) === undefined) { @@ -119,13 +118,13 @@ const JIT = { } }) - _.each(nodes, function (node) { + _.each(nodes, function(node) { jitReady.push(node) }) return [jitReady, synapsesToRemove] }, - prepareVizData: function () { + prepareVizData: function() { const self = JIT let mapping @@ -138,7 +137,7 @@ const JIT = { self.vizData = results[0] // clean up the synapses array in case of any faulty data - _.each(results[1], function (synapse) { + _.each(results[1], function(synapse) { mapping = synapse.getMapping() DataModel.Synapses.remove(synapse) if (DataModel.Mappings) DataModel.Mappings.remove(mapping) @@ -160,7 +159,7 @@ const JIT = { Visualize.render() }, // prepareVizData - edgeRender: function (adj, canvas) { + edgeRender: function(adj, canvas) { // get nodes cartesian coordinates const pos = adj.nodeFrom.pos.getc(true) const posChild = adj.nodeTo.pos.getc(true) @@ -191,7 +190,7 @@ const JIT = { const showDesc = adj.getData('showDesc') - const drawSynapseCount = function (context, x, y, count) { + const drawSynapseCount = function(context, x, y, count) { /* circle size: 16x16px positioning: overlay and center on top right corner of synapse label - 8px left and 8px down @@ -287,7 +286,7 @@ const JIT = { // TODO fix tests so we don't need _.get transition: _.get($jit, 'Trans.Quad.easeInOut'), duration: 800, - onComplete: function () { + onComplete: function() { Visualize.mGraph.busy = false $(document).trigger(JIT.events.animationDone) } @@ -297,7 +296,7 @@ const JIT = { // TODO fix tests so we don't need _.get transition: _.get($jit, 'Trans.Elastic.easeOut'), duration: 800, - onComplete: function () { + onComplete: function() { Visualize.mGraph.busy = false } }, @@ -342,40 +341,40 @@ const JIT = { // Add Tips Tips: { enable: false, - onShow: function (tip, node) {} + onShow: function(tip, node) {} }, // Add node events Events: { enable: true, enableForEdges: true, - onMouseMove: function (node, eventInfo, e) { + onMouseMove: function(node, eventInfo, e) { JIT.onMouseMoveHandler(node, eventInfo, e) // console.log('called mouse move handler') }, // Update node positions when dragged - onDragMove: function (node, eventInfo, e) { + onDragMove: function(node, eventInfo, e) { JIT.onDragMoveTopicHandler(node, eventInfo, e) // console.log('called drag move handler') }, - onDragEnd: function (node, eventInfo, e) { + onDragEnd: function(node, eventInfo, e) { JIT.onDragEndTopicHandler(node, eventInfo, e, false) // console.log('called drag end handler') }, - onDragCancel: function (node, eventInfo, e) { + onDragCancel: function(node, eventInfo, e) { JIT.onDragCancelHandler(node, eventInfo, e, false) }, // Implement the same handler for touchscreens - onTouchStart: function (node, eventInfo, e) {}, + onTouchStart: function(node, eventInfo, e) {}, // Implement the same handler for touchscreens - onTouchMove: function (node, eventInfo, e) { + onTouchMove: function(node, eventInfo, e) { JIT.onDragMoveTopicHandler(node, eventInfo, e) }, // Implement the same handler for touchscreens - onTouchEnd: function (node, eventInfo, e) {}, + onTouchEnd: function(node, eventInfo, e) {}, // Implement the same handler for touchscreens - onTouchCancel: function (node, eventInfo, e) {}, + onTouchCancel: function(node, eventInfo, e) {}, // Add also a click handler to nodes - onClick: function (node, eventInfo, e) { + onClick: function(node, eventInfo, e) { // remove the rightclickmenu $('.rightclickmenu').remove() @@ -399,7 +398,7 @@ const JIT = { Visualize.mGraph.busy = false Mouse.boxEndCoordinates = eventInfo.getPos() JIT.selectWithBox(e) - + return } } @@ -416,7 +415,7 @@ const JIT = { } // if }, // Add also a click handler to nodes - onRightClick: function (node, eventInfo, e) { + onRightClick: function(node, eventInfo, e) { // remove the rightclickmenu $('.rightclickmenu').remove() @@ -446,7 +445,7 @@ const JIT = { }, nodeSettings: { 'customNode': { - 'render': function (node, canvas) { + 'render': function(node, canvas) { const pos = node.pos.getc(true) const dim = node.getData('dim') const topic = node.getData('topic') @@ -495,7 +494,7 @@ const JIT = { ctx.drawImage(descImage, pos.x + dim - 8, pos.y - dim - 8, 16, 16) } }, - 'contains': function (node, pos) { + 'contains': function(node, pos) { const npos = node.pos.getc(true) const dim = node.getData('dim') const arrayOfLabelLines = Util.splitLine(node.name, 30).split('\n') @@ -521,10 +520,10 @@ const JIT = { }, edgeSettings: { 'customEdge': { - 'render': function (adj, canvas) { + 'render': function(adj, canvas) { JIT.edgeRender(adj, canvas) }, - 'contains': function (adj, pos) { + 'contains': function(adj, pos) { const from = adj.nodeFrom.pos.getc() const to = adj.nodeTo.pos.getc() @@ -544,7 +543,7 @@ const JIT = { // TODO fix tests so we don't need _.get transition: _.get($jit, 'Trans.Elastic.easeOut'), duration: 2500, - onComplete: function () { + onComplete: function() { Visualize.mGraph.busy = false } }, @@ -603,18 +602,18 @@ const JIT = { enable: true, type: 'Native', i: 0, - onMouseMove: function (node, eventInfo, e) { + onMouseMove: function(node, eventInfo, e) { // if(this.i++ % 3) return const pos = eventInfo.getPos() Visualize.cameraPosition.x += (pos.x - Visualize.cameraPosition.x) * 0.5 Visualize.cameraPosition.y += (-pos.y - Visualize.cameraPosition.y) * 0.5 Visualize.mGraph.plot() }, - onMouseWheel: function (delta) { + onMouseWheel: function(delta) { Visualize.cameraPosition.z += -delta * 20 Visualize.mGraph.plot() }, - onClick: function () {} + onClick: function() {} }, // Number of iterations for the FD algorithm iterations: 200, @@ -632,7 +631,7 @@ const JIT = { animate: { modes: ['polar'], duration: 800, - onComplete: function () { + onComplete: function() { Visualize.mGraph.busy = false } }, @@ -647,7 +646,7 @@ const JIT = { }, levelDistance: 200 }, - onMouseEnter: function (edge) { + onMouseEnter: function(edge) { const filtered = edge.getData('alpha') === 0 // don't do anything if the edge is filtered @@ -670,7 +669,7 @@ const JIT = { }) Visualize.mGraph.plot() }, // onMouseEnter - onMouseLeave: function (edge) { + onMouseLeave: function(edge) { if (edge.getData('alpha') === 0) return // don't do anything if the edge is filtered $('canvas').css('cursor', 'default') const edgeIsSelected = Selected.Edges.indexOf(edge) @@ -688,7 +687,7 @@ const JIT = { }) Visualize.mGraph.plot() }, // onMouseLeave - onMouseMoveHandler: function (_node, eventInfo, e) { + onMouseMoveHandler: function(_node, eventInfo, e) { const self = JIT if (Visualize.mGraph.busy) return @@ -724,7 +723,7 @@ const JIT = { $('canvas').css('cursor', 'default') } }, // onMouseMoveHandler - enterKeyHandler: function () { + enterKeyHandler: function() { const creatingMap = GlobalUI.lightbox if (creatingMap === 'newmap' || creatingMap === 'forkmap') { GlobalUI.CreateMap.submit() @@ -734,11 +733,11 @@ const JIT = { Synapse.createSynapseLocally() } }, // enterKeyHandler - escKeyHandler: function () { + escKeyHandler: function() { Control.deselectAllEdges() Control.deselectAllNodes() }, // escKeyHandler - onDragMoveTopicHandler: function (node, eventInfo, e) { + onDragMoveTopicHandler: function(node, eventInfo, e) { var self = JIT var authorized = Active.Map && Active.Map.authorizeToEdit(Active.Mapper) @@ -746,111 +745,109 @@ const JIT = { if (node && !node.nodeFrom) { self.handleSelectionBeforeDragging(node, e) - var pos = eventInfo.getPos(), - EDGE_THICKNESS = 30 /** Metamaps.Visualize.mGraph.canvas.scaleOffsetX*/, - SHIFT = 2 / Metamaps.Visualize.mGraph.canvas.scaleOffsetX, - PERIOD = 5; - - //self.virtualPointer = pos; + const pos = eventInfo.getPos() + const EDGE_THICKNESS = 30 + const SHIFT = 2 / Visualize.mGraph.canvas.scaleOffsetX + const PERIOD = 5 + + // self.virtualPointer = pos; + // if it's a left click, or a touch, move the node if (e.touches || (e.button === 0 && !e.altKey && !e.ctrlKey && (e.buttons === 0 || e.buttons === 1 || e.buttons === undefined))) { + const width = Visualize.mGraph.canvas.getSize().width + const height = Visualize.mGraph.canvas.getSize().height + const xPix = Util.coordsToPixels(Visualize.mGraph, pos).x + const yPix = Util.coordsToPixels(Visualize.mGraph, pos).y - var width = Visualize.mGraph.canvas.getSize().width, - height = Visualize.mGraph.canvas.getSize().height, - xPix = Util.coordsToPixels(Visualize.mGraph, pos).x, - yPix = Util.coordsToPixels(Visualize.mGraph, pos).y; - - if(self.dragFlag === 0){ - self.mouseDownPix = Util.coordsToPixels(Visualize.mGraph, eventInfo.getPos()); - self.dragFlag = 1; - } - - if(Util.getDistance(Util.coordsToPixels(Visualize.mGraph, pos),self.mouseDownPix) > 2 && !self.dragTolerance){ - self.dragTolerance = 1; + if (self.dragFlag === 0) { + self.mouseDownPix = Util.coordsToPixels(Visualize.mGraph, eventInfo.getPos()) + self.dragFlag = 1 } - if(xPix < EDGE_THICKNESS && self.dragTolerance ){ - clearInterval(self.dragLeftEdge); - clearInterval(self.dragRightEdge); - clearInterval(self.dragTopEdge); - clearInterval(self.dragBottomEdge); + if (Util.getDistance(Util.coordsToPixels(Visualize.mGraph, pos), self.mouseDownPix) > 2 && !self.dragTolerance) { + self.dragTolerance = 1 + } + + if (xPix < EDGE_THICKNESS && self.dragTolerance) { + clearInterval(self.dragLeftEdge) + clearInterval(self.dragRightEdge) + clearInterval(self.dragTopEdge) + clearInterval(self.dragBottomEdge) self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: EDGE_THICKNESS, y: yPix }).x - SHIFT, y: pos.y } - Visualize.mGraph.canvas.translate(SHIFT, 0); - self.updateTopicPositions(node, self.virtualPointer); - Visualize.mGraph.plot(); - - self.dragLeftEdge = setInterval( function(){ + Visualize.mGraph.canvas.translate(SHIFT, 0) + self.updateTopicPositions(node, self.virtualPointer) + Visualize.mGraph.plot() + + self.dragLeftEdge = setInterval(function() { self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: EDGE_THICKNESS, y: yPix }).x - SHIFT, y: pos.y } - Visualize.mGraph.canvas.translate(SHIFT, 0); - self.updateTopicPositions(node,self.virtualPointer); - Visualize.mGraph.plot(); - } , PERIOD); - - } - if(width - xPix < EDGE_THICKNESS && self.dragTolerance){ - clearInterval(self.dragLeftEdge); - clearInterval(self.dragRightEdge); - clearInterval(self.dragTopEdge); - clearInterval(self.dragBottomEdge); - self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: width - EDGE_THICKNESS, y: yPix }).x + SHIFT, y: pos.y } - Visualize.mGraph.canvas.translate(-SHIFT, 0); - self.updateTopicPositions(node, self.virtualPointer); - Visualize.mGraph.plot(); - - self.dragRightEdge = setInterval( function(){ - self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: width - EDGE_THICKNESS, y: yPix }).x + SHIFT, y: pos.y } - Visualize.mGraph.canvas.translate(-SHIFT, 0); - self.updateTopicPositions(node, self.virtualPointer); - Visualize.mGraph.plot(); - } , PERIOD); - } - if(yPix < EDGE_THICKNESS && self.dragTolerance){ - clearInterval(self.dragLeftEdge); - clearInterval(self.dragRightEdge); - clearInterval(self.dragTopEdge); - clearInterval(self.dragBottomEdge); - self.virtualPointer = { x:pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: EDGE_THICKNESS }).y - SHIFT } - Visualize.mGraph.canvas.translate(0, SHIFT); - self.updateTopicPositions(node, self.virtualPointer); - Visualize.mGraph.plot(); - - self.dragTopEdge = setInterval( function(){ - self.virtualPointer = { x: pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: EDGE_THICKNESS }).y - SHIFT } - Visualize.mGraph.canvas.translate(0, SHIFT); - self.updateTopicPositions(node, self.virtualPointer); - Visualize.mGraph.plot(); - } , PERIOD); - } - if(height - yPix < EDGE_THICKNESS && self.dragTolerance){ - clearInterval(self.dragLeftEdge); - clearInterval(self.dragRightEdge); - clearInterval(self.dragTopEdge); - clearInterval(self.dragBottomEdge); - self.virtualPointer = { x: pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: height - EDGE_THICKNESS }).y + SHIFT } - Visualize.mGraph.canvas.translate(0, -SHIFT); - self.updateTopicPositions(node, self.virtualPointer); - Visualize.mGraph.plot(); - - self.dragBottomEdge = setInterval(function () { - self.virtualPointer = { x: pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: height - EDGE_THICKNESS }).y + SHIFT } - Visualize.mGraph.canvas.translate(0, -SHIFT); - self.updateTopicPositions(node, self.virtualPointer); - Visualize.mGraph.plot(); + Visualize.mGraph.canvas.translate(SHIFT, 0) + self.updateTopicPositions(node, self.virtualPointer) + Visualize.mGraph.plot() }, PERIOD) } - - if(xPix >= EDGE_THICKNESS && width - xPix >= EDGE_THICKNESS && yPix >= EDGE_THICKNESS && height - yPix >= EDGE_THICKNESS) { - clearInterval(self.dragLeftEdge); - clearInterval(self.dragRightEdge); - clearInterval(self.dragTopEdge); - clearInterval(self.dragBottomEdge); + if (width - xPix < EDGE_THICKNESS && self.dragTolerance) { + clearInterval(self.dragLeftEdge) + clearInterval(self.dragRightEdge) + clearInterval(self.dragTopEdge) + clearInterval(self.dragBottomEdge) + self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: width - EDGE_THICKNESS, y: yPix }).x + SHIFT, y: pos.y } + Visualize.mGraph.canvas.translate(-SHIFT, 0) + self.updateTopicPositions(node, self.virtualPointer) + Visualize.mGraph.plot() - self.updateTopicPositions(node,pos); + self.dragRightEdge = setInterval(function() { + self.virtualPointer = { x: Util.pixelsToCoords(Visualize.mGraph, { x: width - EDGE_THICKNESS, y: yPix }).x + SHIFT, y: pos.y } + Visualize.mGraph.canvas.translate(-SHIFT, 0) + self.updateTopicPositions(node, self.virtualPointer) + Visualize.mGraph.plot() + }, PERIOD) + } + if (yPix < EDGE_THICKNESS && self.dragTolerance) { + clearInterval(self.dragLeftEdge) + clearInterval(self.dragRightEdge) + clearInterval(self.dragTopEdge) + clearInterval(self.dragBottomEdge) + self.virtualPointer = { x: pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: EDGE_THICKNESS }).y - SHIFT } + Visualize.mGraph.canvas.translate(0, SHIFT) + self.updateTopicPositions(node, self.virtualPointer) + Visualize.mGraph.plot() + + self.dragTopEdge = setInterval(function() { + self.virtualPointer = { x: pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: EDGE_THICKNESS }).y - SHIFT } + Visualize.mGraph.canvas.translate(0, SHIFT) + self.updateTopicPositions(node, self.virtualPointer) + Visualize.mGraph.plot() + }, PERIOD) + } + if (height - yPix < EDGE_THICKNESS && self.dragTolerance) { + clearInterval(self.dragLeftEdge) + clearInterval(self.dragRightEdge) + clearInterval(self.dragTopEdge) + clearInterval(self.dragBottomEdge) + self.virtualPointer = { x: pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: height - EDGE_THICKNESS }).y + SHIFT } + Visualize.mGraph.canvas.translate(0, -SHIFT) + self.updateTopicPositions(node, self.virtualPointer) + Visualize.mGraph.plot() + + self.dragBottomEdge = setInterval(function() { + self.virtualPointer = { x: pos.x, y: Util.pixelsToCoords(Visualize.mGraph, { x: xPix, y: height - EDGE_THICKNESS }).y + SHIFT } + Visualize.mGraph.canvas.translate(0, -SHIFT) + self.updateTopicPositions(node, self.virtualPointer) + Visualize.mGraph.plot() + }, PERIOD) + } + + if (xPix >= EDGE_THICKNESS && width - xPix >= EDGE_THICKNESS && yPix >= EDGE_THICKNESS && height - yPix >= EDGE_THICKNESS) { + clearInterval(self.dragLeftEdge) + clearInterval(self.dragRightEdge) + clearInterval(self.dragTopEdge) + clearInterval(self.dragBottomEdge) + + self.updateTopicPositions(node, pos) Visualize.mGraph.plot() } - } - // if it's a right click or holding down alt, start synapse creation ->third option is for firefox - else if ((e.button === 2 || (e.button === 0 && e.altKey) || e.buttons === 2) && authorized) { + } else if ((e.button === 2 || (e.button === 0 && e.altKey) || e.buttons === 2) && authorized) { + // if it's a right click or holding down alt, start synapse creation ->third option is for firefox if (JIT.tempInit === false) { JIT.tempNode = node JIT.tempInit = true @@ -889,14 +886,14 @@ const JIT = { } // before making the highlighted one bigger, make sure all the others are regular size - Visualize.mGraph.graph.eachNode(function (n) { + Visualize.mGraph.graph.eachNode(function(n) { n.setData('dim', 25, 'current') }) temp.setData('dim', 35, 'current') Visualize.mGraph.plot() } else if (!temp) { JIT.tempNode2 = null - Visualize.mGraph.graph.eachNode(function (n) { + Visualize.mGraph.graph.eachNode(function(n) { n.setData('dim', 25, 'current') }) // pop up node creation :) @@ -913,16 +910,14 @@ const JIT = { y: pos.y } } - } - else if ((e.button === 2 || (e.button === 0 && e.altKey) || e.buttons === 2) && Active.Topic) { + } else if ((e.button === 2 || (e.button === 0 && e.altKey) || e.buttons === 2) && Active.Topic) { GlobalUI.notifyUser('Cannot create in Topic view.') - } - else if ((e.button === 2 || (e.button === 0 && e.altKey) || e.buttons === 2) && !authorized) { + } else if ((e.button === 2 || (e.button === 0 && e.altKey) || e.buttons === 2) && !authorized) { GlobalUI.notifyUser('Cannot edit this map.') } } }, // onDragMoveTopicHandler - onDragCancelHandler: function (node, eventInfo, e) { + onDragCancelHandler: function(node, eventInfo, e) { JIT.tempNode = null if (JIT.tempNode2) JIT.tempNode2.setData('dim', 25, 'current') JIT.tempNode2 = null @@ -932,22 +927,24 @@ const JIT = { Mouse.synapseEndCoordinates = null Visualize.mGraph.plot() }, // onDragCancelHandler - onDragEndTopicHandler: function (node, eventInfo, e) { - var self = JIT; - var midpoint = {}, pixelPos, mapping - - clearInterval(self.dragLeftEdge); - clearInterval(self.dragRightEdge); - clearInterval(self.dragTopEdge); - clearInterval(self.dragBottomEdge); - - delete self.dragLeftEdge; - delete self.dragRightEdge; - delete self.dragTopEdge; - delete self.dragBottomEdge; + onDragEndTopicHandler: function(node, eventInfo, e) { + const self = JIT + const midpoint = {} + let pixelPos + let mapping - self.dragFlag = 0; - self.dragTolerance = 0; + clearInterval(self.dragLeftEdge) + clearInterval(self.dragRightEdge) + clearInterval(self.dragTopEdge) + clearInterval(self.dragBottomEdge) + + delete self.dragLeftEdge + delete self.dragRightEdge + delete self.dragTopEdge + delete self.dragBottomEdge + + self.dragFlag = 0 + self.dragTolerance = 0 if (JIT.tempInit && JIT.tempNode2 === null) { // this means you want to add a new topic, and then a synapse @@ -973,7 +970,7 @@ const JIT = { // this means you dragged an existing node, autosave that to the database // check whether to save mappings - const checkWhetherToSave = function () { + const checkWhetherToSave = function() { const map = Active.Map if (!map) return false return map.authorizeToEdit(Active.Mapper) @@ -1000,7 +997,7 @@ const JIT = { } } }, // onDragEndTopicHandler - canvasClickHandler: function (canvasLoc, e) { + canvasClickHandler: function(canvasLoc, e) { // grab the location and timestamp of the click const storedTime = Mouse.lastCanvasClick const now = Date.now() // not compatible with IE8 FYI @@ -1045,37 +1042,37 @@ const JIT = { // SINGLE CLICK, resulting from pan Create.newTopic.hide() } - }, // canvasClickHandler - updateTopicPositions: function (node, pos){ - var len = Selected.Nodes.length; - var topic; - // this is used to send nodes that are moving to + }, // canvasClickHandler + updateTopicPositions: function(node, pos) { + const len = Selected.Nodes.length + // this is used to send nodes that are moving to // other realtime collaborators on the same map - var positionsToSend = {}; + const positionsToSend = {} // first define offset for each node var xOffset = [] var yOffset = [] - for (var i = 0; i < len; i += 1) { - var n = Selected.Nodes[i] + for (let i = 0; i < len; i += 1) { + const n = Selected.Nodes[i] xOffset[i] = n.pos.getc().x - node.pos.getc().x yOffset[i] = n.pos.getc().y - node.pos.getc().y } // for - for (var i = 0; i < len; i += 1) { - var n = Selected.Nodes[i] - var x = pos.x + xOffset[i] - var y = pos.y + yOffset[i] + for (let i = 0; i < len; i += 1) { + const n = Selected.Nodes[i] + const x = pos.x + xOffset[i] + const y = pos.y + yOffset[i] if (n.pos.rho || n.pos.rho === 0) { // this means we're in topic view - var rho = Math.sqrt(x * x + y * y) - var theta = Math.atan2(y, x) + const rho = Math.sqrt(x * x + y * y) + const theta = Math.atan2(y, x) n.pos.setp(theta, rho) + } else { + n.pos.setc(x, y) } - else n.pos.setc(x, y) if (Active.Map) { - topic = n.getData('topic') + const topic = n.getData('topic') // we use the topic ID not the node id // because we can't depend on the node id // to be the same as on other collaborators @@ -1089,13 +1086,13 @@ const JIT = { } }, - nodeDoubleClickHandler: function (node, e) { + nodeDoubleClickHandler: function(node, e) { TopicCard.showCard(node) }, // nodeDoubleClickHandler - edgeDoubleClickHandler: function (adj, e) { + edgeDoubleClickHandler: function(adj, e) { SynapseCard.showCard(adj, e) }, // nodeDoubleClickHandler - nodeWasDoubleClicked: function () { + nodeWasDoubleClicked: function() { // grab the timestamp of the click const storedTime = Mouse.lastNodeClick const now = Date.now() // not compatible with IE8 FYI @@ -1107,7 +1104,7 @@ const JIT = { return false } }, // nodeWasDoubleClicked - handleSelectionBeforeDragging: function (node, e) { + handleSelectionBeforeDragging: function(node, e) { if (Selected.Nodes.length === 0) { Control.selectNode(node, e) } @@ -1121,7 +1118,7 @@ const JIT = { } } }, // handleSelectionBeforeDragging - getNodeXY: function (node) { + getNodeXY: function(node) { if (typeof node.pos.x === 'number' && typeof node.pos.y === 'number') { return node.pos } else if (typeof node.pos.theta === 'number' && typeof node.pos.rho === 'number') { @@ -1131,7 +1128,7 @@ const JIT = { return {} } }, - selectWithBox: function (e) { + selectWithBox: function(e) { const self = this let sX = Mouse.boxStartCoordinates.x let sY = Mouse.boxStartCoordinates.y @@ -1144,7 +1141,7 @@ const JIT = { } // select all nodes that are within the box - Visualize.mGraph.graph.eachNode(function (n) { + Visualize.mGraph.graph.eachNode(function(n) { const pos = self.getNodeXY(n) const x = pos.x const y = pos.y @@ -1172,13 +1169,13 @@ const JIT = { eY = -1 * eY const edgesToToggle = [] - DataModel.Synapses.each(function (synapse) { + DataModel.Synapses.each(function(synapse) { const e = synapse.get('edge') if (edgesToToggle.indexOf(e) === -1) { edgesToToggle.push(e) } }) - edgesToToggle.forEach(function (edge) { + edgesToToggle.forEach(function(edge) { const fromNodePos = self.getNodeXY(edge.nodeFrom) const fromNodeX = fromNodePos.x const fromNodeY = -1 * fromNodePos.y @@ -1213,7 +1210,7 @@ const JIT = { let minSlope = slopes[0] let maxSlope = slopes[0] - slopes.forEach(function (entry) { + slopes.forEach(function(entry) { if (entry > maxSlope) maxSlope = entry if (entry < minSlope) minSlope = entry }) @@ -1277,7 +1274,7 @@ const JIT = { Mouse.boxEndCoordinates = false Visualize.mGraph.plot() }, // selectWithBox - drawSelectBox: function (eventInfo, e) { + drawSelectBox: function(eventInfo, e) { const ctx = Visualize.mGraph.canvas.getCtx() const startX = Mouse.boxStartCoordinates.x @@ -1297,13 +1294,13 @@ const JIT = { ctx.strokeStyle = 'black' ctx.stroke() }, // drawSelectBox - selectNodeOnClickHandler: function (node, e) { + selectNodeOnClickHandler: function(node, e) { if (Visualize.mGraph.busy) return const self = JIT - - //Copy topic title to clipboard - if(e.button===1 && e.ctrlKey) clipboard.copy(node.name); + + // Copy topic title to clipboard + if (e.button === 1 && e.ctrlKey) clipboard.copy(node.name) // catch right click on mac, which is often like ctrl+click if (navigator.platform.indexOf('Mac') !== -1 && e.ctrlKey) { @@ -1323,44 +1320,43 @@ const JIT = { return } else { // wait a certain length of time, then check again, then run this code - setTimeout(function () { + setTimeout(function() { if (!JIT.nodeWasDoubleClicked()) { var nodeAlreadySelected = node.selected - - if(e.button!==1){ + + if (e.button !== 1) { if (!e.shiftKey) { Control.deselectAllNodes() Control.deselectAllEdges() } - + if (nodeAlreadySelected) { Control.deselectNode(node) } else { Control.selectNode(node, e) } - + // trigger animation to final styles Visualize.mGraph.fx.animate({ modes: ['edge-property:lineWidth:color:alpha'], duration: 500 }) Visualize.mGraph.plot() - } else { - if(!e.ctrlKey){ - var len = Selected.Nodes.length; - + if (!e.ctrlKey) { + var len = Selected.Nodes.length + for (let i = 0; i < len; i += 1) { - let n = Selected.Nodes[i]; - let result = Metamaps.Util.openLink(Metamaps.Topics.get(n.id).attributes.link); - - if (!result) { //if link failed to open - break; + let n = Selected.Nodes[i] + let result = Util.openLink(DataModel.Topics.get(n.id).attributes.link) + + if (!result) { // if link failed to open + break } } - - if(!node.selected){ - Metamaps.Util.openLink(Metamaps.Topics.get(node.id).attributes.link); + + if (!node.selected) { + Util.openLink(DataModel.Topics.get(node.id).attributes.link) } } } @@ -1368,7 +1364,7 @@ const JIT = { }, Mouse.DOUBLE_CLICK_TOLERANCE) } }, // selectNodeOnClickHandler - selectNodeOnRightClickHandler: function (node, e) { + selectNodeOnRightClickHandler: function(node, e) { // the 'node' variable is a JIT node, the one that was clicked on // the 'e' variable is the click event @@ -1485,7 +1481,7 @@ const JIT = { // delete the selected things from the database if (authorized) { - $('.rc-delete').click(function () { + $('.rc-delete').click(function() { $('.rightclickmenu').remove() Control.deleteSelected() }) @@ -1493,7 +1489,7 @@ const JIT = { // remove the selected things from the map if (Active.Topic || authorized) { - $('.rc-remove').click(function () { + $('.rc-remove').click(function() { $('.rightclickmenu').remove() Control.removeSelectedEdges() Control.removeSelectedNodes() @@ -1501,34 +1497,34 @@ const JIT = { } // hide selected nodes and synapses until refresh - $('.rc-hide').click(function () { + $('.rc-hide').click(function() { $('.rightclickmenu').remove() Control.hideSelectedEdges() Control.hideSelectedNodes() }) // when in radial, center on the topic you picked - $('.rc-center').click(function () { + $('.rc-center').click(function() { $('.rightclickmenu').remove() Topic.centerOn(node.id) }) // open the entity in a new tab - $('.rc-popout').click(function () { + $('.rc-popout').click(function() { $('.rightclickmenu').remove() const win = window.open('/topics/' + node.id, '_blank') win.focus() }) // change the permission of all the selected nodes and synapses that you were the originator of - $('.rc-permission li').click(function () { + $('.rc-permission li').click(function() { $('.rightclickmenu').remove() // $(this).text() will be 'commons' 'public' or 'private' Control.updateSelectedPermissions($(this).text()) }) // change the metacode of all the selected nodes that you have edit permission for - $('.rc-metacode li li').click(function () { + $('.rc-metacode li li').click(function() { $('.rightclickmenu').remove() // Control.updateSelectedMetacodes($(this).attr('data-id')) @@ -1536,19 +1532,19 @@ const JIT = { // fetch relatives let fetchSent = false - $('.rc-siblings').hover(function () { + $('.rc-siblings').hover(function() { if (!fetchSent) { JIT.populateRightClickSiblings(node) fetchSent = true } }) - $('.rc-siblings .fetchAll').click(function () { + $('.rc-siblings .fetchAll').click(function() { $('.rightclickmenu').remove() // data-id is a metacode id Topic.fetchRelatives(node) }) }, // selectNodeOnRightClickHandler, - populateRightClickSiblings: function (node) { + populateRightClickSiblings: function(node) { // depending on how many topics are selected, do different things const topic = node.getData('topic') @@ -1560,10 +1556,10 @@ const JIT = { loader.setRange(0.9) // default is 1.3 loader.show() // Hidden by default - const topics = DataModel.Topics.map(function (t) { return t.id }) + const topics = DataModel.Topics.map(function(t) { return t.id }) const topicsString = topics.join() - const successCallback = function (data) { + const successCallback = function(data) { $('#loadingSiblings').remove() for (var key in data) { @@ -1571,7 +1567,7 @@ const JIT = { $('#fetchSiblingList').append(`
  • ${string}
  • `) } - $('.rc-siblings .getSiblings').click(function () { + $('.rc-siblings .getSiblings').click(function() { $('.rightclickmenu').remove() // data-id is a metacode id Topic.fetchRelatives(node, $(this).attr('data-id')) @@ -1582,16 +1578,16 @@ const JIT = { type: 'GET', url: '/topics/' + topic.id + '/relative_numbers.json?network=' + topicsString, success: successCallback, - error: function () {} + error: function() {} }) }, - selectEdgeOnClickHandler: function (adj, e) { + selectEdgeOnClickHandler: function(adj, e) { if (Visualize.mGraph.busy) return const self = JIT - var synapseText = adj.data.$synapses[0].attributes.desc; - //Copy synapse label to clipboard - if(e.button===1 && e.ctrlKey && synapseText !== "") clipboard.copy(synapseText); + var synapseText = adj.data.$synapses[0].attributes.desc + // Copy synapse label to clipboard + if (e.button === 1 && e.ctrlKey && synapseText !== '') clipboard.copy(synapseText) // catch right click on mac, which is often like ctrl+click if (navigator.platform.indexOf('Mac') !== -1 && e.ctrlKey) { @@ -1605,7 +1601,7 @@ const JIT = { return } else { // wait a certain length of time, then check again, then run this code - setTimeout(function () { + setTimeout(function() { if (!JIT.nodeWasDoubleClicked()) { const edgeAlreadySelected = Selected.Edges.indexOf(adj) !== -1 @@ -1625,7 +1621,7 @@ const JIT = { }, Mouse.DOUBLE_CLICK_TOLERANCE) } }, // selectEdgeOnClickHandler - selectEdgeOnRightClickHandler: function (adj, e) { + selectEdgeOnRightClickHandler: function(adj, e) { // the 'node' variable is a JIT node, the one that was clicked on // the 'e' variable is the click event @@ -1705,7 +1701,7 @@ const JIT = { // delete the selected things from the database if (authorized) { - $('.rc-delete').click(function () { + $('.rc-delete').click(function() { $('.rightclickmenu').remove() Control.deleteSelected() }) @@ -1713,7 +1709,7 @@ const JIT = { // remove the selected things from the map if (authorized) { - $('.rc-remove').click(function () { + $('.rc-remove').click(function() { $('.rightclickmenu').remove() Control.removeSelectedEdges() Control.removeSelectedNodes() @@ -1721,20 +1717,20 @@ const JIT = { } // hide selected nodes and synapses until refresh - $('.rc-hide').click(function () { + $('.rc-hide').click(function() { $('.rightclickmenu').remove() Control.hideSelectedEdges() Control.hideSelectedNodes() }) // change the permission of all the selected nodes and synapses that you were the originator of - $('.rc-permission li').click(function () { + $('.rc-permission li').click(function() { $('.rightclickmenu').remove() // $(this).text() will be 'commons' 'public' or 'private' Control.updateSelectedPermissions($(this).text()) }) }, // selectEdgeOnRightClickHandler - SmoothPanning: function () { + SmoothPanning: function() { const sx = Visualize.mGraph.canvas.scaleOffsetX const sy = Visualize.mGraph.canvas.scaleOffsetY const yVelocity = Mouse.changeInY // initial y velocity @@ -1742,11 +1738,11 @@ const JIT = { let easing = 1 // frictional value window.clearInterval(panningInt) - panningInt = setInterval(function () { + panningInt = setInterval(function() { myTimer() }, 1) - function myTimer () { + function myTimer() { Visualize.mGraph.canvas.translate(xVelocity * easing * 1 / sx, yVelocity * easing * 1 / sy) $(document).trigger(JIT.events.pan) easing = easing * 0.75 @@ -1754,7 +1750,7 @@ const JIT = { if (easing < 0.1) window.clearInterval(panningInt) } }, // SmoothPanning - renderMidArrow: function (from, to, dim, swap, canvas, placement, newSynapse) { + renderMidArrow: function(from, to, dim, swap, canvas, placement, newSynapse) { const ctx = canvas.getCtx() // invert edge direction if (swap) { @@ -1795,7 +1791,7 @@ const JIT = { ctx.lineTo(v2.x, v2.y) ctx.stroke() }, // renderMidArrow - renderEdgeArrows: function (edgeHelper, adj, synapse, canvas) { + renderEdgeArrows: function(edgeHelper, adj, synapse, canvas) { const self = JIT const directionCat = synapse.get('category') @@ -1848,15 +1844,15 @@ const JIT = { }, 13, inv, canvas, 0.3) } }, // renderEdgeArrows - zoomIn: function (event) { + zoomIn: function(event) { Visualize.mGraph.canvas.scale(1.25, 1.25) $(document).trigger(JIT.events.zoom, [event]) }, - zoomOut: function (event) { + zoomOut: function(event) { Visualize.mGraph.canvas.scale(0.8, 0.8) $(document).trigger(JIT.events.zoom, [event]) }, - centerMap: function (canvas) { + centerMap: function(canvas) { const offsetScale = canvas.scaleOffsetX canvas.scale(1 / offsetScale, 1 / offsetScale) @@ -1866,7 +1862,7 @@ const JIT = { canvas.translate(-1 * offsetX, -1 * offsetY) }, - zoomToBox: function (event) { + zoomToBox: function(event) { const sX = Mouse.boxStartCoordinates.x const sY = Mouse.boxStartCoordinates.y const eX = Mouse.boxEndCoordinates.x @@ -1905,7 +1901,7 @@ const JIT = { Mouse.boxEndCoordinates = false Visualize.mGraph.plot() }, - zoomExtents: function (event, canvas, denySelected) { + zoomExtents: function(event, canvas, denySelected) { JIT.centerMap(canvas) let height = canvas.getSize().height let width = canvas.getSize().width @@ -1923,7 +1919,7 @@ const JIT = { } if (nodes.length > 1) { - nodes.forEach(function (n) { + nodes.forEach(function(n) { let x = n.pos.x let y = n.pos.y @@ -1982,7 +1978,7 @@ const JIT = { $(document).trigger(JIT.events.zoom, [event]) } else if (nodes.length === 1) { - nodes.forEach(function (n) { + nodes.forEach(function(n) { const x = n.pos.x const y = n.pos.y diff --git a/frontend/src/Metamaps/Listeners.js b/frontend/src/Metamaps/Listeners.js index 522bb255..470e8cbe 100644 --- a/frontend/src/Metamaps/Listeners.js +++ b/frontend/src/Metamaps/Listeners.js @@ -12,9 +12,9 @@ import Visualize from './Visualize' import { Search } from './GlobalUI' const Listeners = { - init: function () { + init: function() { var self = this - $(document).on('keydown', function (e) { + $(document).on('keydown', function(e) { if (!(Active.Map || Active.Topic)) return const onCanvas = e.target.tagName === 'BODY' @@ -35,7 +35,7 @@ const Listeners = { Control.deselectAllEdges() e.preventDefault() - Visualize.mGraph.graph.eachNode(function (n) { + Visualize.mGraph.graph.eachNode(function(n) { Control.selectNode(n, e) }) @@ -110,7 +110,7 @@ const Listeners = { } }) - $(window).resize(function () { + $(window).resize(function() { if (Visualize && Visualize.mGraph) { Util.resizeCanvas(Visualize.mGraph.canvas) } @@ -119,11 +119,11 @@ const Listeners = { Mobile.resizeTitle() }) }, - centerAndReveal: function (nodes, opts) { + centerAndReveal: function(nodes, opts) { if (nodes.length < 1) return var node = nodes[nodes.length - 1] if (opts.center && opts.reveal) { - Topic.centerOn(node.id, function () { + Topic.centerOn(node.id, function() { Topic.fetchRelatives(nodes) }) } else if (opts.center) { diff --git a/frontend/src/Metamaps/Loading.js b/frontend/src/Metamaps/Loading.js index b1fc2abb..50d2191b 100644 --- a/frontend/src/Metamaps/Loading.js +++ b/frontend/src/Metamaps/Loading.js @@ -2,13 +2,13 @@ const Loading = { loader: null, // needs CanvasLoader to be defined - hide: function () { + hide: function() { $('#loading').hide() }, - show: function () { + show: function() { $('#loading').show() }, - setup: function () { + setup: function() { if (!Loading.loader) Loading.loader = new CanvasLoader('loading') Loading.loader.setColor('#4fb5c0') // default is '#000000' Loading.loader.setDiameter(28) // default is 40 diff --git a/frontend/src/Metamaps/Map/CheatSheet.js b/frontend/src/Metamaps/Map/CheatSheet.js index be9fbfab..d791b5c7 100644 --- a/frontend/src/Metamaps/Map/CheatSheet.js +++ b/frontend/src/Metamaps/Map/CheatSheet.js @@ -1,28 +1,28 @@ /* global $ */ const CheatSheet = { - init: function () { + init: function() { // tab the cheatsheet $('#cheatSheet').tabs() $('#quickReference').tabs().addClass('ui-tabs-vertical ui-helper-clearfix') $('#quickReference .ui-tabs-nav li').removeClass('ui-corner-top').addClass('ui-corner-left') - // id = the id of a vimeo video - var switchVideo = function (element, id) { - $('.tutorialItem').removeClass('active') - $(element).addClass('active') - $('#tutorialVideo').attr('src', '//player.vimeo.com/video/' + id) - } + // // id = the id of a vimeo video + // var switchVideo = function(element, id) { + // $('.tutorialItem').removeClass('active') + // $(element).addClass('active') + // $('#tutorialVideo').attr('src', '//player.vimeo.com/video/' + id) + // } - $('#gettingStarted').click(function () { - // switchVideo(this,'88334167') - }) - $('#upYourSkillz').click(function () { - // switchVideo(this,'100118167') - }) - $('#advancedMapping').click(function () { - // switchVideo(this,'88334167') - }) + // $('#gettingStarted').click(function() { + // switchVideo(this,'88334167') + // }) + // $('#upYourSkillz').click(function() { + // switchVideo(this,'100118167') + // }) + // $('#advancedMapping').click(function() { + // switchVideo(this,'88334167') + // }) } } diff --git a/frontend/src/Metamaps/Map/InfoBox.js b/frontend/src/Metamaps/Map/InfoBox.js index bf56dc90..1b06daf5 100644 --- a/frontend/src/Metamaps/Map/InfoBox.js +++ b/frontend/src/Metamaps/Map/InfoBox.js @@ -35,23 +35,23 @@ const InfoBox = { data-bip-value="{{desc}}" >{{desc}}`, userImageUrl: '', - init: function (serverData) { + init: function(serverData) { var self = InfoBox $('.mapInfoIcon').click(self.toggleBox) - $('.mapInfoBox').click(function (event) { + $('.mapInfoBox').click(function(event) { event.stopPropagation() }) $('body').click(self.close) - self.attachEventListeners() + self.attachEventListeners() self.generateBoxHTML = Hogan.compile($('#mapInfoBoxTemplate').html()) self.userImageUrl = serverData['user.png'] var querystring = window.location.search.replace(/^\?/, '') - if (querystring == 'new') { + if (querystring === 'new') { self.open() $('.mapInfoBox').addClass('mapRequestTitle') $('#mapInfoName').trigger('click') @@ -59,7 +59,7 @@ const InfoBox = { $('#mapInfoName textarea').select() } }, - toggleBox: function (event) { + toggleBox: function(event) { var self = InfoBox if (self.isOpen) self.close() @@ -67,24 +67,24 @@ const InfoBox = { event.stopPropagation() }, - open: function () { + open: function() { var self = InfoBox $('.mapInfoIcon div').addClass('hide') if (!self.isOpen && !self.changing) { self.changing = true - $('.mapInfoBox').fadeIn(200, function () { + $('.mapInfoBox').fadeIn(200, function() { self.changing = false self.isOpen = true }) } }, - close: function () { + close: function() { var self = InfoBox $('.mapInfoIcon div').removeClass('hide') if (!self.changing) { self.changing = true - $('.mapInfoBox').fadeOut(200, function () { + $('.mapInfoBox').fadeOut(200, function() { self.changing = false self.isOpen = false self.hidePermissionSelect() @@ -92,7 +92,7 @@ const InfoBox = { }) } }, - load: function () { + load: function() { var self = InfoBox var map = Active.Map @@ -127,14 +127,14 @@ const InfoBox = { self.attachEventListeners() }, - attachEventListeners: function () { + attachEventListeners: function() { var self = InfoBox $('.mapInfoBox.canEdit .best_in_place').best_in_place() // because anyone who can edit the map can change the map title var bipName = $('.mapInfoBox .best_in_place_name') - bipName.unbind('best_in_place:activate').bind('best_in_place:activate', function () { + bipName.unbind('best_in_place:activate').bind('best_in_place:activate', function() { var $el = bipName.find('textarea') var el = $el[0] @@ -142,16 +142,16 @@ const InfoBox = { $('.mapInfoName').append('
    ') - var callback = function (data) { + var callback = function(data) { $('.nameCounter.forMap').html(data.all + '/140') } Countable.live(el, callback) }) - bipName.unbind('best_in_place:deactivate').bind('best_in_place:deactivate', function () { + bipName.unbind('best_in_place:deactivate').bind('best_in_place:deactivate', function() { $('.nameCounter.forMap').remove() }) - $('.mapInfoName .best_in_place_name').unbind('ajax:success').bind('ajax:success', function () { + $('.mapInfoName .best_in_place_name').unbind('ajax:success').bind('ajax:success', function() { var name = $(this).html() Active.Map.set('name', name) Active.Map.trigger('saved') @@ -162,7 +162,7 @@ const InfoBox = { window.history.replaceState('', `${name} | Metamaps`, window.location.pathname) }) - $('.mapInfoDesc .best_in_place_desc').unbind('ajax:success').bind('ajax:success', function () { + $('.mapInfoDesc .best_in_place_desc').unbind('ajax:success').bind('ajax:success', function() { var desc = $(this).html() Active.Map.set('desc', desc) Active.Map.trigger('saved') @@ -182,76 +182,76 @@ const InfoBox = { $('.yourMap .mapInfoDelete').unbind().click(self.deleteActiveMap) - $('.mapContributors span, #mapContribs').unbind().click(function (event) { + $('.mapContributors span, #mapContribs').unbind().click(function(event) { $('.mapContributors .tip').toggle() event.stopPropagation() }) - $('.mapContributors .tip').unbind().click(function (event) { + $('.mapContributors .tip').unbind().click(function(event) { event.stopPropagation() }) $('.mapContributors .tip li a').click(Router.intercept) - $('.mapInfoBox').unbind('.hideTip').bind('click.hideTip', function () { + $('.mapInfoBox').unbind('.hideTip').bind('click.hideTip', function() { $('.mapContributors .tip').hide() }) - self.addTypeahead() + self.addTypeahead() }, - addTypeahead: function () { + addTypeahead: function() { var self = InfoBox if (!Active.Map) return // for autocomplete var collaborators = { - name: 'collaborators', - limit: 9999, - display: function(s) { return s.label; }, - templates: { - notFound: function(s) { - return Hogan.compile($('#collaboratorSearchTemplate').html()).render({ - value: "No results", - label: "No results", - rtype: "noresult", - profile: self.userImageUrl - }); - }, - suggestion: function(s) { - return Hogan.compile($('#collaboratorSearchTemplate').html()).render(s); - }, + name: 'collaborators', + limit: 9999, + display: function(s) { return s.label }, + templates: { + notFound: function(s) { + return Hogan.compile($('#collaboratorSearchTemplate').html()).render({ + value: 'No results', + label: 'No results', + rtype: 'noresult', + profile: self.userImageUrl + }) }, - source: new Bloodhound({ - datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), - queryTokenizer: Bloodhound.tokenizers.whitespace, - remote: { - url: '/search/mappers?term=%QUERY', - wildcard: '%QUERY', - }, - }) + suggestion: function(s) { + return Hogan.compile($('#collaboratorSearchTemplate').html()).render(s) + } + }, + source: new Bloodhound({ + datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), + queryTokenizer: Bloodhound.tokenizers.whitespace, + remote: { + url: '/search/mappers?term=%QUERY', + wildcard: '%QUERY' + } + }) } // for adding map collaborators, who will have edit rights if (Active.Mapper && Active.Mapper.id === Active.Map.get('user_id')) { $('.collaboratorSearchField').typeahead( { - highlight: false, + highlight: false }, [collaborators] ) $('.collaboratorSearchField').bind('typeahead:select', self.handleResultClick) - $('.mapContributors .removeCollaborator').click(function () { + $('.mapContributors .removeCollaborator').click(function() { self.removeCollaborator(parseInt($(this).data('id'))) }) - } + } }, - removeCollaborator: function (collaboratorId) { + removeCollaborator: function(collaboratorId) { var self = InfoBox DataModel.Collaborators.remove(DataModel.Collaborators.get(collaboratorId)) - var mapperIds = DataModel.Collaborators.models.map(function (mapper) { return mapper.id }) + var mapperIds = DataModel.Collaborators.models.map(function(mapper) { return mapper.id }) $.post('/maps/' + Active.Map.id + '/access', { access: mapperIds }) self.updateNumbers() }, - addCollaborator: function (newCollaboratorId) { + addCollaborator: function(newCollaboratorId) { var self = InfoBox if (DataModel.Collaborators.get(newCollaboratorId)) { @@ -261,7 +261,7 @@ const InfoBox = { function callback(mapper) { DataModel.Collaborators.add(mapper) - var mapperIds = DataModel.Collaborators.models.map(function (mapper) { return mapper.id }) + var mapperIds = DataModel.Collaborators.models.map(function(mapper) { return mapper.id }) $.post('/maps/' + Active.Map.id + '/access', { access: mapperIds }) var name = DataModel.Collaborators.get(newCollaboratorId).get('name') GlobalUI.notifyUser(name + ' will be notified by email') @@ -270,29 +270,28 @@ const InfoBox = { $.getJSON('/users/' + newCollaboratorId + '.json', callback) }, - handleResultClick: function (event, item) { + handleResultClick: function(event, item) { var self = InfoBox - self.addCollaborator(item.id) - $('.collaboratorSearchField').typeahead('val', '') + self.addCollaborator(item.id) + $('.collaboratorSearchField').typeahead('val', '') }, - updateNameDescPerm: function (name, desc, perm) { + updateNameDescPerm: function(name, desc, perm) { $('.mapInfoBox').removeClass('mapRequestTitle') $('.mapInfoName .best_in_place_name').html(name) $('.mapInfoDesc .best_in_place_desc').html(desc) $('.mapInfoBox .mapPermission').removeClass('commons public private').addClass(perm) }, - createContributorList: function () { - var self = InfoBox + createContributorList: function() { var relevantPeople = Active.Map.get('permission') === 'commons' ? DataModel.Mappers : DataModel.Collaborators var activeMapperIsCreator = Active.Mapper && Active.Mapper.id === Active.Map.get('user_id') var string = '' string += '