1
0
mirror of https://github.com/twitter/twemoji.git synced 2024-07-03 03:18:58 +00:00

Add options.attributes callback

This commit is contained in:
Derek Mooney 2015-02-24 20:05:47 -05:00
parent 39a091da4b
commit 13eac7a2d8
5 changed files with 89 additions and 1 deletions

View File

@ -642,6 +642,15 @@ function createTwemoji(re) {
img.onerror = twemoji.onerror;
img.className = options.className;
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.src = src;
}
@ -694,6 +703,17 @@ function createTwemoji(re) {
if (src) {
// recycle the match string replacing the emoji
// 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(
'class="', options.className, '" ',
'draggable="false" ',
@ -702,6 +722,7 @@ function createTwemoji(re) {
'alt="',
match,
'" ',
attr_text,
'src="',
src,
'"',
@ -754,6 +775,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: how.attributes,
base: typeof how.base === 'string' ? how.base : twemoji.base,
ext: how.ext || twemoji.ext,
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),

View File

@ -365,6 +365,15 @@ define(function () {
img.onerror = twemoji.onerror;
img.className = options.className;
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.src = src;
}
@ -417,6 +426,17 @@ define(function () {
if (src) {
// recycle the match string replacing the emoji
// 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, '&quot;') + '"';
}
}
match = '<img '.concat(
'class="', options.className, '" ',
'draggable="false" ',
@ -425,6 +445,7 @@ define(function () {
'alt="',
match,
'" ',
attr_text,
'src="',
src,
'"',
@ -477,6 +498,7 @@ define(function () {
// otherwise use the DOM tree and parse text nodes only
return (typeof what === 'string' ? parseString : parseNode)(what, {
callback: how.callback || defaultImageSrcGenerator,
attributes: how.attributes,
base: typeof how.base === 'string' ? how.base : twemoji.base,
ext: how.ext || twemoji.ext,
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),

View File

@ -364,6 +364,15 @@ var twemoji = (function (
img.onerror = twemoji.onerror;
img.className = options.className;
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.src = src;
}
@ -416,6 +425,17 @@ var twemoji = (function (
if (src) {
// recycle the match string replacing the emoji
// 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, '&quot;') + '"';
}
}
match = '<img '.concat(
'class="', options.className, '" ',
'draggable="false" ',
@ -424,6 +444,7 @@ var twemoji = (function (
'alt="',
match,
'" ',
attr_text,
'src="',
src,
'"',
@ -476,6 +497,7 @@ var twemoji = (function (
// otherwise use the DOM tree and parse text nodes only
return (typeof what === 'string' ? parseString : parseNode)(what, {
callback: how.callback || defaultImageSrcGenerator,
attributes: how.attributes,
base: typeof how.base === 'string' ? how.base : twemoji.base,
ext: how.ext || twemoji.ext,
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),

2
twemoji.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -365,6 +365,15 @@ var twemoji = (function (
img.onerror = twemoji.onerror;
img.className = options.className;
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.src = src;
}
@ -417,6 +426,17 @@ var twemoji = (function (
if (src) {
// recycle the match string replacing the emoji
// 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, '&quot;') + '"';
}
}
match = '<img '.concat(
'class="', options.className, '" ',
'draggable="false" ',
@ -425,6 +445,7 @@ var twemoji = (function (
'alt="',
match,
'" ',
attr_text,
'src="',
src,
'"',
@ -477,6 +498,7 @@ var twemoji = (function (
// otherwise use the DOM tree and parse text nodes only
return (typeof what === 'string' ? parseString : parseNode)(what, {
callback: how.callback || defaultImageSrcGenerator,
attributes: how.attributes,
base: typeof how.base === 'string' ? how.base : twemoji.base,
ext: how.ext || twemoji.ext,
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),