diff --git a/blocks.js b/blocks.js index 70d73730b7e9a..e7fe7a19f7788 100644 --- a/blocks.js +++ b/blocks.js @@ -222,8 +222,7 @@ var editor = queryFirst( '.editor' ); var switcher = queryFirst( '.block-switcher' ); var switcherButtons = query( '.block-switcher .type svg' ); var switcherMenu = queryFirst( '.switch-block__menu' ); -var blockControls = queryFirst( '.block-controls' ); -var inlineControls = queryFirst( '.inline-controls' ); +var dockedControls = queryFirst( '.docked-controls' ); var insertBlockButton = queryFirst( '.insert-block__button' ); var insertBlockMenu = queryFirst( '.insert-block__menu' ); var insertBlockMenuSearchInput = queryFirst( '.insert-block__search' ); @@ -275,7 +274,6 @@ insertBlockButton.addEventListener( 'click', openBlockMenu, false ); insertBlockMenu.addEventListener( 'click', function( event ) { event.stopPropagation(); }, false ); -window.addEventListener( 'mouseup', onSelectText, false ); attachBlockHandlers(); attachControlActions(); @@ -341,17 +339,17 @@ function showControls( node ) { switcher.style.top = ( position.top + 18 + window.scrollY ) + 'px'; // show/hide block-specific block controls - blockControls.className = 'block-controls'; + dockedControls.className = 'docked-controls'; getTypeKinds( blockType ).forEach( function( kind ) { - blockControls.classList.add( 'is-' + kind ); + dockedControls.classList.add( 'is-' + kind ); } ); - blockControls.style.display = 'block'; + dockedControls.style.display = 'block'; // reposition block-specific block controls - updateBlockControlsPosition(); + updateDockedControlsPosition(); } -function updateBlockControlsPosition( newClassName ) { +function updateDockedControlsPosition( newClassName ) { var isImage = selectedBlock.tagName === 'IMG'; var className = selectedBlock.className; var position = selectedBlock.getBoundingClientRect(); @@ -367,53 +365,22 @@ function updateBlockControlsPosition( newClassName ) { topPosition = newClassName ? topPosition - 15 : topPosition; } else if ( isImage && alignedLeft && newClassName ) { topPosition = topPosition - 15; - } else if ( isImage && className === 'is-selected' && blockControls.style.left ) { + } else if ( isImage && className === 'is-selected' && dockedControls.style.left ) { leftPosition = null; topPosition = topPosition + 15; } else if ( fullBleed ) { - leftPosition = ( window.innerWidth / 2 ) - ( blockControls.clientWidth / 2 ); + leftPosition = ( window.innerWidth / 2 ) - ( dockedControls.clientWidth / 2 ); } - blockControls.style.maxHeight = 'none'; - blockControls.style.top = topPosition + 'px'; - blockControls.style.left = leftPosition ? leftPosition + 'px' : null; + dockedControls.style.maxHeight = 'none'; + dockedControls.style.top = topPosition + 'px'; + dockedControls.style.left = leftPosition ? leftPosition + 'px' : null; } function hideControls() { switcher.style.opacity = 0; switcherMenu.style.display = 'none'; - blockControls.style.display = 'none'; -} - -function hideInlineControls() { - inlineControls.style.display = 'none'; -} - -// Show popup on text selection -function onSelectText( event ) { - event.stopPropagation(); - var txt = ""; - - if ( window.getSelection ) { - txt = window.getSelection(); - } else if ( document.getSelection ) { - txt = document.getSelection(); - } else if ( document.selection ) { - txt = document.selection.createRange().text; - } - - // Show formatting bar - if ( txt != '' ) { - inlineControls.style.display = 'block'; - var range = txt.getRangeAt(0); - var pos = range.getBoundingClientRect(); - var selectCenter = pos.width / 2; - var controlsCenter = inlineControls.offsetWidth / 2; - inlineControls.style.left = ( pos.left + selectCenter - controlsCenter ) + 'px'; - inlineControls.style.top = ( pos.top - 48 + window.scrollY ) + 'px'; - } else { - inlineControls.style.display = 'none'; - } + dockedControls.style.display = 'none'; } function attachControlActions() { @@ -688,7 +655,6 @@ function siblingGetter( direction ) { } function openBlockMenu( event ) { - hideInlineControls(); clearBlocks(); event && event.stopPropagation(); insertBlockMenu.style.display = 'block'; diff --git a/index.html b/index.html index 4510c93e07958..d21b3a41ff463 100644 --- a/index.html +++ b/index.html @@ -22,36 +22,38 @@ Quote -
- - - - - - - -
-
- - - - - - +
+
+ + + + + + + +
+
+ + + + + + +
diff --git a/style.css b/style.css index 190ec91a8e362..6e2197bee4b37 100644 --- a/style.css +++ b/style.css @@ -105,7 +105,7 @@ h6.is-selected, p.is-selected, blockquote.is-selected, img.is-selected { - box-shadow: inset 0px 0px 0px 2px #6d7882; + box-shadow: inset 0px 0px 0px 2px #e0e5e9; position: relative; z-index: 1; } @@ -163,12 +163,23 @@ img.is-selected { display: none; } - /** - * Inline controls + * Controls */ +.docked-controls { + position: absolute; + display: none; + z-index: 10; + transform: translateZ( 0 ); +} + +.docked-controls.is-image .block-image, +.docked-controls.is-text .block-text { + display: block; +} -.inline-controls { +.inline-controls, +.block-controls { background: #fff; border: 1px solid #e1e6ea; box-shadow: 0px 3px 20px rgba( 18, 24, 30, .1 ), 0px 1px 3px rgba( 18, 24, 30, .1 ); @@ -176,12 +187,15 @@ img.is-selected { display: inline-block; height: 38px; overflow: hidden; - position: absolute; - z-index: 10; + margin-left: 20px; +} + +.docked-controls.is-image .inline-controls { display: none; } -.inline-controls button { +.inline-controls button, +.block-controls button { background: #fff; border: none; width: 36px; @@ -192,29 +206,38 @@ img.is-selected { float: left; } -.inline-controls button.do-not-work { +.inline-controls button.do-not-work, +.block-controls button.do-not-work { margin: 0 8px; width: auto; } -.inline-controls button:hover { +.inline-controls button:hover, +.block-controls button:hover { background: #f0f2f4; } -.inline-controls button:focus { +.inline-controls button:focus, +.block-controls button:focus { outline: none; } -.control-group { +.control-group, { display: inline-block; margin-left: 20px; } -.inline-controls button.heading-dropdown { +.inline-controls button.heading-dropdown, +.block-controls button.heading-dropdown { width: 54px; position: relative; } +.inline-controls button.is-active, +.block-controls button.is-active { + background: #e0e5e9; +} + .heading-dropdown .heading { position: absolute; left: 0; @@ -239,47 +262,10 @@ img.is-selected { bottom: 8px; } - -/** - * Block Controls - */ - -.block-controls { - background: #191e23; - display: inline-block; - max-height: 36px; - overflow: hidden; - position: absolute; - z-index: 10; - display: none; - transform: translateZ( 0 ); - } - -.block-controls button { - background: #191e23; - color: #fff; - border: none; - width: 36px; - height: 36px; - padding: 6px; - cursor: pointer; - display: block; - float: left; - } - -.block-controls button.is-active { - background: #6d7882; -} - .block-controls button { display: none; } -.block-controls.is-image .block-image, -.block-controls.is-text .block-text { - display: block; -} - /** * Block inserter and switcher */