Smileys module provides an input filter converting text smileys into images. It allows creation or import of new smileys.
The smiley button dynamically gets the list of smileys and displays them in a dialog for users to choose. For demonstrating the effect of smiley filter, the preview button is also modified in order to convert text smileys into images.
php:
$L = drupal_to_js(_smileys_list());
$P = base_path();
drupal_add_js("
var smlyList = $L, smlyPath = '$P';
var smlyWrap = \$('<div style=\"width:200px\"></div>');
\$.each(smlyList, function(i, s) {\$('<a href=\"#\" title=\"'+ s.description +'\"><img src=\"$P'+ s.image +'\" alt=\" '+ s.acronyms.split(' ')[0] +' \" /></a>').css('margin', '0.5em').appendTo(smlyWrap)});
", 'inline');
return 'js:
editor.dialog.open("Smileys");
$("tr.body>td", editor.dialog.popup).empty().append(smlyWrap);
$("a", smlyWrap).each(function(){this.onclick=function(){editor.dialog.close();editor.active.replaceSelection(this.firstChild.alt, "end"); return false;};});';js:
function SMLY2HTML(S) {
function A(s, p) {for (var i in p) s = s.replace(new RegExp(i, 'g'), p[i]); return s;}
var B = {}, b = '(^|[ ,\\.\\?!:\\(\\)\r\n<>]|$)';
for (var s, i=0; s = smlyList[i]; i++) {
var a = A(A(s.acronyms, {'([\\\\\\^\\$\\*\\+\\?\\.\\(\\)\\[\\]\\{\\}\\|])': '\\$1'}), {'\\s+': '|'}), h = '<img src="'+ smlyPath + s.image +'" />';
parseInt(s.standalone) ? (B[b + a + b] = '$1'+ h +'$2') : (B[a] = h);
}
return A(S, B);
}
E.preview && $(E.preview).css('display') != 'none' ? E.setContent(E.oriCnt) : E.setContent(SMLY2HTML(E.oriCnt = E.getContent()));
eDefPreview();Note: You can combine smiley preview with BBCode preview by copying SMLY2HTML function and changing BBC2HTML(E.oriCnt = E.getContent()) to SMLY2HTML(BBC2HTML(E.oriCnt = E.getContent())). Also note that SMLY2HTML requires smlyList and smlyPath variables defined by smiley button