Authored by 郭成尧

back

... ... @@ -14,8 +14,8 @@ const domains = {
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
global: 'http://api-global.yohobuy.com',
// liveApi: 'http://api.live.yoho.cn/',
... ...
/*
* @Author: Targaryen
* @Date: 2017-04-26 17:22:32
* @Last Modified by: Targaryen
* @Last Modified time: 2017-04-26 17:45:28
/**
* 逛首页
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/10
*/
'use strict';
require('guang/index.page.css');
const index = './index';
const IndexController = require(`${index}/controller`);
let $ = require('yoho-jquery');
new IndexController();
let info = require('./info');
let loadMore = info.loadMore;
let $loadMoreInfo = $('#load-more-info');
let $loading = $(''),
$noMore = $('');
let winH = $(window).height();
let $infoList = $('#info-list'),
$infos = $infoList.children('.info-list'),
$nav = $('#guang-nav'),
$curNav = $nav.children('.focus'),
curType = $curNav.data('type');
let getDynamicData = require('./list-dynamic');
let state = {};
require('common');
if ($loadMoreInfo.length > 0) {
$loading = $loadMoreInfo.children('.loading');
$noMore = $loadMoreInfo.children('.no-more');
}
info.initSwiper(curType);
info.initInfosEvt($infoList);
// 初始化各Nav下资讯加载的状态
(function() {
let gender = $('#gender').val();
$nav.children('.guang-nav-item').each(function() {
let type = $(this).data('type'),
focus = $(this).hasClass('focus');
state[type] = {
page: focus ? 2 : 1,
gender: gender,
type: type,
end: false
};
});
getDynamicData.getDynamicData();
}());
$nav.bind('contextmenu', function() {
return false;
});
$nav.on('touchend touchcancel', function(e) {
let $this = $(e.target).closest('.guang-nav-item'),
$content,
index;
if ($this.hasClass('focus')) {
return;
}
e.preventDefault();
index = $this.index();
$this.addClass('focus');
$curNav.removeClass('focus');
$content = $infos.eq(index);
$curNav = $this;
curType = $this.data('type');
// 当未加载数据时去请求数据
if (state[curType].page === 1) {
// 无数据时隐藏正在加载和没有更多字样
$loading.addClass('hide');
$noMore.addClass('hide');
state[curType].isTab = true;
loadMore($content, state[curType]);
} else {
// 重置当前Tab的load-more
if (state[curType].end) {
$loading.addClass('hide');
$noMore.removeClass('hide');
} else {
$loading.removeClass('hide');
$noMore.addClass('hide');
}
}
$infos.not('.hide').addClass('hide');
$content.removeClass('hide');
if (state[curType].page === 1) {
window.rePosFooter();// 进入空内容时重新定位footer位置
}
});
function scrollHandler() {
let $c = $infos.not('.hide');
if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $c.height()) {
loadMore($c, state[curType]);
}
}
// srcoll to load more
$(document).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
$nav.on('touchstart', function(e) {
let target = e.target || e.srcElement;
target.className = 'bytouch ' + target.className;
}).on('touchend touchcancel', function() {
$nav.find('li').removeClass('bytouch');
});
... ...