...
|
...
|
@@ -16,7 +16,11 @@ var searchH = $('.newbrand-search').outerHeight(), |
|
|
headerH = $('.yoho-header').outerHeight(),
|
|
|
brandSwipe = parseInt(searchH) + parseInt(headerH) - 1;
|
|
|
|
|
|
var myHammer;
|
|
|
var myHammer,
|
|
|
searchHammer,
|
|
|
clearTextHammer,
|
|
|
brandsData,
|
|
|
$keyword;
|
|
|
|
|
|
swiper = new Swiper('.swiper-container', {
|
|
|
lazyLoading: true,
|
...
|
...
|
@@ -32,8 +36,7 @@ $('.yoho-header').css({ |
|
|
});
|
|
|
$('.banner-top').css('padding-top', '90px');
|
|
|
|
|
|
if ($brandList.length > 0) {
|
|
|
$(window).scroll(function() {
|
|
|
$(window).scroll(function() {
|
|
|
var scrTop = $(window).scrollTop();
|
|
|
|
|
|
$('.brand-list').each(function() {
|
...
|
...
|
@@ -49,10 +52,9 @@ if ($brandList.length > 0) { |
|
|
$(this).find('.title-bar').css('position', 'static');
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if ($('#right-bar .con').find('b').unbind()[0]) {
|
|
|
function rightBarBindClick() {
|
|
|
myHammer = new Hammer($('#right-bar .con').find('b').unbind()[0]);
|
|
|
myHammer.on('tap', function(e) {
|
|
|
var index = $(this).index();
|
...
|
...
|
@@ -63,49 +65,118 @@ if ($('#right-bar .con').find('b').unbind()[0]) { |
|
|
});
|
|
|
}
|
|
|
|
|
|
function searchResult(type) {
|
|
|
var keyword = $('#keyword').val(),
|
|
|
gender = $('#gender').val();
|
|
|
if ($('#right-bar .con').find('b').unbind()[0]) {
|
|
|
rightBarBindClick();
|
|
|
}
|
|
|
|
|
|
$.get('/brands/search', {
|
|
|
keyword: keyword,
|
|
|
gender: gender,
|
|
|
type: type
|
|
|
}, function(html) {
|
|
|
$('.search-result').html(html);
|
|
|
/**
|
|
|
* 品牌搜索
|
|
|
*/
|
|
|
|
|
|
function searchResult() {
|
|
|
var keyword = ($keyword.val() + '').toLowerCase();
|
|
|
var result = {},
|
|
|
i = 0,
|
|
|
rightBarHtml,
|
|
|
html = '';
|
|
|
|
|
|
// 遍历首字母搜索
|
|
|
$.each(brandsData, function(k, v) {
|
|
|
if ($.isArray(v)) {
|
|
|
|
|
|
// 遍历品牌,进行匹配
|
|
|
$.each(v, function(i, brand) {
|
|
|
if (brand.name.toLowerCase().indexOf(keyword) > -1) {
|
|
|
result[k] = result[k] || [];
|
|
|
result[k].push(brand);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 根据搜索结果生成 HTML
|
|
|
rightBarHtml = '<div id="right-bar" class="right-bar"><div class="con" id="con">';
|
|
|
$.each(result, function(k, v) {
|
|
|
var brandHtml = ['<div class="brand-list bar-', i, '">'];
|
|
|
|
|
|
i++;
|
|
|
brandHtml.push('<div class="title-bar"><h2>');
|
|
|
brandHtml.push(k);
|
|
|
brandHtml.push('</h2></div>');
|
|
|
$.each(v, function(i, brand) {
|
|
|
brandHtml.push('<p><a href="' + brand.url + '">' + brand.name);
|
|
|
if (brand.isNew) {
|
|
|
brandHtml.push('<i class="icon-hot">Hot</i>');
|
|
|
}
|
|
|
if (brand.isHot) {
|
|
|
brandHtml.push('<i class="icon-new">New</i>');
|
|
|
}
|
|
|
brandHtml.push('</a></p>');
|
|
|
});
|
|
|
brandHtml.push('</div>');
|
|
|
html += brandHtml.join('');
|
|
|
|
|
|
if (k.indexOf(0) > -1) {
|
|
|
k = '#';
|
|
|
}
|
|
|
|
|
|
rightBarHtml = rightBarHtml + '<b>' + k + '</b>';
|
|
|
});
|
|
|
|
|
|
rightBarHtml += '</div>';
|
|
|
|
|
|
if (Object.keys(result).length > 0) {
|
|
|
html += rightBarHtml;
|
|
|
}
|
|
|
|
|
|
// 插入 dom,绑定事件
|
|
|
$('.search-result').html(html);
|
|
|
|
|
|
if (Object.keys(result).length > 0) {
|
|
|
rightBarBindClick();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$('#keyword').on('keyup', function() {
|
|
|
searchResult(0);
|
|
|
}).on('keydown', function() {
|
|
|
if ($('.brand-search-page').length) {
|
|
|
brandsData = $.parseJSON($('#brands-data').html());
|
|
|
$keyword = $('#keyword');
|
|
|
|
|
|
$keyword.on('input', function() {
|
|
|
if ($keyword.val().length) {
|
|
|
searchResult();
|
|
|
$(this).closest('.search-box').css('width', '11.25rem');
|
|
|
$('.search-action').show();
|
|
|
}).on('blur', function() {
|
|
|
} else {
|
|
|
$(this).closest('.search-box').css('width', '12.5rem');
|
|
|
$('.search-action').hide();
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$('#search-btn').on('tap', function() {
|
|
|
searchResult(1);
|
|
|
});
|
|
|
searchHammer = new Hammer($('.search-btn')[0]);
|
|
|
searchHammer.on('tap', function() {
|
|
|
searchResult();
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
$('.clear-text').on('tap', function() {
|
|
|
$('#keyword').val('').trigger('input');
|
|
|
});
|
|
|
clearTextHammer = new Hammer($('.clear-text')[0]);
|
|
|
clearTextHammer.on('tap', function() {
|
|
|
$keyword.val('').trigger('input');
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
$('form.search-box').on('submit', function() {
|
|
|
$('form.search-box').on('submit', function() {
|
|
|
return false;
|
|
|
});
|
|
|
});
|
|
|
|
|
|
$('.clear-history').on('tap', function() {
|
|
|
// clearHistoryHammer = new Hammer($('#clear-text')[0]);
|
|
|
// clearHistoryHammer.on('tap', function() {
|
|
|
|
|
|
// setcookie('h_brands', '', {
|
|
|
// expire: -1,
|
|
|
// path: '/',
|
|
|
// domain: '.m.yohobuy.com'
|
|
|
// // setcookie('h_brands', '', {
|
|
|
// // expire: -1,
|
|
|
// // path: '/',
|
|
|
// // domain: '.m.yohobuy.com'
|
|
|
// // });
|
|
|
// $('#history-keyword').remove();
|
|
|
// $(this).hide();
|
|
|
// });
|
|
|
$('#history-keyword').remove();
|
|
|
$(this).hide();
|
|
|
}); |
|
|
} |
...
|
...
|
|