diff --git a/css/80_app.css b/css/80_app.css index c7d5302b9..62d2674ea 100644 --- a/css/80_app.css +++ b/css/80_app.css @@ -491,6 +491,14 @@ button[disabled].action:hover { padding: 0 5px; } +.tool-group button.dragging { + opacity: 0.75; + z-index: 200; +} +.tool-group button.dragging .tooltip { + display: none; +} + button.save .count { display: inline-block; border: 0px solid #ccc; diff --git a/modules/ui/modes.js b/modules/ui/modes.js index dece898cd..f95d2f780 100644 --- a/modules/ui/modes.js +++ b/modules/ui/modes.js @@ -1,6 +1,7 @@ import _debounce from 'lodash-es/debounce'; -import { select as d3_select } from 'd3-selection'; +import { drag as d3_drag } from 'd3-drag'; +import { event as d3_event, select as d3_select } from 'd3-selection'; import { modeAddArea, @@ -168,6 +169,39 @@ export function uiModes(context) { ); } }); + + var dragOrigin; + + buttonsEnter.call(d3_drag() + .on('start', function(d) { + //if (d3_select(this).classed('disabled')) return; + dragOrigin = { + x: d3_event.x, + y: d3_event.y + }; + }) + .on('drag', function(d) { + var x = d3_event.x - dragOrigin.x, + y = d3_event.y - dragOrigin.y; + + d3_select(this) + .classed('dragging', true) + .style('transform', 'translate(' + x + 'px, ' + y + 'px)'); + }) + .on('end', function(d) { + + d3_select(this) + .style('transform', null) + .classed('dragging', false); + + var y = d3_event.y - dragOrigin.y; + if (y > 50) { + // dragged out of the top bar, remove the favorite + context.favoritePreset(d.preset, d.geometry); + } + }) + ); + /* buttonsEnter .append('span')