index-editor.page.js 2.07 KB
/**
 * 列表页,编辑页
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/10/10
 */
require('guang/index-editor.page.css');


var $ = require('yoho-jquery');

var info = require('./info-common');

var loadMore = info.loadMore;

var winH = $(window).height();

var $author = $('#author-infos');
var $tag = $('#tag');
var $gender = $('#gender');
var $isApp = $('#isApp');

var setting = {
    page: 2,
    end: false
};

var $infos = $('#info-list');
var getDynamicData = require('./list-dynamic');

require('../common');

getDynamicData.getDynamicData();

info.initInfosEvt($infos);

if ($author.length > 0) {
    $.extend(setting, {
        authorId: $author.data('id'),
        isApp: $isApp.val()
    });
}

if ($tag.length > 0) {
    $.extend(setting, {
        tag: $tag.val(),
        gender: $gender.val(),
        isApp: $isApp.val()
    });
}

function scrollHandler() {
    if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $infos.height()) {
        loadMore($infos, setting);
    }
}

// srcoll to load more
$(window).scroll(function() {
    window.requestAnimationFrame(scrollHandler);
});

// app埋点
var C_ID = window._ChannelVary[window.cookie('_Channel')];

$('.info-list').on('click', function(e) {
    if (!window._yas || !window._yas.sendAppLogs) {
        return;
    }

    var $this = $(e.target),
        $btn = $this.closest('.like-btn'),
        $info = $this.closest('.guang-info');

    if ($btn.length > 0) {
        // 点赞
        window._yas.sendAppLogs({
            appop: 'YB_H5_STROLL_AUTHOR_LIKE_C',
            param: JSON.stringify({
                C_ID: C_ID,
                TYPE: $btn.hasClass('like') ? 2 : 1,
                CONTENT_ID: $info.data('id')
            })
        }, true);
    } else if ($info.length > 0) {
        // 点击各楼层
        window._yas.sendAppLogs({
            appop: 'YB_H5_STROLL_AUTHOR_FLR_C',
            param: JSON.stringify({
                C_ID: C_ID,
                CONTENT_INDEX: $('.guang-info').index($info) + 1,
                CONTENT_ID: $info.data('id')
            })
        }, true);
    }
});