Blame view

public/js/product/hot-rank.page.js 3.72 KB
zhangxiaoru authored
1
var $ = require('yoho-jquery'),
zhangxiaoru authored
2 3

    // Swiper = require('yoho.iswiper'),
zhangxiaoru authored
4 5 6 7 8 9 10 11 12 13 14 15 16 17
    lazyLoad = require('yoho-jquery-lazyload'),
    loading = require('../plugin/loading');

var page = 1,
    winH,
    listTop,
    navSwiper,
    notab = 0,
    sort = '',
    id = '',
    hotrankNav,
    noResult = '<p class="no-result">未找到相关搜索结果</p>';

require('../common/suspend-cart');
zhangxiaoru authored
18
require('../common');
zhangxiaoru authored
19
zhangxiaoru authored
20 21 22 23 24 25 26 27 28 29
var share = require('../common/share');

share({
    title: '有货【会员日】开启啦!9月28日潮集狂欢趴等你来HI!限时6大福利,快参与起来喽~',
    link: location.href,
    desc: 'YOHO!BUY',
    imgUrl: 'http://static.yohobuy.com/m/v1/img/touch/apple-touch-icon-144x144-precomposed-new.png'

});
zhangxiaoru authored
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
function hotrank(page, sort, tabId, notab) {
    loading.showLoadingMask();
    $.ajax({
        type: 'GET',
        url: '/product/newsale/selectHotrank?' + sort,
        dataType: 'html',
        data: {
            page: page,
            tab_id: tabId,
            notab: notab
        },
        success: function(data) {
            if (data === ' ') {
                if ($('.rank-main').length < 1 && $('.goods-nav').length < 1) {
                    $('#hotRank').html(noResult);
                } else {
                    if (page === 1) {
                        hotrankNav = $('.goods-nav').prop('outerHTML');

                        $('#hotRank').html(hotrankNav + noResult);
                    }
                }
            } else {
                $('.no-result').remove();
                if (page === 1) {
                    $('.rank-main').remove();
                }
                $('#hotRank').append(data);
            }

            lazyLoad($('img.lazy'));
            $('.rank-main ul li:gt(9)').find('.item-content i').removeClass('top');
            winH = $(window).height();
            if ($('.rank-main').length !== 0) {
                $('#yoho-footer').css('position', 'static');
                listTop = $('.rank-main').find('ul').offset().top;
            } else {
                $('#yoho-footer').css({
                    position: 'fixed',
                    width: '100%'
                });
            }
            navSwiper = new Swiper('.s-goods-nav', {
                grabCursor: true,
                slidesPerView: 'auto',
                slideElement: 'li'
            });
            loading.hideLoadingMask();
        }
    });
}

function scrollHandler() {
    if (page === 2) {
        return;
    }
    if ($(window).scrollTop() + winH < listTop + $('#hotRank').height() - 100) {
        return;
    }
    page = 2;
    notab = 1;
    hotrank(page, sort, id, notab);
}

$(window).scroll(function() {
    window.requestAnimationFrame(scrollHandler);
});

hotrank(page, sort, id, notab);
$('#hotRank').on('touchend touchcancel', function(e) {
    var ev = ev || window.event;
    var target = ev.target || ev.srcElement;

    if (target.nodeName.toLowerCase() === 'span') {
        $('.s-goods-nav .nav-item').removeClass('active');
        target.parentNode.className = 'active ' + target.parentNode.className;
        id = target.getAttribute('data-id') ? target.getAttribute('data-id') : '';
        sort = target.getAttribute('data-sort') ? target.getAttribute('data-sort') : '';
        page = 1;
        notab = 1;
        hotrank(page, sort, id, notab);
    }
});
$('#hotRank').bind('contextmenu', function(e) {
    return false;
});
$('#hotRank').on('touchstart', function(e) {
    var ev = ev || window.event;
    var target = ev.target || ev.srcElement;

    if (target.nodeName.toLowerCase() === 'span') {
        target.parentNode.className = 'bgActive ' + target.parentNode.className;
    }
}).on('touchend touchcancel', function() {
    $('.s-goods-nav .nav-item').removeClass('bgActive');
});