ps.js
6.13 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/**
* plus+star页js
* @author: xuqi(qi.xu@yoho.cn)
* @date;2015/4/16
*/
var $ = require('jquery'),
Mustache = require('mustache'),
ellipsis = require('mlellipsis');
require('lazyload');
/**
* 初始化页面功能
*/
exports.init = function() {
$(function() {
var $intro = $('#intro'),
$moreIntro = $('#more-intro'),
$introTxt = $moreIntro.find('.more-intro-text'),
$iconUp = $moreIntro.find('.up'),
$iconDown = $moreIntro.find('.down'),
winH = $(window).height(),
mIntro, //品牌介绍文字介绍
aIntro,
tpl;
var isLogin = $('#is-login').val();
isLogin = isLogin ? isLogin : 'N';
//登录提示变量
var $loginTip = $('#login-tip'),
winW,
tipH,
tipW;
//获取相关资讯模板
$.get('/common/articletpl', function(data) {
tpl = data;
Mustache.parse(tpl); //pre-compile and cache template
});
//文字截取
ellipsis.init();
setTimeout(function() {
$intro.mlellipsis(3); //品牌介绍
$('.info-block-content, .info-block-title').each(function() { //相关文章
$(this).mlellipsis(2);
});
mIntro = $intro.text();
aIntro = $intro.attr('_title');
}, 0);
//lazyload
$('img.lazy').lazyload();
aIntro = $intro.attr('_title');
//显示品牌介绍所有文字/隐藏
function showMoreIntro() {
$moreIntro.toggleClass('show');
if ($moreIntro.hasClass('show')) {
$intro.text(aIntro);
$introTxt.text('收起');
$iconDown.addClass('hide');
$iconUp.removeClass('hide');
} else {
$intro.text(mIntro);
$introTxt.text('more');
$iconUp.addClass('hide');
$iconDown.removeClass('hide');
}
}
$moreIntro.delegate('.more', 'click', function() {
showMoreIntro();
});
//提示信息位置
winW = $(window).width();
tipH = $loginTip.height();
tipW = $loginTip.width();
$loginTip.css({
top: (winH - tipH) / 2,
left: (winW - tipW) / 2
});
//绑定商品信息的收藏和取消收藏事件(相关推荐和搭配模块)
$('.new-arrival-content').delegate('.good-islike', 'touchstart', function(e) {
var $cur,
$good,
id;
if (isLogin === 'N') {
$cur = $(e.currentTarget);
$good = $cur.closest('.good-info');
id = $good.data('id');
$.ajax({
type: 'GET',
url: '/favorite/product',
data: {
st: 0,
product_skn: id
}
}).then(function(data) {
if (data.code === 200) {
$cur.toggleClass('good-like');
} else if (data.code === 400) {
//提示登录信息
$('#login-tip').fadeIn(500, function() {
setTimeout(function() {
$('#login-tip').fadeOut(500);
}, 1000);
});
}
});
}
}).delegate('.good-islike', 'click', function(e) {
if (isLogin === 'N') {
e.preventDefault();
}
});
//文章点赞
$('#info-content').delegate('.like-btn', 'touchstart', function(e) {
var $cur = $(e.currentTarget),
$info = $cur.closest('.info-block'),
id = $info.data('id');
//取消点赞的处理
if ($cur.hasClass('like')) {
$cur.next('span.like-count').text('');
$cur.toggleClass('like');
return;
}
$.ajax({
type: 'GET',
url: '/favorite/praise',
data: {
id: id
}
}).then(function(data) {
if (data.code === 200) {
$cur.toggleClass('like');
//更新点赞数
$cur.next('span.like-count').text(data.data);
} else if (data.code === 400) {
//提示登录信息
$('#login-tip').fadeIn(500, function() {
setTimeout(function() {
$('#login-tip').fadeOut(500);
}, 1000);
});
}
});
});
$('#brand-like').bind('touchstart', function(e) {
var $cur,
id;
if (isLogin === 'Y') {
$cur = $(this);
id = $(this).closest('.brand-info').data('id');
//
$.ajax({
type: 'GET',
url: '/favorite/brand',
data: {
brand_id: id
}
}).then(function(data) {
if (data.code === 200) {
$cur.toggleClass('like');
} else if (data.code === 400) {
$('#login-tip').fadeIn(500, function() {
setTimeout(function() {
$('#login-tip').fadeOut(500);
}, 1000);
});
}
});
}
}).bind('click', function(e) {
if (isLogin === 'Y') {
//阻止链接跳转
e.preventDefault();
}
});
});
};