mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 15:08:10 +01:00
Emoji: Always skip nodes with the wp-exclude-emoji
CSS class.
Patches twemoji.js to add support for a `doNotParse()` callback. Uses that callback to always exclude emojis in HTML elements with the above class. Props: dd32, peterwilsoncc, azaozz. Fixes #52219. Built from https://develop.svn.wordpress.org/trunk@55186 git-svn-id: http://core.svn.wordpress.org/trunk@54719 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9feba5fa8b
commit
9d580a0fcb
@ -4,6 +4,11 @@ var twemoji = (function (
|
|||||||
https://github.com/twitter/twemoji/blob/gh-pages/LICENSE
|
https://github.com/twitter/twemoji/blob/gh-pages/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note: this file was modified in two places to add support for a doNotParse() callback.
|
||||||
|
* The modifications are surrounded by `// WP start` and `// WP end` comments.
|
||||||
|
*/
|
||||||
|
|
||||||
// WARNING: this file is generated automatically via
|
// WARNING: this file is generated automatically via
|
||||||
// `node scripts/build.js`
|
// `node scripts/build.js`
|
||||||
// please update its `createTwemoji` function
|
// please update its `createTwemoji` function
|
||||||
@ -305,6 +310,14 @@ var twemoji = (function (
|
|||||||
// should not be parsed as script, style, and others
|
// should not be parsed as script, style, and others
|
||||||
else if (nodeType === 1 && !('ownerSVGElement' in subnode) &&
|
else if (nodeType === 1 && !('ownerSVGElement' in subnode) &&
|
||||||
!shouldntBeParsed.test(subnode.nodeName.toLowerCase())) {
|
!shouldntBeParsed.test(subnode.nodeName.toLowerCase())) {
|
||||||
|
|
||||||
|
// WP start
|
||||||
|
// Use doNotParse() callback if set.
|
||||||
|
if ( twemoji.doNotParse && twemoji.doNotParse( subnode ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// WP end
|
||||||
|
|
||||||
grabAllTextNodes(subnode, allText);
|
grabAllTextNodes(subnode, allText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -520,6 +533,14 @@ var twemoji = (function (
|
|||||||
if (!how || typeof how === 'function') {
|
if (!how || typeof how === 'function') {
|
||||||
how = {callback: how};
|
how = {callback: how};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WP start
|
||||||
|
// Allow passing of the doNotParse() callback in the settings.
|
||||||
|
// The callback is used in `grabAllTextNodes()` (DOM mode only) as a filter
|
||||||
|
// that allows bypassing of some of the text nodes. It gets the current subnode as argument.
|
||||||
|
twemoji.doNotParse = how.doNotParse;
|
||||||
|
// WP end
|
||||||
|
|
||||||
// if first argument is string, inject html <img> tags
|
// if first argument is string, inject html <img> tags
|
||||||
// otherwise use the DOM tree and parse text nodes only
|
// otherwise use the DOM tree and parse text nodes only
|
||||||
return (typeof what === 'string' ? parseString : parseNode)(what, {
|
return (typeof what === 'string' ? parseString : parseNode)(what, {
|
||||||
@ -565,4 +586,4 @@ var twemoji = (function (
|
|||||||
return r.join(sep || '-');
|
return r.join(sep || '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
2
wp-includes/js/twemoji.min.js
vendored
2
wp-includes/js/twemoji.min.js
vendored
File diff suppressed because one or more lines are too long
4
wp-includes/js/wp-emoji-release.min.js
vendored
4
wp-includes/js/wp-emoji-release.min.js
vendored
File diff suppressed because one or more lines are too long
@ -145,17 +145,6 @@
|
|||||||
node = node.parentNode;
|
node = node.parentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* If the class name of a non-element node contains 'wp-exclude-emoji' ignore it.
|
|
||||||
*
|
|
||||||
* Node type 1 is an ELEMENT_NODE.
|
|
||||||
*/
|
|
||||||
if ( ! node || node.nodeType !== 1 ||
|
|
||||||
( node.className && typeof node.className === 'string' && node.className.indexOf( 'wp-exclude-emoji' ) !== -1 ) ) {
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( test( node.textContent ) ) {
|
if ( test( node.textContent ) ) {
|
||||||
parse( node );
|
parse( node );
|
||||||
}
|
}
|
||||||
@ -263,6 +252,19 @@
|
|||||||
this.setAttribute( 'data-error', 'load-failed' );
|
this.setAttribute( 'data-error', 'load-failed' );
|
||||||
twemoji.parentNode.replaceChild( document.createTextNode( twemoji.alt ), twemoji );
|
twemoji.parentNode.replaceChild( document.createTextNode( twemoji.alt ), twemoji );
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
doNotParse: function( node ) {
|
||||||
|
if (
|
||||||
|
node &&
|
||||||
|
node.className &&
|
||||||
|
typeof node.className === 'string' &&
|
||||||
|
node.className.indexOf( 'wp-exclude-emoji' ) !== -1
|
||||||
|
) {
|
||||||
|
// Do not parse this node. Emojis will not be replaced in this node and all sub-nodes.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
2
wp-includes/js/wp-emoji.min.js
vendored
2
wp-includes/js/wp-emoji.min.js
vendored
@ -1,2 +1,2 @@
|
|||||||
/*! This file is auto-generated */
|
/*! This file is auto-generated */
|
||||||
!function(c,l){c.wp=c.wp||{},c.wp.emoji=new function(){var n,u,e=c.MutationObserver||c.WebKitMutationObserver||c.MozMutationObserver,a=c.document,t=!1,r=0,o=0<c.navigator.userAgent.indexOf("Trident/7.0");function i(){return!a.implementation.hasFeature||a.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1")}function s(){if(!t){if(void 0===c.twemoji)return 600<r?void 0:(c.clearTimeout(u),u=c.setTimeout(s,50),void r++);n=c.twemoji,t=!0,e&&new e(function(u){for(var e,t,n,a,r=u.length;r--;){if(e=u[r].addedNodes,t=u[r].removedNodes,1===(n=e.length)&&1===t.length&&3===e[0].nodeType&&"IMG"===t[0].nodeName&&e[0].data===t[0].alt&&"load-failed"===t[0].getAttribute("data-error"))return;for(;n--;){if(3===(a=e[n]).nodeType){if(!a.parentNode)continue;if(o)for(;a.nextSibling&&3===a.nextSibling.nodeType;)a.nodeValue=a.nodeValue+a.nextSibling.nodeValue,a.parentNode.removeChild(a.nextSibling);a=a.parentNode}!a||1!==a.nodeType||a.className&&"string"==typeof a.className&&-1!==a.className.indexOf("wp-exclude-emoji")||d(a.textContent)&&f(a)}}}).observe(a.body,{childList:!0,subtree:!0}),f(a.body)}}function d(u){return!!u&&(/[\uDC00-\uDFFF]/.test(u)||/[\u203C\u2049\u20E3\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2300\u231A\u231B\u2328\u2388\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638\u2639\u263A\u2648-\u2653\u2660\u2663\u2665\u2666\u2668\u267B\u267F\u2692\u2693\u2694\u2696\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753\u2754\u2755\u2757\u2763\u2764\u2795\u2796\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05\u2B06\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]/.test(u))}function f(u,e){var t;return!l.supports.everything&&n&&u&&("string"==typeof u||u.childNodes&&u.childNodes.length)?(e=e||{},t={base:i()?l.svgUrl:l.baseUrl,ext:i()?l.svgExt:l.ext,className:e.className||"emoji",callback:function(u,e){switch(u){case"a9":case"ae":case"2122":case"2194":case"2660":case"2663":case"2665":case"2666":return!1}return!(l.supports.everythingExceptFlag&&!/^1f1(?:e[6-9a-f]|f[0-9a-f])-1f1(?:e[6-9a-f]|f[0-9a-f])$/.test(u)&&!/^(1f3f3-fe0f-200d-1f308|1f3f4-200d-2620-fe0f)$/.test(u))&&"".concat(e.base,u,e.ext)},attributes:function(){return{role:"img"}},onerror:function(){n.parentNode&&(this.setAttribute("data-error","load-failed"),n.parentNode.replaceChild(a.createTextNode(n.alt),n))}},"object"==typeof e.imgAttr&&(t.attributes=function(){return e.imgAttr}),n.parse(u,t)):u}return l&&(l.DOMReady?s():l.readyCallback=s),{parse:f,test:d}}}(window,window._wpemojiSettings);
|
!function(c,l){c.wp=c.wp||{},c.wp.emoji=new function(){var n,u,e=c.MutationObserver||c.WebKitMutationObserver||c.MozMutationObserver,a=c.document,t=!1,r=0,o=0<c.navigator.userAgent.indexOf("Trident/7.0");function i(){return!a.implementation.hasFeature||a.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1")}function s(){if(!t){if(void 0===c.twemoji)return 600<r?void 0:(c.clearTimeout(u),u=c.setTimeout(s,50),void r++);n=c.twemoji,t=!0,e&&new e(function(u){for(var e,t,n,a,r=u.length;r--;){if(e=u[r].addedNodes,t=u[r].removedNodes,1===(n=e.length)&&1===t.length&&3===e[0].nodeType&&"IMG"===t[0].nodeName&&e[0].data===t[0].alt&&"load-failed"===t[0].getAttribute("data-error"))return;for(;n--;){if(3===(a=e[n]).nodeType){if(!a.parentNode)continue;if(o)for(;a.nextSibling&&3===a.nextSibling.nodeType;)a.nodeValue=a.nodeValue+a.nextSibling.nodeValue,a.parentNode.removeChild(a.nextSibling);a=a.parentNode}d(a.textContent)&&f(a)}}}).observe(a.body,{childList:!0,subtree:!0}),f(a.body)}}function d(u){return!!u&&(/[\uDC00-\uDFFF]/.test(u)||/[\u203C\u2049\u20E3\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2300\u231A\u231B\u2328\u2388\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638\u2639\u263A\u2648-\u2653\u2660\u2663\u2665\u2666\u2668\u267B\u267F\u2692\u2693\u2694\u2696\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753\u2754\u2755\u2757\u2763\u2764\u2795\u2796\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05\u2B06\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]/.test(u))}function f(u,e){var t;return!l.supports.everything&&n&&u&&("string"==typeof u||u.childNodes&&u.childNodes.length)?(e=e||{},t={base:i()?l.svgUrl:l.baseUrl,ext:i()?l.svgExt:l.ext,className:e.className||"emoji",callback:function(u,e){switch(u){case"a9":case"ae":case"2122":case"2194":case"2660":case"2663":case"2665":case"2666":return!1}return!(l.supports.everythingExceptFlag&&!/^1f1(?:e[6-9a-f]|f[0-9a-f])-1f1(?:e[6-9a-f]|f[0-9a-f])$/.test(u)&&!/^(1f3f3-fe0f-200d-1f308|1f3f4-200d-2620-fe0f)$/.test(u))&&"".concat(e.base,u,e.ext)},attributes:function(){return{role:"img"}},onerror:function(){n.parentNode&&(this.setAttribute("data-error","load-failed"),n.parentNode.replaceChild(a.createTextNode(n.alt),n))},doNotParse:function(u){return!(!u||!u.className||"string"!=typeof u.className||-1===u.className.indexOf("wp-exclude-emoji"))}},"object"==typeof e.imgAttr&&(t.attributes=function(){return e.imgAttr}),n.parse(u,t)):u}return l&&(l.DOMReady?s():l.readyCallback=s),{parse:f,test:d}}}(window,window._wpemojiSettings);
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.2-alpha-55185';
|
$wp_version = '6.2-alpha-55186';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user