|
98 | 98 |
|
99 | 99 | return query; |
100 | 100 | }, |
101 | | - regexAccent : [ |
| 101 | + regexAccent : [ |
102 | 102 | [/[\xC0-\xC5\u0100-\u0105]/ig,'a'], |
103 | 103 | [/[\xC7\u0106-\u010D]/ig,'c'], |
104 | 104 | [/[\xC8-\xCB]/ig,'e'], |
|
112 | 112 | [/[\x91\x92\u2018\u2019]/ig,'\''] |
113 | 113 | ], |
114 | 114 | matchAccent : /[\x91\x92\xC0-\xC5\xC7-\xCF\xD1-\xD6\xD8-\xDC\xFF\u0100-\u010D\u015A-\u0167\u2018\u2019]/ig, |
115 | | - replaceAccent: function(q) { |
116 | | - SearchHighlight.matchAccent.lastIndex = 0; |
| 115 | + replaceAccent: function(q) { |
| 116 | + SearchHighlight.matchAccent.lastIndex = 0; |
117 | 117 | if(SearchHighlight.matchAccent.test(q)) { |
118 | 118 | for(var i=0,l=SearchHighlight.regexAccent.length;i<l;i++) |
119 | 119 | q = q.replace(SearchHighlight.regexAccent[i][0],SearchHighlight.regexAccent[i][1]); |
120 | 120 | } |
121 | 121 | return q; |
122 | 122 | }, |
123 | 123 | escapeRegEx : /((?:\\{2})*)([[\]{}*?|])/g, //the special chars . and + are already gone at this point because they are considered split chars |
| 124 | + escapeAllRegEx : /[\(\)\[\]\?\.\+\*\^\$]/g, |
124 | 125 | buildReplaceTools : function(query) { |
125 | 126 | var re = [], regex; |
126 | 127 | $.each(query,function(i,n){ |
127 | | - if(n = SearchHighlight.replaceAccent(n).replace(SearchHighlight.escapeRegEx,"$1\\$2")) |
| 128 | + if(n = SearchHighlight.replaceAccent(n).replace(SearchHighlight.escapeRegEx,"$1\\$2")){ |
| 129 | + SearchHighlight.escapeAllRegEx.lastIndex = 0; |
| 130 | + n = n.replace(SearchHighlight.escapeAllRegEx, "\\$&"); |
128 | 131 | re.push(n); |
| 132 | + } |
129 | 133 | }); |
130 | 134 |
|
131 | 135 | regex = re.join("|"); |
|
161 | 165 | for(var startIndex=0,endIndex=el.childNodes.length;startIndex<endIndex;startIndex++) { |
162 | 166 | var item = el.childNodes[startIndex]; |
163 | 167 | if ( item.nodeType != 8 ) {//comment node |
164 | | - //text node |
| 168 | + //text node |
165 | 169 | if(item.nodeType==3) { |
166 | 170 | var text = item.data, textNoAcc = SearchHighlight.replaceAccent(text); |
167 | 171 | var newtext="",match,index=0; |
168 | 172 | SearchHighlight.regex.lastIndex = 0; |
169 | 173 | while(match = SearchHighlight.regex.exec(textNoAcc)) { |
170 | 174 | newtext += text.substr(index,match.index-index)+'<span class="'+ |
171 | | - SearchHighlight.subs[match[matchIndex].toLowerCase()]+'">'+text.substr(match.index,match[0].length)+"</span>"; |
| 175 | + (SearchHighlight.subs[match[matchIndex].toLowerCase()]||SearchHighlight.options.style_name)+'">'+text.substr(match.index,match[0].length)+"</span>"; |
172 | 176 | index = match.index+match[0].length; |
173 | 177 | } |
174 | 178 | if(newtext) { |
|
182 | 186 | } else { |
183 | 187 | if(item.nodeType==1 && item.nodeName.search(SearchHighlight.nosearch)==-1) |
184 | 188 | SearchHighlight.hiliteTree(item,query,noHighlight); |
185 | | - } |
| 189 | + } |
186 | 190 | } |
187 | 191 | } |
188 | 192 | } |
|
0 commit comments