share.js
4.2 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
/*商品列表tab*/
$(".goods-tab").on("click","li",function(){
var index = $(this).index();
$(this).addClass("current").siblings().removeClass("current");
$(".goods-list").find("ul").eq(index).addClass("current").siblings().removeClass('current');
});
/*分享弹出框*/
$(".share-btn").on("click",function(){
$(".share-dialog").show();
$(".shade").show();
});
$(".close-btn").on("click",function(){
$(".share-dialog").hide();
$(".shade").hide();
});
/*省略多余文字并显示...*/
Element.prototype.getText=function(){
if(this.innerText==undefined){return this.textContent;}
else{return this.innerText;}
}
Element.prototype.setText=function(str){
if(this.innerText==undefined){this.textContent=str||"";}
else{this.innerText=str||"";}
}
Element.prototype.getFinalStyle=function(property,fontSize){
var s;
if(window.getComputedStyle){
s = window.getComputedStyle(this, null)[property];
}
else{
s = this.currentStyle[property];
}
//兼容IEbug:IE解析getComputedStyle或currentStyle,然而若line-height=1.5,它会获取计算后是1.5,而其他浏览器获得1.5*line-height
if(fontSize!=undefined){
s = s*fontSize + "px";
}
return s.substring(0,s.toString().length-2);
}
Element.prototype.mlellipsis=function(row){
//省略后加上title
var str = this.getText();
var title = this.getAttribute("title");
if(title==null){this.setAttribute("title",str);}
else{this.setText(title);}
//获取计算后的样式
var fontSize = this.getFinalStyle("fontSize");
if(/msie/i.test(navigator.userAgent)){
var lineHeight = this.getFinalStyle("lineHeight",fontSize);
}
else{
var lineHeight = this.getFinalStyle("lineHeight");
}
var height = this.clientHeight;
if(lineHeight == "norm"){
lineHeight = Number(fontSize*1.5);
var nowStyle = this.getAttribute("style")||"";
this.setAttribute("style",nowStyle+";line-height:"+lineHeight+"px");
}
else{lineHeight = Number(lineHeight);}
//若高度足够,则不用省略
var dheight = Math.floor(row*lineHeight);
if(height >= dheight){
str = this.getText();
while(dheight*3<this.clientHeight){
this.setText(str.substring(0,str.length/2));
str = this.getText();
}
//减去末尾文字
while(dheight<this.clientHeight){
str = this.getText();
this.setText(str.replace(/(\s)*([a-zA-Z0-9]?|\W)(\.\.\.)?$/,"..."));
}
}
}
if(!!$('.goods-info').find("p").size()){
$('.goods-info').find("p")[0].mlellipsis(3);
}
$(".goods-info").find(".more").on("click",function(){
var textLen = $('.goods-info').find("p").text().length,
attrLen = $('.goods-info').find("p").attr("title").length;
if(textLen == attrLen){
$('.goods-info').find("p")[0].mlellipsis(3);
//$(this).text("查看更多");
}else{
$('.more').css('display','none');
$('.goods-info').find("p").text(function(){
return $(this).attr("title");
});
//$(this).text("收回");
}
})
if(!!$("#slider").size()){
var slider =
Swipe(document.getElementById('slider'), {
auto: 3000,
continuous: true,
callback: function(pos) {
var i = bullets.length;
while (i--) {
bullets[i].className = ' ';
}
bullets[pos].className = 'on';
}
});
var bullets = document.getElementById('control-point').getElementsByTagName('span');
}
function starNum(num){
if(num!=0){
$(".user-pic").find(".star").eq(num-1).addClass("current");
$(".user-pic").find(".star").eq(num-1).prevAll().addClass("current");
}
}
starNum($("#hidden_star").val());
/*图片轮播小圆点*/
(function(){
var len = $(".swipe-wrap").find("li").length;
for (var i=0;i<len;i++) {
//console.log(i);
var point = $('<span>');
if(len!=1){
point.appendTo($(".control-point"));
}
}
$(".control-point").find("span").eq(0).addClass("on");
for(var i =0;i<$(".buyer-info").length;i++){
var num = $(".buyer-info").eq(i).attr("star");
if(num!=0){
$(".buyer-info").eq(i).find(".star").eq(num-1).addClass("curr");
$(".buyer-info").eq(i).find(".star").eq(num-1).prevAll().addClass("curr");
}
}
})();
$(".evaluation").css({"min-height":$(window).height()});
console.log($(window).height());