search320.js
1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* @description: 搜索
* @author: chenglong.wang@yoho.cn
* @date: 2015/1/13
*/
var $ = require("jquery");
require("jquery.autocomplete");
exports.init = function () {
var search = $('.search_input input');
var searchBtn = $('.search_btn');
search.keydown(function (event) {
if (event.keyCode == 13) {
searchBtn.trigger("click");
}
}).autocomplete('/search/default/words', {
width: 290,
scrollHeight: 100,
max: 10,
selectFirst: false,
autoFill: false,
formatResult: function (row, data) {
return data.replace(/<\/?[^>]*>/g, '');
}
}).result(function (event, data, formatted) {
window.location.href = './search?q=' + encodeURIComponent(formatted.replace(/<\/?[^>]*>/g, ''));
});
searchBtn.click(function () {
if (search.val() !== "") {
window.location = YohoConfig.mainUrl + "/search?q=" + search.val();
return false;
} else {
$(document).trigger("click");
}
});
};