diff --git a/README.md b/README.md index ccedaa9d..5ce0f2bd 100644 --- a/README.md +++ b/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" } ``` diff --git a/package.json b/package.json index a3e6c0ca..5e1998e7 100644 --- a/package.json +++ b/package.json @@ -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.", diff --git a/test.js b/test.js index 9f5f1c13..77bb12f8 100644 --- a/test.js +++ b/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(/]+?>/i, '') === html); } +},{ + name: 'string parsing + className', + test: function () { + var className = 'img-' + Math.random(); + var img = 'I \u2764 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 + ); + } }]); \ No newline at end of file diff --git a/twemoji-generator.js b/twemoji-generator.js index c6d97aba..1a45a361 100755 --- a/twemoji-generator.js +++ b/twemoji-generator.js @@ -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 = '")}}return match})}function toSizeSquaredAsset(value){return typeof value==="number"?value+"x"+value:value}function fromCodePoint(codepoint){var code=typeof codepoint==="string"?parseInt(codepoint,16):codepoint;if(code<65536){return fromCharCode(code)}code-=65536;return fromCharCode(55296+(code>>10),56320+(code&1023))}function parse(what,how){if(!how||typeof how==="function"){how={callback:how}}return(typeof what==="string"?parseString:parseNode)(what,{callback:how.callback||defaultImageSrcGenerator,base:typeof how.base==="string"?how.base:twemoji.base,ext:how.ext||twemoji.ext,size:toSizeSquaredAsset(how.size||twemoji.size)})}function replace(text,callback){return String(text).replace(re,callback)}function test(text){re.lastIndex=0;var result=re.test(text);re.lastIndex=0;return result}function toCodePoint(unicodeSurrogates,sep){var r=[],c=0,p=0,i=0;while(i")}}return match})}function toSizeSquaredAsset(value){return typeof value==="number"?value+"x"+value:value}function fromCodePoint(codepoint){var code=typeof codepoint==="string"?parseInt(codepoint,16):codepoint;if(code<65536){return fromCharCode(code)}code-=65536;return fromCharCode(55296+(code>>10),56320+(code&1023))}function parse(what,how){if(!how||typeof how==="function"){how={callback:how}}return(typeof what==="string"?parseString:parseNode)(what,{callback:how.callback||defaultImageSrcGenerator,base:typeof how.base==="string"?how.base:twemoji.base,ext:how.ext||twemoji.ext,size:toSizeSquaredAsset(how.size||twemoji.size),className:how.className||"emoji"})}function replace(text,callback){return String(text).replace(re,callback)}function test(text){re.lastIndex=0;var result=re.test(text);re.lastIndex=0;return result}function toCodePoint(unicodeSurrogates,sep){var r=[],c=0,p=0,i=0;while(i