order.js 1.2 KB
/**
 * 个人中心--我的订单
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/11/10
 */

var $ = require('jquery'),
    Hammer = require('yoho.hammer'),
    lazyLoad = require('yoho.lazyload');

var $navLi = $('#order-nav > li'),
    $orderContainer = $('#order-container');

var $curContainer = $orderContainer.children('.orders').first();//保存当前显示的order-container

var navHammer, orderHammer;

lazyLoad();

navHammer = new Hammer(document.getElementById('order-nav'));
navHammer.on('tap', function(e) {
    var $cur = $(e.target).closest('li'),
        index;

    if ($cur.length === 0 || $cur.hasClass('active')) {
        return;
    }

    index = $cur.index();

    $navLi.filter('.active').removeClass('active');
    $cur.addClass('active');

    $curContainer.addClass('hide');
    $curContainer = $orderContainer.children(':eq(' + index + ')').removeClass('hide');
});

orderHammer = new Hammer(document.getElementById('order-container'));
orderHammer.on('tap', function(e) {
    var $cur = $(e.target),
        $order,
        url;

    if ($cur.closest('.locHref').length > 0) {
        return;
    }

    $order = $cur.closest('.order');
    url = $order.data('href');

    location.href = url;
});