home.js 1.64 KB
/**
 * 逛首页
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/10/10
 */

var $ = require('yoho.zepto'),
    Swiper = require('yoho.iswiper');

var info = require('./info'),
    setLazyLoadAndMellipsis = info.setLazyLoadAndMellipsis,
    loadMore = info.loadMore;

var winH = $(window).height(),
    loadMoreH = $('#load-more').height();

var $infoList = $('#info-list'),
    $infos = $infoList.children('.info-list'),
    $nav = $('#guang-nav'),
    $curNav = $nav.children('.focus'),
    curType = $curNav.data('type');

var state = {};

var mySwiper;

mySwiper = new Swiper('.swiper-container', {
    lazyLoading: true,
    pagination: '.swiper-pagination'
});

info.initInfosEvt($infoList);

//初始化各Nav下资讯加载的状态
(function() {
    $nav.children('.guang-nav-item').each(function() {
        var type = $(this).data('type');

        state[type] = {
            page: 1,
            end: false,
            type: type
        };
    });
}());

$nav.delegate('.guang-nav-item', 'touchstart', function() {
    var $this = $(this),
        $content,
        index;

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

    index = $this.index();

    $this.addClass('focus');
    $curNav.removeClass('focus');

    $infos.not('.hide').addClass('hide');

    $content = $infos.eq(index);
    $content.removeClass('hide');

    //lazyload & mellipsis
    setLazyLoadAndMellipsis($content.children('.guang-info'));

    $curNav = $this;
    curType = $this.data('type');
});

$(document).scroll(function() {
    if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH && !state[curType].end) {
        loadMore($infos, state[curType]);
    }
});