diff --git a/modules/behavior/add_way.js b/modules/behavior/add_way.js index 41a36e35c..8fb6b3ca1 100644 --- a/modules/behavior/add_way.js +++ b/modules/behavior/add_way.js @@ -6,8 +6,8 @@ import { utilRebind } from '../util/rebind'; export function behaviorAddWay(context) { - var dispatch = d3_dispatch('start', 'startFromWay', 'startFromNode'), - draw = behaviorDraw(context); + var dispatch = d3_dispatch('start', 'startFromWay', 'startFromNode'); + var draw = behaviorDraw(context); var addWay = function(surface) { draw.on('click', function() { dispatch.apply('start', this, arguments); }) diff --git a/modules/behavior/breathe.js b/modules/behavior/breathe.js index f90a89f30..6b09fe476 100644 --- a/modules/behavior/breathe.js +++ b/modules/behavior/breathe.js @@ -11,14 +11,14 @@ import { timer as d3_timer } from 'd3-timer'; export function behaviorBreathe() { - var duration = 800, - steps = 4, - selector = '.selected.shadow, .selected .shadow', - selected = d3_select(null), - classed = '', - params = {}, - done = false, - timer; + var duration = 800; + var steps = 4; + var selector = '.selected.shadow, .selected .shadow'; + var _selected = d3_select(null); + var _classed = ''; + var _params = {}; + var _done = false; + var _timer; function ratchetyInterpolator(a, b, steps, units) { @@ -49,30 +49,30 @@ export function behaviorBreathe() { transition .styleTween('stroke-opacity', function(d) { return ratchetyInterpolator( - params[d.id][toFrom].opacity, - params[d.id][fromTo].opacity, + _params[d.id][toFrom].opacity, + _params[d.id][fromTo].opacity, steps ); }) .styleTween('stroke-width', function(d) { return ratchetyInterpolator( - params[d.id][toFrom].width, - params[d.id][fromTo].width, + _params[d.id][toFrom].width, + _params[d.id][fromTo].width, steps, 'px' ); }) .styleTween('fill-opacity', function(d) { return ratchetyInterpolator( - params[d.id][toFrom].opacity, - params[d.id][fromTo].opacity, + _params[d.id][toFrom].opacity, + _params[d.id][fromTo].opacity, steps ); }) .styleTween('r', function(d) { return ratchetyInterpolator( - params[d.id][toFrom].width, - params[d.id][fromTo].width, + _params[d.id][toFrom].width, + _params[d.id][fromTo].width, steps, 'px' ); @@ -84,10 +84,11 @@ export function behaviorBreathe() { selection .call(reset) .each(function(d) { - var s = d3_select(this), - tag = s.node().tagName, - p = {'from': {}, 'to': {}}, - opacity, width; + var s = d3_select(this); + var tag = s.node().tagName; + var p = {'from': {}, 'to': {}}; + var opacity; + var width; // determine base opacity and width if (tag === 'circle') { @@ -104,28 +105,28 @@ export function behaviorBreathe() { p.to.opacity = opacity * 1.25; p.from.width = width * 0.7; p.to.width = width * (tag === 'circle' ? 1.5 : 1); - params[d.id] = p; + _params[d.id] = p; }); } function run(surface, fromTo) { - var toFrom = (fromTo === 'from' ? 'to' : 'from'), - currSelected = surface.selectAll(selector), - currClassed = surface.attr('class'); + var toFrom = (fromTo === 'from' ? 'to' : 'from'); + var currSelected = surface.selectAll(selector); + var currClassed = surface.attr('class'); - if (done || currSelected.empty()) { - selected.call(reset); + if (_done || currSelected.empty()) { + _selected.call(reset); return; } - if (!_isEqual(currSelected.data(), selected.data()) || currClassed !== classed) { - selected.call(reset); - classed = currClassed; - selected = currSelected.call(calcAnimationParams); + if (!_isEqual(currSelected.data(), _selected.data()) || currClassed !== _classed) { + _selected.call(reset); + _classed = currClassed; + _selected = currSelected.call(calcAnimationParams); } - selected + _selected .transition() .duration(duration) .call(setAnimationParams, fromTo) @@ -136,26 +137,26 @@ export function behaviorBreathe() { var breathe = function(surface) { - done = false; - timer = d3_timer(function() { + _done = false; + _timer = d3_timer(function() { // wait for elements to actually become selected if (surface.selectAll(selector).empty()) { return false; } surface.call(run, 'from'); - timer.stop(); + _timer.stop(); return true; }, 20); }; breathe.off = function() { - done = true; - if (timer) { - timer.stop(); + _done = true; + if (_timer) { + _timer.stop(); } - selected + _selected .interrupt() .call(reset); }; diff --git a/modules/behavior/copy.js b/modules/behavior/copy.js index 73fe16b5e..4aaca957f 100644 --- a/modules/behavior/copy.js +++ b/modules/behavior/copy.js @@ -23,8 +23,8 @@ export function behaviorCopy(context) { function getDescendants(id, graph, descendants) { - var entity = graph.entity(id), - i, children; + var entity = graph.entity(id); + var children; descendants = descendants || {}; @@ -36,7 +36,7 @@ export function behaviorCopy(context) { children = []; } - for (i = 0; i < children.length; i++) { + for (var i = 0; i < children.length; i++) { if (!descendants[children[i]]) { descendants[children[i]] = true; descendants = getDescendants(children[i], graph, descendants); @@ -50,11 +50,12 @@ export function behaviorCopy(context) { function doCopy() { if (!getSelectionText()) d3_event.preventDefault(); - var graph = context.graph(), - selected = groupEntities(context.selectedIDs(), graph), - canCopy = [], - skip = {}, - i, entity; + var graph = context.graph(); + var selected = groupEntities(context.selectedIDs(), graph); + var canCopy = []; + var skip = {}; + var entity; + var i; for (i = 0; i < selected.relation.length; i++) { entity = selected.relation[i]; diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index e5ffa4b83..148a6fd89 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -120,7 +120,7 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { for (var i = 0; i < parents.length; i++) { var parent = parents[i]; var nodes = parent.nodes.map(function(nodeID) { return graph.entity(nodeID); }); - + if (origWay.isClosed()) { // Check if Area if (finishDraw) { nodes.splice(-2, 1); diff --git a/modules/behavior/lasso.js b/modules/behavior/lasso.js index 9fe82bcd2..bc4a808b1 100644 --- a/modules/behavior/lasso.js +++ b/modules/behavior/lasso.js @@ -54,9 +54,9 @@ export function behaviorLasso(context) { function lassoed() { if (!lasso) return []; - var graph = context.graph(), - bounds = lasso.extent().map(context.projection.invert), - extent = geoExtent(normalize(bounds[0], bounds[1])); + var graph = context.graph(); + var bounds = lasso.extent().map(context.projection.invert); + var extent = geoExtent(normalize(bounds[0], bounds[1])); return _map(context.intersects(extent).filter(function(entity) { return entity.type === 'node' && diff --git a/modules/behavior/operation.js b/modules/behavior/operation.js index 61a62eb78..0fc96e1f0 100644 --- a/modules/behavior/operation.js +++ b/modules/behavior/operation.js @@ -9,7 +9,8 @@ import { uiFlash } from '../ui'; /* Creates a keybinding behavior for an operation */ export function behaviorOperation() { - var _operation, keybinding; + var keybinding; + var _operation; var behavior = function () { if (_operation && _operation.available()) { diff --git a/modules/behavior/paste.js b/modules/behavior/paste.js index f29c5fe72..6a2f44326 100644 --- a/modules/behavior/paste.js +++ b/modules/behavior/paste.js @@ -15,8 +15,9 @@ import { import { geoExtent, - geoPointInPolygon -} from '../geo/'; + geoPointInPolygon, + geoVecSubtract +} from '../geo'; import { modeMove } from '../modes'; import { uiCmd } from '../ui'; @@ -29,17 +30,17 @@ export function behaviorPaste(context) { function doPaste() { d3_event.preventDefault(); - var baseGraph = context.graph(), - mouse = context.mouse(), - projection = context.projection, - viewport = geoExtent(projection.clipExtent()).polygon(); + var baseGraph = context.graph(); + var mouse = context.mouse(); + var projection = context.projection; + var viewport = geoExtent(projection.clipExtent()).polygon(); if (!geoPointInPolygon(mouse, viewport)) return; - var extent = geoExtent(), - oldIDs = context.copyIDs(), - oldGraph = context.copyGraph(), - newIDs = []; + var extent = geoExtent(); + var oldIDs = context.copyIDs(); + var oldGraph = context.copyGraph(); + var newIDs = []; if (!oldIDs.length) return; @@ -49,14 +50,14 @@ export function behaviorPaste(context) { var copies = action.copies(); var originals = _invert(_mapValues(copies, 'id')); for (var id in copies) { - var oldEntity = oldGraph.entity(id), - newEntity = copies[id]; + var oldEntity = oldGraph.entity(id); + var newEntity = copies[id]; extent._extend(oldEntity.extent(oldGraph)); // Exclude child nodes from newIDs if their parent way was also copied. - var parents = context.graph().parentWays(newEntity), - parentCopied = false; + var parents = context.graph().parentWays(newEntity); + var parentCopied = false; for (var i = 0; i < parents.length; i++) { if (originals[parents[i].id]) { parentCopied = true; @@ -70,8 +71,8 @@ export function behaviorPaste(context) { } // Put pasted objects where mouse pointer is.. - var center = projection(extent.center()), - delta = [ mouse[0] - center[0], mouse[1] - center[1] ]; + var center = projection(extent.center()); + var delta = geoVecSubtract(mouse, center); context.perform(actionMove(newIDs, delta, projection)); context.enter(modeMove(context, newIDs, baseGraph)); diff --git a/modules/behavior/tail.js b/modules/behavior/tail.js index 7aff12cad..3b4919516 100644 --- a/modules/behavior/tail.js +++ b/modules/behavior/tail.js @@ -8,15 +8,15 @@ import { utilGetDimensions } from '../util/dimensions'; export function behaviorTail() { - var text, - container, - xmargin = 25, - tooltipSize = [0, 0], - selectionSize = [0, 0]; + var container; + var xmargin = 25; + var tooltipSize = [0, 0]; + var selectionSize = [0, 0]; + var _text; function tail(selection) { - if (!text) return; + if (!_text) return; d3_select(window) .on('resize.tail', function() { selectionSize = utilGetDimensions(selection); }); @@ -27,7 +27,7 @@ export function behaviorTail() { .attr('class', 'tail tooltip-inner'); container.append('div') - .text(text); + .text(_text); selection .on('mousemove.tail', mousemove) @@ -72,7 +72,7 @@ export function behaviorTail() { tail.off = function(selection) { - if (!text) return; + if (!_text) return; container .on('mousemove.tail', null) @@ -88,9 +88,9 @@ export function behaviorTail() { }; - tail.text = function(_) { - if (!arguments.length) return text; - text = _; + tail.text = function(val) { + if (!arguments.length) return _text; + _text = val; return tail; }; diff --git a/modules/modes/add_area.js b/modules/modes/add_area.js index 4e0af4318..7b4d6f5d9 100644 --- a/modules/modes/add_area.js +++ b/modules/modes/add_area.js @@ -20,11 +20,12 @@ export function modeAddArea(context) { }; var behavior = behaviorAddWay(context) - .tail(t('modes.add_area.tail')) - .on('start', start) - .on('startFromWay', startFromWay) - .on('startFromNode', startFromNode), - defaultTags = { area: 'yes' }; + .tail(t('modes.add_area.tail')) + .on('start', start) + .on('startFromWay', startFromWay) + .on('startFromNode', startFromNode); + + var defaultTags = { area: 'yes' }; function actionClose(wayId) { @@ -35,9 +36,9 @@ export function modeAddArea(context) { function start(loc) { - var startGraph = context.graph(), - node = osmNode({ loc: loc }), - way = osmWay({ tags: defaultTags }); + var startGraph = context.graph(); + var node = osmNode({ loc: loc }); + var way = osmWay({ tags: defaultTags }); context.perform( actionAddEntity(node), @@ -51,9 +52,9 @@ export function modeAddArea(context) { function startFromWay(loc, edge) { - var startGraph = context.graph(), - node = osmNode({ loc: loc }), - way = osmWay({ tags: defaultTags }); + var startGraph = context.graph(); + var node = osmNode({ loc: loc }); + var way = osmWay({ tags: defaultTags }); context.perform( actionAddEntity(node), @@ -68,8 +69,8 @@ export function modeAddArea(context) { function startFromNode(node) { - var startGraph = context.graph(), - way = osmWay({ tags: defaultTags }); + var startGraph = context.graph(); + var way = osmWay({ tags: defaultTags }); context.perform( actionAddEntity(way), diff --git a/modules/modes/add_line.js b/modules/modes/add_line.js index d18deff14..bd4e6c482 100644 --- a/modules/modes/add_line.js +++ b/modules/modes/add_line.js @@ -27,9 +27,9 @@ export function modeAddLine(context) { function start(loc) { - var startGraph = context.graph(), - node = osmNode({ loc: loc }), - way = osmWay(); + var startGraph = context.graph(); + var node = osmNode({ loc: loc }); + var way = osmWay(); context.perform( actionAddEntity(node), @@ -42,9 +42,9 @@ export function modeAddLine(context) { function startFromWay(loc, edge) { - var startGraph = context.graph(), - node = osmNode({ loc: loc }), - way = osmWay(); + var startGraph = context.graph(); + var node = osmNode({ loc: loc }); + var way = osmWay(); context.perform( actionAddEntity(node), @@ -58,8 +58,8 @@ export function modeAddLine(context) { function startFromNode(node) { - var startGraph = context.graph(), - way = osmWay(); + var startGraph = context.graph(); + var way = osmWay(); context.perform( actionAddEntity(way), diff --git a/modules/modes/add_note.js b/modules/modes/add_note.js index 4d63b8ee0..8f7f065a0 100644 --- a/modules/modes/add_note.js +++ b/modules/modes/add_note.js @@ -6,7 +6,6 @@ import { services } from '../services'; export function modeAddNote(context) { - var mode = { id: 'add-note', button: 'note',