...
|
...
|
@@ -11,9 +11,11 @@ var $miniBag = $('.mini-bag-box'), |
|
|
var $searchWrap = $('.search-wrapper'),
|
|
|
$searchForm = $('#search-form'),
|
|
|
$searchKey = $('#search-key'),
|
|
|
$searchHint = $('.search-hint'),
|
|
|
$clearInput = $('.clear-input');
|
|
|
|
|
|
var goodsTpl = require('../../tpl/common/bag-goods.hbs');
|
|
|
var searchHintTpl = require('../../tpl/header/search-hint.hbs');
|
|
|
var delayer;
|
|
|
|
|
|
require('yoho-jquery-nanoscroller');
|
...
|
...
|
@@ -178,6 +180,62 @@ $searchKey.keyup(function(e) { |
|
|
}
|
|
|
});
|
|
|
|
|
|
// 关键词搜索联想
|
|
|
function searchSuggest(key) {
|
|
|
$.get('//www.yohoblk.com/product/query/suggest', {
|
|
|
keyword: key
|
|
|
}, function(data) {
|
|
|
if (data.length >=1) {
|
|
|
$searchHint.html(searchHintTpl({list: data})).show();
|
|
|
} else {
|
|
|
$searchHint.hide();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
$searchKey.keyup(function(e) {
|
|
|
var val = $.trim($(this).val()),
|
|
|
$child = $searchHint.find('li'),
|
|
|
$act = $searchHint.find('.action'),
|
|
|
$focus;
|
|
|
|
|
|
if (e.which > 36 && e.which < 41) {
|
|
|
|
|
|
if (e.which === 38) {
|
|
|
$focus = $act.prev();
|
|
|
if (!$act.length || !$focus.length) {
|
|
|
$focus = $child.eq($child.length - 1);
|
|
|
}
|
|
|
} else if (e.which === 40) {
|
|
|
$focus = $act.next();
|
|
|
if (!$act.length || !$focus.length) {
|
|
|
$focus = $child.eq(0);
|
|
|
}
|
|
|
} else {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$child.removeClass('action');
|
|
|
$focus.addClass('action');
|
|
|
$(this).val($focus.find('.search-value').text());
|
|
|
} else if (e.which === 13) {
|
|
|
if (val) {
|
|
|
$searchForm.submit();
|
|
|
}
|
|
|
} else {
|
|
|
if ($searchHint && $searchHint.length) {
|
|
|
val = val.replace(new RegExp('\'', 'gm'), ''); // 去掉特殊字符
|
|
|
searchSuggest(val);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (val) {
|
|
|
$clearInput.show();
|
|
|
} else {
|
|
|
$clearInput.hide();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// ie8输入框提示特殊处理
|
|
|
// 应产品要求所有浏览器获得焦点提示文字隐藏
|
|
|
// if (!!window.ActiveXObject && !!document.documentMode) {
|
...
|
...
|
@@ -193,6 +251,10 @@ $searchKey.focus(function() { |
|
|
if ($.trim(key) === '') {
|
|
|
$searchKey.val('search').css('color', '#aaa');
|
|
|
}
|
|
|
|
|
|
setTimeout(function() {
|
|
|
$searchHint.hide();
|
|
|
}, 200);
|
|
|
}).val('search').css('color', '#aaa');
|
|
|
|
|
|
// }
|
...
|
...
|
|