recommend-for-you-product-desc.js
2.45 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
/**
* 为您优选
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/11/16
*/
var lazyLoad = require('yoho-jquery-lazyload'),
$ = require('yoho-jquery');
var $recommendForYou = $('.recommend-for-you'),
preferenceUrl = $('#preferenceUrl').val(),
winH = $(window).height(),
end = false,
requesting = false;
var RECID = (new Date().getTime() + '_H5_YOHOBUY_' + Math.floor(Math.random() * 1000000 + 1000000) +
'_' + Math.floor(Math.random() * 1000000 + 1000000));
var C_ID, goodid, goodIds = [],
prdLoad;
C_ID = window._ChannelVary[window.cookie('_Channel')];
function yasRequest(PRD_ID, PRD_NUM, ACTION_ID) {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_CHOOSE_FOR_YOU_Y',
param: JSON.stringify({
REC_POSE: 100013,
REC_ID: RECID,
PRD_ID: PRD_ID,
PRD_NUM: PRD_NUM,
C_ID: C_ID,
ACTION_ID: ACTION_ID,
PAGE_NUM: 1
})
}, true);
}
}
function request() {
if (requesting || end) {
return;
}
requesting = true;
if (preferenceUrl) {
$.get(preferenceUrl).then(function(html) {
if (typeof html !== 'string') {
return;
}
$recommendForYou.html(html.replace(/https?:/gi, '')).show();
lazyLoad($recommendForYou.find('img.lazy'));
// 为你优选埋点- 加载
$('.goods-container').find('.good-info').each(function() {
goodid = $(this).data('good-id');
if (goodid) {
goodIds.push(goodid);
}
});
prdLoad = JSON.stringify(goodIds).replace(/\[|\]|/g, '');
yasRequest(prdLoad, goodIds.length, 0);
// 点击商品
$('.good-info').on('click', function() {
var PRD_ID = $(this).data('good-id'),
PRD_NUM = $(this).index();
yasRequest(PRD_ID, PRD_NUM, 1);
// return false;
});
window.rePosFooter && window.rePosFooter();
}).fail(function() {
$recommendForYou.hide();
});
}
}
function scrollHandler() {
if (!end || $(window).scrollTop() + winH >= $(document).height() - 200) {
request();
}
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});