搜索bug

This commit is contained in:
Van 2014-12-23 15:40:28 +08:00
parent 4ba5c4925d
commit 56238e26e3
1 changed files with 17 additions and 7 deletions

View File

@ -621,14 +621,24 @@ var editors = {
}; };
}, },
appendSearch: function (data, type, key) { appendSearch: function (data, type, key) {
var searcHTML = '<ul class="list">'; var searcHTML = '<ul class="list">',
key = key.toLowerCase();
for (var i = 0, ii = data.length; i < ii; i++) { for (var i = 0, ii = data.length; i < ii; i++) {
var contents = data[i].contents[0], var contents = '',
index = contents.indexOf(key); lowerCaseContents = data[i].contents[0].toLowerCase(),
contents = contents.substring(0, index) matches = lowerCaseContents.split(key),
+ '<b>' + key + '</b>' startIndex = 0,
+ contents.substring(index + key.length); endIndex = 0;
for (var j = 0, max = matches.length; j < max; j++) {
startIndex = endIndex + matches[j].length;
endIndex = startIndex + key.length;
var keyWord = data[i].contents[0].substring(startIndex, endIndex);
if (keyWord !== '') {
keyWord = '<b>' + keyWord + '</b>';
}
contents += matches[j] + keyWord;
}
searcHTML += '<li title="' + data[i].path + '">' searcHTML += '<li title="' + data[i].path + '">'
+ contents + "&nbsp;&nbsp;&nbsp;&nbsp;<span class='ft-small'>" + data[i].path + contents + "&nbsp;&nbsp;&nbsp;&nbsp;<span class='ft-small'>" + data[i].path