Edit File by line
/home/barbar84/www/wp-inclu.../js/tinymce/plugins/wpemoji
File: plugin.js
( function( tinymce ) {
[0] Fix | Delete
tinymce.PluginManager.add( 'wpemoji', function( editor ) {
[1] Fix | Delete
var typing,
[2] Fix | Delete
wp = window.wp,
[3] Fix | Delete
settings = window._wpemojiSettings,
[4] Fix | Delete
env = tinymce.Env,
[5] Fix | Delete
ua = window.navigator.userAgent,
[6] Fix | Delete
isWin = ua.indexOf( 'Windows' ) > -1,
[7] Fix | Delete
isWin8 = ( function() {
[8] Fix | Delete
var match = ua.match( /Windows NT 6\.(\d)/ );
[9] Fix | Delete
[10] Fix | Delete
if ( match && match[1] > 1 ) {
[11] Fix | Delete
return true;
[12] Fix | Delete
}
[13] Fix | Delete
[14] Fix | Delete
return false;
[15] Fix | Delete
}());
[16] Fix | Delete
[17] Fix | Delete
if ( ! wp || ! wp.emoji || settings.supports.everything ) {
[18] Fix | Delete
return;
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
function setImgAttr( image ) {
[22] Fix | Delete
image.className = 'emoji';
[23] Fix | Delete
image.setAttribute( 'data-mce-resize', 'false' );
[24] Fix | Delete
image.setAttribute( 'data-mce-placeholder', '1' );
[25] Fix | Delete
image.setAttribute( 'data-wp-emoji', '1' );
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
function replaceEmoji( node ) {
[29] Fix | Delete
var imgAttr = {
[30] Fix | Delete
'data-mce-resize': 'false',
[31] Fix | Delete
'data-mce-placeholder': '1',
[32] Fix | Delete
'data-wp-emoji': '1'
[33] Fix | Delete
};
[34] Fix | Delete
[35] Fix | Delete
wp.emoji.parse( node, { imgAttr: imgAttr } );
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
// Test if the node text contains emoji char(s) and replace.
[39] Fix | Delete
function parseNode( node ) {
[40] Fix | Delete
var selection, bookmark;
[41] Fix | Delete
[42] Fix | Delete
if ( node && window.twemoji && window.twemoji.test( node.textContent || node.innerText ) ) {
[43] Fix | Delete
if ( env.webkit ) {
[44] Fix | Delete
selection = editor.selection;
[45] Fix | Delete
bookmark = selection.getBookmark();
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
replaceEmoji( node );
[49] Fix | Delete
[50] Fix | Delete
if ( env.webkit ) {
[51] Fix | Delete
selection.moveToBookmark( bookmark );
[52] Fix | Delete
}
[53] Fix | Delete
}
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
if ( isWin8 ) {
[57] Fix | Delete
/*
[58] Fix | Delete
* Windows 8+ emoji can be "typed" with the onscreen keyboard.
[59] Fix | Delete
* That triggers the normal keyboard events, but not the 'input' event.
[60] Fix | Delete
* Thankfully it sets keyCode 231 when the onscreen keyboard inserts any emoji.
[61] Fix | Delete
*/
[62] Fix | Delete
editor.on( 'keyup', function( event ) {
[63] Fix | Delete
if ( event.keyCode === 231 ) {
[64] Fix | Delete
parseNode( editor.selection.getNode() );
[65] Fix | Delete
}
[66] Fix | Delete
} );
[67] Fix | Delete
} else if ( ! isWin ) {
[68] Fix | Delete
/*
[69] Fix | Delete
* In MacOS inserting emoji doesn't trigger the stanradr keyboard events.
[70] Fix | Delete
* Thankfully it triggers the 'input' event.
[71] Fix | Delete
* This works in Android and iOS as well.
[72] Fix | Delete
*/
[73] Fix | Delete
editor.on( 'keydown keyup', function( event ) {
[74] Fix | Delete
typing = ( event.type === 'keydown' );
[75] Fix | Delete
} );
[76] Fix | Delete
[77] Fix | Delete
editor.on( 'input', function() {
[78] Fix | Delete
if ( typing ) {
[79] Fix | Delete
return;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
parseNode( editor.selection.getNode() );
[83] Fix | Delete
});
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
editor.on( 'setcontent', function( event ) {
[87] Fix | Delete
var selection = editor.selection,
[88] Fix | Delete
node = selection.getNode();
[89] Fix | Delete
[90] Fix | Delete
if ( window.twemoji && window.twemoji.test( node.textContent || node.innerText ) ) {
[91] Fix | Delete
replaceEmoji( node );
[92] Fix | Delete
[93] Fix | Delete
// In IE all content in the editor is left selected after wp.emoji.parse()...
[94] Fix | Delete
// Collapse the selection to the beginning.
[95] Fix | Delete
if ( env.ie && env.ie < 9 && event.load && node && node.nodeName === 'BODY' ) {
[96] Fix | Delete
selection.collapse( true );
[97] Fix | Delete
}
[98] Fix | Delete
}
[99] Fix | Delete
} );
[100] Fix | Delete
[101] Fix | Delete
// Convert Twemoji compatible pasted emoji replacement images into our format.
[102] Fix | Delete
editor.on( 'PastePostProcess', function( event ) {
[103] Fix | Delete
if ( window.twemoji ) {
[104] Fix | Delete
tinymce.each( editor.dom.$( 'img.emoji', event.node ), function( image ) {
[105] Fix | Delete
if ( image.alt && window.twemoji.test( image.alt ) ) {
[106] Fix | Delete
setImgAttr( image );
[107] Fix | Delete
}
[108] Fix | Delete
});
[109] Fix | Delete
}
[110] Fix | Delete
});
[111] Fix | Delete
[112] Fix | Delete
editor.on( 'postprocess', function( event ) {
[113] Fix | Delete
if ( event.content ) {
[114] Fix | Delete
event.content = event.content.replace( /<img[^>]+data-wp-emoji="[^>]+>/g, function( img ) {
[115] Fix | Delete
var alt = img.match( /alt="([^"]+)"/ );
[116] Fix | Delete
[117] Fix | Delete
if ( alt && alt[1] ) {
[118] Fix | Delete
return alt[1];
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
return img;
[122] Fix | Delete
});
[123] Fix | Delete
}
[124] Fix | Delete
} );
[125] Fix | Delete
[126] Fix | Delete
editor.on( 'resolvename', function( event ) {
[127] Fix | Delete
if ( event.target.nodeName === 'IMG' && editor.dom.getAttrib( event.target, 'data-wp-emoji' ) ) {
[128] Fix | Delete
event.preventDefault();
[129] Fix | Delete
}
[130] Fix | Delete
} );
[131] Fix | Delete
} );
[132] Fix | Delete
} )( window.tinymce );
[133] Fix | Delete
[134] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function