Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 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 @@ -104,11 +106,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 );
Expand All @@ -126,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