Skip to content

Commit

Permalink
Merge pull request #66 from mitogh/use-classlist
Browse files Browse the repository at this point in the history
Use classlist instead of appending and removing class names
  • Loading branch information
mcsf authored Feb 13, 2017
2 parents 35db542 + d45dfee commit c0391f5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ function getBlocks() {
function selectBlock( event ) {
clearBlocks();
event.stopPropagation();
event.target.className += ' is-selected';
event.target.classList.add( 'is-selected' );

selectedBlock = event.target;
showControls( selectedBlock );
}

function clearBlocks() {
getBlocks().forEach( function( block ) {
block.className = block.className.replace( 'is-selected', '' );
block.classList.remove( 'is-selected' );
} );
selectedBlock = null;

Expand All @@ -121,11 +121,10 @@ function showControls( node ) {
switcher.style.top = ( position.top + 18 + window.scrollY ) + 'px';

// show/hide block-specific block controls
var kinds = getTypeKinds( blockType );
var kindClasses = kinds.map( function( kind ) {
return 'is-' + kind;
} ).join( ' ' );
blockControls.className = 'block-controls ' + kindClasses;
blockControls.className = 'block-controls';
getTypeKinds( blockType ).forEach( function( kind ) {
blockControls.classList.add( 'is-' + kind );
} );
blockControls.style.display = 'block';

// reposition block-specific block controls
Expand Down Expand Up @@ -310,9 +309,12 @@ function showSwitcherMenu( event ) {
switcherMenu.style.display = 'block';
}

function setImageState( classes, event ) {
function setImageState( className, event ) {
event.stopPropagation();
selectedBlock.className = 'is-selected ' + classes;
selectedBlock.className = 'is-selected';
if ( className ) {
selectedBlock.classList.add( className );
}
}

function l( data ) {
Expand Down

0 comments on commit c0391f5

Please sign in to comment.