mirror of
https://github.com/twitter/twemoji.git
synced 2024-11-16 11:18:37 +00:00
made consistent with already used style
This commit is contained in:
parent
226e5ac6d5
commit
ca1c298ddd
@ -500,10 +500,22 @@ function createTwemoji(re) {
|
||||
test: test
|
||||
},
|
||||
|
||||
// used to escape HTML special chars in attributes
|
||||
escaper = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
"'": ''',
|
||||
'"': '"'
|
||||
},
|
||||
|
||||
// RegExp based on emoji's official Unicode standards
|
||||
// http://www.unicode.org/Public/UNIDATA/EmojiSources.txt
|
||||
re = /twemoji/,
|
||||
|
||||
// used to find HTML special chars in attributes
|
||||
rescaper = /[&<>'"]/g,
|
||||
|
||||
// nodes with type 1 which should **not** be parsed
|
||||
shouldntBeParsed = /IFRAME|NOFRAMES|NOSCRIPT|SCRIPT|SELECT|STYLE|TEXTAREA/,
|
||||
|
||||
@ -533,16 +545,7 @@ function createTwemoji(re) {
|
||||
* @return string text encoded to use in HTML attribute
|
||||
*/
|
||||
function escapeHTML(s) {
|
||||
var escaped = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
"'": ''',
|
||||
'"': '"'
|
||||
};
|
||||
return s.replace(/[&<>'"]/g, function (m) {
|
||||
return escaped[m];
|
||||
});
|
||||
return s.replace(rescaper, replacer);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -622,6 +625,8 @@ function createTwemoji(re) {
|
||||
var
|
||||
allText = grabAllTextNodes(node, []),
|
||||
length = allText.length,
|
||||
attrib,
|
||||
attrname,
|
||||
modified,
|
||||
fragment,
|
||||
subnode,
|
||||
@ -661,19 +666,17 @@ function createTwemoji(re) {
|
||||
img = new Image();
|
||||
img.onerror = twemoji.onerror;
|
||||
img.setAttribute('draggable', 'false');
|
||||
|
||||
var attrib = options.attributes(icon, variant);
|
||||
if (attrib) {
|
||||
for (var attrname in attrib) {
|
||||
if (attrib.hasOwnProperty(attrname)) {
|
||||
// don't allow any handlers to be set, don't allow overrides
|
||||
if (attrname.indexOf('on') !== 0 && !img.hasAttribute(attrname)) {
|
||||
img.setAttribute(attrname, attrib[attrname]);
|
||||
}
|
||||
}
|
||||
attrib = options.attributes(icon, variant);
|
||||
for (attrname in attrib) {
|
||||
if (
|
||||
attrib.hasOwnProperty(attrname) &&
|
||||
// don't allow any handlers to be set + don't allow overrides
|
||||
attrname.indexOf('on') !== 0 &&
|
||||
!img.hasAttribute(attrname)
|
||||
) {
|
||||
img.setAttribute(attrname, attrib[attrname]);
|
||||
}
|
||||
}
|
||||
|
||||
img.className = options.className;
|
||||
img.alt = alt;
|
||||
img.src = src;
|
||||
@ -715,8 +718,11 @@ function createTwemoji(re) {
|
||||
*/
|
||||
function parseString(str, options) {
|
||||
return replace(str, function (match, icon, variant) {
|
||||
var src;
|
||||
var ret = match;
|
||||
var
|
||||
ret = match,
|
||||
attrib,
|
||||
attrname,
|
||||
src;
|
||||
// verify the variant is not the FE0E one
|
||||
// this variant means "emoji as text" and should not
|
||||
// require any action/replacement
|
||||
@ -742,18 +748,17 @@ function createTwemoji(re) {
|
||||
src,
|
||||
'"'
|
||||
);
|
||||
var attrib = options.attributes(icon, variant);
|
||||
if (attrib) {
|
||||
for (var attrname in attrib) {
|
||||
if (attrib.hasOwnProperty(attrname)) {
|
||||
// don't allow any handlers to be set, don't allow overrides
|
||||
if (attrname.indexOf('on') !== 0 && ret.indexOf(' ' + attrname + '=') === -1) {
|
||||
ret = ret.concat(' ', attrname, '="', escapeHTML(attrib[attrname]), '"');
|
||||
}
|
||||
}
|
||||
attrib = options.attributes(icon, variant);
|
||||
for (attrname in attrib) {
|
||||
if (
|
||||
attrib.hasOwnProperty(attrname) &&
|
||||
// don't allow any handlers to be set + don't allow overrides
|
||||
attrname.indexOf('on') !== 0 &&
|
||||
ret.indexOf(' ' + attrname + '=') === -1
|
||||
) {
|
||||
ret = ret.concat(' ', attrname, '="', escapeHTML(attrib[attrname]), '"');
|
||||
}
|
||||
}
|
||||
|
||||
ret = ret.concat('>');
|
||||
}
|
||||
}
|
||||
@ -761,6 +766,23 @@ function createTwemoji(re) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Function used to actually replace HTML special chars
|
||||
* @param string HTML special char
|
||||
* @return string encoded HTML special char
|
||||
*/
|
||||
function replacer(m) {
|
||||
return escaper[m];
|
||||
}
|
||||
|
||||
/**
|
||||
* Default options.attribute callback
|
||||
* @return null
|
||||
*/
|
||||
function returnNull() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a generic value, creates its squared counterpart if it's a number.
|
||||
* As example, number 36 will return '36x36'.
|
||||
@ -802,7 +824,7 @@ function createTwemoji(re) {
|
||||
// otherwise use the DOM tree and parse text nodes only
|
||||
return (typeof what === 'string' ? parseString : parseNode)(what, {
|
||||
callback: how.callback || defaultImageSrcGenerator,
|
||||
attributes: typeof how.attributes === 'function' ? how.attributes : function() {return {};},
|
||||
attributes: typeof how.attributes === 'function' ? how.attributes : returnNull,
|
||||
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
||||
ext: how.ext || twemoji.ext,
|
||||
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),
|
||||
|
File diff suppressed because one or more lines are too long
90
twemoji.js
90
twemoji.js
File diff suppressed because one or more lines are too long
2
twemoji.min.js
vendored
2
twemoji.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user