<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[43360] trunk/src/js/_enqueues/wp/emoji.js: Docs: Improve JSDoc for `emoji.js`.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/43360">43360</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/43360","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>atimmer</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-06-16 12:53:07 +0000 (Sat, 16 Jun 2018)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Docs: Improve JSDoc for `emoji.js`.
Props lisannekluitmans, hansjovisyoast, igorsch, nicollle.
Fixes <a href="https://core.trac.wordpress.org/ticket/44367">#44367</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcjs_enqueueswpemojijs">trunk/src/js/_enqueues/wp/emoji.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcjs_enqueueswpemojijs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/js/_enqueues/wp/emoji.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/js/_enqueues/wp/emoji.js 2018-06-16 12:44:46 UTC (rev 43359)
+++ trunk/src/js/_enqueues/wp/emoji.js 2018-06-16 12:53:07 UTC (rev 43360)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,8 +1,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * wp-emoji.js is used to replace emoji with images in browsers when the browser
+ * doesn't support emoji natively.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @output wp-includes/js/wp-emoji.js
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> ( function( window, settings ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Replaces emoji with images when browsers don't support emoji.
+ *
+ * @since 4.2.0
+ * @access private
+ *
+ * @class
+ *
+ * @see Twitter Emoji library
+ * @link https://github.com/twitter/twemoji
+ *
+ * @return {Object} The wpEmoji parse and test functions.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function wpEmoji() {
</span><span class="cx" style="display: block; padding: 0 10px"> var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver,
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,13 +35,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Detect if the browser supports SVG.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.6.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @private
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return {Boolean} True if the browser supports svg, false if not.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see Modernizr
+ * @link https://github.com/Modernizr/Modernizr/blob/master/feature-detects/svg/asimg.js
+ *
+ * @return {boolean} True if the browser supports svg, false if not.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function browserSupportsSvgAsImage() {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( !! document.implementation.hasFeature ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Source: Modernizr
- // https://github.com/Modernizr/Modernizr/blob/master/feature-detects/svg/asimg.js
</del><span class="cx" style="display: block; padding: 0 10px"> return document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -35,9 +53,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Runs when the document load event is fired, so we can do our first parse of the page.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Runs when the document load event is fired, so we can do our first parse of
+ * the page.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Listens to all the DOM mutations and checks for added nodes that contain
+ * emoji characters and replaces those with twitter emoji images.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @since 4.2.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @private
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function load() {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( loaded ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -44,6 +67,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Ensure twemoji is available on the global window before proceeding.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( typeof window.twemoji === 'undefined' ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Break if waiting for longer than 30 sec.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( count > 600 ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -61,6 +85,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> twemoji = window.twemoji;
</span><span class="cx" style="display: block; padding: 0 10px"> loaded = true;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Initialize the mutation observer, which checks all added nodes for
+ // replaceable emoji characters.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( MutationObserver ) {
</span><span class="cx" style="display: block; padding: 0 10px"> new MutationObserver( function( mutationRecords ) {
</span><span class="cx" style="display: block; padding: 0 10px"> var i = mutationRecords.length,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -71,6 +97,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> removedNodes = mutationRecords[ i ].removedNodes;
</span><span class="cx" style="display: block; padding: 0 10px"> ii = addedNodes.length;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * Checks if an image has been replaced by a text element
+ * with the same text as the alternate description of the replaced image.
+ * (presumably because the image could not be loaded).
+ * If it is, do absolutely nothing.
+ *
+ * Node type 3 is a TEXT_NODE.
+ *
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> if (
</span><span class="cx" style="display: block; padding: 0 10px"> ii === 1 && removedNodes.length === 1 &&
</span><span class="cx" style="display: block; padding: 0 10px"> addedNodes[0].nodeType === 3 &&
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -81,9 +117,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Loop through all the added nodes.
</ins><span class="cx" style="display: block; padding: 0 10px"> while ( ii-- ) {
</span><span class="cx" style="display: block; padding: 0 10px"> node = addedNodes[ ii ];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Node type 3 is a TEXT_NODE.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( node.nodeType === 3 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! node.parentNode ) {
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -95,6 +133,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * It unnecessarily splits text nodes when it encounters a HTML
</span><span class="cx" style="display: block; padding: 0 10px"> * template interpolation symbol ( "{{", for example ). So, we
</span><span class="cx" style="display: block; padding: 0 10px"> * join the text nodes back together as a work-around.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
+ * Node type 3 is a TEXT_NODE.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> while( node.nextSibling && 3 === node.nextSibling.nodeType ) {
</span><span class="cx" style="display: block; padding: 0 10px"> node.nodeValue = node.nodeValue + node.nextSibling.nodeValue;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -105,6 +145,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> node = node.parentNode;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * If the class name of a non-element node contains 'wp-exclude-emoji' ignore it.
+ *
+ * Node type 1 is an ELEMENT_NODE.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! node || node.nodeType !== 1 ||
</span><span class="cx" style="display: block; padding: 0 10px"> ( node.className && typeof node.className === 'string' && node.className.indexOf( 'wp-exclude-emoji' ) !== -1 ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -126,13 +171,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Test if a text string contains emoji characters.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Tests if a text string contains emoji characters.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.3.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param {String} text The string to test
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @memberOf wp.emoji
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return {Boolean} Whether the string contains emoji characters.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param {string} text The string to test.
+ *
+ * @return {boolean} Whether the string contains emoji characters.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test( text ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Single char. U+20E3 to detect keycaps. U+00A9 "copyright sign" and U+00AE "registered sign" not included.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -148,16 +195,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Given an element or string, parse any emoji characters into Twemoji images.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Parses any emoji characters into Twemoji images.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * - When passed an element the emoji characters are replaced inline.
+ * - When passed a string the emoji characters are replaced and the result is
+ * returned.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @since 4.2.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param {HTMLElement|String} object The element or string to parse.
- * @param {Object} args Additional options for Twemoji.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @memberOf wp.emoji
+ *
+ * @param {HTMLElement|string} object The element or string to parse.
+ * @param {Object} args Additional options for Twemoji.
+ *
+ * @return {HTMLElement|string} A string where all emoji are now image tags of
+ * emoji. Or the element that was passed as the first argument.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function parse( object, args ) {
</span><span class="cx" style="display: block; padding: 0 10px"> var params;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * If the browser has full support, twemoji is not loaded or our
+ * object is not what was expected, we do not parse anything.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( settings.supports.everything || ! twemoji || ! object ||
</span><span class="cx" style="display: block; padding: 0 10px"> ( 'string' !== typeof object && ( ! object.childNodes || ! object.childNodes.length ) ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -164,6 +224,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return object;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Compose the params for the twitter emoji library.
</ins><span class="cx" style="display: block; padding: 0 10px"> args = args || {};
</span><span class="cx" style="display: block; padding: 0 10px"> params = {
</span><span class="cx" style="display: block; padding: 0 10px"> base: browserSupportsSvgAsImage() ? settings.svgUrl : settings.baseUrl,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -227,6 +288,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> window.wp = window.wp || {};
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @namespace wp.emoji
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> window.wp.emoji = new wpEmoji();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> } )( window, window._wpemojiSettings );
</span></span></pre>
</div>
</div>
</body>
</html>