diff --git a/blocks.js b/blocks.js index a703714f9ae0c4..09a378a1c8c683 100644 --- a/blocks.js +++ b/blocks.js @@ -7,11 +7,12 @@ var getNextSibling = siblingGetter( 'next' ); var getPreviousSibling = siblingGetter( 'previous' ); /** - * Globals + * Globals */ var editor = document.getElementsByClassName( 'editor' )[0]; var controls = document.getElementsByClassName( 'block-controls' )[0]; +var inlineControls = document.getElementsByClassName( 'inline-controls' )[0]; var selectedBlock = null; /** @@ -21,6 +22,7 @@ var selectedBlock = null; window.addEventListener( 'click', clearBlocks, false ); editor.addEventListener( 'input', attachBlockHandlers, false ); editor.addEventListener( 'input', clearBlocks, false ); +window.addEventListener( 'mouseup', onSelectText, false ); attachBlockHandlers(); attachControlActions(); @@ -70,6 +72,31 @@ function hideControls() { controls.style.opacity = 0; } +/* 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(); + inlineControls.style.left = pos.left + 'px'; + inlineControls.style.top = ( pos.top - 48 ) + 'px'; + } else { + inlineControls.style.display = 'none'; + } +} + function attachControlActions() { Array.from( controls.childNodes ).forEach( function( node ) { if ( 'svg' !== node.nodeName ) { @@ -135,4 +162,4 @@ function siblingGetter( direction ) { function l( data ) { console.log( data ); return data; -} \ No newline at end of file +} diff --git a/index.html b/index.html index 111fdabbd6cc10..4c1ce1de7d7032 100644 --- a/index.html +++ b/index.html @@ -12,15 +12,30 @@ +
Many entrepreneurs idolize Steve Jobs. He’s such a perfectionist, they say. Nothing leaves the doors of 1 Infinite Loop in Cupertino without a polish and finish that makes geeks everywhere drool. No compromise!
+I like Apple for the opposite reason: they’re not afraid of getting a rudimentary 1.0 out into the world.
- --