Authored by OF1706

searchTerms sum2

... ... @@ -120,29 +120,29 @@ const searchHistory = (req, res) => {
let history = _.trim(req.cookies['_History']);
let q = _.trim(decodeURIComponent(req.query.query) || '');
let data = [];
let list = {};
let ResData = {};
history = history ? history.split(',') : [];
history = _.reject(history, old => old === q ? true : false);
if (q !== '') {
if(q !== ''){
history.unshift(q);
res.cookie('_History',_.take(history, 9).join(','), {
domain: config.cookieDomain,
maxAge: 60 * 60 * 24 * 1000 * 30 // 一月
});
}
res.cookie('_History', _.take(history, 9).join(','), {
domain: config.cookieDomain,
maxAge: 60 * 60 * 24 * 1000 * 30 // 一月
});
_.forEach(history, function(item) {
let list = {};
list['keyword'] = item;
list['href'] = helpers.urlFormat('', {query: list['keyword']}, 'search');
data.push(list);
});
ResData['data'] = data;
res.type('text/plain');
... ...
... ... @@ -322,7 +322,7 @@
\{{/data}}
</script>
<script type="text/html" id="search-suggest-history">
<p class="search-suggest-title">最近搜过<a class="searchDel" href="#">清空</a></p>
\{{#if data}}<p class="search-suggest-title">最近搜过<a class="searchDel" href="#">清空</a></p>
\{{#data}}
<li>
<a style="display: block;" href="\{{href}}" class="clearfix clear search-item" title="\{{keyword}}"
... ... @@ -331,6 +331,7 @@
</a>
</li>
\{{/data}}
\{{/if}}
</script>
</div>
... ...
... ... @@ -92,7 +92,7 @@ loginFn = handlebars.compile($('#header-login-info-tpl').html() || '');
cartFn = handlebars.compile($('#mini-cart-tpl').html() || '');
// handlebars helper
handlebars.registerHelper('notzero', function(v1, options) {
handlebars.registerHelper('notzero', function (v1, options) {
if (v1 !== '0') {
return options.fn(this);
} else {
... ... @@ -214,7 +214,7 @@ function getBannerAndNotice() {
$.getJSON('//new.yohobuy.com/common/getbanner?callback=?', {
client_type: 'web',
content_code: code
}, function(JsonData) {
}, function (JsonData) {
if (+JsonData.code === 200) {
if (typeof JsonData.data === 'object') {
if (JsonData.data.url !== '') {
... ... @@ -229,13 +229,13 @@ function getBannerAndNotice() {
// 格式化三级菜单
function formatThirdMenu() {
$subNav.each(function() {
$subNav.each(function () {
var $thirdList = $(this).find('.hide-list'),
list = [],
i = 0;
if ($thirdList.length) {
$thirdList.children().each(function() {
$thirdList.children().each(function () {
if (i % thirdLineNum === 0) {
list.push('');
}
... ... @@ -269,7 +269,7 @@ function syncLoginInfo() {
method: 'open.passport.get'
};
return $.getJSON('//www.yohobuy.com/common/passport/?callback=?', param, function(jsonData) {
return $.getJSON('//www.yohobuy.com/common/passport/?callback=?', param, function (jsonData) {
if (jsonData && jsonData.data && jsonData.data.result !== -1) {
updateLoginInfo(jsonData.data);
} else {
... ... @@ -288,7 +288,7 @@ function searchSuggest(key) {
keyword: key
};
$.getJSON('//search.yohobuy.com/product/search/suggest?callback=?', param, function(jsonData) {
$.getJSON('//search.yohobuy.com/product/search/suggest?callback=?', param, function (jsonData) {
var searchSuggestHtml;
if (jsonData.code === 200) {
... ... @@ -315,6 +315,8 @@ function submitSearch() {
}
$searchForm.submit();
}
//触发历史搜索保存
searchSuggestHistory();
}
// 同步mini购物车数据
... ... @@ -353,7 +355,7 @@ function loadCartDetail(key) {
shopping_key: key
};
$.getJSON('//www.yohobuy.com/common/shoppingCart/?callback=?', param, function(jsonData) {
$.getJSON('//www.yohobuy.com/common/shoppingCart/?callback=?', param, function (jsonData) {
var totalGoods = [],
infoArr = [
'main_goods',
... ... @@ -366,7 +368,7 @@ function loadCartDetail(key) {
if (jsonData.code === 200) {
data = jsonData.data;
$.each(infoArr, function(k, v) {
$.each(infoArr, function (k, v) {
if (data[v]) {
totalGoods = $.merge(totalGoods, data[v]);
}
... ... @@ -393,7 +395,7 @@ function delCartGoods(data, callback) {
product_num: data.num
};
$.getJSON('//www.yohobuy.com/common/delCartGoods/?callback=?', param, function(jsonData) {
$.getJSON('//www.yohobuy.com/common/delCartGoods/?callback=?', param, function (jsonData) {
var strG = '';
if (jsonData.code === 200) {
... ... @@ -424,21 +426,21 @@ function requestFrameAct() {
var func3 = prefixList[2] + 'RequestAnimationFrame';
if (window[func1]) {
return function(callback) {
return function (callback) {
requestAnimationFrame(callback);
};
}
if (window[func2]) {
return function(callback) {
return function (callback) {
window[func2](callback);
};
}
if (window[func3]) {
return function(callback) {
return function (callback) {
window[func3](callback);
};
}
return function(callback) {
return function (callback) {
window.setTimeout(callback, 67);
};
}
... ... @@ -465,7 +467,7 @@ function tsAnimate() {
if (logoAngle % 360 === 0) {
window.setTimeout(tsAnimate, 1 * 60 * 1000);
} else {
requestFrame(function() {
requestFrame(function () {
tsAnimate();
});
}
... ... @@ -483,10 +485,10 @@ function fadeAnimate() {
cycle = 1 * 60 * 1000;
}
$logotrans.fadeOut(loopTime, function() {
$logotrans.fadeOut(loopTime, function () {
$logotrans.toggleClass('logo-cn-ie');
$logotrans.fadeIn(loopTime, function() {
window.setTimeout(function() {
$logotrans.fadeIn(loopTime, function () {
window.setTimeout(function () {
fadeAnimate();
}, cycle);
});
... ... @@ -555,7 +557,7 @@ formatThirdMenu(); // 格式化三级菜单
cartTimer = setInterval(syncCratInfo, 2000); // 定时同步购物车数量
// 获取头部登陆信息
(function() {
(function () {
var uid = getUid(), //eslint-disable-line
profileName = getProfileName(); // eslint-disable-line
... ... @@ -572,14 +574,14 @@ cartTimer = setInterval(syncCratInfo, 2000); // 定时同步购物车数量
$loginBox.show();
}());
fetchUserInfoEvent.add(function() {
fetchUserInfoEvent.add(function () {
if ($('.simple-user-center').length === 0) {
return;
}
syncLoginInfo();
});
$myYohoBox.hover(function() {
$myYohoBox.hover(function () {
var uid = getUid(); // eslint-disable-line
$myYohoBox.addClass('myyoho-hover');
... ... @@ -589,21 +591,21 @@ $myYohoBox.hover(function() {
}
fetchUserInfoEvent.fire();
}, function() {
}, function () {
$myYohoBox.removeClass('myyoho-hover');
});
$yohoGroup.hover(function() {
$yohoGroup.hover(function () {
var data = $(this).data();
$(this).text(data.cn);
}, function() {
}, function () {
var data = $(this).data();
$(this).text(data.en);
});
$searchKey.keyup(function(e) {
$searchKey.keyup(function (e) {
var val = $.trim($(this).val()),
$child = $searchSug.find('li'),
$act = $searchSug.find('.action'),
... ... @@ -636,7 +638,10 @@ $searchKey.keyup(function(e) {
searchSuggest(val);
}
}
}).focus(function() {
if ($searchKey.val() === '') {
$searchKey.mouseenter();
}
}).focus(function () {
var val = $.trim($(this).val());
if (val === defaultSearch) {
... ... @@ -644,19 +649,24 @@ $searchKey.keyup(function(e) {
}
$(this).css('color', '#333');
}).blur(function() {
setTimeout(function () {
$searchKey.mouseenter();
}, 10000);
}).blur(function () {
var val = $.trim($(this).val());
if (val === '') {
$(this).val(defaultSearch).css('color', '#999');
}
setTimeout(function() {
setTimeout(function () {
$searchSug.hide();
}, 200);
});
if ($miniCart && $miniCart.length) {
$goCart.hover(function() {
$goCart.hover(function () {
var data, _html = '';
if ($goCart.hasClass('on-hover')) {
... ... @@ -672,17 +682,17 @@ if ($miniCart && $miniCart.length) {
}
$miniCart.html(_html);
$goCart.addClass('on-hover');
}, function() {
}, function () {
$goCart.removeClass('on-hover');
});
$goCart.on('click', '.cart-goods-del', function() {
$goCart.on('click', '.cart-goods-del', function () {
var $dom = $(this),
data = $dom.data(),
callback;
if (data) {
callback = function() {
callback = function () {
$dom.closest('.goods-item').remove();
};
data.key = $goCart.data().key;
... ... @@ -692,12 +702,12 @@ if ($miniCart && $miniCart.length) {
}
$subNav.on({
mouseenter: function() {
mouseenter: function () {
var $thirdNav = $(this).children('.third-nav-wrapper'),
$show = $thirdNav.find('.show-detail'),
param = {};
delayer = setTimeout(function() {
delayer = setTimeout(function () {
$thirdNav.show();
}, 200);
... ... @@ -709,7 +719,7 @@ $subNav.on({
param.width = 337;
param.height = 250;
param._ = new Date();
$.getJSON('//new.yohobuy.com/common/getbanner?callback=?', param, function(JsonData) {
$.getJSON('//new.yohobuy.com/common/getbanner?callback=?', param, function (JsonData) {
if (JsonData.code === 200) {
$show.addClass('show');
$show.find('img').attr('src', JsonData.data.src);
... ... @@ -718,7 +728,7 @@ $subNav.on({
}
});
},
mouseleave: function() {
mouseleave: function () {
var $thirdNav = $(this).children('.third-nav-wrapper');
if (delayer) {
... ... @@ -742,7 +752,7 @@ function actionCover() {
if (window.location.href === 'http://www.yohobuy.com/' &&
(typeof gender === 'undefined' || gender === '' || gender === null)) {
$.get('/guide', function(data) {
$.get('/guide', function (data) {
newMask = document.createElement('div');
newMask.id = 'cover';
newMask.innerHTML = data;
... ... @@ -755,7 +765,7 @@ function actionCover() {
width: (200 * length) + 'px',
top: containertop + 'px'
});
$('#cover').bind('click', function() {
$('#cover').bind('click', function () {
window.setCookie('_Gender', '1,3', {
path: '/',
domain: '.yohobuy.com',
... ... @@ -768,7 +778,7 @@ function actionCover() {
});
closeCover();
});
$('#cover .guide-box .close').bind('click', function() {
$('#cover .guide-box .close').bind('click', function () {
getSource('弹窗', 'CLOSE', 'homepage_man');
window.setCookie('_Gender', '1,3', {
path: '/',
... ... @@ -782,7 +792,7 @@ function actionCover() {
});
closeCover();
});
$('.boys img , .boys .go').bind('click', function() {
$('.boys img , .boys .go').bind('click', function () {
getSource('弹窗', 'BOYS', 'homepage_man');
window.setCookie('_Gender', '1,3', {
path: '/',
... ... @@ -796,7 +806,7 @@ function actionCover() {
});
closeCover();
});
$('.girls img, .girls .go').bind('click', function() {
$('.girls img, .girls .go').bind('click', function () {
getSource('弹窗', 'GIRLS', 'homepage_woman');
window.setCookie('_Gender', '2,3', {
path: '/',
... ... @@ -809,7 +819,7 @@ function actionCover() {
expires: 7
});
});
$('.lifestyle img, .lifestyle .go').bind('click', function() {
$('.lifestyle img, .lifestyle .go').bind('click', function () {
window.setCookie('_Channel', 'lifestyle', {
path: '/',
domain: '.yohobuy.com',
... ... @@ -817,11 +827,11 @@ function actionCover() {
});
getSource('弹窗', 'LIEFSTYLE', 'homepage_lifestyle');
});
$('#cover .guide-box').bind('click', function(event) {
$('#cover .guide-box').bind('click', function (event) {
event.stopPropagation();
});
});
$('#cover .guide-box').bind('click', function(e) {
$('#cover .guide-box').bind('click', function (e) {
e.stopPropagation();
});
}
... ... @@ -831,7 +841,7 @@ window.submitSearch = submitSearch;
function emailUserCertTip() {
return $.getJSON('//www.yohobuy.com/passport/cert/headerTip?callback=?', function(jsonData) {
return $.getJSON('//www.yohobuy.com/passport/cert/headerTip?callback=?', function (jsonData) {
if (jsonData && jsonData.data === 'Y') {
$('#yoho-header .yoho-cert-tip').html(
'<i class="iconfont left">&#xe63f;</i> ' +
... ... @@ -852,7 +862,7 @@ function actionAddKeyWords() {
} else {
$searchKey.val(defaultSearch).css('color', '#999');
}
$(document).click(function(e) {
$(document).click(function (e) {
if (!$(e.target).closest('.searchspan, .search-list').length) {
$('.search-list').hide();
}
... ... @@ -866,45 +876,54 @@ function actionAddKeyWords() {
function searchSuggestHistory() {
let $queryKey = $('#query-key');
$.getJSON('//search.yohobuy.com/product/search/history?query=' +
encodeURIComponent($queryKey.val()), function(jsonData) {
var searchSuggestHistoryHtml;
encodeURIComponent($searchKey.val()), function (jsonData) {
searchSuggestHistoryHtml = handlebars.compile($searchHistoryHbs.html() || '');
$searchHistory.html(searchSuggestHistoryHtml(jsonData)).show();
if ($searchKey.val() === '') {
$('.search-suggest-title .searchDel').click(function() {
window.setCookie('_History', '', {domain: '.yohobuy.com'});
$(this).closest('.search-suggest-history').hide();
return false;
});
var searchSuggestHistoryHtml;
searchSuggestHistoryHtml = handlebars.compile($searchHistoryHbs.html() || '');
$searchHistory.html(searchSuggestHistoryHtml(jsonData)).show();
if($searchHistory.find("li").length === 0){
$searchHistory.hide();
}
//历史记录清空
$('.search-suggest-title .searchDel').click(function () {
window.setCookie('_History', '', {domain: '.yohobuy.com'});
$(this).closest('.search-suggest-history').hide();
return false;
});
}
});
}
/**
* 搜索 历史记录 dom
* @return {[type]} [description]
*/
$searchKey.keydown(function() {
}).focus(function() {
// if(e.keyCode === 13){
$searchKey.mouseenter(function () {
var val = $.trim($(this).val());
searchSuggestHistory();
if (val === '') {
if ($searchHistory && $searchHistory.length) {
val = val.replace(new RegExp('\'', 'gm'), ''); // 去掉特殊字符
searchSuggestHistory(val);
}
if (val == '') {
searchSuggestHistory();
}
}).mouseleave(function () {
$searchHistory.hide();
});
// }
$('.search-suggest-history').mouseenter(function () {
if($searchHistory.find("li").length === 0){
$searchHistory.hide();
}else{
$searchHistory.show();
}
}).mouseleave(function () {
$searchHistory.hide();
});
/**
... ... @@ -917,7 +936,7 @@ function searchSuggestRecommend(key) {
keyword: key
};
$.getJSON('//search.yohobuy.com/product/search/recommend?callback=?', param, function(jsonData) {
$.getJSON('//search.yohobuy.com/product/search/recommend?callback=?', param, function (jsonData) {
var searchSuggestRecommendHtml;
... ... @@ -939,7 +958,7 @@ function searchSuggestRecommend(key) {
* 搜索 热门搜索和默认搜索 dom
* @return {[type]} [description]
*/
$(function() {
$(function () {
searchSuggestRecommend();
});
... ...