From 113a5a253070817f806344bfae98b1d29c8fe574 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 4 Oct 2016 23:38:32 +0800 Subject: [PATCH] fix a bunch of bug risk eslint warnings --- frontend/src/Metamaps/Account.js | 6 ++-- frontend/src/Metamaps/Admin.js | 2 +- frontend/src/Metamaps/Control.js | 4 +-- frontend/src/Metamaps/Create.js | 8 ++--- frontend/src/Metamaps/Import.js | 6 ++-- frontend/src/Metamaps/JIT.js | 40 +++++++++++++++++-------- frontend/src/Metamaps/Map/CheatSheet.js | 2 ++ frontend/src/Metamaps/Map/InfoBox.js | 4 +-- frontend/src/Metamaps/Map/index.js | 5 ++-- frontend/src/Metamaps/Organize.js | 7 ++--- frontend/src/Metamaps/PasteInput.js | 8 ++--- frontend/src/Metamaps/Realtime.js | 1 + frontend/src/Metamaps/Selected.js | 2 +- frontend/src/Metamaps/Settings.js | 2 +- frontend/src/Metamaps/TopicCard.js | 2 +- 15 files changed, 59 insertions(+), 40 deletions(-) diff --git a/frontend/src/Metamaps/Account.js b/frontend/src/Metamaps/Account.js index 10311cbd..1ac87811 100644 --- a/frontend/src/Metamaps/Account.js +++ b/frontend/src/Metamaps/Account.js @@ -1,3 +1,5 @@ +/* global $, CanvasLoader */ + /* * Metamaps.Erb */ @@ -43,7 +45,7 @@ const Account = { var file = $('#user_image')[0].files[0] - var reader = new FileReader() + var reader = new window.FileReader() reader.onload = function (e) { var $canvas = $('').attr({ @@ -51,7 +53,7 @@ const Account = { height: 84 }) var context = $canvas[0].getContext('2d') - var imageObj = new Image() + var imageObj = new window.Image() imageObj.onload = function () { $('.userImageDiv canvas').remove() diff --git a/frontend/src/Metamaps/Admin.js b/frontend/src/Metamaps/Admin.js index 5d080c2e..d78fcecb 100644 --- a/frontend/src/Metamaps/Admin.js +++ b/frontend/src/Metamaps/Admin.js @@ -41,7 +41,7 @@ const Admin = { var self = Admin if (self.selectMetacodes.length == 0) { - alert('Would you pretty please select at least one metacode for the set?') + window.alert('Would you pretty please select at least one metacode for the set?') return false } } diff --git a/frontend/src/Metamaps/Control.js b/frontend/src/Metamaps/Control.js index c6c963ac..7662f47d 100644 --- a/frontend/src/Metamaps/Control.js +++ b/frontend/src/Metamaps/Control.js @@ -63,7 +63,7 @@ const Control = { return } - var r = confirm(outdent` + var r = window.confirm(outdent` You have ${ntext} and ${etext} selected. Are you sure you want to permanently delete them all? This will remove them from all maps they appear on.`) @@ -456,7 +456,7 @@ const Control = { var message = nString + ' you can edit updated to ' + metacode.get('name') GlobalUI.notifyUser(message) Visualize.mGraph.plot() - }, + } } export default Control diff --git a/frontend/src/Metamaps/Create.js b/frontend/src/Metamaps/Create.js index bfb9b94c..92271223 100644 --- a/frontend/src/Metamaps/Create.js +++ b/frontend/src/Metamaps/Create.js @@ -169,15 +169,15 @@ const Create = { queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { url: '/topics/autocomplete_topic?term=%QUERY', - wildcard: '%QUERY', - }, + wildcard: '%QUERY' + } }) // initialize the autocomplete results for the metacode spinner $('#topic_name').typeahead( { highlight: true, - minLength: 2, + minLength: 2 }, [{ name: 'topic_autocomplete', @@ -186,7 +186,7 @@ const Create = { templates: { suggestion: function (s) { return Hogan.compile($('#topicAutocompleteTemplate').html()).render(s) - }, + } }, source: topicBloodhound, }] diff --git a/frontend/src/Metamaps/Import.js b/frontend/src/Metamaps/Import.js index 5d5f91a7..6788335f 100644 --- a/frontend/src/Metamaps/Import.js +++ b/frontend/src/Metamaps/Import.js @@ -143,7 +143,7 @@ const Import = { // FALL THROUGH - if we're not sure what to do, pretend // we're on the TOPICS_NEED_HEADERS state and parse some headers - case STATES.TOPICS_NEED_HEADERS: // eslint-disable-line + case STATES.TOPICS_NEED_HEADERS: // eslint-disable-line no-fallthrough if (noblanks.length < 2) { self.abort('Not enough topic headers on line ' + index) state = STATES.ABORT @@ -207,8 +207,8 @@ const Import = { } break case STATES.ABORT: - - default: + // FALL THROUGH + default: // eslint-disable-line no-fallthrough self.abort('Invalid state while parsing import data. Check code.') state = STATES.ABORT } diff --git a/frontend/src/Metamaps/JIT.js b/frontend/src/Metamaps/JIT.js index 54ec74b1..f8ffeb26 100644 --- a/frontend/src/Metamaps/JIT.js +++ b/frontend/src/Metamaps/JIT.js @@ -1,6 +1,7 @@ /* global Metamaps, $, Image, CanvasLoader */ import _ from 'lodash' +import outdent from 'outdent' import $jit from '../patched/JIT' @@ -1323,16 +1324,26 @@ const JIT = { if (Active.Topic) { menustring += '
  • Center this topic
    Alt+E
  • ' } + menustring += '
  • Open in new tab
  • ' + if (Active.Mapper) { - var options = '' + var options = outdent` + ` menustring += '
  • ' - menustring += '
  • Change permissions' + options + '
  • ' + menustring += outdent` +
  • +
    + Change permissions + ${options} +
    +
  • ` var metacodeOptions = $('#metacodeOptions').html() @@ -1345,10 +1356,11 @@ const JIT = { // set up the get sibling menu as a "lazy load" // only fill in the submenu when they hover over the get siblings list item - var siblingMenu = '' + var siblingMenu = outdent` + ` menustring += '
  • Reveal siblings' + siblingMenu + '
  • ' } @@ -1571,10 +1583,12 @@ const JIT = { if (Active.Map && Active.Mapper) menustring += '
  • ' if (Active.Mapper) { - var permOptions = '' + var permOptions = outdent` + ` menustring += '
  • Change permissions' + permOptions + '
  • ' } diff --git a/frontend/src/Metamaps/Map/CheatSheet.js b/frontend/src/Metamaps/Map/CheatSheet.js index 969ee159..be9fbfab 100644 --- a/frontend/src/Metamaps/Map/CheatSheet.js +++ b/frontend/src/Metamaps/Map/CheatSheet.js @@ -1,3 +1,5 @@ +/* global $ */ + const CheatSheet = { init: function () { // tab the cheatsheet diff --git a/frontend/src/Metamaps/Map/InfoBox.js b/frontend/src/Metamaps/Map/InfoBox.js index ba95df4b..0d3a5c5f 100644 --- a/frontend/src/Metamaps/Map/InfoBox.js +++ b/frontend/src/Metamaps/Map/InfoBox.js @@ -343,7 +343,7 @@ const InfoBox = { permission: permission }) Active.Map.updateMapWrapper() - shareable = permission === 'private' ? '' : 'shareable' + const shareable = permission === 'private' ? '' : 'shareable' $('.mapPermission').removeClass('commons public private minimize').addClass(permission) $('.mapPermission .permissionSelect').remove() $('.mapInfoBox').removeClass('shareable').addClass(shareable) @@ -369,7 +369,7 @@ const InfoBox = { GlobalUI.notifyUser('Map eliminated!') } else if (!authorized) { - alert("Hey now. We can't just go around willy nilly deleting other people's maps now can we? Run off and find something constructive to do, eh?") + window.alert("Hey now. We can't just go around willy nilly deleting other people's maps now can we? Run off and find something constructive to do, eh?") } } } diff --git a/frontend/src/Metamaps/Map/index.js b/frontend/src/Metamaps/Map/index.js index 387311c2..dc9b4eb8 100644 --- a/frontend/src/Metamaps/Map/index.js +++ b/frontend/src/Metamaps/Map/index.js @@ -230,7 +230,7 @@ const Map = { canEditNow: function () { var confirmString = "You've been granted permission to edit this map. " confirmString += 'Do you want to reload and enable realtime collaboration?' - var c = confirm(confirmString) + var c = window.confirm(confirmString) if (c) { Router.maps(Active.Map.id) } @@ -256,10 +256,11 @@ const Map = { canvas.getSize = function () { if (this.size) return this.size var canvas = this.canvas - return this.size = { + this.size = { width: canvas.width, height: canvas.height } + return this.size } canvas.scale = function (x, y) { var px = this.scaleOffsetX * x, diff --git a/frontend/src/Metamaps/Organize.js b/frontend/src/Metamaps/Organize.js index ed005d39..c79bd8d7 100644 --- a/frontend/src/Metamaps/Organize.js +++ b/frontend/src/Metamaps/Organize.js @@ -1,5 +1,3 @@ -/* global $ */ - import _ from 'lodash' import $jit from '../patched/JIT' @@ -44,7 +42,7 @@ const Organize = { var column = floor(width / cellWidth) var totalCells = row * column - if (totalCells) + if (totalCells) { Visualize.mGraph.graph.eachNode(function (n) { if (column == numColumns) { column = 0 @@ -56,6 +54,7 @@ const Organize = { n.setPos(newPos, 'end') column += 1 }) + } Visualize.mGraph.animate(JIT.ForceDirected.animateSavedLayout) } else if (layout == 'radial') { var centerX = centerNode.getPos().x @@ -112,7 +111,7 @@ const Organize = { console.log(lowX, lowY, highX, highY) var newOriginX = (lowX + highX) / 2 var newOriginY = (lowY + highY) / 2 - } else alert('please call function with a valid layout dammit!') + } else window.alert('please call function with a valid layout dammit!') } } diff --git a/frontend/src/Metamaps/PasteInput.js b/frontend/src/Metamaps/PasteInput.js index bc20ec43..6f1cc03f 100644 --- a/frontend/src/Metamaps/PasteInput.js +++ b/frontend/src/Metamaps/PasteInput.js @@ -13,16 +13,16 @@ const PasteInput = { // intercept dragged files // see http://stackoverflow.com/questions/6756583 window.addEventListener("dragover", function(e) { - e = e || event; + e = e || window.event; e.preventDefault(); }, false); window.addEventListener("drop", function(e) { - e = e || event; + e = e || window.event; e.preventDefault(); var coords = Util.pixelsToCoords({ x: e.clientX, y: e.clientY }) if (e.dataTransfer.files.length > 0) { - var fileReader = new FileReader() - var text = fileReader.readAsText(e.dataTransfer.files[0]) + var fileReader = new window.FileReader() + fileReader.readAsText(e.dataTransfer.files[0]) fileReader.onload = function(e) { var text = e.currentTarget.result if (text.substring(0,5) === '