// JSmile for jQuery - Andrea Giammarchi [webreflection.blogspot.com] - V0.3 - 0.000414 jQuery.fn.extend({ smile: (function(){ function smile(show){ show = !arguments.length || !!show; this.each(function(i, firstChild){ jQuery.each(firstChild.childNodes, function(i, firstChild){ switch(firstChild.nodeType){ case 1: show ? jQuery(firstChild).smile(show) : smile.remove(firstChild); break; case 3: if(show && !smile.nodeName[firstChild.parentNode.nodeName.toUpperCase()]) smile.add(firstChild); break; } }); }); return this; }; smile.add = function(firstChild){ var parentNode = firstChild.parentNode, nodeValue = firstChild.nodeValue, i = 0, length = 0, img; nodeValue.replace( smile.RegExp, function(createTextNode, pos){ if(++length < 21){ img = new Image(); img.className = smile.className; img.src = smile.link(img.alt = img.title = createTextNode); jQuery(firstChild).before(document.createTextNode(nodeValue.substring(i, pos))).before(img); i = pos + createTextNode.length; } } ); if(i) jQuery(firstChild).before(document.createTextNode(nodeValue.substring(i))).remove(); }; smile.link = function(join){ var split = join.split(""), length = split.length; while(length--) split[length] = split[length].charCodeAt(0); return smile.src + split.join("."); }; smile.remove = function(firstChild){ jQuery(firstChild).find("img." + smile.className).each(function(i, firstChild){ jQuery(firstChild).replaceWith(document.createTextNode(firstChild.alt || firstChild.title)); }); }; smile.className = "jsmile"; smile.nodeName = {"CODE":true, "NOSCRIPT":true, "PRE":true, "SCRIPT":true, "STYLE":true}; smile.RegExp = /:arrow:|:cry:|:evil:|:geek:|:idea:|:lol:|:mrgreen:|:oops:|:roll:|:shock:|:twisted:|:ugeek:|8-\)|:o|:x|:\||:!:|:\(|:\)|:\?:|:\?|:D|:P|;\)/g; smile.src = "http://packed.it/JSmile/smiles/phpbb/"; return smile; })() });