Emoji:
- Enhance twemoji.js to support passing of additional attributes for the replacement images. - Use that to add the needed attributes when replacing emoji inside the editor. Fixes #31627. git-svn-id: https://develop.svn.wordpress.org/trunk@31948 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
55792b59a8
commit
235b83b4c0
@ -22,12 +22,17 @@
|
|||||||
image.className = 'emoji';
|
image.className = 'emoji';
|
||||||
image.setAttribute( 'data-mce-resize', 'false' );
|
image.setAttribute( 'data-mce-resize', 'false' );
|
||||||
image.setAttribute( 'data-mce-placeholder', '1' );
|
image.setAttribute( 'data-mce-placeholder', '1' );
|
||||||
image.setAttribute( 'data-wp-emoji', image.alt );
|
image.setAttribute( 'data-wp-emoji', '1' );
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceEmoji( node ) {
|
function replaceEmoji( node ) {
|
||||||
wp.emoji.parse( node, { className: 'emoji _inserted-emoji' } );
|
var imgAttr = {
|
||||||
tinymce.each( editor.dom.$( 'img._inserted-emoji', node ), setImgAttr );
|
'data-mce-resize': 'false',
|
||||||
|
'data-mce-placeholder': '1',
|
||||||
|
'data-wp-emoji': '1'
|
||||||
|
};
|
||||||
|
|
||||||
|
wp.emoji.parse( node, { imgAttr: imgAttr } );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test if the node text contains emoji char(s) and replace.
|
// Test if the node text contains emoji char(s) and replace.
|
||||||
@ -102,7 +107,15 @@
|
|||||||
|
|
||||||
editor.on( 'postprocess', function( event ) {
|
editor.on( 'postprocess', function( event ) {
|
||||||
if ( event.content ) {
|
if ( event.content ) {
|
||||||
event.content = event.content.replace( /<img[^>]+data-wp-emoji="([^"]+)"[^>]*>/g, '$1' );
|
event.content = event.content.replace( /<img[^>]+data-wp-emoji="[^>]+>/g, function( img ) {
|
||||||
|
var alt = img.match( /alt="([^"]+)"/ );
|
||||||
|
|
||||||
|
if ( alt && alt[1] ) {
|
||||||
|
return alt[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return img;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -337,7 +337,8 @@ var twemoji = (function (
|
|||||||
alt,
|
alt,
|
||||||
icon,
|
icon,
|
||||||
variant,
|
variant,
|
||||||
src;
|
src,
|
||||||
|
attr;
|
||||||
while (length--) {
|
while (length--) {
|
||||||
modified = false;
|
modified = false;
|
||||||
fragment = document.createDocumentFragment();
|
fragment = document.createDocumentFragment();
|
||||||
@ -363,6 +364,14 @@ var twemoji = (function (
|
|||||||
);
|
);
|
||||||
if (src) {
|
if (src) {
|
||||||
img = new Image();
|
img = new Image();
|
||||||
|
|
||||||
|
// Set additional image attributes.
|
||||||
|
if ( options.imgAttr ) {
|
||||||
|
for ( attr in options.imgAttr ) {
|
||||||
|
img.setAttribute( attr, options.imgAttr[attr] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
img.onerror = twemoji.onerror;
|
img.onerror = twemoji.onerror;
|
||||||
img.className = options.className;
|
img.className = options.className;
|
||||||
img.setAttribute('draggable', 'false');
|
img.setAttribute('draggable', 'false');
|
||||||
@ -406,7 +415,7 @@ var twemoji = (function (
|
|||||||
*/
|
*/
|
||||||
function parseString(str, options) {
|
function parseString(str, options) {
|
||||||
return replace(str, function (match, icon, variant) {
|
return replace(str, function (match, icon, variant) {
|
||||||
var src;
|
var src, attr, attributes = '';
|
||||||
// verify the variant is not the FE0E one
|
// verify the variant is not the FE0E one
|
||||||
// this variant means "emoji as text" and should not
|
// this variant means "emoji as text" and should not
|
||||||
// require any action/replacement
|
// require any action/replacement
|
||||||
@ -418,6 +427,15 @@ var twemoji = (function (
|
|||||||
variant
|
variant
|
||||||
);
|
);
|
||||||
if (src) {
|
if (src) {
|
||||||
|
// Set additional image attributes.
|
||||||
|
if ( options.imgAttr ) {
|
||||||
|
for ( attr in options.imgAttr ) {
|
||||||
|
if ( ! /draggable|class|alt|src/i.test( attr ) ) {
|
||||||
|
attributes += ' '.concat( attr, '="', options.imgAttr[attr], '"' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// recycle the match string replacing the emoji
|
// recycle the match string replacing the emoji
|
||||||
// with its image counter part
|
// with its image counter part
|
||||||
match = '<img '.concat(
|
match = '<img '.concat(
|
||||||
@ -431,6 +449,7 @@ var twemoji = (function (
|
|||||||
'src="',
|
'src="',
|
||||||
src,
|
src,
|
||||||
'"',
|
'"',
|
||||||
|
attributes,
|
||||||
'>'
|
'>'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -483,7 +502,8 @@ var twemoji = (function (
|
|||||||
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
||||||
ext: how.ext || twemoji.ext,
|
ext: how.ext || twemoji.ext,
|
||||||
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),
|
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),
|
||||||
className:how.className || twemoji.className
|
className:how.className || twemoji.className,
|
||||||
|
imgAttr: how.imgAttr
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,12 +100,13 @@
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
var className = ( args && args.className ) || 'emoji';
|
args = args || {};
|
||||||
|
|
||||||
return twemoji.parse( object, {
|
return twemoji.parse( object, {
|
||||||
base: settings.baseUrl,
|
base: settings.baseUrl,
|
||||||
ext: settings.ext,
|
ext: settings.ext,
|
||||||
className: className,
|
className: args.className || 'emoji',
|
||||||
|
imgAttr: args.imgAttr,
|
||||||
callback: function( icon, options ) {
|
callback: function( icon, options ) {
|
||||||
// Ignore some standard characters that TinyMCE recommends in its character map.
|
// Ignore some standard characters that TinyMCE recommends in its character map.
|
||||||
switch ( icon ) {
|
switch ( icon ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user