Blame view

public/js/guang/collocation.page.js 2.33 KB
王水玲 authored
1 2 3 4 5 6
/**
 * 星潮教室-星搭配分页加载
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/4/12
 */
陈峰 authored
7
let $ = require('yoho-jquery'),
陈峰 authored
8 9
    tip = require('js/plugin/tip'),
    loading = require('js/plugin/loading'),
郭成尧 authored
10
    lazyLoad = require('yoho-jquery-lazyload');
陈峰 authored
11
let stopLoading = false,
王水玲 authored
12
    page = 1;
王水玲 authored
13
王水玲 authored
14
require('./list-common');
王水玲 authored
15
王水玲 authored
16
function massageAJAX(pageData) {
王水玲 authored
17 18 19 20 21
    loading.showLoadingMask();
    $.ajax({
        type: 'GET',
        url: '/guang/star/collocation/list',
        data: {
ccbikai authored
22 23
            page: pageData,
            appVersion: window.queryString.app_version
王水玲 authored
24 25 26 27 28 29 30 31 32 33 34 35
        },
        dataType: 'html',
        success: function(data) {
            stopLoading = false;

            if (data === '') {
                stopLoading = true;
                tip.show('没有更多内容了');
            }

            $('.collocation-list').append(data);
王水玲 authored
36
            loading.hideLoadingMask();
王水玲 authored
37
            lazyLoad($('img.lazy'));
沈志敏 authored
38 39

            if (pageData === 1) {
陈峰 authored
40
                $('.buriedpoint').on('click', bpClickHdl); // eslint-disable-line
沈志敏 authored
41
            }
王水玲 authored
42 43 44 45 46 47 48 49
        },
        error: function() {
            tip.show('网络断开连接了~');
        }
    });
}

function scrollHandler() {
王水玲 authored
50
    if (!stopLoading && ($(window).scrollTop() + $(window).height() > $('body').height() * 0.75)) {
王水玲 authored
51 52 53 54 55 56 57
        stopLoading = true;
        page++;
        massageAJAX(page);
    }
}

$(window).scroll(function() {
王水玲 authored
58
    window.requestAnimationFrame(scrollHandler);
王水玲 authored
59 60 61 62 63
});

if ($('.collocation-list').find('li').length === 0) {
    massageAJAX(1);
}
沈志敏 authored
64 65

// app埋点
陈峰 authored
66 67
let C_ID = window._ChannelVary[window.cookie('_Channel')];
let bpClickHdl = function() {
沈志敏 authored
68 69 70 71
    if (!window._yas || !window._yas.sendAppLogs) {
        return;
    }
陈峰 authored
72
    let $this = $(this);
ccbikai(👎🏻🍜) authored
73
沈志敏 authored
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    window._yas.sendAppLogs({
        appop: 'YB_H5_STROLL_STAR_FLR_C',
        param: JSON.stringify({
            C_ID: C_ID,
            TAB_INDEX: 2,
            TAB_NAME: '星搭配',
            CONTENT_INDEX: $this.index() + 1,
            CONTENT_ID: $this.attr('articleId')
        })
    }, true);
};

setTimeout(function() {
    if (!window._yas || !window._yas.sendAppLogs) {
        return;
    }
    window._yas.sendAppLogs({
        appop: 'YB_H5_STROLL_STAR_TAB_C',
        param: JSON.stringify({
            C_ID: C_ID,
            TAB_INDEX: 2,
            TAB_NAME: '星搭配'
        })
    }, true);
}, 500);