share.js 4.2 KB
/*商品列表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());