plustar-detail.page.js
3.82 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
/**
* PLUS+STAR详情页
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/10
*/
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer'),
ellipsis = require('yoho-mlellipsis'),
lazyLoad = require('yoho-jquery-lazyload');
var $intro = $('#intro'),
$imt = $('#intro-more-txt'),
$infosContainer = $('#related-infos-container'),
uid = $('input[name="uid"]').val(),
isApp = $('input[name="isApp"]').val();
var info = require('./info');
var tip = require('../plugin/tip');
var brandId = $('#brand-info').data('id');
var jumpToApp = $('#jump-to-app').val();
var mIntro, aIntro, logoImg;
var moreHammer, likeHammer, $goodName, $title;
var saveImage = require('../home/save-image');
require('../plugin/wx-share');
require('../common');
require('./plustar-detail-render')(function() {
lazyLoad($('img.lazy'));
});
ellipsis.init();
// Init LazyLoad
lazyLoad($('img.lazy'));
logoImg = saveImage.getSourceUrl($('.logo').attr('src'), 'brandLogo');
$('.logo').attr('src', logoImg);
if ($('.good-detail-text .name').length > 0) {
$('.good-detail-text .name').each(function() {
$goodName = $(this);
$title = $goodName.find('a');
$title[0].mlellipsis(2);
});
}
// 文字介绍文字截取
$intro[0].mlellipsis(3);
// 获取截取文字和完整文字
setTimeout(function() {
mIntro = $intro.text();
aIntro = $intro.attr('title');
});
info.initInfosEvt($infosContainer);
// 文字介绍收起与展开
moreHammer = new Hammer(document.getElementById('more-intro-click-range'));
moreHammer.on('tap', function(e) {
var $this = $imt.parent();
$this.toggleClass('spread');
if ($this.hasClass('spread')) {
// 显示
$intro.text(aIntro);
$imt.text('收起');
} else {
// 隐藏
$intro.text(mIntro);
$imt.text('more');
$(window).scrollTop(0, 400); // 滑动到顶部
}
e.preventDefault(); // 防止收缩后误点到商品产生跳转
});
if ($('#brand-like').length) {
// 品牌收藏
likeHammer = new Hammer(document.getElementById('brand-like'));
likeHammer.on('tap', function(e) {
var opt = 'ok',
$this = $(e.target);
// jumpToApp = 1表示APP未登录的情况,此时不发送ajax请求而由a链接直接跳转APP
// if (jumpToApp === '1') {
// return true;
// }
e.preventDefault();
if ($this.hasClass('like')) {
opt = 'cancel';
}
$.ajax({
type: 'POST',
url: '/guang/opt/favoriteBrand',
data: {
id: brandId,
opt: opt,
uid: uid,
isBrand: 'brand'
},
success: function(data) {
if (data.code === 200) {
$this.toggleClass('like');
tip.show(data.message);
} else if (data.code === 400 || data.code === 412) {
if (jumpToApp === '1') {
var url = location.href + '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"http:\/\/guang.m.yohobuy.com\/plustar\/brandinfo","param":{"id":'
+ window.queryString.id + '}},"requesturl":{"url":"\/guang\/api\/v1\/favorite\/togglebrand","param":{"brand_id":"' + $('#brand-info').data('id') + '"}},"priority":"Y"}}';
$('body').append('<a href=' + url + ' style="display:none;"><span class="jump-login"> </span></a>');
$('.jump-login').click();
} else {
location.href = data.data; // 未登录跳转登录页面
}
} else {
tip.show(data.message);
}
}
});
return false;
});
}
// console.log($('.logo').attr('src'))