channel.page.js 8.71 KB
/**
 * 首页
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/11/23
 */

var $ = require('yoho-jquery'),
    lazyLoad = require('yoho-jquery-lazyload');

var homePage = $('.home-page').data('page'),
    shownum = $('.logo-brand').data('shownum'),
    mChannel = $('.home-page').data('mchannel') || '';

var newArrParams = {};
var yas = require('../common/data-yas');

// 给头部js获取当前频道
window.homePage = homePage;

require('../common');

require('../plugins/slider');
require('../product/index/logo-brand');

require('../plugins/accordion');

require('../common/center-slider');

$(document).on('mouseenter', '.imgopacity a img', function() {
    $(this).css('opacity', 0.8); // eslint-disable-line
});
$(document).on('mouseout', '.imgopacity a img', function() {
    $(this).css('opacity', 1); // eslint-disable-line
});

if ($.inArray(homePage, ['boys', 'girls', 'kids', 'lifestyle']) > -1) {
    newArrParams = {
        type: homePage,
        url: '/common/getNewArrival',
        count: (homePage === 'boys') || (homePage === 'lifestyle') ? 5 : 4,
        rows: [5, 3]
    };

    if (mChannel !== '') {
        newArrParams.mChannel = mChannel;
        newArrParams.poolId = window.queryString().template_id;
    }

    require('../product/index/new-arrivls')(newArrParams);
    window.setCookie('_Channel', homePage, {
        domain: '.yohobuy.com',
        path: '/',
        expires: 365
    });
}

// lazyLoad($('img.lazy'));
lazyLoad($('img.lazy'));
if (homePage === 'boys') {
    $('.slide-container').slider({
        pagination: '.thumb-pagination'
    });
} else {
    $('.center-col').slider();
    $('.slide-container').slider();
}

if (homePage === 'boys') {
    $('.logo-brand').logoBrand({
        showNum: shownum
    });

    $('.img-brand').slider2({autoplay: true});
} else {
    $('.logo-brand').logoBrand({
        showNum: shownum
    });
    $('.img-slider-wrapper').slider2({autoplay: true});
}

$('.new-user-prolist').slider2({
    shownum: 5,
    isCircle: false
});

if (window.cookie('_UID')) {
    // 判断是否有新人专享
    $.ajax({
        type: 'GET',
        url: '/channel/isNewUserAjax',
        data: {},
        success: function(res) {
            if (!res.isNewUser) {
                $('.new-user').addClass('hide');
            }
        }
    });
}

if (mChannel !== '') {
    /** *****  埋点  *******/
// banner埋点
    $('.slide-wrapper > ul li > a').click(function() {
        var floorId = $('#bannerFloorId').html(),
            url = $(this).attr('href'),
            index = parseInt($(this).parent().index(), 10) + 1;

        // banner点击埋点
        yas.givePoint('YB_JK_PAV_FLR_C', {
            F_ID: floorId,
            F_NAME: '焦点图',
            F_URL: url,
            F_INDEX: 1,
            I_INDEX: index
        });

    });

// 最新速报
// 左1+中6
    $('.new-report .report-list li > a').click(function() {
        var $header = $('.new-report .floor-header');
        var floorId = $header.attr('floorid'),
            floorName = $header.find('.floor-title').html(),
            url = $(this).attr('href'),
            index = parseInt($(this).parent().index(), 10) + 1;

        // banner点击埋点
        yas.givePoint('YB_JK_PAV_FLR_C', {
            F_ID: floorId,
            F_NAME: floorName,
            F_URL: url,
            F_INDEX: 2,
            I_INDEX: index
        });
    });

// 右1
    $('.new-report .last-item > a').click(function() {
        var $header = $('.new-report .floor-header');
        var floorId = $header.attr('floorid'),
            floorName = $header.find('.floor-title').html(),
            url = $(this).attr('href');

        // banner点击埋点
        yas.givePoint('YB_JK_PAV_FLR_C', {
            F_ID: floorId,
            F_NAME: floorName,
            F_URL: url,
            F_INDEX: 2,
            I_INDEX: 8
        });
    });

// logo列表
    $('.logo-brand > ul li > a').click(function() {
        var $header;
        var floorId, floorName, url, content, index;

        if ($(this).hasClass('iconfont')) {
            return;
        }

        $header = $('.new-report .floor-header');
        floorId = $header.attr('floorid');
        floorName = $header.find('.floor-title').html();
        url = $(this).attr('href');
        content = $(this).html();

        index = $(this).closest('li').prevAll('li:not(.logo-brand-switch, .brand-more)').length + 9;

        if (content.indexOf('MORE') >= 0) {
            index = 0;
        }

        // 话题楼层的广告位
        yas.givePoint('YB_JK_PAV_FLR_C', {
            F_ID: floorId,
            F_NAME: floorName,
            F_URL: url,
            F_INDEX: 2,
            I_INDEX: index
        });
    });

// 广告位
    $('.floor-ad > a').click(function() {
        var $header = $('.floor-ad').prev().prev();
        var floorId = $header.attr('floorid'),
            floorName = $header.find('.floor-title').html(),
            url = $(this).attr('href');

        // 话题楼层的广告位
        yas.givePoint('YB_JK_PAV_FLR_C', {
            F_ID: floorId,
            F_NAME: floorName,
            F_URL: url,
            F_INDEX: 3,
            I_INDEX: 8
        });
    });

// 左一右六埋点
// 左一
    $('.tpl-left-pic > a').click(function() {
        var $topic = $(this).closest('.topic'),
            $header = $topic.prev(),
            url = $(this).attr('href'),
            fIndex = 4,
            fName = '',
            i;

        var num = $('.topic').length;

        for (i = 0; i < num; i++) {
            if ($header.hasClass('floor-header')) {
                fName = $header.find('.floor-title').html();
                if (fName.indexOf('话题') >= 0) {
                    fIndex = 3;
                }
                yas.givePoint('YB_JK_PAV_FLR_C', {
                    F_ID: $header.attr('floorid'),
                    F_NAME: fName,
                    F_URL: url,
                    F_INDEX: fIndex,
                    I_INDEX: (i * 7) + 1
                });

                break;
            } else {
                $header = $header.prev();
            }
        }
    });

// 右六
    $('.tpl-types > ul li > a').click(function() {
        var $topic = $(this).closest('.topic'),
            $header = $topic.prev(),
            url = $(this).attr('href'),
            fIndex = 4,
            fName = '',
            i;

        var index = parseInt($(this).parent().index(), 10) + 1;

        var num = $('.topic').length;

        for (i = 0; i < num; i++) {
            if ($header.hasClass('floor-header')) {
                fName = $header.find('.floor-title').html();
                if (fName.indexOf('话题') >= 0) {
                    fIndex = 3;
                }
                yas.givePoint('YB_JK_PAV_FLR_C', {
                    F_ID: $header.attr('floorid'),
                    F_NAME: fName,
                    F_URL: url,
                    F_INDEX: fIndex,
                    I_INDEX: (i * 7) + 1 + index
                });

                break;
            } else {
                $header = $header.prev();
            }
        }
    });

// 7个品类
    $('.seven-product .tpl-products > ul li > a').click(function() {
        var floorId = $(this).closest('.tpl-products').attr('floorid'),
            url = $(this).attr('href'),
            index = parseInt($(this).parent().index(), 10) + 1;

        yas.givePoint('YB_JK_PAV_FLR_C', {
            F_ID: floorId,
            F_NAME: '品类楼层',
            F_URL: url,
            F_INDEX: 5,
            I_INDEX: index
        });
    });

// 最新上架
// more链接
    $('.commodity .floor-header .header-navs li > a').click(function() {
        var $header = $(this).closest('.floor-header'),
            name = $header.find('.floor-title').html(),
            url = $(this).attr('href'),
            menu = $(this).html(),
            index = parseInt($(this).parent().index(), 10) + 1;

        if (menu === 'MORE') {
            index = 0;
        }
        yas.givePoint('YB_JK_PAV_FLR_C', {
            F_ID: $header.attr('floorid'),
            F_NAME: name,
            F_URL: url,
            F_INDEX: 6,
            I_INDEX: index
        });
    });

// 商品列表
    $('.commodity .goods-container').on('click', '.good-info .good-detail-img > a,' +
        '.good-info .good-detail-text > a', function() {
            var $header = $('.commodity .floor-header'),
                name = $header.find('.floor-title').html(),
                url = $(this).attr('href'),
                index = parseInt($(this).closest('.good-info').index(), 10) + 1;

            yas.givePoint('YB_JK_PAV_FLR_C', {
                F_ID: $header.attr('floorid'),
                F_NAME: name,
                F_URL: url,
                F_INDEX: 6,
                I_INDEX: index + 10
            });
        });

}