comments-consults.js
1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* 商品详情 --评论和咨询tab
* @author: Lynnic
* @date: 2015/11/18
*/
var $ = require('jquery'),
tip = require('../../plugin/tip'),
Hammer = require('yoho.hammer');
var commentsNum,consultsNum;
var consultFooterEle = document.getElementById('consult-content-footer'),
consultFooterHammer = consultFooterEle && new Hammer(consultFooterEle),
navtabEle = document.getElementById('nav-tab'),
navtabHammer = navtabEle && new Hammer(navtabEle);
(function() {
consultsNum = $('#nav-tab .consults-num').html() - 0;
commentsNum = $('#nav-tab .comments-num').html() - 0;
$('#nav-tab li').each(function() {
$(this).removeClass('focus');
});
$('#feedback-content .content').each(function() {
$(this).addClass('hide');
});
if (0 !== commentsNum) {
$('#nav-tab .comment-nav').addClass('focus');
$('#feedback-content .comment-content').removeClass('hide');
} else if (0 !== consultsNum) {
$('#nav-tab .consult-nav').addClass('focus');
$('#feedback-content .consult-content').removeClass('hide');
}
})();
if (navtabHammer) {
navtabHammer.on('tap', function(e) {
var $this = $(e.target).closest('li');
var index = $this.index();
if ($this.hasClass('comment-nav') && 0 === commentsNum) {
tip.show('暂无商品评价');
} else {
if (!$this.hasClass('focus')) {
$('#nav-tab li').each(function() {
$this.removeClass('focus');
});
$('#feedback-content .content').each(function() {
$this.addClass('hide');
});
$this.addClass('focus');
$('#feedback-content .content:eq(' + index + ')').removeClass('hide');
}
}
});
}
if (consultFooterHammer) {
consultFooterHammer.on('tap', function() {
location.href = $(consultFooterEle).find('a').attr('href');
});
}