Authored by htoooth

Merge branch 'feature/searchTerms' into release/5.5

... ... @@ -121,7 +121,7 @@ const serachFilterBrands = (req, res, next) => {
const searchHistory = (req, res) => {
let history = _.trim(req.cookies['_History']); //eslint-disable-line
let q = _.trim(decodeURIComponent(req.query.query) || '');
let q = _.trim(decodeURIComponent(req.query.query));
let data = [];
let ResData = {};
... ... @@ -129,7 +129,7 @@ const searchHistory = (req, res) => {
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,
... ... @@ -138,12 +138,13 @@ const searchHistory = (req, res) => {
}
_.forEach(history, function(item) {
if (item !== 'undefined') {
let list = {};
let list = {};
list['keyword'] = item; //eslint-disable-line
list['href'] = helpers.urlFormat('', {query: list['keyword']}, 'search'); //eslint-disable-line
data.push(list);
list['keyword'] = item; //eslint-disable-line
list['href'] = helpers.urlFormat('', {query: list['keyword']}, 'search'); //eslint-disable-line
data.push(list);
}
});
ResData['data'] = data; //eslint-disable-line
... ...
... ... @@ -328,6 +328,7 @@ function submitSearch() {
if (searchKey === '') {
$('#query-key').val(defaultSearch);
}
$searchKey.val(searchKey);
$searchForm.submit();
}
... ... @@ -927,9 +928,14 @@ function actionAddKeyWords() {
function searchSuggestHistory() {
var param = {
return_type: 'jsonp',
query: encodeURIComponent(window.queryString().query) || ''
query: window.queryString().query
};
if ($searchKey.attr('alt')) {
param.query = '';
$searchKey.attr('alt', false);
}
$.getJSON('//search.yohobuy.com/product/search/history?callback=?', param, function(jsonData) {
if ($searchKey.val() === '') {
... ... @@ -949,6 +955,7 @@ function searchSuggestHistory() {
$('.search-suggest-title .searchDel').click(function() {
window.setCookie('_History', '', {domain: '.yohobuy.com'});
$(this).closest('.search-suggest-history').hide();
$searchKey.attr('alt', true);
return false;
});
... ... @@ -1008,7 +1015,9 @@ function searchSuggestRecommend(channel, key) {
*/
$(function() {
searchSuggestRecommend();
searchSuggestHistory();
if (location.href.indexOf('www.yohobuy.com') < 0) {
searchSuggestHistory();
}
});
actionCover();
... ...