plustar-detail-render.js
3.71 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
var $ = require('yoho-jquery'),
dbClass = 'data-bind';
module.exports = function(callback) {
var brandId = $('#brandId').val();
var clientType = $('#clientType').val();
if (brandId) {
$.ajax({
type: 'POST',
url: '/guang/plustar/brandinfoAsync',
data: {
client_type: clientType,
brand_id: brandId
},
success: function(data) {
render(data);
callback && callback(data);
}
});
}
};
function render(data) {
if (data.isLike) {
$('.brand-islike').addClass('like');
}
if (data.infos && data.infos.length) {
var guangInfoEl = $('#related-infos-container>.guang-info').remove();
for (var i = 0; i < data.infos.length; i++) {
var info = data.infos[i];
var item = guangInfoEl.clone().attr('data-id', info.id);
item.find('.info-img-link')
.attr('href', info.url)
.find('img')
.attr('data-original', info.img)
.attr('alt', info.alt);
var depsEl = item.find('.info-deps');
depsEl.find('.info-title-container').attr('href', info.url).find('.info-title').text(info.title);
depsEl.find('.info-text').text(info.text);
var timeEl = item.find('.time-view-like-share');
timeEl.find('.publish-time').text(info.publishTime);
timeEl.find('.page-view').text(info.pageView);
var likeEl = timeEl.find('.like-share-container');
if (info.like) {
likeEl.find('.like-btn').removeClass(dbClass);
if (info.like.isLiked) {
likeEl.find('.like-btn').addClass('like');
}
likeEl.find('.like-count').text(info.like.count).removeClass(dbClass);
}
if (info.collect) {
likeEl.find('.collect-link').attr('href', info.collect.url).removeClass(dbClass);
if (info.collect.isCollected) {
likeEl.find('.collect-link').find('.collect-btn').addClass('collected');
}
}
if (info.share) {
likeEl.find('.share-btn').attr('href', info.share).removeClass(dbClass);
}
if (info.author) {
item.find('.info-author')
.attr('href', info.author.url)
.find('.avatar')
.attr('data-original', info.author.avatar)
.parent()
.find('.name')
.text(info.author.name)
.removeClass(dbClass);
}
var infoImgEl = item.find('.info-img');
if (info.showTags) {
infoImgEl.find('.data-bind').removeClass(dbClass);
if (info.isTip) {
infoImgEl.find('.is-tips').removeClass(dbClass);
}
if (info.isCollocation) {
infoImgEl.find('.is-collocation').removeClass(dbClass);
}
if (info.isFashionMan) {
infoImgEl.find('.is-fashionMan').removeClass(dbClass);
}
if (info.isFashionGood) {
infoImgEl.find('.is-fashion-good').removeClass(dbClass);
}
if (info.isTopic) {
infoImgEl.find('.is-topic').removeClass(dbClass);
}
if (info.isSpecialTopic) {
infoImgEl.find('.is-special-topic').removeClass(dbClass);
}
}
$('#related-infos-container').append(item);
}
$('.related-infos').removeClass(dbClass);
}
$('.' + dbClass).remove();
}