[Phpfreechat-svn] SF.net SVN: phpfreechat: [1141] trunk/data/public/js/pfcclient.js
Status: Beta
Brought to you by:
kerphi
From: <gpi...@us...> - 2007-08-23 19:40:14
|
Revision: 1141 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1141&view=rev Author: gpinzone Date: 2007-08-23 12:40:15 -0700 (Thu, 23 Aug 2007) Log Message: ----------- Revised smiley bugfix to use negative lookahead since it's natively supported in JavaScript. Sort smiley keys by length (longest to shortest) to prevent shorter smileys from taking precedence over longer ones. Modified Paths: -------------- trunk/data/public/js/pfcclient.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-22 06:38:33 UTC (rev 1140) +++ trunk/data/public/js/pfcclient.js 2007-08-23 19:40:15 UTC (rev 1141) @@ -1455,14 +1455,14 @@ // try to parse smileys var smileys = this.res.getSmileyHash(); - var sl = smileys.keys(); + // Sort keys by longest to shortest. This prevents a smiley like :) from being used on >:) + var sl = smileys.keys().sort(function (a,b){return (b.unescapeHTML().length - a.unescapeHTML().length);}); for(var i = 0; i < sl.length; i++) { - // Emulate negative lookbehind in JavaScript. // We don't want to replace smiley strings inside of tags. - // See http://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript for more info. - rx = new RegExp("(<[^>]*)?" + RegExp.escape(sl[i]),'g'); - msg = msg.replace(rx, function($0, $1){ return $1 ? $0 : '<img src="'+ smileys[sl[i]] +'" alt="' + sl[i] + '" title="' + sl[i] + '" />'; }); + // Use negative lookahead to search for end of tag. + rx = new RegExp(RegExp.escape(sl[i]) + "(?![^<]*>)",'g'); + msg = msg.replace(rx, '<img src="'+ smileys[sl[i]] +'" alt="' + sl[i] + '" title="' + sl[i] + '" />'); } // try to parse nickname for highlighting This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |