detail.js
1.68 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* PLUS+STAR详情页
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/10
*/
var $ = require('jquery'),
ellipsis = require('mlellipsis'),
lazyLoad = require('yoho.lazyload');
var $intro = $('#intro'),
$imt = $('#intro-more-txt'),
$infosContainer = $('#related-infos-container');
var info = require('../info');
var tip = require('../../plugin/tip');
var brandId = $('#brand-info').data('id');
var mIntro, aIntro;
ellipsis.init();
//Init LazyLoad
lazyLoad($('img.lazy'));
//文字介绍文字截取
$intro[0].mlellipsis(3);
//获取截取文字和完整文字
setTimeout(function() {
mIntro = $intro.text();
aIntro = $intro.attr('title');
});
info.initInfosEvt($infosContainer);
//文字介绍收起与展开
$('#more-intro').bind('tap', function() {
var $this = $(this);
$this.toggleClass('spread');
if ($this.hasClass('spread')) {
//显示
$intro.text(aIntro);
$imt.text('收起');
} else {
//隐藏
$intro.text(mIntro);
$imt.text('more');
}
});
//品牌收藏
$('#brand-like').bind('tap', function(e) {
var opt = 'ok',
$this = $(this);
e.preventDefault();
if ($this.hasClass('like')) {
opt = 'cancel';
}
$.ajax({
type: 'POST',
url: '/product/opt/favoriteBrand',
data: {
id: brandId,
opt: opt
},
success: function(data) {
if (data.code === 200) {
$this.toggleClass('like');
} else if (data.code === 400) {
tip.show('未登录');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
});