2015-03-11 23:17:26 -04:00
|
|
|
( function( tinymce, wp ) {
|
2015-03-11 18:49:28 -04:00
|
|
|
tinymce.PluginManager.add( 'wpemoji', function( editor, url ) {
|
|
|
|
var typing;
|
|
|
|
|
2015-03-11 23:17:26 -04:00
|
|
|
if ( ! wp.emoji.parseEmoji ) {
|
2015-03-11 18:49:28 -04:00
|
|
|
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';
|
|
|
|
} );
|
|
|
|
|
2015-03-12 08:52:26 -04:00
|
|
|
editor.on( 'input setcontent', function( event ) {
|
2015-03-11 18:49:28 -04:00
|
|
|
var selection, node, bookmark, imgs;
|
|
|
|
|
2015-03-12 08:52:26 -04:00
|
|
|
if ( typing && event.type === 'input' ) {
|
2015-03-11 18:49:28 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
selection = editor.selection;
|
|
|
|
node = selection.getNode();
|
|
|
|
bookmark = selection.getBookmark();
|
|
|
|
|
2015-03-11 23:17:26 -04:00
|
|
|
wp.emoji.parse( node );
|
2015-03-11 18:49:28 -04:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
2015-03-11 23:17:26 -04:00
|
|
|
} )( window.tinymce, window.wp );
|