WordPress.org

Make WordPress Core

Changeset 35637


Ignore:
Timestamp:
11/14/2015 09:51:02 AM (4 years ago)
Author:
pento
Message:

Emoji: Ensure twemoji kicks in on certain DOM mutations.

Twemoji will replace the img with the emoji character, in the event that the image fails to load. We deliberately avoid trying to change that emoji character when it's changed back. We do need to replace emoji characters that are changed by something other than Twemoji, which this rectifies.

Fixes #34640.

Location:
trunk/src/wp-includes/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/twemoji.js

    r35596 r35637  
    387387          if (src) {
    388388            img = new Image();
    389             img.onerror = twemoji.onerror;
     389            img.onerror = options.onerror;
    390390            img.setAttribute('draggable', 'false');
    391391            attrib = options.attributes(icon, variant);
     
    551551      ext:        how.ext || twemoji.ext,
    552552      size:       how.folder || toSizeSquaredAsset(how.size || twemoji.size),
    553       className:  how.className || twemoji.className
     553      className:  how.className || twemoji.className,
     554      onerror:    how.onerror || twemoji.onerror
    554555    });
    555556  }
  • trunk/src/wp-includes/js/wp-emoji.js

    r35606 r35637  
    5959                            addedNodes[0].nodeType === 3 &&
    6060                            removedNodes[0].nodeName === 'IMG' &&
    61                             addedNodes[0].data === removedNodes[0].alt
     61                            addedNodes[0].data === removedNodes[0].alt &&
     62                            'load-failed' === removedNodes[0].getAttribute( 'data-error' )
    6263                        ) {
    6364                            return;
     
    156157
    157158                    return ''.concat( options.base, icon, options.ext );
     159                },
     160                onerror: function() {
     161                    if ( twemoji.parentNode ) {
     162                        this.setAttribute( 'data-error', 'load-failed' );
     163                        twemoji.parentNode.replaceChild( document.createTextNode( twemoji.alt ), twemoji );
     164                    }
    158165                }
    159166            };
Note: See TracChangeset for help on using the changeset viewer.