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

Text align block controls #60

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a8743b2
Merge pull request #1 from WordPress/master
BE-Webdesign Feb 9, 2017
e2fd749
Merge remote-tracking branch 'refs/remotes/origin/master' into develop
BE-Webdesign Feb 9, 2017
5203b8e
Add text block controls for alignment.
BE-Webdesign Feb 11, 2017
fbe7e1c
Merge remote-tracking branch 'refs/remotes/WordPress/master' into dev…
BE-Webdesign Feb 11, 2017
f04c25c
Revert text alignment commits.
BE-Webdesign Feb 11, 2017
8b07c15
Remove styles to match origin.
BE-Webdesign Feb 11, 2017
1f06e13
Revert changes to blocks.js
BE-Webdesign Feb 11, 2017
d7ae47c
Change append and remove by classList functions instead.
mitogh Feb 12, 2017
47840ab
Add controls for the block
mitogh Feb 12, 2017
12fdeb0
Add class from the parameter into the selected block
mitogh Feb 12, 2017
ec197f2
Rename parameter name since it only allows a single className as value
mitogh Feb 12, 2017
043d62d
Use a single function to add the class names
mitogh Feb 13, 2017
d45dfee
Reset classes when required otherwise multiple behavors are attached
mitogh Feb 13, 2017
632a2c6
Merge remote-tracking branch 'refs/remotes/origin/develop' into text-…
BE-Webdesign Feb 13, 2017
7f60d7e
Add event handlers to the text block's block level controls. This ena…
BE-Webdesign Feb 13, 2017
c0391f5
Merge pull request #66 from mitogh/use-classlist
mcsf Feb 13, 2017
0075cd0
Add event handlers to the text block's block level controls. This ena…
BE-Webdesign Feb 9, 2017
59ba2e5
Resolve conflicts
BE-Webdesign Feb 13, 2017
4f3e424
Add event handlers to the text block's block level controls. This ena…
BE-Webdesign Feb 11, 2017
0a5f64c
Resolving conflicts
BE-Webdesign Feb 13, 2017
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
45 changes: 32 additions & 13 deletions blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ var getNextSibling = siblingGetter( 'next' );
var getPreviousSibling = siblingGetter( 'previous' );
var getTagType = getConfig.bind( null, 'tagTypes' );
var getTypeKinds = getConfig.bind( null, 'typeKinds' );
var setImageFullBleed = setImageState.bind( null, 'align-full-bleed' );
var setImageAlignNone = setImageState.bind( null, '' );
var setImageAlignLeft = setImageState.bind( null, 'align-left' );
var setImageAlignRight = setImageState.bind( null, 'align-right' );
var setImageFullBleed = setElementState.bind( null, 'align-full-bleed' );
var setImageAlignNone = setElementState.bind( null, '' );
var setImageAlignLeft = setElementState.bind( null, 'align-left' );
var setImageAlignRight = setElementState.bind( null, 'align-right' );

var setTextAlignLeft = setElementState.bind( null, 'align-left' );
var setTextAlignCenter = setElementState.bind( null, 'align-center' );
var setTextAlignRight = setElementState.bind( null, 'align-right' );

/**
* Globals
Expand Down Expand Up @@ -45,6 +49,9 @@ var blockControls = queryFirst( '.block-controls' );
var inlineControls = queryFirst( '.inline-controls' );
var insertBlockButton = queryFirst( '.insert-block__button' );
var insertBlockMenu = queryFirst( '.insert-block__menu' );
var textAlignLeft = queryFirst( '.block-text__align-left' );
var textAlignCenter = queryFirst( '.block-text__align-center' );
var textAlignRight = queryFirst( '.block-text__align-right' );
var imageFullBleed = queryFirst( '.block-image__full-width' );
var imageAlignNone = queryFirst( '.block-image__no-align' );
var imageAlignLeft = queryFirst( '.block-image__align-left' );
Expand Down Expand Up @@ -90,15 +97,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 +128,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 @@ -188,6 +194,16 @@ function attachControlActions() {
}
} );

// Text block event handlers.
textAlignLeft.addEventListener( 'click', setTextAlignLeft, false );
textAlignCenter.addEventListener( 'click', setTextAlignCenter, false );
textAlignRight.addEventListener( 'click', setTextAlignRight, false );

switcherButtons.forEach( function( button ) {
button.addEventListener( 'click', showSwitcherMenu, false );
} );

// Image block event handlers.
imageFullBleed.addEventListener( 'click', setImageFullBleed, false );
imageAlignNone.addEventListener( 'click', setImageAlignNone, false );
imageAlignLeft.addEventListener( 'click', setImageAlignLeft, false );
Expand Down Expand Up @@ -310,9 +326,12 @@ function showSwitcherMenu( event ) {
switcherMenu.style.display = 'block';
}

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

function l( data ) {
Expand Down
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
</span>
</div>
<div class="block-controls">
<button class="block-text is-active">
<button class="block-text block-text__align-left is-active">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>Align Left</title><rect x="0" fill="none" width="24" height="24"/><g><path d="M4 19h16v-2H4v2zm10-6H4v2h10v-2zM4 9v2h16V9H4zm10-4H4v2h10V5z"/></g></svg>
</button>
<button class="block-text">
<button class="block-text block-text__align-center">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>Align Center</title><rect x="0" fill="none" width="24" height="24"/><g><path d="M4 19h16v-2H4v2zm13-6H7v2h10v-2zM4 9v2h16V9H4zm13-4H7v2h10V5z"/></g></svg>
</button>
<button class="block-text">
<button class="block-text block-text__align-right">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>Align Right</title><rect x="0" fill="none" width="24" height="24"/><g><path d="M20 17H4v2h16v-2zm-10-2h10v-2H10v2zM4 9v2h16V9H4zm6-2h10V5H10v2z"/></g></svg>
</button>
<button class="block-image block-image__no-align">
Expand Down
37 changes: 37 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,43 @@ img.is-selected {
fill: #191e23;
}

/*
* Text actions
*/

p.align-left,
h1.align-left,
h2.align-left,
h3.align-left,
h4.align-left,
h5.align-left,
h6.align-left,
blockquote.align-left {
text-align: left;
}

p.align-center,
h1.align-center,
h2.align-center,
h3.align-center,
h4.align-center,
h5.align-center,
h6.align-center,
blockquote.align-center {
text-align: center;
}

p.align-right,
h1.align-right,
h2.align-right,
h3.align-right,
h4.align-right,
h5.align-right,
h6.align-right,
blockquote.align-right {
text-align: right;
}

/*
* Image actions
*/
Expand Down