]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - resources/jquery/jquery.highlightText.js
MediaWiki 1.17.1
[autoinstalls/mediawiki.git] / resources / jquery / jquery.highlightText.js
index 7ca29efde2dc710ba3a5f8d17452153693fa27e4..44ac56e145066a55683cec37c6a82b46b656cf27 100644 (file)
@@ -21,10 +21,12 @@ $.highlightText = {
                // if this is a text node
                if ( node.nodeType == 3 ) {
                        // TODO - need to be smarter about the character matching here. 
-                       // non latin characters can make regex think a new word has begun. 
-                       // look for an occurence of our pattern and store the starting position 
-                       var pos = node.data.search( new RegExp( "\\b" + $.escapeRE( pat ), "i" ) );
-                       if ( pos >= 0 ) {
+                       // non latin characters can make regex think a new word has begun: do not use \b
+                       // http://stackoverflow.com/questions/3787072/regex-wordwrap-with-utf8-characters-in-js
+                       // look for an occurence of our pattern and store the starting position
+                       var match = node.data.match( new RegExp( "(^|\\s)" + $.escapeRE( pat ), "i" ) );
+                       if ( match ) {
+                               var pos = match.index + match[1].length; // include length of any matched spaces
                                // create the span wrapper for the matched text
                                var spannode = document.createElement( 'span' );
                                spannode.className = 'highlight';