Blame view

public/js/guang/collocation.page.js 2.7 KB
王水玲 authored
1 2 3 4 5 6 7 8 9 10
/**
 * 星潮教室-星搭配分页加载
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/4/12
 */

var $ = require('yoho-jquery'),
    tip = require('../plugin/tip'),
    loading = require('../plugin/loading'),
    lazyLoad = require('yoho-jquery-lazyload'),
王水玲 authored
11
    ellipsis = require('yoho-mlellipsis');
王水玲 authored
12
王水玲 authored
13 14
var stopLoading = false,
    page = 1;
王水玲 authored
15
王水玲 authored
16
require('./list-common');
王水玲 authored
17
王水玲 authored
18
ellipsis.init();
王水玲 authored
19
王水玲 authored
20
function massageAJAX(pageData) {
王水玲 authored
21 22 23 24 25 26 27
    var $this, $title, $cont;

    loading.showLoadingMask();
    $.ajax({
        type: 'GET',
        url: '/guang/star/collocation/list',
        data: {
ccbikai authored
28 29
            page: pageData,
            appVersion: window.queryString.app_version
王水玲 authored
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
        },
        dataType: 'html',
        success: function(data) {
            stopLoading = false;

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

            $('.collocation-list').append(data);

            // 限制标题字数
            $('.cont-area').each(function() {
                $this = $(this);
                $title = $this.find('.title');
                $cont = $this.find('.cont-txt');

                $title[0].mlellipsis(2);
                $cont[0].mlellipsis(2);
            });
王水玲 authored
52
            loading.hideLoadingMask();
王水玲 authored
53
            lazyLoad($('img.lazy'));
沈志敏 authored
54 55 56 57

            if (pageData === 1) {
                $('.buriedpoint').on('click', bpClickHdl);
            }
王水玲 authored
58 59 60 61 62 63 64 65
        },
        error: function() {
            tip.show('网络断开连接了~');
        }
    });
}

function scrollHandler() {
王水玲 authored
66
    if (!stopLoading && ($(window).scrollTop() + $(window).height() > $('body').height() * 0.75)) {
王水玲 authored
67 68 69 70 71 72 73
        stopLoading = true;
        page++;
        massageAJAX(page);
    }
}

$(window).scroll(function() {
王水玲 authored
74
    window.requestAnimationFrame(scrollHandler);
王水玲 authored
75 76 77 78 79
});

if ($('.collocation-list').find('li').length === 0) {
    massageAJAX(1);
}
沈志敏 authored
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

// app埋点
var C_ID = window._ChannelVary[window.cookie('_Channel')];
var bpClickHdl = function() {
    if (!window._yas || !window._yas.sendAppLogs) {
        return;
    }

    var $this = $(this);
    
    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);