mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-10 14:48:07 +02:00
Replace exisiting smilies with equivalent emoji, or with shiny new smiley images where no emoji existed. Props batmoo, joen and mkaz for the original plugin upon which this is based. Props pento, iseulde, kraftbj and peterwilsoncc for making the internet's dreams come true. See #31242 Built from https://develop.svn.wordpress.org/trunk@31733 git-svn-id: http://core.svn.wordpress.org/trunk@31714 1a063a9b-81f0-0310-95a4-ce76da25c4cd
65 lines
1.6 KiB
JavaScript
65 lines
1.6 KiB
JavaScript
( function( tinymce, WPEmoji ) {
|
|
tinymce.PluginManager.add( 'wpemoji', function( editor, url ) {
|
|
var typing;
|
|
|
|
if ( ! WPEmoji.parseEmoji ) {
|
|
return;
|
|
}
|
|
|
|
// Loads stylesheet for custom styles within the editor
|
|
editor.on( 'init', function() {
|
|
var cssId = editor.dom.uniqueId();
|
|
var linkElm = editor.dom.create( 'link', {
|
|
id: cssId,
|
|
rel: 'stylesheet',
|
|
href: url + '/css/editor.css'
|
|
});
|
|
editor.getDoc().getElementsByTagName( 'head' )[0].appendChild( linkElm );
|
|
} );
|
|
|
|
editor.on( 'keydown keyup', function( event ) {
|
|
typing = event.type === 'keydown';
|
|
} );
|
|
|
|
editor.on( 'input setcontent', function() {
|
|
var selection, node, bookmark, imgs;
|
|
|
|
if ( typing ) {
|
|
return;
|
|
}
|
|
|
|
selection = editor.selection;
|
|
node = selection.getNode();
|
|
bookmark = selection.getBookmark();
|
|
|
|
WPEmoji.parse( node );
|
|
|
|
imgs = editor.dom.select( 'img.emoji', node );
|
|
|
|
tinymce.each( imgs, function( elem ) {
|
|
if ( ! elem.getAttribute( 'data-wp-emoji' ) ) {
|
|
elem.setAttribute( 'data-mce-resize', 'false' );
|
|
elem.setAttribute( 'data-mce-placeholder', '1' );
|
|
elem.setAttribute( 'data-wp-emoji', elem.alt );
|
|
}
|
|
} );
|
|
|
|
selection.moveToBookmark( bookmark );
|
|
} );
|
|
|
|
editor.on( 'postprocess', function( event ) {
|
|
if ( event.content ) {
|
|
event.content = event.content.replace( /<img[^>]+data-wp-emoji="([^"]+)"[^>]*>/g, function( match, emoji ) {
|
|
return emoji;
|
|
} );
|
|
}
|
|
} );
|
|
|
|
editor.on( 'resolvename', function( event ) {
|
|
if ( event.target.nodeName === 'IMG' && editor.dom.getAttrib( event.target, 'data-wp-emoji' ) ) {
|
|
event.preventDefault();
|
|
}
|
|
} );
|
|
} );
|
|
} )( window.tinymce, window.WPEmoji );
|