Skip to content

Commit

Permalink
Slightly refactor controls for repositioning.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtias committed Feb 8, 2017
1 parent 79bc56f commit e619a7c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit e619a7c

Please sign in to comment.