| | 858 | editor.on( 'pastePostProcess', function( event ) { |
| | 859 | var element, captionNode = editor.dom.getParent( editor.selection.getNode(), 'dd.wp-caption-dd' ); |
| | 860 | |
| | 861 | if ( captionNode ) { |
| | 862 | var walker = new tinymce.dom.TreeWalker( event.node, event.node ); |
| | 863 | |
| | 864 | while ( element = walker.next() ) { |
| | 865 | if ( editor.dom.isBlock( element ) ) { |
| | 866 | // Mark nodes for removal. Can't remove them now as that stops the walker. |
| | 867 | editor.dom.setAttrib( element, 'data-wp-removeme', 'true' ); |
| | 868 | } else if ( element.nodeName === 'IMG' || element.nodeName === 'AUDIO' || element.nodeName === 'VIDEO' || element.nodeName === 'svg' ) { |
| | 869 | // Can't be pasted in the image caption. Will be inserted in a new paragraph under it. |
| | 870 | return; |
| | 871 | } |
| | 872 | } |
| | 873 | |
| | 874 | editor.$( '[data-wp-removeme]', event.node ).each( function( i, node ) { |
| | 875 | // Insert <br> where the blocks used to be. Otherwise longer text runs together and looks bad. |
| | 876 | editor.dom.insertAfter( editor.dom.create( 'br' ), node ); |
| | 877 | editor.dom.remove( node, true ); |
| | 878 | }); |
| | 879 | |
| | 880 | // Pasted HTML is cleaned up for inserting in the caption. |
| | 881 | letPasteInCaption = true; |
| | 882 | } |
| | 883 | }); |
| | 884 | |
| 864 | | // When inserting content, if the caret is inside a caption create new paragraph under |
| 865 | | // and move the caret there |
| 866 | | if ( node = dom.getParent( editor.selection.getNode(), 'div.mceTemp' ) ) { |
| | 891 | node = editor.selection.getNode(); |
| | 892 | captionParent = dom.getParent( node, 'div.mceTemp' ); |
| | 893 | |
| | 894 | if ( captionParent ) { |
| | 895 | if ( letPasteInCaption && dom.getParent( node, 'dd.wp-caption-dd' ) && event.value.data && event.value.data.paste ) { |
| | 896 | letPasteInCaption = false; |
| | 897 | // We are in the caption element, and in 'paste' context, |
| | 898 | // and the pasted HTML was cleaned up on 'pastePostProcess' above. |
| | 899 | // Let it be pasted! |
| | 900 | return; |
| | 901 | } |
| | 902 | |
| | 903 | // Make new paragraph under the caption parent element and move the caret there. |