Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow insertion by returning string or node #218

Merged
merged 1 commit into from
Mar 9, 2017
Merged
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
4 changes: 1 addition & 3 deletions tinymce-single/blocks/core/gallery/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ window.wp.blocks.registerBlock( {
icon: 'gridicons-cog'
}
],
insert: function( block, editor ) {

}
insert: function() {}
} );
4 changes: 2 additions & 2 deletions tinymce-single/blocks/elements/blockquote/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ window.wp.blocks.registerBlock( {
}
}
],
insert: function( block, editor ) {
editor.formatter.apply( 'blockquote', block );
insert: function() {
return '<blockquote><p><br></p></blockquote>';
}
} );

4 changes: 2 additions & 2 deletions tinymce-single/blocks/elements/headings/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
type: 'text',
icon: 'gridicons-heading',
controls: getControls(),
insert: function( block, editor ) {
insert: function() {
// Maybe detect best heading based on document outline.
editor.formatter.apply( 'h1', block );
return '<h1><br></h1>';
}
} );
} )( window.wp );
4 changes: 2 additions & 2 deletions tinymce-single/blocks/elements/horizontal-rule/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ window.wp.blocks.registerBlock( {
elements: [ 'hr' ],
type: 'separator',
icon: 'gridicons-minus',
insert: function( block ) {
block.parentNode.replaceChild( document.createElement( 'hr' ), block );
insert: function() {
return '<hr>';
}
} );
4 changes: 2 additions & 2 deletions tinymce-single/blocks/elements/lists/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ window.wp.blocks.registerBlock( {
}
}
],
insert: function( block, editor ) {
editor.execCommand( 'InsertUnorderedList' );
insert: function() {
return '<ul><li><br></li></ul>';
}
} );
4 changes: 2 additions & 2 deletions tinymce-single/blocks/elements/paragraph/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ window.wp.blocks.registerBlock( {
'text-align-center',
'text-align-right'
],
insert: function( block, editor ) {
editor.formatter.apply( 'p', block );
insert: function() {
return '<p><br></p>';
}
} );
4 changes: 2 additions & 2 deletions tinymce-single/blocks/elements/preformatted/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ window.wp.blocks.registerBlock( {
}
}
],
insert: function( block, editor ) {
editor.formatter.apply( 'pre' );
insert: function() {
return '<pre><br></pre>';
}
} );
4 changes: 1 addition & 3 deletions tinymce-single/blocks/my-awesome-plugin/youtube/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ window.wp.blocks.registerBlock( {
icon: 'gridicons-cog'
}
],
insert: function( block, editor ) {

}
insert: function() {}
} );
19 changes: 18 additions & 1 deletion tinymce-single/tinymce/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,24 @@
buttons.push( {
text: allSettings[ key ].displayName,
icon: allSettings[ key ].icon,
onClick: allSettings[ key ].insert
onClick: ( function( callback ) {
return function( block ) {
var content = callback.apply( this, arguments );

if ( content ) {
if ( typeof content === 'string' ) {
var temp = document.createElement( 'div' );
temp.innerHTML = content;
content = temp.firstChild;
temp = null;
}

block.parentNode.replaceChild( content, block );
}

editor.selection.setCursorLocation( content, 0 );
}
} )( allSettings[ key ].insert )
} );
}
}
Expand Down