Skip to content

Commit

Permalink
Merge pull request #173 from WordPress/remove-element-global
Browse files Browse the repository at this point in the history
Remove element global (tinymce-single)
  • Loading branch information
ellatrix committed Mar 3, 2017
2 parents db9035c + 3b07e96 commit 2145e41
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 97 deletions.
2 changes: 1 addition & 1 deletion shared/tinymce/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
function onClick( callback ) {
return function() {
editor.undoManager.transact( function() {
callback( editor, window.element );
callback( window.wp.blocks.getSelectedBlock(), editor );
} );
}
}
Expand Down
20 changes: 20 additions & 0 deletions tinymce-single/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@
},
getControls: function() {
return _controls;
},
getSelectedBlocks: function() {

},
getSelectedBlock: function( editor ) {
var editor = window.tinyMCE.activeEditor;
var node = editor.selection.getNode();
var rootNode = editor.getBody();

if ( node === rootNode ) {
return rootNode.firstChild;
}

while ( node.parentNode ) {
if ( node.parentNode === rootNode ) {
return node;
}

node = node.parentNode;
}
}
};
} )( window.wp = window.wp || {} );
6 changes: 3 additions & 3 deletions tinymce-single/blocks/elements/blockquote/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ window.wp.blocks.registerBlock( {
{
classes: 'remove-formatting',
icon: 'gridicons-quote',
onClick: function( editor ) {
onClick: function( block, editor ) {
editor.formatter.remove( 'blockquote' );
}
}
],
insert: function( editor, element ) {
editor.formatter.apply( 'blockquote', element );
insert: function( block, editor ) {
editor.formatter.apply( 'blockquote', block );
}
} );

8 changes: 4 additions & 4 deletions tinymce-single/blocks/elements/headings/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
icon: 'gridicons-heading',
text: level,
stateSelector: 'h' + level,
onClick: function( editor, element ) {
editor.formatter.apply( 'h' + level, element );
onClick: function( block, editor ) {
editor.formatter.apply( 'h' + level, block );
}
} );
} );

controls.push( {
classes: 'remove-formatting',
icon: 'gridicons-heading',
onClick: function( editor, element ) {
editor.formatter.apply( 'p', element );
onClick: function( block, editor ) {
editor.formatter.apply( 'p', block );
}
} );

Expand Down
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 @@ -2,7 +2,7 @@ window.wp.blocks.registerBlock( {
elements: [ 'hr' ],
type: 'separator',
icon: 'gridicons-minus',
insert: function( editor, element ) {
element.parentNode.replaceChild( document.createElement( 'hr' ), element );
insert: function( block ) {
block.parentNode.replaceChild( document.createElement( 'hr' ), block );
}
} );
10 changes: 5 additions & 5 deletions tinymce-single/blocks/elements/lists/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ window.wp.blocks.registerBlock( {
{
icon: 'gridicons-list-unordered',
stateSelector: 'ul',
onClick: function( editor, element ) {
onClick: function( editor ) {
editor.execCommand( 'InsertUnorderedList' );
}
},
{
icon: 'gridicons-list-ordered',
stateSelector: 'ol',
onClick: function( editor, element ) {
onClick: function( editor ) {
editor.execCommand( 'InsertOrderedList' );
}
},
{
classes: 'remove-formatting',
icon: 'gridicons-list-unordered',
onClick: function( editor, element ) {
if ( element.nodeName === 'UL' ) {
onClick: function( block, editor ) {
if ( block.nodeName === 'UL' ) {
editor.execCommand( 'InsertUnorderedList' );
} else if ( element.nodeName === 'OL' ) {
} else if ( block.nodeName === 'OL' ) {
editor.execCommand( 'InsertOrderedList' );
}
}
Expand Down
8 changes: 4 additions & 4 deletions tinymce-single/blocks/elements/paragraph/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ window.wp.blocks.registerBlock( {
controls: [
{
icon: 'gridicons-heading',
onClick: function( editor ) {
onClick: function( block, editor ) {
editor.formatter.apply( 'h1' );
}
},
{
icon: 'gridicons-quote',
onClick: function( editor ) {
onClick: function( block, editor ) {
editor.formatter.apply( 'blockquote' );
}
},
{
icon: 'gridicons-list-unordered',
onClick: function( editor, element ) {
onClick: function( block, editor ) {
editor.execCommand( 'InsertUnorderedList' );
}
},
{
icon: 'gridicons-code',
onClick: function( editor ) {
onClick: function( block, editor ) {
editor.formatter.apply( 'pre' );
}
},
Expand Down
2 changes: 1 addition & 1 deletion tinymce-single/blocks/elements/preformatted/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ window.wp.blocks.registerBlock( {
{
classes: 'remove-formatting',
icon: 'gridicons-code',
onClick: function( editor ) {
onClick: function( block, editor ) {
editor.formatter.remove( 'pre' );
}
}
Expand Down
Loading

0 comments on commit 2145e41

Please sign in to comment.