category.page.js 1.97 KB
/**
 * 分类
 * @author: berry<lixia.zhang@yoho.cn>
 * @date: 2016/4/25
 */
var $ = require('yoho-jquery');

var $allProductCell = $('.allproduct'),
    $categoryContainer = $('.category-container'),
    $contents = $categoryContainer.children('.content'),
    $subLevelItem = $categoryContainer.find('.sub-level li'),
    $trilangle = $categoryContainer.find('.primary-level-trilangle');

require('../common');

//初始化container高度
(function() {
    var $header = $('.yoho-header');
    var h = $(window).height() - $header.outerHeight() - $allProductCell.outerHeight();
    var trilangleRightMargin = $(window).width() * 0.55;

    $categoryContainer.css('min-height', h);
    $trilangle.css('margin-right', trilangleRightMargin);
    $contents.height(h);

}());


$categoryContainer.on('touchend', function(e) {
    var $this = $(e.target),
        $subLevel,
        $cur, index,
        $subLevelContainer, $trilangleItem;

    $cur = $this.closest('.p-level-item');

    $subLevelContainer = $this.closest('.content').find('.sub-level-container');
    $subLevelContainer.removeClass('hide');

    if ($cur.length > 0) {
        index = $cur.index();
        $subLevel = $this.closest('.content').find('.sub-level');
        $trilangleItem = $this.closest('.content').find('.primary-level-trilangle');

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

        $subLevel.not('.hide').addClass('hide');
        $subLevel.eq(index).removeClass('hide');

        $trilangleItem.not('.hide').addClass('hide');
        $trilangleItem.eq(index).removeClass('hide');
    }
});

$categoryContainer.find('.sub-level').on('touchstart', 'li', function() {
    $subLevelItem.removeClass('highlight');
    $(this).addClass('highlight');
}).on('touchend touchcancel', 'li', function() {
    $(this).removeClass('highlight');
});

$allProductCell.on('touchstart', function() {
    $(this).addClass('highlight');
}).on('touchend touchcancel', function() {
    $(this).removeClass('highlight');
});