mirror of
https://github.com/twitter/twemoji.git
synced 2024-10-06 14:49:44 +00:00
Add options.attributes callback
This commit is contained in:
parent
39a091da4b
commit
13eac7a2d8
@ -642,6 +642,15 @@ function createTwemoji(re) {
|
|||||||
img.onerror = twemoji.onerror;
|
img.onerror = twemoji.onerror;
|
||||||
img.className = options.className;
|
img.className = options.className;
|
||||||
img.setAttribute('draggable', 'false');
|
img.setAttribute('draggable', 'false');
|
||||||
|
var attrib = options.attributes;
|
||||||
|
if (typeof(attrib) === 'function') {
|
||||||
|
attrib = attrib(alt);
|
||||||
|
}
|
||||||
|
if (attrib) {
|
||||||
|
for (var attrname in attrib) {
|
||||||
|
img.setAttribute(attrname) = attrib[attrname];
|
||||||
|
}
|
||||||
|
}
|
||||||
img.alt = alt;
|
img.alt = alt;
|
||||||
img.src = src;
|
img.src = src;
|
||||||
}
|
}
|
||||||
@ -694,6 +703,17 @@ function createTwemoji(re) {
|
|||||||
if (src) {
|
if (src) {
|
||||||
// recycle the match string replacing the emoji
|
// recycle the match string replacing the emoji
|
||||||
// with its image counter part
|
// with its image counter part
|
||||||
|
var attrib = options.attributes;
|
||||||
|
if (typeof(attrib) === 'function') {
|
||||||
|
attrib = attrib(match);
|
||||||
|
}
|
||||||
|
var attr_text = '';
|
||||||
|
if (attrib) {
|
||||||
|
for (var attrname in attrib) {
|
||||||
|
attr_text = attr_text + ' ' + attrname + '="' + attrib[attrname].replace(/"/g, '"') + '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match = '<img '.concat(
|
match = '<img '.concat(
|
||||||
'class="', options.className, '" ',
|
'class="', options.className, '" ',
|
||||||
'draggable="false" ',
|
'draggable="false" ',
|
||||||
@ -702,6 +722,7 @@ function createTwemoji(re) {
|
|||||||
'alt="',
|
'alt="',
|
||||||
match,
|
match,
|
||||||
'" ',
|
'" ',
|
||||||
|
attr_text,
|
||||||
'src="',
|
'src="',
|
||||||
src,
|
src,
|
||||||
'"',
|
'"',
|
||||||
@ -754,6 +775,7 @@ function createTwemoji(re) {
|
|||||||
// otherwise use the DOM tree and parse text nodes only
|
// otherwise use the DOM tree and parse text nodes only
|
||||||
return (typeof what === 'string' ? parseString : parseNode)(what, {
|
return (typeof what === 'string' ? parseString : parseNode)(what, {
|
||||||
callback: how.callback || defaultImageSrcGenerator,
|
callback: how.callback || defaultImageSrcGenerator,
|
||||||
|
attributes: how.attributes,
|
||||||
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
||||||
ext: how.ext || twemoji.ext,
|
ext: how.ext || twemoji.ext,
|
||||||
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),
|
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),
|
||||||
|
@ -365,6 +365,15 @@ define(function () {
|
|||||||
img.onerror = twemoji.onerror;
|
img.onerror = twemoji.onerror;
|
||||||
img.className = options.className;
|
img.className = options.className;
|
||||||
img.setAttribute('draggable', 'false');
|
img.setAttribute('draggable', 'false');
|
||||||
|
var attrib = options.attributes;
|
||||||
|
if (typeof(attrib) === 'function') {
|
||||||
|
attrib = attrib(alt);
|
||||||
|
}
|
||||||
|
if (attrib) {
|
||||||
|
for (var attrname in attrib) {
|
||||||
|
img.setAttribute(attrname) = attrib[attrname];
|
||||||
|
}
|
||||||
|
}
|
||||||
img.alt = alt;
|
img.alt = alt;
|
||||||
img.src = src;
|
img.src = src;
|
||||||
}
|
}
|
||||||
@ -417,6 +426,17 @@ define(function () {
|
|||||||
if (src) {
|
if (src) {
|
||||||
// recycle the match string replacing the emoji
|
// recycle the match string replacing the emoji
|
||||||
// with its image counter part
|
// with its image counter part
|
||||||
|
var attrib = options.attributes;
|
||||||
|
if (typeof(attrib) === 'function') {
|
||||||
|
attrib = attrib(match);
|
||||||
|
}
|
||||||
|
var attr_text = '';
|
||||||
|
if (attrib) {
|
||||||
|
for (var attrname in attrib) {
|
||||||
|
attr_text = attr_text + ' ' + attrname + '="' + attrib[attrname].replace(/"/g, '"') + '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match = '<img '.concat(
|
match = '<img '.concat(
|
||||||
'class="', options.className, '" ',
|
'class="', options.className, '" ',
|
||||||
'draggable="false" ',
|
'draggable="false" ',
|
||||||
@ -425,6 +445,7 @@ define(function () {
|
|||||||
'alt="',
|
'alt="',
|
||||||
match,
|
match,
|
||||||
'" ',
|
'" ',
|
||||||
|
attr_text,
|
||||||
'src="',
|
'src="',
|
||||||
src,
|
src,
|
||||||
'"',
|
'"',
|
||||||
@ -477,6 +498,7 @@ define(function () {
|
|||||||
// otherwise use the DOM tree and parse text nodes only
|
// otherwise use the DOM tree and parse text nodes only
|
||||||
return (typeof what === 'string' ? parseString : parseNode)(what, {
|
return (typeof what === 'string' ? parseString : parseNode)(what, {
|
||||||
callback: how.callback || defaultImageSrcGenerator,
|
callback: how.callback || defaultImageSrcGenerator,
|
||||||
|
attributes: how.attributes,
|
||||||
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
||||||
ext: how.ext || twemoji.ext,
|
ext: how.ext || twemoji.ext,
|
||||||
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),
|
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),
|
||||||
|
22
twemoji.js
22
twemoji.js
@ -364,6 +364,15 @@ var twemoji = (function (
|
|||||||
img.onerror = twemoji.onerror;
|
img.onerror = twemoji.onerror;
|
||||||
img.className = options.className;
|
img.className = options.className;
|
||||||
img.setAttribute('draggable', 'false');
|
img.setAttribute('draggable', 'false');
|
||||||
|
var attrib = options.attributes;
|
||||||
|
if (typeof(attrib) === 'function') {
|
||||||
|
attrib = attrib(alt);
|
||||||
|
}
|
||||||
|
if (attrib) {
|
||||||
|
for (var attrname in attrib) {
|
||||||
|
img.setAttribute(attrname) = attrib[attrname];
|
||||||
|
}
|
||||||
|
}
|
||||||
img.alt = alt;
|
img.alt = alt;
|
||||||
img.src = src;
|
img.src = src;
|
||||||
}
|
}
|
||||||
@ -416,6 +425,17 @@ var twemoji = (function (
|
|||||||
if (src) {
|
if (src) {
|
||||||
// recycle the match string replacing the emoji
|
// recycle the match string replacing the emoji
|
||||||
// with its image counter part
|
// with its image counter part
|
||||||
|
var attrib = options.attributes;
|
||||||
|
if (typeof(attrib) === 'function') {
|
||||||
|
attrib = attrib(match);
|
||||||
|
}
|
||||||
|
var attr_text = '';
|
||||||
|
if (attrib) {
|
||||||
|
for (var attrname in attrib) {
|
||||||
|
attr_text = attr_text + ' ' + attrname + '="' + attrib[attrname].replace(/"/g, '"') + '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match = '<img '.concat(
|
match = '<img '.concat(
|
||||||
'class="', options.className, '" ',
|
'class="', options.className, '" ',
|
||||||
'draggable="false" ',
|
'draggable="false" ',
|
||||||
@ -424,6 +444,7 @@ var twemoji = (function (
|
|||||||
'alt="',
|
'alt="',
|
||||||
match,
|
match,
|
||||||
'" ',
|
'" ',
|
||||||
|
attr_text,
|
||||||
'src="',
|
'src="',
|
||||||
src,
|
src,
|
||||||
'"',
|
'"',
|
||||||
@ -476,6 +497,7 @@ var twemoji = (function (
|
|||||||
// otherwise use the DOM tree and parse text nodes only
|
// otherwise use the DOM tree and parse text nodes only
|
||||||
return (typeof what === 'string' ? parseString : parseNode)(what, {
|
return (typeof what === 'string' ? parseString : parseNode)(what, {
|
||||||
callback: how.callback || defaultImageSrcGenerator,
|
callback: how.callback || defaultImageSrcGenerator,
|
||||||
|
attributes: how.attributes,
|
||||||
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
||||||
ext: how.ext || twemoji.ext,
|
ext: how.ext || twemoji.ext,
|
||||||
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),
|
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),
|
||||||
|
2
twemoji.min.js
vendored
2
twemoji.min.js
vendored
File diff suppressed because one or more lines are too long
@ -365,6 +365,15 @@ var twemoji = (function (
|
|||||||
img.onerror = twemoji.onerror;
|
img.onerror = twemoji.onerror;
|
||||||
img.className = options.className;
|
img.className = options.className;
|
||||||
img.setAttribute('draggable', 'false');
|
img.setAttribute('draggable', 'false');
|
||||||
|
var attrib = options.attributes;
|
||||||
|
if (typeof(attrib) === 'function') {
|
||||||
|
attrib = attrib(alt);
|
||||||
|
}
|
||||||
|
if (attrib) {
|
||||||
|
for (var attrname in attrib) {
|
||||||
|
img.setAttribute(attrname) = attrib[attrname];
|
||||||
|
}
|
||||||
|
}
|
||||||
img.alt = alt;
|
img.alt = alt;
|
||||||
img.src = src;
|
img.src = src;
|
||||||
}
|
}
|
||||||
@ -417,6 +426,17 @@ var twemoji = (function (
|
|||||||
if (src) {
|
if (src) {
|
||||||
// recycle the match string replacing the emoji
|
// recycle the match string replacing the emoji
|
||||||
// with its image counter part
|
// with its image counter part
|
||||||
|
var attrib = options.attributes;
|
||||||
|
if (typeof(attrib) === 'function') {
|
||||||
|
attrib = attrib(match);
|
||||||
|
}
|
||||||
|
var attr_text = '';
|
||||||
|
if (attrib) {
|
||||||
|
for (var attrname in attrib) {
|
||||||
|
attr_text = attr_text + ' ' + attrname + '="' + attrib[attrname].replace(/"/g, '"') + '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match = '<img '.concat(
|
match = '<img '.concat(
|
||||||
'class="', options.className, '" ',
|
'class="', options.className, '" ',
|
||||||
'draggable="false" ',
|
'draggable="false" ',
|
||||||
@ -425,6 +445,7 @@ var twemoji = (function (
|
|||||||
'alt="',
|
'alt="',
|
||||||
match,
|
match,
|
||||||
'" ',
|
'" ',
|
||||||
|
attr_text,
|
||||||
'src="',
|
'src="',
|
||||||
src,
|
src,
|
||||||
'"',
|
'"',
|
||||||
@ -477,6 +498,7 @@ var twemoji = (function (
|
|||||||
// otherwise use the DOM tree and parse text nodes only
|
// otherwise use the DOM tree and parse text nodes only
|
||||||
return (typeof what === 'string' ? parseString : parseNode)(what, {
|
return (typeof what === 'string' ? parseString : parseNode)(what, {
|
||||||
callback: how.callback || defaultImageSrcGenerator,
|
callback: how.callback || defaultImageSrcGenerator,
|
||||||
|
attributes: how.attributes,
|
||||||
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
base: typeof how.base === 'string' ? how.base : twemoji.base,
|
||||||
ext: how.ext || twemoji.ext,
|
ext: how.ext || twemoji.ext,
|
||||||
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),
|
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),
|
||||||
|
Loading…
Reference in New Issue
Block a user