...
|
...
|
@@ -10,14 +10,16 @@ var $ = require('yoho-jquery'), |
|
|
|
|
|
var $filter;
|
|
|
|
|
|
var fCbFn, hCbFn; // 筛选和关闭的回调
|
|
|
var fCbFn, hCbFn; //筛选和关闭的回调
|
|
|
|
|
|
// 隐藏筛选界面
|
|
|
var missStatus; //是否忽略选中状态
|
|
|
|
|
|
//隐藏筛选界面
|
|
|
function hideFilter() {
|
|
|
$filter.addClass('hide');
|
|
|
}
|
|
|
|
|
|
// 显示筛选界面
|
|
|
//显示筛选界面
|
|
|
function showFilter() {
|
|
|
$filter.removeClass('hide');
|
|
|
}
|
...
|
...
|
@@ -27,8 +29,12 @@ function highlightMainItem() { |
|
|
var $mainItem = $('.filter-body .classify');
|
|
|
|
|
|
$mainItem.on('touchstart', '.shower', function() {
|
|
|
var bpIdData = $(this).attr('data-bp-id') || '';
|
|
|
|
|
|
$mainItem.removeClass('highlight');
|
|
|
$(this).addClass('highlight');
|
|
|
|
|
|
$(document).trigger('shouldSendBpData', [bpIdData]);
|
|
|
}).on('touchend touchcancel', '.shower', function() {
|
|
|
$(this).removeClass('highlight');
|
|
|
});
|
...
|
...
|
@@ -46,7 +52,7 @@ function highlightSubItem() { |
|
|
});
|
|
|
}
|
|
|
|
|
|
// 主筛选项Tap事件句柄
|
|
|
//主筛选项Tap事件句柄
|
|
|
function classifyTapEvt($this) {
|
|
|
if ($this.hasClass('active')) {
|
|
|
return;
|
...
|
...
|
@@ -55,9 +61,10 @@ function classifyTapEvt($this) { |
|
|
$this.siblings('.active').removeClass('active');
|
|
|
|
|
|
$this.addClass('active');
|
|
|
|
|
|
}
|
|
|
|
|
|
// 子筛选项选中处理
|
|
|
//子筛选项选中处理
|
|
|
function setSubClassify($this) {
|
|
|
var $sub = $this.closest('.sub-classify');
|
|
|
|
...
|
...
|
@@ -77,8 +84,8 @@ function setSubClassify($this) { |
|
|
shower = $.trim($shower.html());
|
|
|
|
|
|
$shower.html(
|
|
|
shower.substring(0, shower.indexOf('</span>') + 7) + // 拆分出shower的title
|
|
|
html.substring(0, html.indexOf('<i')) // 拆分选中筛选值
|
|
|
shower.substring(0, shower.indexOf('</span>') + 7) + //拆分出shower的title
|
|
|
html.substring(0, html.indexOf('<i')) //拆分选中筛选值
|
|
|
);
|
|
|
|
|
|
if ($this.index() === 0) {
|
...
|
...
|
@@ -90,7 +97,7 @@ function setSubClassify($this) { |
|
|
return $sub;
|
|
|
}
|
|
|
|
|
|
// 子筛选项Tap句柄
|
|
|
//子筛选项Tap句柄
|
|
|
function subClassifyTapEvt($this) {
|
|
|
var id = $this.data('id');
|
|
|
|
...
|
...
|
@@ -105,52 +112,41 @@ function subClassifyTapEvt($this) { |
|
|
});
|
|
|
}
|
|
|
|
|
|
if (hCbFn) {
|
|
|
hCbFn();
|
|
|
}
|
|
|
|
|
|
hideFilter();
|
|
|
}
|
|
|
|
|
|
// 初始化筛选
|
|
|
//初始化筛选
|
|
|
function initFilter(opt) {
|
|
|
var filterHammer;
|
|
|
|
|
|
// 注册回调
|
|
|
//注册回调
|
|
|
fCbFn = opt.fCbFn;
|
|
|
hCbFn = opt.hCbFn;
|
|
|
|
|
|
// 是否忽略选中状态
|
|
|
window.missStatus = opt.missStatus;
|
|
|
missStatus = opt.missStatus;
|
|
|
|
|
|
highlightMainItem();
|
|
|
highlightSubItem();
|
|
|
|
|
|
$filter = $('.filter-mask');
|
|
|
|
|
|
// 页面没有filter的时候什么都不做
|
|
|
if (!$filter[0]) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
filterHammer = new Hammer($filter[0]);
|
|
|
filterHammer.on('tap', function(e) {
|
|
|
var $this = $(e.target),
|
|
|
$cur;
|
|
|
|
|
|
e.preventDefault();// 防止透点
|
|
|
// e.preventDefault();//防止透点
|
|
|
|
|
|
if ($this.closest('.filter-body').length > 0) {
|
|
|
$cur = $this.closest('.sub-item');
|
|
|
if ($cur.length > 0) {
|
|
|
|
|
|
// tap subclassify
|
|
|
//tap subclassify
|
|
|
$cur = $this.closest('li');
|
|
|
|
|
|
subClassifyTapEvt($cur);
|
|
|
} else {
|
|
|
|
|
|
// tap classify
|
|
|
//tap classify
|
|
|
$cur = $this.closest('.classify-item');
|
|
|
|
|
|
e.srcEvent.stopPropagation();
|
...
|
...
|
@@ -165,21 +161,56 @@ function initFilter(opt) { |
|
|
}
|
|
|
}
|
|
|
});
|
|
|
if(opt.isScroll){
|
|
|
$("ul.sub-classify").each(function(){
|
|
|
|
|
|
$(this).wrap("<div class='sub-classify-farther' data-type='" + $(this).data("type") + "'></div>");
|
|
|
// $(this).removeClass("sub-classify");
|
|
|
|
|
|
var lastY=0,y=0;
|
|
|
var $slider=$(this);
|
|
|
|
|
|
$slider.on('touchstart', function(e) {
|
|
|
lastY = e.originalEvent.touches[0].pageY;
|
|
|
});
|
|
|
$slider.on('touchmove', function(e) {
|
|
|
var curY = e.originalEvent.touches[0].pageY;
|
|
|
var deltaY = curY - lastY;
|
|
|
var height = $(this)[0].scrollHeight;
|
|
|
var limit = height - $(this).parent().height();
|
|
|
y = y + deltaY;
|
|
|
if (y < limit * -1)
|
|
|
y = limit * -1;
|
|
|
if (y > 0)
|
|
|
y = 0;
|
|
|
var translate = 'translate3d(0,' + y + 'px,0)';
|
|
|
$(this).css({
|
|
|
'-moz-transform': translate,
|
|
|
'-ms-transform': translate,
|
|
|
'transform': translate,
|
|
|
'-webkit-transform': translate,
|
|
|
});
|
|
|
lastY = curY;
|
|
|
});
|
|
|
$slider.on('touchend', function(e) {});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
// 重置筛选面板
|
|
|
//重置筛选面板
|
|
|
function resetFilter() {
|
|
|
if (typeof $filter === 'undefined') {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 重置子筛选项
|
|
|
//重置子筛选项
|
|
|
$('.sub-classify').each(function() {
|
|
|
setSubClassify($(this).children(':first-child'));
|
|
|
});
|
|
|
|
|
|
// 重置主筛选项
|
|
|
//重置主筛选项
|
|
|
classifyTapEvt($('.classify > :first-child'));
|
|
|
}
|
|
|
|
...
|
...
|
|