Skip to content

Commit

Permalink
Only show inline UI on editable areas
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Mar 15, 2017
1 parent ab8117f commit f44503a
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions tinymce-single/tinymce/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,19 +560,20 @@
function createInlineToolbar() {
var inline = editor.wp._createToolbar( [ 'bold', 'italic', 'strikethrough', 'link' ] );

inline.reposition = function () {
inline.reposition = function( editableRoot ) {
this.show();

var toolbar = this.getEl();
var toolbarRect = toolbar.getBoundingClientRect();
var elementRect = getSelectedBlock().getBoundingClientRect();
var elementRect = ( editableRoot || getSelectedBlock() ).getBoundingClientRect();
var contentRect = editor.getBody().getBoundingClientRect();
var offset = editableRoot ? 0 : blockToolbarWidth;

DOM.setStyles( toolbar, {
position: 'absolute',
left: Math.max( contentRect.left + editorPadding, elementRect.left ) + blockToolbarWidth + 'px',
left: Math.max( contentRect.left + editorPadding, elementRect.left ) + offset + 'px',
top: elementRect.top + window.pageYOffset - toolbarRect.height - 8 + 'px'
} );

this.show();
}

return inline;
Expand Down Expand Up @@ -818,12 +819,22 @@
UI.blocks[ settings._id ].reposition();
focus && focusToolbar( UI.blocks[ settings._id ] );

var selection = window.getSelection();
UI.inline.hide();

if ( selection.anchorNode.nodeType === 3 ) {
UI.inline.reposition();
} else {
UI.inline.hide();
if ( settings.editable && settings.editable.length ) {
var selection = window.getSelection();
var editableRoot = getEditableRoot( selection.anchorNode );

settings.editable.forEach( function( selector ) {
if ( selector ) {
if ( editor.$( editableRoot ).is( selector ) ) {
UI.inline.reposition( editableRoot );
return;
}
} else {
UI.inline.reposition();
}
} );
}

UI.insert.reposition();
Expand Down

0 comments on commit f44503a

Please sign in to comment.