mirror of
https://github.com/twitter/twemoji.git
synced 2025-01-27 06:35:16 +00:00
added className
object property
This commit is contained in:
parent
a8ad0e4e07
commit
0450e3e5e3
13
README.md
13
README.md
@ -133,9 +133,9 @@ var img = div.querySelector('img');
|
||||
// note the div is preserved
|
||||
img.parentNode === div; // true
|
||||
|
||||
img.src; // https://abs.twimg.com/emoji/v1/36x36/2764.png
|
||||
img.src; // https://twemoji.maxcdn.com/36x36/2764.png
|
||||
img.alt; // \u2764\uFE0F
|
||||
img.class; // emoji
|
||||
img.className; // emoji
|
||||
img.draggable; // false
|
||||
|
||||
```
|
||||
@ -147,10 +147,11 @@ Here the list of properties accepted by the optional object that could be passed
|
||||
|
||||
```js
|
||||
{
|
||||
callback: Function,
|
||||
base: string,
|
||||
ext: string,
|
||||
size: string|number
|
||||
callback: Function, // default the common replacer
|
||||
base: string, // default MaxCDN
|
||||
ext: string, // default ".png"
|
||||
size: string|number, // default "36x36"
|
||||
className: string // default "emoji"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"name": "twemoji",
|
||||
"license": ["MIT", "CC-BY-4.0"],
|
||||
"description": "A Unicode standard based way to implement emoji across all platforms.",
|
||||
|
30
test.js
30
test.js
@ -279,4 +279,34 @@ wru.test([{
|
||||
wru.assert('third child is the expected one', div.childNodes[2].nodeValue === text);
|
||||
wru.assert('html unaltered', div.innerHTML.replace(/<img[^>]+?>/i, '') === html);
|
||||
}
|
||||
},{
|
||||
name: 'string parsing + className',
|
||||
test: function () {
|
||||
var className = 'img-' + Math.random();
|
||||
var img = 'I <img class="' + className + '" draggable="false" alt="\u2764" src="36x36/2764.png"> emoji!';
|
||||
wru.assert(
|
||||
'className is overwritten',
|
||||
img ===
|
||||
twemoji.parse(
|
||||
'I \u2764 emoji!',
|
||||
{
|
||||
className: className,
|
||||
base: ''
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
},{
|
||||
name: 'DOM parsing + className',
|
||||
test: function () {
|
||||
var className = 'img-' + Math.random();
|
||||
var img,
|
||||
div = document.createElement('div');
|
||||
div.appendChild(document.createTextNode('I \u2764 emoji!'));
|
||||
twemoji.parse(div, {className: className});
|
||||
wru.assert(
|
||||
'className is overwritten',
|
||||
div.getElementsByTagName('img')[0].className === className
|
||||
);
|
||||
}
|
||||
}]);
|
@ -634,7 +634,7 @@ function createTwemoji(re) {
|
||||
if (src) {
|
||||
img = new Image();
|
||||
img.onerror = twemoji.onerror;
|
||||
img.className = 'emoji';
|
||||
img.className = options.className;
|
||||
img.setAttribute('draggable', 'false');
|
||||
img.alt = alt;
|
||||
img.src = src;
|
||||
@ -689,7 +689,7 @@ function createTwemoji(re) {
|
||||
// recycle the match string replacing the emoji
|
||||
// with its image counter part
|
||||
match = '<img '.concat(
|
||||
'class="emoji" ',
|
||||
'class="', options.className, '" ',
|
||||
'draggable="false" ',
|
||||
// needs to preserve user original intent
|
||||
// when variants should be copied and pasted too
|
||||
@ -750,7 +750,8 @@ function createTwemoji(re) {
|
||||
callback: how.callback || defaultImageSrcGenerator,
|
||||
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
||||
ext: how.ext || twemoji.ext,
|
||||
size: toSizeSquaredAsset(how.size || twemoji.size)
|
||||
size: toSizeSquaredAsset(how.size || twemoji.size),
|
||||
className:how.className || 'emoji'
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -358,7 +358,7 @@ define(function () {
|
||||
if (src) {
|
||||
img = new Image();
|
||||
img.onerror = twemoji.onerror;
|
||||
img.className = 'emoji';
|
||||
img.className = options.className;
|
||||
img.setAttribute('draggable', 'false');
|
||||
img.alt = alt;
|
||||
img.src = src;
|
||||
@ -413,7 +413,7 @@ define(function () {
|
||||
// recycle the match string replacing the emoji
|
||||
// with its image counter part
|
||||
match = '<img '.concat(
|
||||
'class="emoji" ',
|
||||
'class="', options.className, '" ',
|
||||
'draggable="false" ',
|
||||
// needs to preserve user original intent
|
||||
// when variants should be copied and pasted too
|
||||
@ -474,7 +474,8 @@ define(function () {
|
||||
callback: how.callback || defaultImageSrcGenerator,
|
||||
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
||||
ext: how.ext || twemoji.ext,
|
||||
size: toSizeSquaredAsset(how.size || twemoji.size)
|
||||
size: toSizeSquaredAsset(how.size || twemoji.size),
|
||||
className:how.className || 'emoji'
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -357,7 +357,7 @@ var twemoji = (function (
|
||||
if (src) {
|
||||
img = new Image();
|
||||
img.onerror = twemoji.onerror;
|
||||
img.className = 'emoji';
|
||||
img.className = options.className;
|
||||
img.setAttribute('draggable', 'false');
|
||||
img.alt = alt;
|
||||
img.src = src;
|
||||
@ -412,7 +412,7 @@ var twemoji = (function (
|
||||
// recycle the match string replacing the emoji
|
||||
// with its image counter part
|
||||
match = '<img '.concat(
|
||||
'class="emoji" ',
|
||||
'class="', options.className, '" ',
|
||||
'draggable="false" ',
|
||||
// needs to preserve user original intent
|
||||
// when variants should be copied and pasted too
|
||||
@ -473,7 +473,8 @@ var twemoji = (function (
|
||||
callback: how.callback || defaultImageSrcGenerator,
|
||||
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
||||
ext: how.ext || twemoji.ext,
|
||||
size: toSizeSquaredAsset(how.size || twemoji.size)
|
||||
size: toSizeSquaredAsset(how.size || twemoji.size),
|
||||
className:how.className || 'emoji'
|
||||
});
|
||||
}
|
||||
|
||||
|
2
twemoji.min.js
vendored
2
twemoji.min.js
vendored
File diff suppressed because one or more lines are too long
@ -358,7 +358,7 @@ var twemoji = (function (
|
||||
if (src) {
|
||||
img = new Image();
|
||||
img.onerror = twemoji.onerror;
|
||||
img.className = 'emoji';
|
||||
img.className = options.className;
|
||||
img.setAttribute('draggable', 'false');
|
||||
img.alt = alt;
|
||||
img.src = src;
|
||||
@ -413,7 +413,7 @@ var twemoji = (function (
|
||||
// recycle the match string replacing the emoji
|
||||
// with its image counter part
|
||||
match = '<img '.concat(
|
||||
'class="emoji" ',
|
||||
'class="', options.className, '" ',
|
||||
'draggable="false" ',
|
||||
// needs to preserve user original intent
|
||||
// when variants should be copied and pasted too
|
||||
@ -474,7 +474,8 @@ var twemoji = (function (
|
||||
callback: how.callback || defaultImageSrcGenerator,
|
||||
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
||||
ext: how.ext || twemoji.ext,
|
||||
size: toSizeSquaredAsset(how.size || twemoji.size)
|
||||
size: toSizeSquaredAsset(how.size || twemoji.size),
|
||||
className:how.className || 'emoji'
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user