Skip to content

Commit

Permalink
Merge pull request #241 from WordPress/try/tinymce-single/contentedit…
Browse files Browse the repository at this point in the history
…able-false

Only allow inline elements within block editable fields
  • Loading branch information
ellatrix authored Mar 10, 2017
2 parents cf11103 + d80a66d commit 26d085e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tinymce-single/tinymce/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,36 @@
} );
} );

editor.on( 'beforeSetContent', function( event ) {
if ( event.initial ) {
return;
}

var settings = {
valid_elements: 'strong,em,del,a[href]'
};

var selectedBlock = wp.blocks.getSelectedBlock();

if ( editor.$( selectedBlock ).attr( 'contenteditable' ) === 'false' ) {
var schema = new tinymce.html.Schema( settings );
var parser = new tinymce.html.DomParser( settings, schema );
var serializer = new tinymce.html.Serializer( settings, schema );

event.content = serializer.serialize( parser.parse( event.content, { forced_root_block: false } ) );
}
} );

editor.on( 'keydown', function( event ) {
if ( event.keyCode === tinymce.util.VK.ENTER ) {
var selectedBlock = wp.blocks.getSelectedBlock();

if ( editor.$( selectedBlock ).attr( 'contenteditable' ) === 'false' ) {
event.preventDefault();
}
}
} );

// Attach block UI.

editor.on( 'preinit', function() {
Expand Down

0 comments on commit 26d085e

Please sign in to comment.