...
|
...
|
@@ -17,10 +17,19 @@ moreUnicode = { |
|
|
|
|
|
var $brandDefault = $('.brand .default'),
|
|
|
$brandPanel = $('.brand .brand-panel'),
|
|
|
$brandMore = $('#brand-more');
|
|
|
$brandAttrs = $('.brand .attr'),
|
|
|
$brandMore = $('#brand-more'),
|
|
|
$brandMulti = $('#brand-multi');
|
|
|
|
|
|
var $brandMoreTxt, $brandMoreIcon;
|
|
|
|
|
|
// var uriLoc = require('./uri');
|
|
|
|
|
|
//清除checkbox选中状态
|
|
|
function clearChecked($checkbox) {
|
|
|
$checkbox.removeClass('checked').html(checkUnicode.unchecked);
|
|
|
}
|
|
|
|
|
|
//显示更多品牌面板
|
|
|
function brandShowMore() {
|
|
|
$brandDefault.addClass('hide');
|
...
|
...
|
@@ -33,19 +42,36 @@ function brandHideMore() { |
|
|
$brandDefault.removeClass('hide');
|
|
|
}
|
|
|
|
|
|
//url构造&跳转
|
|
|
function uriLoc(attr, val) {
|
|
|
var href = decodeURIComponent(window.location.search),
|
|
|
query = attr + '=' + val,
|
|
|
newHref;
|
|
|
|
|
|
if (href === '') {
|
|
|
newHref = '?' + query;
|
|
|
} else {
|
|
|
newHref = href + '&' + query;
|
|
|
}
|
|
|
|
|
|
window.location.href = newHref;
|
|
|
}
|
|
|
|
|
|
if ($brandMore.length > 0) {
|
|
|
$brandMoreTxt = $brandMore.children('em');
|
|
|
$brandMoreIcon = $brandMore.children('.iconfont');
|
|
|
}
|
|
|
|
|
|
//屏蔽筛选项双击文字选中
|
|
|
$('.filter-box').on('selectstart', '.attr', function() {
|
|
|
$('.filter-box').on('selectstart', '.attr, .brands-index span', function() {
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
//checkbox
|
|
|
$('.check-container').on('click', '.attr', function() {
|
|
|
var $check = $(this).find('.checkbox');
|
|
|
var $this = $(this),
|
|
|
$check = $this.find('.checkbox'),
|
|
|
$btnOk = $this.parent('.check-container').next('.btns').find('.multi-select-ok');
|
|
|
|
|
|
$check.toggleClass('checked');
|
|
|
|
...
|
...
|
@@ -54,10 +80,18 @@ $('.check-container').on('click', '.attr', function() { |
|
|
} else {
|
|
|
$check.html(checkUnicode.unchecked);
|
|
|
}
|
|
|
|
|
|
//更新按钮状态
|
|
|
if ($check.hasClass('checked') ||
|
|
|
$this.siblings('.attr').find('.checked').length > 0) {
|
|
|
$btnOk.removeClass('dis');
|
|
|
} else {
|
|
|
$btnOk.addClass('dis');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//品牌多选
|
|
|
$('#brand-multi').click(function() {
|
|
|
$brandMulti.click(function() {
|
|
|
if ($brandPanel.css('display') === 'none') {
|
|
|
|
|
|
//显示品牌面板
|
...
|
...
|
@@ -86,7 +120,139 @@ $brandMore.click(function() { |
|
|
$(this).toggleClass('more');
|
|
|
});
|
|
|
|
|
|
//品牌索引
|
|
|
$('.brands-index').on('click', 'span', function() {
|
|
|
var $this = $(this),
|
|
|
index = $this.data('index');
|
|
|
|
|
|
if ($this.index() === 0) {
|
|
|
|
|
|
//全部
|
|
|
$brandAttrs.removeClass('hide');
|
|
|
} else {
|
|
|
$brandAttrs.addClass('hide').filter('[data-index=' + index + ']').removeClass('hide');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//品牌搜索
|
|
|
$('#brand-search-input').keyup(function() {
|
|
|
var val = $(this).val().toLowerCase();
|
|
|
|
|
|
if (val === '') {
|
|
|
$brandAttrs.removeClass('hide');
|
|
|
} else {
|
|
|
$brandAttrs.addClass('hide').filter('[data-key*=' + val + ']').removeClass('hide');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$('#brand-multi-ok').click(function() {
|
|
|
var val = '';
|
|
|
|
|
|
if ($(this).hasClass('dis')) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$brandPanel.find('.checked').each(function() {
|
|
|
var id = $(this).data('id');
|
|
|
|
|
|
val += (val === '') ? id : (',' + id);
|
|
|
});
|
|
|
|
|
|
uriLoc('brand', val);
|
|
|
});
|
|
|
|
|
|
//多选取消(品牌/高级选项)
|
|
|
$('.multi-select-cancel').click(function() {
|
|
|
var $panel = $(this).closest('.multi');
|
|
|
|
|
|
if ($panel.hasClass('brand-panel')) {
|
|
|
brandHideMore();
|
|
|
|
|
|
$brandMulti.removeClass('hide'); //显示多选按钮
|
|
|
}
|
|
|
|
|
|
$panel.removeClass('multi');
|
|
|
clearChecked($panel.find('.checkbox.checked')); //清除选中状态
|
|
|
});
|
|
|
|
|
|
//用户定义价格处理
|
|
|
(function() {
|
|
|
var $udPrice = $('.ud-price-range'),
|
|
|
interReg = /^\d+$/,
|
|
|
$limit, $min, $max, $btn;
|
|
|
|
|
|
if ($udPrice.length === 0) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$limit = $udPrice.find('.limit');
|
|
|
$min = $limit.filter('.min');
|
|
|
$max = $limit.filter('.max');
|
|
|
$btn = $udPrice.find('.price-sure');
|
|
|
|
|
|
$limit.keyup(function() {
|
|
|
var min = $.trim($min.val()),
|
|
|
max = $.trim($max.val()),
|
|
|
isMinInt = interReg.test(min),
|
|
|
isMaxInt = interReg.test(max);
|
|
|
|
|
|
if (isMaxInt && (min === '' || isMinInt) ||
|
|
|
isMinInt && (max === '' || isMaxInt)
|
|
|
) {
|
|
|
$btn.removeClass('hide');
|
|
|
} else {
|
|
|
$btn.addClass('hide');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//价格多项查询
|
|
|
$btn.click(function() {
|
|
|
var min = $.trim($min.val()),
|
|
|
max = $.trim($max.val()),
|
|
|
tmp;
|
|
|
|
|
|
//对于min大于max的情况,交换位置
|
|
|
if (min !== '' && max !== '' && +min > +max) {
|
|
|
tmp = max;
|
|
|
max = min;
|
|
|
min = tmp;
|
|
|
}
|
|
|
|
|
|
uriLoc('price', min + ',' + max);
|
|
|
});
|
|
|
}());
|
|
|
|
|
|
//高级选项
|
|
|
$('.senior-attr-wrap').on('mouseenter', '.attr', function() {
|
|
|
$(this).children('.sub').removeClass('hide');
|
|
|
}).on('mouseleave', '.attr', function() {
|
|
|
$(this).children('.sub').addClass('hide');
|
|
|
});
|
|
|
|
|
|
//高级选项多选
|
|
|
$('.sub-senior-wrap').on('click', '.multi-select', function() {
|
|
|
$('.sub').on('click', '.multi-select', function() {
|
|
|
$(this).closest('.sub').addClass('multi');
|
|
|
}).on('click', '.multi-select-ok', function() {
|
|
|
var $btn = $(this),
|
|
|
$sub = $btn.closest('.sub'),
|
|
|
val = '';
|
|
|
|
|
|
if ($btn.hasClass('dis')) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$sub.find('.checked').each(function() {
|
|
|
var id = $(this).data('id');
|
|
|
|
|
|
val += (val === '') ? id : (',' + id);
|
|
|
});
|
|
|
|
|
|
uriLoc($sub.data('attr'), val);
|
|
|
});
|
|
|
|
|
|
//当多选时阻止品牌和高级选项的默认跳转
|
|
|
$('.brand, .senior').on('click', '.attr > a', function(e) {
|
|
|
if ($(this).closest('.multi').length > 0) {
|
|
|
e.preventDefault();
|
|
|
}
|
|
|
}); |
|
|
\ No newline at end of file |
...
|
...
|
|