@@ -384,35 +384,43 @@ d3.layout.force = function() {
384384 force . drag = function ( ) {
385385
386386 this
387- . on ( "mouseover" , d3_layout_forceDragOver )
388- . on ( "mouseout" , d3_layout_forceDragOut )
389- . on ( "mousedown" , d3_layout_forceDragDown ) ;
387+ . on ( "mouseover.force " , d3_layout_forceDragOver )
388+ . on ( "mouseout.force " , d3_layout_forceDragOut )
389+ . on ( "mousedown.force " , d3_layout_forceDragDown ) ;
390390
391391 d3 . select ( window )
392- . on ( "mousemove" , dragmove )
393- . on ( "mouseup" , dragup ) ;
392+ . on ( "mousemove.force " , dragmove )
393+ . on ( "mouseup.force " , dragup , true ) ;
394394
395395 return force ;
396396 } ;
397397
398398 function dragmove ( ) {
399399 if ( ! d3_layout_forceDragNode ) return ;
400400
401- // O NOES! The drag element was removed from the DOM.
401+ // O NOES! The drag element was removed from the DOM.
402402 if ( ! d3_layout_forceDragElement . parentNode ) {
403- d3_layout_forceDragNode . fixed = false ;
404- d3_layout_forceDragNode = d3_layout_forceDragElement = null ;
405- return ;
403+ d3_layout_forceDragNode . fixed = false ;
404+ d3_layout_forceDragNode = d3_layout_forceDragElement = null ;
405+ return ;
406406 }
407407
408408 var m = d3 . svg . mouse ( d3_layout_forceDragElement ) ;
409+ d3_layout_forceDragMoved = true ;
409410 d3_layout_forceDragNode . px = m [ 0 ] ;
410411 d3_layout_forceDragNode . py = m [ 1 ] ;
411412 force . resume ( ) ; // restart annealing
412413 }
413414
414415 function dragup ( ) {
415416 if ( ! d3_layout_forceDragNode ) return ;
417+
418+ // If the node was moved, prevent the mouseup from propagating.
419+ if ( d3_layout_forceDragMoved ) {
420+ d3 . event . stopPropagation ( ) ;
421+ d3 . event . preventDefault ( ) ;
422+ }
423+
416424 dragmove ( ) ;
417425 d3_layout_forceDragNode . fixed = false ;
418426 d3_layout_forceDragNode = d3_layout_forceDragElement = null ;
@@ -422,6 +430,7 @@ d3.layout.force = function() {
422430} ;
423431
424432var d3_layout_forceDragNode ,
433+ d3_layout_forceDragMoved ,
425434 d3_layout_forceDragElement ;
426435
427436function d3_layout_forceDragOver ( d ) {
@@ -434,8 +443,9 @@ function d3_layout_forceDragOut(d) {
434443 }
435444}
436445
437- function d3_layout_forceDragDown ( d ) {
446+ function d3_layout_forceDragDown ( d , i ) {
438447 ( d3_layout_forceDragNode = d ) . fixed = true ;
448+ d3_layout_forceDragMoved = false ;
439449 d3_layout_forceDragElement = this ;
440450 d3 . event . stopPropagation ( ) ;
441451 d3 . event . preventDefault ( ) ;
0 commit comments