Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use classlist instead of appending and removing class names #66

Merged
merged 6 commits into from
Feb 13, 2017
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
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