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

Add image alignment buttons and functionality. #32

Merged
merged 1 commit into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
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
42 changes: 40 additions & 2 deletions blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ function getBlocks() {
function selectBlock( event ) {
clearBlocks();
event.stopPropagation();
event.target.className = 'is-selected';
event.target.className += ' is-selected';

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

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

Expand All @@ -70,12 +70,24 @@ function showControls( node ) {
document.getElementsByClassName( 'type-icon-paragraph' )[0].style.display = 'none';
if ( node.nodeName == 'IMG' ) {
document.getElementsByClassName( 'type-icon-image' )[0].style.display = 'block';
blockControls.className = 'block-controls is-image';
} else if ( node.nodeName == 'H1' || node.nodeName == 'H2' || node.nodeName == 'H3' || node.nodeName == 'H4' || node.nodeName == 'H5' || node.nodeName == 'H6' ) {
document.getElementsByClassName( 'type-icon-heading' )[0].style.display = 'block';
blockControls.className = 'block-controls is-heading';
} else {
document.getElementsByClassName( 'type-icon-paragraph' )[0].style.display = 'block';
blockControls.className = 'block-controls is-text';
}

var imageFullBleed = document.getElementsByClassName( 'block-image__full-width' )[0];
var imageAlignNone = document.getElementsByClassName( 'block-image__no-align' )[0];
var imageAlignLeft = document.getElementsByClassName( 'block-image__align-left' )[0];
var imageAlignRight = document.getElementsByClassName( 'block-image__align-right' )[0];
imageFullBleed.addEventListener( 'click', setImageFullBleed, false );
imageAlignNone.addEventListener( 'click', setImageAlignNone, false );
imageAlignLeft.addEventListener( 'click', setImageAlignLeft, false );
imageAlignRight.addEventListener( 'click', setImageAlignRight, false );

// show controls
var position = node.getBoundingClientRect();
switcher.style.opacity = 1;
Expand Down Expand Up @@ -203,6 +215,32 @@ function hideMenu() {
menu.style.display = 'none';
}

function setImageFullBleed( event ) {
event.stopPropagation();
var image = query('img')[0];
console.log(image);
image.className = 'is-selected align-full-bleed';
}

function setImageAlignNone( event ) {
event.stopPropagation();
var image = query('img')[0];
console.log(image);
image.className = 'is-selected';
}

function setImageAlignLeft( event ) {
event.stopPropagation();
var image = query('img')[0];
image.className = 'is-selected align-left';
}

function setImageAlignRight( event ) {
event.stopPropagation();
var image = query('img')[0];
image.className = 'is-selected align-right';
}

function l( data ) {
console.log( data );
return data;
Expand Down
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
<button>
<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__no-align">
<svg class="gridicon gridicons-align-image-center" height="24" width="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g><path d="M3 5h18v2H3V5zm0 14h18v-2H3v2zm5-4h8V9H8v6z"></path></g></svg>
</button>
<button class="block-image__align-left">
<svg class="gridicon gridicons-align-image-left" height="24" width="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g><path d="M3 5h18v2H3V5zm0 14h18v-2H3v2zm0-4h8V9H3v6zm10 0h8v-2h-8v2zm0-4h8V9h-8v2z"></path></g></svg>
</button>
<button class="block-image__align-right">
<svg class="gridicon gridicons-align-image-right" height="24" width="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g><path d="M21 7H3V5h18v2zm0 10H3v2h18v-2zm0-8h-8v6h8V9zm-10 4H3v2h8v-2zm0-4H3v2h8V9z"></path></g></svg>
</button>
<button class="block-image__full-width">
<svg class="gridicon gridicons-fullscreen" height="24" width="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g><title>Full Bleed</title><path d="M21 3v6h-2V6.41l-3.29 3.3-1.42-1.42L17.59 5H15V3zM3 3v6h2V6.41l3.29 3.3 1.42-1.42L6.41 5H9V3zm18 18v-6h-2v2.59l-3.29-3.29-1.41 1.41L17.59 19H15v2zM9 21v-2H6.41l3.29-3.29-1.41-1.42L5 17.59V15H3v6z"></path></g></svg>
</button>
</div>
<div class="inline-controls">
<button><svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>Bold</title><rect x="0" fill="none" width="24" height="24"/><g><path d="M7 5.01h4.547c2.126 0 3.67.302 4.632.906.96.605 1.44 1.567 1.44 2.887 0 .896-.21 1.63-.63 2.205-.42.574-.98.92-1.678 1.036v.103c.95.212 1.637.608 2.057 1.19.42.58.63 1.35.63 2.315 0 1.367-.494 2.434-1.482 3.2-.99.765-2.332 1.148-4.027 1.148H7V5.01zm3 5.936h2.027c.862 0 1.486-.133 1.872-.4.386-.267.578-.708.578-1.323 0-.574-.21-.986-.63-1.236-.42-.25-1.087-.374-1.996-.374H10v3.333zm0 2.523v3.905h2.253c.876 0 1.52-.167 1.94-.502.416-.335.625-.848.625-1.54 0-1.243-.89-1.864-2.668-1.864H10z"/></g></svg></button>
Expand Down
40 changes: 40 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,43 @@ p {
.insert-block__block svg {
margin-right: 4px;
}

img.align-full-bleed {
margin-left: calc(50% - 50vw);
width: 100vw;
max-width: none;
padding-left: 0;
padding-right: 0;
}

img.align-left {
float: left;
width: 340px;
margin: 0 16px 0 0;
}

img.align-right {
float: right;
width: 340px;
margin: 0 0 0 16px;
}

button.block-image__full-width,
button.block-image__no-alignment,
button.block-image__no-align,
button.block-image__align-left,
button.block-image__align-right {
display: none;
}

.block-controls.is-image button {
display: none;
}

.block-controls.is-image .block-image__full-width,
.block-controls.is-image .block-image__no-alignment,
.block-controls.is-image .block-image__no-align,
.block-controls.is-image .block-image__align-left,
.block-controls.is-image .block-image__align-right {
display: block;
}