index.js 1.05 KB
/**
 * 分类
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/10/14
 */

var $ = require('yoho.zepto');

var $nav = $('.category-nav'),
    $contents = $('.category-container > .content');

var $curContent = $contents.not('.hide');

$('#search-input').focus(function() {
    $(this).blur();
});

$nav.delegate('li', 'touchstart', function() {
    var $this = $(this),
        index = $this.index();

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

    $nav.find('li.focus').removeClass('focus');
    $this.addClass('focus');

    $curContent.addClass('hide');
    $curContent = $contents.eq(index).removeClass('hide');
});

$('.primary-level').delegate('li', 'touchstart', function() {
    var $this = $(this),
        index = $this.index();

    var $subLevel = $this.closest('.content').find('.sub-level');

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

    $this.closest('.primary-level').children('.focus').removeClass('focus');
    $this.addClass('focus');

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