Вход Регистрация
Файл: wordpress/wp-includes/js/twemoji.js
Строк: 647
<?php
/*jslint indent: 2, browser: true, bitwise: true, plusplus: true */
var twemoji = (function (
  
/*! Copyright Twitter Inc. and other contributors. Licensed under MIT *//*
    https://github.com/twitter/twemoji/blob/gh-pages/LICENSE
  */

  // WARNING:   this file is generated automatically via
  //            `node twemoji-generator.js`
  //            please update its `createTwemoji` function
  //            at the bottom of the same file instead.

) {
  
'use strict';

  
/*jshint maxparams:4 */

  
var
    
// the exported module object
    
twemoji = {


    
/////////////////////////
    //      properties     //
    /////////////////////////

      // default assets url, by default will be Twitter Inc. CDN
      
base: (location.protocol === 'https:' 'https:' 'http:') +
            
'//twemoji.maxcdn.com/',

      
// default assets file extensions, by default '.png'
      
ext'.png',

      
// default assets/folder size, by default "36x36"
      // available via Twitter CDN: 16, 36, 72
      
size'36x36',

      
// default class name, by default 'emoji'
      
className'emoji',

      
// basic utilities / helpers to convert code points
      // to JavaScript surrogates and vice versa
      
convert: {

        
/**
         * Given an HEX codepoint, returns UTF16 surrogate pairs.
         *
         * @param   string  generic codepoint, i.e. '1F4A9'
         * @return  string  codepoint transformed into utf16 surrogates pair,
         *          i.e. uD83DuDCA9
         *
         * @example
         *  twemoji.convert.fromCodePoint('1f1e8');
         *  // "ud83cudde8"
         *
         *  '1f1e8-1f1f3'.split('-').map(twemoji.convert.fromCodePoint).join('')
         *  // "ud83cudde8ud83cuddf3"
         */
        
fromCodePointfromCodePoint,

        
/**
         * Given UTF16 surrogate pairs, returns the equivalent HEX codepoint.
         *
         * @param   string  generic utf16 surrogates pair, i.e. uD83DuDCA9
         * @param   string  optional separator for double code points, default='-'
         * @return  string  utf16 transformed into codepoint, i.e. '1F4A9'
         *
         * @example
         *  twemoji.convert.toCodePoint('ud83cudde8ud83cuddf3');
         *  // "1f1e8-1f1f3"
         *
         *  twemoji.convert.toCodePoint('ud83cudde8ud83cuddf3', '~');
         *  // "1f1e8~1f1f3"
         */
        
toCodePointtoCodePoint
      
},


    
/////////////////////////
    //       methods       //
    /////////////////////////

      /**
       * User first: used to remove missing images
       * preserving the original text intent when
       * a fallback for network problems is desired.
       * Automatically added to Image nodes via DOM
       * It could be recycled for string operations via:
       *  $('img.emoji').on('error', twemoji.onerror)
       */
      
onerror: function onerror() {
        if (
this.parentNode) {
          
this.parentNode.replaceChild(createText(this.alt), this);
        }
      },

      
/**
       * Main method/logic to generate either <img> tags or HTMLImage nodes.
       *  "emojify" a generic text or DOM Element.
       *
       * @overloads
       *
       * String replacement for `innerHTML` or server side operations
       *  twemoji.parse(string);
       *  twemoji.parse(string, Function);
       *  twemoji.parse(string, Object);
       *
       * HTMLElement tree parsing for safer operations over existing DOM
       *  twemoji.parse(HTMLElement);
       *  twemoji.parse(HTMLElement, Function);
       *  twemoji.parse(HTMLElement, Object);
       *
       * @param   string|HTMLElement  the source to parse and enrich with emoji.
       *
       *          string              replace emoji matches with <img> tags.
       *                              Mainly used to inject emoji via `innerHTML`
       *                              It does **not** parse the string or validate it,
       *                              it simply replaces found emoji with a tag.
       *                              NOTE: be sure this won't affect security.
       *
       *          HTMLElement         walk through the DOM tree and find emoji
       *                              that are inside **text node only** (nodeType === 3)
       *                              Mainly used to put emoji in already generated DOM
       *                              without compromising surrounding nodes and
       *                              **avoiding** the usage of `innerHTML`.
       *                              NOTE: Using DOM elements instead of strings should
       *                              improve security without compromising too much
       *                              performance compared with a less safe `innerHTML`.
       *
       * @param   Function|Object  [optional]
       *                              either the callback that will be invoked or an object
       *                              with all properties to use per each found emoji.
       *
       *          Function            if specified, this will be invoked per each emoji
       *                              that has been found through the RegExp except
       *                              those follwed by the invariant uFE0E ("as text").
       *                              Once invoked, parameters will be:
       *
       *                                codePoint:string  the lower case HEX code point
       *                                                  i.e. "1f4a9"
       *
       *                                options:Object    all info for this parsing operation
       *
       *                                variant:char      the optional uFE0F ("as image")
       *                                                  variant, in case this info
       *                                                  is anyhow meaningful.
       *                                                  By default this is ignored.
       *
       *                              If such callback will return a falsy value instead
       *                              of a valid `src` to use for the image, nothing will
       *                              actually change for that specific emoji.
       *
       *
       *          Object              if specified, an object containing the following properties
       *
       *            callback   Function  the callback to invoke per each found emoji.
       *            base       string    the base url, by default twemoji.base
       *            ext        string    the image extension, by default twemoji.ext
       *            size       string    the assets size, by default twemoji.size
       *
       * @example
       *
       *  twemoji.parse("I u2764uFE0F emoji!");
       *  // I <img class="emoji" draggable="false" alt="❤️" src="/assets/2764.gif"> emoji!
       *
       *
       *  twemoji.parse("I u2764uFE0F emoji!", function(icon, options, variant) {
       *    return '/assets/' + icon + '.gif';
       *  });
       *  // I <img class="emoji" draggable="false" alt="❤️" src="/assets/2764.gif"> emoji!
       *
       *
       * twemoji.parse("I u2764uFE0F emoji!", {
       *   size: 72,
       *   callback: function(icon, options, variant) {
       *     return '/assets/' + options.size + '/' + icon + options.ext;
       *   }
       * });
       *  // I <img class="emoji" draggable="false" alt="❤️" src="/assets/72x72/2764.png"> emoji!
       *
       */
      
parseparse,

      
/**
       * Given a string, invokes the callback argument
       *  per each emoji found in such string.
       * This is the most raw version used by
       *  the .parse(string) method itself.
       *
       * @param   string    generic string to parse
       * @param   Function  a generic callback that will be
       *                    invoked to replace the content.
       *                    This calback wil receive standard
       *                    String.prototype.replace(str, callback)
       *                    arguments such:
       *  callback(
       *    match,  // the emoji match
       *    icon,   // the emoji text (same as text)
       *    variant // either 'uFE0E' or 'uFE0F', if present
       *  );
       *
       *                    and others commonly received via replace.
       *
       *  NOTE: When the variant uFE0E is found, remember this is an explicit intent
       *  from the user: the emoji should **not** be replaced with an image.
       *  In uFE0F case one, it's the opposite, it should be graphic.
       *  This utility convetion is that only uFE0E are not translated into images.
       */
      
replacereplace,

      
/**
       * Simplify string tests against emoji.
       *
       * @param   string  some text that might contain emoji
       * @return  boolean true if any emoji was found, false otherwise.
       *
       * @example
       *
       *  if (twemoji.test(someContent)) {
       *    console.log("emoji All The Things!");
       *  }
       */
      
testtest
    
},

    
// RegExp based on emoji's official Unicode standards
    // http://www.unicode.org/Public/UNIDATA/EmojiSources.txt
    
re = /((?:ud83cudde8ud83cuddf3|ud83cuddfaud83cuddf8|ud83cuddf7ud83cuddfa|ud83cuddf0ud83cuddf7|ud83cuddefud83cuddf5|ud83cuddeeud83cuddf9|ud83cuddecud83cudde7|ud83cuddebud83cuddf7|ud83cuddeaud83cuddf8|ud83cudde9ud83cuddea|u0039ufe0f?u20e3|u0038ufe0f?u20e3|u0037ufe0f?u20e3|u0036ufe0f?u20e3|u0035ufe0f?u20e3|u0034ufe0f?u20e3|u0033ufe0f?u20e3|u0032ufe0f?u20e3|u0031ufe0f?u20e3|u0030ufe0f?u20e3|u0023ufe0f?u20e3|ud83dudeb3|ud83dudeb1|ud83dudeb0|ud83dudeaf|ud83dudeae|ud83dudea6|ud83dudea3|ud83dudea1|ud83dudea0|ud83dude9f|ud83dude9e|ud83dude9d|ud83dude9c|ud83dude9b|ud83dude98|ud83dude96|ud83dude94|ud83dude90|ud83dude8e|ud83dude8d|ud83dude8b|ud83dude8a|ud83dude88|ud83dude86|ud83dude82|ud83dude81|ud83dude36|ud83dude34|ud83dude2f|ud83dude2e|ud83dude2c|ud83dude27|ud83dude26|ud83dude1f|ud83dude1b|ud83dude19|ud83dude17|ud83dude15|ud83dude11|ud83dude10|ud83dude0e|ud83dude08|ud83dude07|ud83dude00|ud83dudd67|ud83dudd66|ud83dudd65|ud83dudd64|ud83dudd63|ud83dudd62|ud83dudd61|ud83dudd60|ud83dudd5f|ud83dudd5e|ud83dudd5d|ud83dudd5c|ud83dudd2d|ud83dudd2c|ud83dudd15|ud83dudd09|ud83dudd08|ud83dudd07|ud83dudd06|ud83dudd05|ud83dudd04|ud83dudd02|ud83dudd01|ud83dudd00|ud83dudcf5|ud83dudcef|ud83dudced|ud83dudcec|ud83dudcb7|ud83dudcb6|ud83dudcad|ud83dudc6d|ud83dudc6c|ud83dudc65|ud83dudc2a|ud83dudc16|ud83dudc15|ud83dudc13|ud83dudc10|ud83dudc0f|ud83dudc0b|ud83dudc0a|ud83dudc09|ud83dudc08|ud83dudc07|ud83dudc06|ud83dudc05|ud83dudc04|ud83dudc03|ud83dudc02|ud83dudc01|ud83dudc00|ud83cudfe4|ud83cudfc9|ud83cudfc7|ud83cudf7c|ud83cudf50|ud83cudf4b|ud83cudf33|ud83cudf32|ud83cudf1e|ud83cudf1d|ud83cudf1c|ud83cudf1a|ud83cudf18|ud83cudccf|ud83cudd70|ud83cudd71|ud83cudd7e|ud83cudd8e|ud83cudd91|ud83cudd92|ud83cudd93|ud83cudd94|ud83cudd95|ud83cudd96|ud83cudd97|ud83cudd98|ud83cudd99|ud83cudd9a|ud83dudc77|ud83dudec5|ud83dudec4|ud83dudec3|ud83dudec2|ud83dudec1|ud83dudebf|ud83dudeb8|ud83dudeb7|ud83dudeb5|ud83cude01|ud83cude02|ud83cude32|ud83cude33|ud83cude34|ud83cude35|ud83cude36|ud83cude37|ud83cude38|ud83cude39|ud83cude3a|ud83cude50|ud83cude51|ud83cudf00|ud83cudf01|ud83cudf02|ud83cudf03|ud83cudf04|ud83cudf05|ud83cudf06|ud83cudf07|ud83cudf08|ud83cudf09|ud83cudf0a|ud83cudf0b|ud83cudf0c|ud83cudf0f|ud83cudf11|ud83cudf13|ud83cudf14|ud83cudf15|ud83cudf19|ud83cudf1b|ud83cudf1f|ud83cudf20|ud83cudf30|ud83cudf31|ud83cudf34|ud83cudf35|ud83cudf37|ud83cudf38|ud83cudf39|ud83cudf3a|ud83cudf3b|ud83cudf3c|ud83cudf3d|ud83cudf3e|ud83cudf3f|ud83cudf40|ud83cudf41|ud83cudf42|ud83cudf43|ud83cudf44|ud83cudf45|ud83cudf46|ud83cudf47|ud83cudf48|ud83cudf49|ud83cudf4a|ud83cudf4c|ud83cudf4d|ud83cudf4e|ud83cudf4f|ud83cudf51|ud83cudf52|ud83cudf53|ud83cudf54|ud83cudf55|ud83cudf56|ud83cudf57|ud83cudf58|ud83cudf59|ud83cudf5a|ud83cudf5b|ud83cudf5c|ud83cudf5d|ud83cudf5e|ud83cudf5f|ud83cudf60|ud83cudf61|ud83cudf62|ud83cudf63|ud83cudf64|ud83cudf65|ud83cudf66|ud83cudf67|ud83cudf68|ud83cudf69|ud83cudf6a|ud83cudf6b|ud83cudf6c|ud83cudf6d|ud83cudf6e|ud83cudf6f|ud83cudf70|ud83cudf71|ud83cudf72|ud83cudf73|ud83cudf74|ud83cudf75|ud83cudf76|ud83cudf77|ud83cudf78|ud83cudf79|ud83cudf7a|ud83cudf7b|ud83cudf80|ud83cudf81|ud83cudf82|ud83cudf83|ud83cudf84|ud83cudf85|ud83cudf86|ud83cudf87|ud83cudf88|ud83cudf89|ud83cudf8a|ud83cudf8b|ud83cudf8c|ud83cudf8d|ud83cudf8e|ud83cudf8f|ud83cudf90|ud83cudf91|ud83cudf92|ud83cudf93|ud83cudfa0|ud83cudfa1|ud83cudfa2|ud83cudfa3|ud83cudfa4|ud83cudfa5|ud83cudfa6|ud83cudfa7|ud83cudfa8|ud83cudfa9|ud83cudfaa|ud83cudfab|ud83cudfac|ud83cudfad|ud83cudfae|ud83cudfaf|ud83cudfb0|ud83cudfb1|ud83cudfb2|ud83cudfb3|ud83cudfb4|ud83cudfb5|ud83cudfb6|ud83cudfb7|ud83cudfb8|ud83cudfb9|ud83cudfba|ud83cudfbb|ud83cudfbc|ud83cudfbd|ud83cudfbe|ud83cudfbf|ud83cudfc0|ud83cudfc1|ud83cudfc2|ud83cudfc3|ud83cudfc4|ud83cudfc6|ud83cudfc8|ud83cudfca|ud83cudfe0|ud83cudfe1|ud83cudfe2|ud83cudfe3|ud83cudfe5|ud83cudfe6|ud83cudfe7|ud83cudfe8|ud83cudfe9|ud83cudfea|ud83cudfeb|ud83cudfec|ud83cudfed|ud83cudfee|ud83cudfef|ud83cudff0|ud83dudc0c|ud83dudc0d|ud83dudc0e|ud83dudc11|ud83dudc12|ud83dudc14|ud83dudc17|ud83dudc18|ud83dudc19|ud83dudc1a|ud83dudc1b|ud83dudc1c|ud83dudc1d|ud83dudc1e|ud83dudc1f|ud83dudc20|ud83dudc21|ud83dudc22|ud83dudc23|ud83dudc24|ud83dudc25|ud83dudc26|ud83dudc27|ud83dudc28|ud83dudc29|ud83dudc2b|ud83dudc2c|ud83dudc2d|ud83dudc2e|ud83dudc2f|ud83dudc30|ud83dudc31|ud83dudc32|ud83dudc33|ud83dudc34|ud83dudc35|ud83dudc36|ud83dudc37|ud83dudc38|ud83dudc39|ud83dudc3a|ud83dudc3b|ud83dudc3c|ud83dudc3d|ud83dudc3e|ud83dudc40|ud83dudc42|ud83dudc43|ud83dudc44|ud83dudc45|ud83dudc46|ud83dudc47|ud83dudc48|ud83dudc49|ud83dudc4a|ud83dudc4b|ud83dudc4c|ud83dudc4d|ud83dudc4e|ud83dudc4f|ud83dudc50|ud83dudc51|ud83dudc52|ud83dudc53|ud83dudc54|ud83dudc55|ud83dudc56|ud83dudc57|ud83dudc58|ud83dudc59|ud83dudc5a|ud83dudc5b|ud83dudc5c|ud83dudc5d|ud83dudc5e|ud83dudc5f|ud83dudc60|ud83dudc61|ud83dudc62|ud83dudc63|ud83dudc64|ud83dudc66|ud83dudc67|ud83dudc68|ud83dudc69|ud83dudc6a|ud83dudc6b|ud83dudc6e|ud83dudc6f|ud83dudc70|ud83dudc71|ud83dudc72|ud83dudc73|ud83dudc74|ud83dudc75|ud83dudc76|ud83dudeb4|ud83dudc78|ud83dudc79|ud83dudc7a|ud83dudc7b|ud83dudc7c|ud83dudc7d|ud83dudc7e|ud83dudc7f|ud83dudc80|ud83dudc81|ud83dudc82|ud83dudc83|ud83dudc84|ud83dudc85|ud83dudc86|ud83dudc87|ud83dudc88|ud83dudc89|ud83dudc8a|ud83dudc8b|ud83dudc8c|ud83dudc8d|ud83dudc8e|ud83dudc8f|ud83dudc90|ud83dudc91|ud83dudc92|ud83dudc93|ud83dudc94|ud83dudc95|ud83dudc96|ud83dudc97|ud83dudc98|ud83dudc99|ud83dudc9a|ud83dudc9b|ud83dudc9c|ud83dudc9d|ud83dudc9e|ud83dudc9f|ud83dudca0|ud83dudca1|ud83dudca2|ud83dudca3|ud83dudca4|ud83dudca5|ud83dudca6|ud83dudca7|ud83dudca8|ud83dudca9|ud83dudcaa|ud83dudcab|ud83dudcac|ud83dudcae|ud83dudcaf|ud83dudcb0|ud83dudcb1|ud83dudcb2|ud83dudcb3|ud83dudcb4|ud83dudcb5|ud83dudcb8|ud83dudcb9|ud83dudcba|ud83dudcbb|ud83dudcbc|ud83dudcbd|ud83dudcbe|ud83dudcbf|ud83dudcc0|ud83dudcc1|ud83dudcc2|ud83dudcc3|ud83dudcc4|ud83dudcc5|ud83dudcc6|ud83dudcc7|ud83dudcc8|ud83dudcc9|ud83dudcca|ud83dudccb|ud83dudccc|ud83dudccd|ud83dudcce|ud83dudccf|ud83dudcd0|ud83dudcd1|ud83dudcd2|ud83dudcd3|ud83dudcd4|ud83dudcd5|ud83dudcd6|ud83dudcd7|ud83dudcd8|ud83dudcd9|ud83dudcda|ud83dudcdb|ud83dudcdc|ud83dudcdd|ud83dudcde|ud83dudcdf|ud83dudce0|ud83dudce1|ud83dudce2|ud83dudce3|ud83dudce4|ud83dudce5|ud83dudce6|ud83dudce7|ud83dudce8|ud83dudce9|ud83dudcea|ud83dudceb|ud83dudcee|ud83dudcf0|ud83dudcf1|ud83dudcf2|ud83dudcf3|ud83dudcf4|ud83dudcf6|ud83dudcf7|ud83dudcf9|ud83dudcfa|ud83dudcfb|ud83dudcfc|ud83dudd03|ud83dudd0a|ud83dudd0b|ud83dudd0c|ud83dudd0d|ud83dudd0e|ud83dudd0f|ud83dudd10|ud83dudd11|ud83dudd12|ud83dudd13|ud83dudd14|ud83dudd16|ud83dudd17|ud83dudd18|ud83dudd19|ud83dudd1a|ud83dudd1b|ud83dudd1c|ud83dudd1d|ud83dudd1e|ud83dudd1f|ud83dudd20|ud83dudd21|ud83dudd22|ud83dudd23|ud83dudd24|ud83dudd25|ud83dudd26|ud83dudd27|ud83dudd28|ud83dudd29|ud83dudd2a|ud83dudd2b|ud83dudd2e|ud83dudd2f|ud83dudd30|ud83dudd31|ud83dudd32|ud83dudd33|ud83dudd34|ud83dudd35|ud83dudd36|ud83dudd37|ud83dudd38|ud83dudd39|ud83dudd3a|ud83dudd3b|ud83dudd3c|ud83dudd3d|ud83dudd50|ud83dudd51|ud83dudd52|ud83dudd53|ud83dudd54|ud83dudd55|ud83dudd56|ud83dudd57|ud83dudd58|ud83dudd59|ud83dudd5a|ud83dudd5b|ud83duddfb|ud83duddfc|ud83duddfd|ud83duddfe|ud83duddff|ud83dude01|ud83dude02|ud83dude03|ud83dude04|ud83dude05|ud83dude06|ud83dude09|ud83dude0a|ud83dude0b|ud83dude0c|ud83dude0d|ud83dude0f|ud83dude12|ud83dude13|ud83dude14|ud83dude16|ud83dude18|ud83dude1a|ud83dude1c|ud83dude1d|ud83dude1e|ud83dude20|ud83dude21|ud83dude22|ud83dude23|ud83dude24|ud83dude25|ud83dude28|ud83dude29|ud83dude2a|ud83dude2b|ud83dude2d|ud83dude30|ud83dude31|ud83dude32|ud83dude33|ud83dude35|ud83dude37|ud83dude38|ud83dude39|ud83dude3a|ud83dude3b|ud83dude3c|ud83dude3d|ud83dude3e|ud83dude3f|ud83dude40|ud83dude45|ud83dude46|ud83dude47|ud83dude48|ud83dude49|ud83dude4a|ud83dude4b|ud83dude4c|ud83dude4d|ud83dude4e|ud83dude4f|ud83dude80|ud83dude83|ud83dude84|ud83dude85|ud83dude87|ud83dude89|ud83dude8c|ud83dude8f|ud83dude91|ud83dude92|ud83dude93|ud83dude95|ud83dude97|ud83dude99|ud83dude9a|ud83dudea2|ud83dudea4|ud83dudea5|ud83dudea7|ud83dudea8|ud83dudea9|ud83dudeaa|ud83dudeab|ud83dudeac|ud83dudead|ud83dudeb2|ud83dudeb6|ud83dudeb9|ud83dudeba|ud83dudebb|ud83dudebc|ud83dudebd|ud83dudebe|ud83dudec0|ud83cudde6|ud83cudde7|ud83cudde8|ud83cudde9|ud83cuddea|ud83cuddeb|ud83cuddec|ud83cudded|ud83cuddee|ud83cuddef|ud83cuddf0|ud83cuddf1|ud83cuddf2|ud83cuddf3|ud83cuddf4|ud83cuddf5|ud83cuddf6|ud83cuddf7|ud83cuddf8|ud83cuddf9|ud83cuddfa|ud83cuddfb|ud83cuddfc|ud83cuddfd|ud83cuddfe|ud83cuddff|ud83cudf0d|ud83cudf0e|ud83cudf10|ud83cudf12|ud83cudf16|ud83cudf17|ue50a|u3030|u27b0|u2797|u2796|u2795|u2755|u2754|u2753|u274e|u274c|u2728|u270b|u270a|u2705|u26ce|u23f3|u23f0|u23ec|u23eb|u23ea|u23e9|u2122|u27bf|u00a9|u00ae)|(?:(?:ud83cudc04|ud83cudd7f|ud83cude1a|ud83cude2f|u3299|u303d|u2b55|u2b50|u2b1c|u2b1b|u2b07|u2b06|u2b05|u2935|u2934|u27a1|u2764|u2757|u2747|u2744|u2734|u2733|u2716|u2714|u2712|u270f|u270c|u2709|u2708|u2702|u26fd|u26fa|u26f5|u26f3|u26f2|u26ea|u26d4|u26c5|u26c4|u26be|u26bd|u26ab|u26aa|u26a1|u26a0|u2693|u267f|u267b|u3297|u2666|u2665|u2663|u2660|u2653|u2652|u2651|u2650|u264f|u264e|u264d|u264c|u264b|u264a|u2649|u2648|u263a|u261d|u2615|u2614|u2611|u260e|u2601|u2600|u25fe|u25fd|u25fc|u25fb|u25c0|u25b6|u25ab|u25aa|u24c2|u231b|u231a|u21aa|u21a9|u2199|u2198|u2197|u2196|u2195|u2194|u2139|u2049|u203c|u2668)([uFE0EuFE0F]?)))/g,

    
// nodes with type 1 which should **not** be parsed
    
shouldntBeParsed = /IFRAME|NOFRAMES|NOSCRIPT|SCRIPT|SELECT|STYLE|TEXTAREA/,

    
// just a private shortcut
    
fromCharCode String.fromCharCode;

  return 
twemoji;


  
/////////////////////////
  //  private functions  //
  //     declaration     //
  /////////////////////////

  /**
   * Shortcut to create text nodes
   * @param   string  text used to create DOM text node
   * @return  Node  a DOM node with that text
   */
  
function createText(text) {
    return 
document.createTextNode(text);
  }

  
/**
   * Default callback used to generate emoji src
   *  based on Twitter CDN
   * @param   string    the emoji codepoint string
   * @param   string    the default size to use, i.e. "36x36"
   * @param   string    optional "uFE0F" variant char, ignored by default
   * @return  string    the image source to use
   */
  
function defaultImageSrcGenerator(iconoptions) {
    return 
''.concat(options.baseoptions.size'/'iconoptions.ext);
  }

  
/**
   * Given a generic DOM nodeType 1, walk through all children
   * and store every nodeType 3 (#text) found in the tree.
   * @param   Element a DOM Element with probably some text in it
   * @param   Array the list of previously discovered text nodes
   * @return  Array same list with new discovered nodes, if any
   */
  
function grabAllTextNodes(nodeallText) {
    var
      
childNodes node.childNodes,
      
length childNodes.length,
      
subnode,
      
nodeType;
    while (
length--) {
      
subnode childNodes[length];
      
nodeType subnode.nodeType;
      
// parse emoji only in text nodes
      
if (nodeType === 3) {
        
// collect them to process emoji later
        
allText.push(subnode);
      }
      
// ignore all nodes that are not type 1 or that
      // should not be parsed as script, style, and others
      
else if (nodeType === && !shouldntBeParsed.test(subnode.nodeName)) {
        
grabAllTextNodes(subnodeallText);
      }
    }
    return 
allText;
  }

  
/**
   * Used to both remove the possible variant
   *  and to convert utf16 into code points
   * @param   string    the emoji surrogate pair
   * @param   string    the optional variant char, if any
   */
  
function grabTheRightIcon(iconvariant) {
    
// if variant is present as uFE0F
    
return toCodePoint(
      
variant === 'uFE0F' ?
        
// the icon should not contain it
        
icon.slice(0, -1) :
        
// fix non standard OSX behavior
        
(icon.length === && icon.charAt(1) === 'uFE0F' ?
          
icon.charAt(0) + icon.charAt(2) : icon)
    );
  }

  
/**
   * DOM version of the same logic / parser:
   *  emojify all found sub-text nodes placing images node instead.
   * @param   Element   generic DOM node with some text in some child node
   * @param   Object    options  containing info about how to parse
    *
    *            .callback   Function  the callback to invoke per each found emoji.
    *            .base       string    the base url, by default twemoji.base
    *            .ext        string    the image extension, by default twemoji.ext
    *            .size       string    the assets size, by default twemoji.size
    *
   * @return  Element same generic node with emoji in place, if any.
   */
  
function parseNode(nodeoptions) {
    var
      
allText grabAllTextNodes(node, []),
      
length allText.length,
      
modified,
      
fragment,
      
subnode,
      
text,
      
match,
      
i,
      
index,
      
img,
      
alt,
      
icon,
      
variant,
      
src,
      
attr;
    while (
length--) {
      
modified false;
      
fragment document.createDocumentFragment();
      
subnode allText[length];
      
text subnode.nodeValue;
      
0;
      while ((
match re.exec(text))) {
        
index match.index;
        if (
index !== i) {
          
fragment.appendChild(
            
createText(text.slice(iindex))
          );
        }
        
alt match[0];
        
icon match[1];
        
variant match[2];
        
index alt.length;
        if (
variant !== 'uFE0E') {
          
src options.callback(
            
grabTheRightIcon(iconvariant),
            
options,
            
variant
          
);
          if (
src) {
            
img = new Image();

            
// Set additional image attributes.
            
if ( options.imgAttr ) {
              for ( 
attr in options.imgAttr ) {
                
img.setAttributeattroptions.imgAttr[attr] );
              }
            }

            
img.onerror twemoji.onerror;
            
img.className options.className;
            
img.setAttribute('draggable''false');
            
img.alt alt;
            
img.src src;
            
modified true;
            
fragment.appendChild(img);
          }
        }
        if (!
imgfragment.appendChild(createText(alt));
        
img null;
      }
      
// is there actually anything to replace in here ?
      
if (modified) {
        
// any text left to be added ?
        
if (text.length) {
          
fragment.appendChild(
            
createText(text.slice(i))
          );
        }
        
// replace the text node only, leave intact
        // anything else surrounding such text
        
subnode.parentNode.replaceChild(fragmentsubnode);
      }
    }
    return 
node;
  }

  
/**
   * String/HTML version of the same logic / parser:
   *  emojify a generic text placing images tags instead of surrogates pair.
   * @param   string    generic string with possibly some emoji in it
   * @param   Object    options  containing info about how to parse
   *
   *            .callback   Function  the callback to invoke per each found emoji.
   *            .base       string    the base url, by default twemoji.base
   *            .ext        string    the image extension, by default twemoji.ext
   *            .size       string    the assets size, by default twemoji.size
   *
   * @return  the string with <img tags> replacing all found and parsed emoji
   */
  
function parseString(stroptions) {
    return 
replace(str, function (matchiconvariant) {
      var 
srcattrattributes '';
      
// verify the variant is not the FE0E one
      // this variant means "emoji as text" and should not
      // require any action/replacement
      // http://unicode.org/Public/UNIDATA/StandardizedVariants.html
      
if (variant !== 'uFE0E') {
        
src options.callback(
          
grabTheRightIcon(iconvariant),
          
options,
          
variant
        
);
        if (
src) {
          
// Set additional image attributes.
          
if ( options.imgAttr ) {
            for ( 
attr in options.imgAttr ) {
              if ( ! /
draggable|class|alt|src/i.testattr ) ) {
                
attributes += ' '.concatattr'="'options.imgAttr[attr], '"' );
              }
            }
          }

          
// recycle the match string replacing the emoji
          // with its image counter part
          
match '<img '.concat(
            
'class="'options.className'" ',
            
'draggable="false" ',
            
// needs to preserve user original intent
            // when variants should be copied and pasted too
            
'alt="',
            
match,
            
'" ',
            
'src="',
            
src,
            
'"',
            
attributes,
            
'>'
          
);
        }
      }
      return 
match;
    });
  }

  
/**
   * Given a generic value, creates its squared counterpart if it's a number.
   *  As example, number 36 will return '36x36'.
   * @param   any     a generic value.
   * @return  any     a string representing asset size, i.e. "36x36"
   *                  only in case the value was a number.
   *                  Returns initial value otherwise.
   */
  
function toSizeSquaredAsset(value) {
    return 
typeof value === 'number' ?
      
value 'x' value :
      
value;
  }


  
/////////////////////////
  //  exported functions //
  //     declaration     //
  /////////////////////////

  
function fromCodePoint(codepoint) {
    var 
code typeof codepoint === 'string' ?
          
parseInt(codepoint16) : codepoint;
    if (
code 0x10000) {
      return 
fromCharCode(code);
    }
    
code -= 0x10000;
    return 
fromCharCode(
      
0xD800 + (code >> 10),
      
0xDC00 + (code 0x3FF)
    );
  }

  function 
parse(whathow) {
    if (!
how || typeof how === 'function') {
      
how = {callbackhow};
    }
    
// if first argument is string, inject html <img> tags
    // otherwise use the DOM tree and parse text nodes only
    
return (typeof what === 'string' parseString parseNode)(what, {
      
callbackhow.callback || defaultImageSrcGenerator,
      
base:     typeof how.base === 'string' how.base twemoji.base,
      
ext:      how.ext || twemoji.ext,
      
size:     how.folder || toSizeSquaredAsset(how.size || twemoji.size),
      
className:how.className || twemoji.className,
      
imgAttr:  how.imgAttr
    
});
  }

  function 
replace(textcallback) {
    return 
String(text).replace(recallback);
  }

  function 
test(text) {
    
// IE6 needs a reset before too
    
re.lastIndex 0;
    var 
result re.test(text);
    
re.lastIndex 0;
    return 
result;
  }

  function 
toCodePoint(unicodeSurrogatessep) {
    var
      
= [],
      
0,
      
0,
      
0;
    while (
unicodeSurrogates.length) {
      
unicodeSurrogates.charCodeAt(i++);
      if (
p) {
        
r.push((0x10000 + ((0xD800) << 10) + (0xDC00)).toString(16));
        
0;
      } else if (
0xD800 <= && <= 0xDBFF) {
        
c;
      } else {
        
r.push(c.toString(16));
      }
    }
    return 
r.join(sep || '-');
  }

}());
?>
Онлайн: 2
Реклама