info-index.page.js
9.24 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/**
* 逛详情页
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/13
*/
require('guang/info-index.page.css');
let $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload');
let $authorIntro = $('.author .intro');
// collocation block variable
let $fixedThumbContainer = $(''),
$coBlock,
$thumbContainer = $('.thumb-container');
let $sideNav = $('.side-nav'),
$guangPage = $('.guang-detail-page'),
$overlay = $('.overlay'),
$subNav = $('.sub-nav');
let $relatedRecoMore = $('.related-reco-more'); // 展开更多
let time = 0;
require('common');
require('plugin/wx-share')();
require('./detail-dynamic');
require('./detail/guang-cart');
require('./detail/guang-comments');
let CollactionBlock = require('./collocation-block');
$('#wrapper').css({
'overflow-y': 'scroll'
});
// 初始化iscroll
function initIscroll() {
let $yohoHeader = $('.yoho-header');
let hH = 0,
winH, tcH, cbH, cbTop, fixedThumbDom;
if (CollactionBlock.exists()) {
new CollactionBlock();
}
// 考虑通用头部的影响:对offset().top以及winH做对应偏移
if ($yohoHeader.length > 0) {
hH = $yohoHeader.outerHeight();
}
winH = $(window).height() - hH;
fixedThumbDom = $fixedThumbContainer[0];
tcH = $thumbContainer ? $thumbContainer.outerHeight() : 0;
if ($coBlock) {
cbH = $coBlock.outerHeight();
cbTop = $coBlock.offset().top - hH;
}
$(window).on('scroll', function() {
let sTop = -this.y;
let classList = fixedThumbDom && fixedThumbDom.className;
if (sTop <= cbTop - winH + tcH) {
if (classList.indexOf('fixed-bottom') === -1) {
$fixedThumbContainer
.addClass('fixed-bottom')
.removeClass('hide');
}
} else if (sTop <= cbTop) {
if (classList.indexOf('hide') === -1) {
$fixedThumbContainer
.addClass('hide')
.removeClass('fixed-bottom fixed-top');
}
} else if (sTop <= cbTop + cbH - tcH) {
if (classList.indexOf('fixed-top') === -1) {
$fixedThumbContainer
.addClass('fixed-top')
.removeClass('hide absolute')
.css('top', '');
}
} else if (sTop <= cbTop + cbH) {
if (classList.indexOf('absolute') === -1) {
$fixedThumbContainer
.addClass('absolute')
.removeClass('fixed-top hide');
}
fixedThumbDom.style.top = cbTop + hH + cbH - tcH - sTop + 'px';
} else if (sTop > cbTop + cbH) {
if (classList.indexOf('hide') === -1) {
$fixedThumbContainer
.addClass('hide')
.removeClass('absolute');
}
}
});
// 评论滚动加载
// setTimeout(function() {
// let afterScroll = document.body.scrollTop;
// if (afterScroll - beforeScroll > 0) {
// window.requestAnimationFrame(scrollHandler);
// beforeScroll = afterScroll;
// } else {
// return false;
// }
// }, 5);
}
/**
* 相关商品点击事件
*/
$relatedRecoMore.on('touchstart', function(e) {
let $relatedRecoBlock = $(e.currentTarget).parent().find('.related-reco-block');
if ($relatedRecoBlock.hasClass('related-reco-hide')) {
$relatedRecoBlock.removeClass('related-reco-hide');
$(e.currentTarget).remove();
} else {
$relatedRecoBlock.addClass('related-reco-hide');
}
return false;
});
// 微信导航
$('.nav-btn').on('touchstart', function() {
$sideNav.css('pointer-events', 'none');
$guangPage.addClass('menu-open');
$overlay.show().css({
opacity: 0.3,
height: $('#scroller').height()
});
$sideNav.addClass('on');
setTimeout(function() {
$sideNav.css('pointer-events', 'auto');
}, 400);
return false;
});
// 点击一级导航,弹出二级导航
$sideNav.on('touchend', 'li', function(e) {
if ($(this).find('.sub-nav').size() > 0) {
$('.sub-nav').removeClass('show');
$(this).find('.sub-nav').addClass('show');
$(this).find('.highlight').removeClass('highlight');
}
if (e.target.pathname === location.pathname) {
hideSideBar(); // eslint-disable-line
return false;
}
});
// 返回一级导航,收起二级导航
$subNav.each(function() {
$(this).find('li').eq(0).on('click', function() {
$('.sub-nav').removeClass('show');
return false;
});
}).on('touchstart', function(e) {
if (e.currentTarget !== e.target) {
$subNav.find('li').removeClass('current');
}
});
// 侧边栏点击背景色变化
function highlight($elem) {
$elem.find('li').on('touchstart', function() {
$elem.find('.highlight').removeClass('highlight');
$(this).addClass('highlight');
}).on('touchend touchcancel', function() {
$(this).removeClass('highlight');
});
}
highlight($sideNav);
highlight($subNav);
function hideSideBar() {
if ($guangPage.hasClass('menu-open')) {
$guangPage.removeClass('menu-open');
$overlay.hide();
$('.sub-nav').removeClass('show');
$sideNav.removeClass('on');
}
}
$overlay.on('touchstart', function() {
hideSideBar();
return false;
});
function setCookie(name, value, options) {
let expires = '',
path,
domain,
secure,
date;
if (typeof value !== 'undefined') {
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
if (options.expires &&
(typeof options.expires === 'number' || options.expires.toUTCString)) {
if (typeof options.expires === 'number') {
date = new Date();
date.setTime(Date.parse((new Date()).toLocaleDateString()) + 86400 * 1000);
} else {
date = options.expires;
}
expires = '; expires=' + date.toGMTString();
}
path = options.path ? '; path=' + options.path : '';
domain = options.domain ? '; domain=' + options.domain : '';
secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
}
}
// 长按二维码埋点
$('.wei-share').on('touchstart', function() {
time = setTimeout(function() {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_PRESS_QRCODE',
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')],
PAGE_URL: window.location.href
})
}, true);
}
}, 500);
});
$('.wei-share').on('touchend', function(e) {
e.stopPropagation();
clearTimeout(time);
});
// 初始化页面,包括是否使用iscorll初始化页面
// 接口暴露在HTML中,使用压缩名
(function() {
let isweixin = navigator.userAgent.indexOf('MicroMessenger') ? true : false;
// pagecache 前端判断是否显示头
let param = location.search;
let isHeader = navigator.userAgent.indexOf('MicroMessenger') > -1 ||
param.indexOf('app_version') > -1 || param.indexOf('appVersion') > -1;
isHeader && $('#yoho-header').remove();
$('.main-wrap').css({
position: 'static'
});
lazyLoad($('.lazy'));
// offset.left约等于marginLeft的值则表示介绍被换行,则清除intro的paddingTop让其更靠近头像和作者名
if ($authorIntro.offset() && (parseInt($authorIntro.offset().left, 10) ===
parseInt($authorIntro.css('margin-left'), 10))) {
$authorIntro.css('padding-top', 0);
}
if (isweixin) {
$overlay.css('position', 'absolute');
}
$('#float-layer-close').on('touchend', function() {
let appClose = window.cookie('_float-layer-app-close') || '0';
if (parseInt(appClose, 10) === 0) {
setCookie('_float-layer-app-close', 1, {expires: -1});
} else if (parseInt(appClose, 10) === 1) {
setCookie('_float-layer-app-close', 2, {expires: -1});
}
$('#float-layer-app').hide();
$('.down-bottom').hide();
return false;
});
if ($('#float-layer-btn') && $('#float-layer-btn')[0]) {
$('#float-layer-btn').on('touchstart', function(e) {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_DOWNLOAD_C',
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')],
TO_URL: 'http://www.yohoshow.com/about/index/yohobuyqr'
})
}, true);
}
window.location = 'http://www.yohoshow.com/about/index/yohobuyqr';
e.srcEvent.stopPropagation();
});
if (typeof window.cookie === 'function' && parseInt(window.cookie('_float-layer-app-close'), 10) !== 2) {
$('.down-bottom').show();
} else {
$('.down-bottom').hide();
}
}
initIscroll();
}());