help-common.js 2.25 KB
/**
 * [帮助中心 常见问题弹框]
 * @author: wsl(shuiling.wang@yoho.cn)
 * @date: 2016/12/02
 */

var problemTpl = require('../../hbs/help/problem-box.hbs');
var yas = require('../common/data-yas');

// 问题弹窗操作
var problemBox = function() {
    var $problemBox;

    $('.help-page').append(problemTpl());
    $problemBox = $('.problem-box');

    $problemBox.css({lineHeight: $(window).height() + 'px'});

    $('.problem a').on('click', function() {
        var ask = $(this).data('ask') || '';
        var answer = $(this).data('answer') || '';

        $problemBox.find('.a-area').html(ask);
        $problemBox.find('.q-area').html(answer);
        $problemBox.show();
    });

    $('.problem-box .close, .problem-box .mark').on('click', function() {
        $problemBox.hide();
    });
};

var $subsets = $('.subsets');

/**
 * 目录切换
 */
$subsets.click(function() {
    var $this = $(this);
    var className = $this.attr('class').split(' ')[1];
    var parentId = 'parentId-' + className.split('-')[1];
    var $child = $this.parent().find('.' + parentId);// 当前子分类

    if ($this.hasClass('open')) {
        $child.hide();
        $this.removeClass('open').children('.icon').removeClass('minus').addClass('plus');
    } else {
        $('.smll-category').hide();
        $('.subsets').children('.icon').removeClass('minus').addClass('plus');
        $child.show();
        $subsets.removeClass('open');
        $this.addClass('open').children('.icon').removeClass('plus').addClass('minus');
    }
});

// 左侧菜单栏点击埋点
$('.help-navigation .nav li').on('click', function() {
    var yasParams;
    var id = $(this).attr('class').split(' ')[1].split('-')[1];
    var text = $(this).find('.menu-txt').html();
    var parentId;

    if ($(this).hasClass('big-category')) {
        yasParams = {
            MENU_ID1: id,
            MENU_NM1: text,
            MENU_ID2: id,
            MENU_NM2: text
        };
    } else {
        parentId = $(this).data('parentId');
        yasParams = {
            MENU_ID1: parentId,
            MENU_NM1: $('.cateId-' + parentId).find('.menu-txt').html(),
            MENU_ID2: id,
            MENU_NM2: text
        };
    }

    yas.yasEvent('YB_HELP_MENU_C', yasParams);
});

module.exports = problemBox;