...
|
...
|
@@ -12,6 +12,7 @@ var $tool = $('.tool-wrapper'), |
|
|
|
|
|
var $head = $('.head-wrapper'),
|
|
|
$searchForm = $('#search-form'),
|
|
|
$searchKey = $searchForm.find('.search-key'),
|
|
|
$logotrans = $head.find('.main-logo'),
|
|
|
$searchSug = $head.find('.search-suggest'),
|
|
|
$goCart = $head.find('.go-cart'),
|
...
|
...
|
@@ -23,6 +24,8 @@ var $subNav = $('.sub-nav-list.cure .contain-third'); |
|
|
|
|
|
var fetchUserInfoEvent = $.Callbacks('once'); // eslint-disable-line
|
|
|
|
|
|
var defaultSearch = $('#defaultsearch').val() || '';
|
|
|
|
|
|
var thirdLineNum = 9,
|
|
|
delayer,
|
|
|
centerFn,
|
...
|
...
|
@@ -32,8 +35,6 @@ var thirdLineNum = 9, |
|
|
|
|
|
var logoAngle = 0,
|
|
|
loopTime = 500,
|
|
|
keyword = '',
|
|
|
link = '',
|
|
|
reg = /^[\^\!\+\-\(\)\:\[\]\\\{\}\~\*\?\|\&\;\/]{0,}$/g;
|
|
|
|
|
|
var dataLayer = [];
|
...
|
...
|
@@ -295,6 +296,21 @@ function searchSuggest(key) { |
|
|
});
|
|
|
}
|
|
|
|
|
|
function submitSearch() {
|
|
|
var searchKey = $searchKey.val();
|
|
|
|
|
|
searchKey = $.trim(searchKey.toLowerCase());
|
|
|
|
|
|
if (reg.test(searchKey) && searchKey !== '') {
|
|
|
location.href = 'http://search.yohobuy.com/error?query=' + searchKey;
|
|
|
} else {
|
|
|
if (searchKey === '') {
|
|
|
$('#query-key').val(defaultSearch);
|
|
|
}
|
|
|
$searchForm.submit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 同步mini购物车数据
|
|
|
function syncCratInfo(strG) {
|
|
|
var info, total;
|
...
|
...
|
@@ -568,7 +584,7 @@ $yohoGroup.hover(function() { |
|
|
$(this).text(data.en);
|
|
|
});
|
|
|
|
|
|
$searchForm.on('keyup', '.search-key', function(e) {
|
|
|
$searchKey.keyup(function(e) {
|
|
|
var val = $.trim($(this).val()),
|
|
|
$child = $searchSug.find('li'),
|
|
|
$act = $searchSug.find('.action'),
|
...
|
...
|
@@ -594,16 +610,27 @@ $searchForm.on('keyup', '.search-key', function(e) { |
|
|
$focus.addClass('action');
|
|
|
$(this).val($focus.find('.searchvalue').text());
|
|
|
} else if (e.which === 13) {
|
|
|
if (val !== '') {
|
|
|
$searchForm.submit();
|
|
|
}
|
|
|
submitSearch();
|
|
|
} else {
|
|
|
val = val.replace(new RegExp('\'', 'gm'), ''); // 去掉特殊字符
|
|
|
|
|
|
$(this).val(val);
|
|
|
searchSuggest(val);
|
|
|
}
|
|
|
}).on('blur', '.search-key', function() {
|
|
|
}).focus(function() {
|
|
|
var val = $.trim($(this).val());
|
|
|
|
|
|
if (val === defaultSearch) {
|
|
|
$(this).val('');
|
|
|
}
|
|
|
|
|
|
$(this).css('color', '#333');
|
|
|
}).blur(function() {
|
|
|
var val = $.trim($(this).val());
|
|
|
|
|
|
if (val === '') {
|
|
|
$(this).val(defaultSearch).css('color', '#999');
|
|
|
}
|
|
|
setTimeout(function() {
|
|
|
$searchSug.hide();
|
|
|
}, 200);
|
...
|
...
|
@@ -779,59 +806,19 @@ function actionCover() { |
|
|
}
|
|
|
}
|
|
|
|
|
|
window.submitSearch = function() {
|
|
|
var $keywordinput = $('#query-key').val();
|
|
|
var $defaultsearch = $('#defaultsearch').val();
|
|
|
var column = 'Search';
|
|
|
var postition = 'Head Search';
|
|
|
var event = 'Search';
|
|
|
var $formatkeyword,
|
|
|
$formatkeywordinput;
|
|
|
|
|
|
$formatkeyword = $.trim(keyword.toLowerCase());
|
|
|
$formatkeywordinput = $.trim($keywordinput.toLowerCase());
|
|
|
getSource(column, postition, event);
|
|
|
if (link !== '' && keyword !== '' && $formatkeyword === $formatkeywordinput) {
|
|
|
location.href = link.replace('\'', '');
|
|
|
} else {
|
|
|
if (reg.test($keywordinput) && $keywordinput !== '') {
|
|
|
location.href = 'http://search.yohobuy.com/error?query=' + $keywordinput + '&result=error';
|
|
|
} else {
|
|
|
if ($keywordinput === '') {
|
|
|
$('#query-key').val($defaultsearch);
|
|
|
}
|
|
|
|
|
|
$searchForm.submit();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
window.submitSearch = submitSearch;
|
|
|
|
|
|
/**
|
|
|
* 查询跳转后保留关键字
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
function actionAddKeyWords() {
|
|
|
var $keywords = $('#nav_keyword').text();
|
|
|
var defaultsearch = $('#defaultsearch').val();
|
|
|
var $querykey = $('#query-key');
|
|
|
var keywords = $('#nav_keyword').text();
|
|
|
|
|
|
if ($keywords !== '') {
|
|
|
$querykey.css({
|
|
|
color: '#000'
|
|
|
});
|
|
|
$querykey.val($keywords);
|
|
|
if (keywords !== '') {
|
|
|
$searchKey.val(keywords).css('color', '#333');
|
|
|
} else {
|
|
|
$querykey.css({
|
|
|
color: '#e0e0e0'
|
|
|
});
|
|
|
$querykey.val(defaultsearch);
|
|
|
$querykey.on('focus', function() {
|
|
|
$querykey.css({
|
|
|
color: '#000'
|
|
|
});
|
|
|
$querykey.val('');
|
|
|
});
|
|
|
$searchKey.val(defaultSearch).css('color', '#999');
|
|
|
}
|
|
|
$(document).click(function(e) {
|
|
|
if (!$(e.target).closest('.searchspan, .search-list').length) {
|
...
|
...
|
|