channel.js 3.11 KB

require('./channel/detail');
require('./channel/magazine')

var $=require("jquery");
var tips=require("yoho-tips");
var box=require("yoho-box");
//首页碎片交互=================================================================================================
function dealItems() {
    var citems = $(".content-item,.content-item-without-border");
    if (!citems.length) {
        return;
    }
    var totalLineNum = 7;
    // 7 行
    var maxTitleStrNum = 45;
    // 15个字
    var maxDetailStrNum = 24;
    // 22个字
    if (document.body.clientWidth < 1190&&document.body.clientWidth>768) {
        totalLineNum = 6;
        // 6 行
        maxTitleStrNum = 15;
        // 13个字
        maxDetailStrNum = 20;
        // 18个字
    }
    else if(document.body.clientWidth<=768){
        totalLineNum = 5;
        // 6 行
        maxTitleStrNum = 10;
        // 13个字
        maxDetailStrNum = 15;
    }

    var titleLineNum = 0;
    var subTitleLineNum = 0;
    var detailLineNum = 0;
    var detailStr = "";
    var self = null;

    citems.each(function() {
        self = $(this);

        var itemTitleObj= self.find(".content-item-detail-title");
        // 主标题行数
        if(typeof(itemTitleObj.attr("_title"))==="undefined"||itemTitleObj.attr("_title")===null)
            return;
        titleLineNum = 1;
        if (maxTitleStrNum < itemTitleObj.attr("_title").length) {
            titleLineNum = 2;
        }

        // 副标题行数
        subTitleLineNum = 1;
        if (maxTitleStrNum < $(".content-item-detail-subtitle").attr("_title").length) {
            subTitleLineNum = 2;
        }

        // 摘要内容行数
        detailLineNum = totalLineNum - titleLineNum - subTitleLineNum;
        if ((maxDetailStrNum * detailLineNum) < self.find(".content-item-detail").attr("_title").length) {
            detailStr = self.find(".content-item-detail").attr("_title").substring(0, (maxDetailStrNum-1) * detailLineNum ) + " ...";
            self.find(".content-item-detail").html(detailStr.replace(/[a-zA-Z]+?\s{1}\.\.\.\$/, " ..."));
            console.log(detailStr);
        }
        else
        {
            self.find(".content-item-detail").text(self.find(".content-item-detail-detail").attr("_title"));
        }
    });
    citems = null;
}
dealItems();
//=============================================================

//邮件订阅=============================================================================================================
    $(".followus-button").click(function(){
        if($(".follow-us-input-content input").val()=='')
        {
            box.alert(tips.getTips("emailEmpty"));
            return;
        }
        if(!tools.IYOHO_isEmail($(".follow-us-input-content input").val()))
        {
            box.alert(tips.getTips("emailError"));
            return;
        }
        $(".search-suggest").hide();
        window.open( '/passport/subscribe/index?email='+$(".follow-us-input-content input").val());
    });
    $(".followus-input").keydown(function(event){
        if(event.keyCode==13)
        
        {
            $(".followus-button").trigger("click");
        }
    });