Skip to content
Closed
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
19 changes: 18 additions & 1 deletion tinymce-single/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@
getControls: function() {
return _controls;
},

getHoverSelectedBlock: function (e) {
var editor = window.tinyMCE.activeEditor;
var targetNode = e.target;
var rootNode = editor.getBody();

if ( targetNode === rootNode || ! editor.getBody().contains( targetNode ) ) {
return null;
}

while ( targetNode.parentNode !== rootNode ) {
targetNode = targetNode.parentNode;
}

return targetNode;
},

getSelectedBlocks: function() {
var editor = window.tinyMCE.activeEditor;
var selection = window.getSelection();
Expand All @@ -55,7 +72,7 @@
var rootNode = editor.getBody();
var blocks = [];

if ( ! startNode || ! editor.getBody().contains( startNode ) ) {
if ( startNode === rootNode || ! editor.getBody().contains( startNode ) ) {
return [ rootNode.firstChild ];
}

Expand Down
4 changes: 4 additions & 0 deletions tinymce-single/tinymce/block.css
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,7 @@ div.mce-inline-toolbar-grp.block-toolbar > div.mce-stack-layout {
display: block;
margin: 0 auto 20px;
}

#editor .wp-hover-block {
box-shadow: -8px 0px 0 #fff, -10px 0px 0 #e1e6ea;
}
24 changes: 21 additions & 3 deletions tinymce-single/tinymce/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

if ( settings.onClick ) {
settings.onClick( event, block, function() { editor.nodeChanged() } )
removeHoverClass();
}
} );

Expand All @@ -78,17 +79,34 @@
} );
} );

var currentEditingBlock = null;
var overBlockClass = 'wp-hover-block';

function removeHoverClass() {
editor.$( editor.getBody() ).find( '.' + overBlockClass ).removeClass( overBlockClass );
}

editor.on( 'nodeChange', function( event ) {
var block = wp.blocks.getSelectedBlock();
var settings = wp.blocks.getBlockSettingsByElement( block );
currentEditingBlock = wp.blocks.getSelectedBlock();
var settings = wp.blocks.getBlockSettingsByElement( currentEditingBlock );

if ( settings && settings.editable ) {
settings.editable.forEach( function( selector ) {
editor.$( block ).find( selector ).attr( 'contenteditable', 'true' );
editor.$( currentEditingBlock ).find( selector ).attr( 'contenteditable', 'true' );
removeHoverClass();
} );
}
} );

editor.on( 'mouseover', function (e) {
var blockOver = wp.blocks.getHoverSelectedBlock(e);
removeHoverClass();
if ( blockOver !== null && currentEditingBlock !== blockOver) {
blockOver.classList.add(overBlockClass);
}

});

function toInlineContent( content ) {
var settings = {
valid_elements: 'strong,em,del,a[href]'
Expand Down