From 79bc56f2679beae393c63896e9894659cf2ccaad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Ventura?= Date: Wed, 8 Feb 2017 13:23:59 +0100 Subject: [PATCH 1/2] Retain selected state when moving blocks. --- blocks.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/blocks.js b/blocks.js index 3c9d5d31043818..b9784df919246e 100644 --- a/blocks.js +++ b/blocks.js @@ -104,11 +104,13 @@ function attachControlActions() { if ( 'up' === classes ) { node.addEventListener( 'click', function() { + event.stopPropagation(); swapNodes( selectedBlock, getPreviousSibling( selectedBlock ) ); attachBlockHandlers(); }, false ); } else if ( 'down' === classes ) { node.addEventListener( 'click', function() { + event.stopPropagation(); swapNodes( selectedBlock, getNextSibling( selectedBlock ) ); attachBlockHandlers(); }, false ); From e619a7c99ce69a0ab23dc0eeb8e9b0cf92482f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Ventura?= Date: Wed, 8 Feb 2017 13:31:46 +0100 Subject: [PATCH 2/2] Slightly refactor controls for repositioning. --- blocks.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/blocks.js b/blocks.js index b9784df919246e..bb7557938bf1c3 100644 --- a/blocks.js +++ b/blocks.js @@ -48,12 +48,8 @@ function selectBlock( event ) { event.stopPropagation(); event.target.className = 'is-selected'; - var position = event.target.getBoundingClientRect(); - - // Show switcher - controls.style.opacity = 1; - controls.style.top = ( position.top + 18 ) + 'px'; selectedBlock = event.target; + showControls( selectedBlock ); } function clearBlocks() { @@ -65,6 +61,12 @@ function clearBlocks() { hideControls(); } +function showControls( node ) { + var position = node.getBoundingClientRect(); + controls.style.opacity = 1; + controls.style.top = ( position.top + 18 ) + 'px'; +} + function hideControls() { controls.style.opacity = 0; } @@ -128,6 +130,9 @@ function swapNodes( a, b ) { return false; } + // how do we handle controls? + showControls( b ); + // insert node copies before removal parent.replaceChild( b.cloneNode( true ), a ); parent.replaceChild( a.cloneNode( true ), b );