Is it a way to improve this infamous syntax… (with arrays)?
$("#rte").val(function(i, v) {
return v.replace(':)','<img src="rte/icons/emoticon_happy.png" />')
});
$("#rte").val(function(i, v) {
return v.replace(';)','<img src="rte/icons/emoticon_wink.png" />')
});
You can make this code way more extensible by supplying a dictionary for all of your smiles and looping through them:
See example →
EDIT: To have this update a preview area like requested in the comments: