this JS code goes towards a plugin for my forum.
the user-code for the smileys is supplied from a <span>user-code</span> or dictionary object as:
"{':\\)':'http://somedomain.com/smile.gif',':\\(':'http://somedomain.com/frown.gif'}"
^while this is user-code, a GUI replaces the textarea containing this, so the user doesn't get to see this code.
as for the code that executes the user-code on a post:
function Tcll5850_BBC_CSmileys(post, data) {
console.log(data);
if (data) {
$.each(eval("("+data+")"), function(smiley, url) {
post = post.replace(new RegExp('\\b'+smiley+'\\b', 'g'), ' <img src="'+url+'" /> ');
});
};
return post
};
where 'data' is the user code...
why doesn't RegExp('\b'+smiley+'\b', 'g') work?? O.o
I want it to work in cases where:
- the first character in the post is the start of a smiley
- the smiley is in the middle of text (and is not merged such as "8)" in "func(8):" )
- the smiley is, of course, at the end of a line
none of these cases work with the code provided
how can I fix this??