|
|
import {
|
|
|
View
|
|
|
} from 'yoho-mvc';
|
|
|
|
|
|
import {
|
|
|
IndexModel
|
|
|
} from './model';
|
|
|
|
|
|
let lazyLoad = require('yoho-jquery-lazyload');
|
|
|
let ellipsis = require('yoho-mlellipsis');
|
|
|
|
|
|
export class IndexView extends View {
|
|
|
constructor() {
|
|
|
super();
|
|
|
}
|
|
|
|
|
|
init() {
|
|
|
let that = this;
|
|
|
let $loadMoreInfo = $('#load-more-info');
|
|
|
|
|
|
ellipsis.init();
|
|
|
|
|
|
this.indexModel = new IndexModel();
|
|
|
this.selector = {
|
|
|
searching: false,
|
|
|
$win: $(window),
|
|
|
$infoList: $('#info-list'),
|
|
|
$loading: $loadMoreInfo.children('.loading'),
|
|
|
$noMore: $loadMoreInfo.children('.no-more'),
|
|
|
$infos: $('#info-list').children('.info-list'),
|
|
|
};
|
|
|
this.navState = [{
|
|
|
page: 2,
|
|
|
end: false
|
|
|
}];
|
|
|
|
|
|
// srcoll to load more
|
|
|
$(document).scroll(function() {
|
|
|
window.requestAnimationFrame(function() {
|
|
|
that.scrollHandler.apply(that, []);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
this.setLazyLoadAndMellipsis(this.selector.$infoList.children('.info-list').not('.hide').find('.news-info'));
|
|
|
}
|
|
|
|
|
|
scrollHandler() {
|
|
|
let $c = this.selector.$infos.not('.hide');
|
|
|
|
|
|
if (this.selector.$win.scrollTop() + this.selector.$win.height() >= $(document).height() - 0.25 * $c.height()) {
|
|
|
this.loadMore($c, 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
loadMore($container, index) {
|
|
|
let that = this;
|
|
|
|
|
|
if (that.selector.searching || that.navState[index].end) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
that.selector.searching = true;
|
|
|
that.selector.$noMore.addClass('hide');
|
|
|
that.selector.$loading.removeClass('hide');
|
|
|
|
|
|
this.indexModel.loadMoreAjax({
|
|
|
type: 'GET',
|
|
|
url: '/news/index/page',
|
|
|
dataType: 'html',
|
|
|
data: that.navState[index]
|
|
|
}).then(rdata => {
|
|
|
that.selector.$loading.addClass('hide');
|
|
|
|
|
|
if (rdata === '') {
|
|
|
that.navState[index].end = true;
|
|
|
that.selector.searching = false;
|
|
|
that.selector.$noMore.removeClass('hide');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let $dataHtml = $(rdata);
|
|
|
|
|
|
$container.append($dataHtml);
|
|
|
that.setLazyLoadAndMellipsis($dataHtml.siblings('.news-info'));
|
|
|
|
|
|
that.navState[index].page++;
|
|
|
that.selector.searching = false;
|
|
|
}).catch(() => {
|
|
|
that.selector.searching = false;
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
setLazyLoadAndMellipsis($infos) {
|
|
|
lazyLoad($infos.find('img.lazy'));
|
|
|
|
|
|
$infos.each(function() {
|
|
|
let $this = $(this),
|
|
|
$title = $this.find('.info-title'),
|
|
|
$text = $this.find('.info-text');
|
|
|
|
|
|
$title[0].mlellipsis(2);
|
|
|
$text[0].mlellipsis(2);
|
|
|
});
|
|
|
}
|
|
|
} |
...
|
...
|
|