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 4 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
18 changes: 11 additions & 7 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 @@ -122,10 +122,13 @@ function showControls( node ) {

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, could you join the two above lines into a single } ).forEach( …?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

blockControls.classList.add( className );
} );
blockControls.classList.add( 'block-controls' );
blockControls.style.display = 'block';

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

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

function l( data ) {
Expand Down