class mFooter {
    constructor() {
        this.$toTop = $('#toTop')

        this.init()
        this.initDwstatic();
    }
    init() {
        if (toTop.length == 0) return

        this.checkScrollTop()
        this.setEvent()
    }
    setEvent() {
        this.$toTop.click(function () {
            $('html,body').animate({
                scrollTop: 0
            })
        })

        $(window).scroll(this.checkScrollTop.bind(this))
    }
    setToTop(state) {
        if (state == 'show' && this.$toTop.is(':hidden'))
            this.$toTop.show()
        else if (state == 'hide' && this.$toTop.is(':visible'))
            this.$toTop.hide()
    }
    checkScrollTop() {
        var scrollTop = document.body.scrollTop
        if (scrollTop >= 300)
            this.setToTop('show')
        else
            this.setToTop('hide')
    }
    /** 自定义点击统计上报 */
    initDwstatic () {
        function sendStatistic($target) {
            var ckstat = $target.data('ckstat')
            var requestTarget = 'http://clickstats.duowan.com/index.php?r=stats/index&event='

            if (!ckstat) return

            setTimeout(function () {
                new Image().src = requestTarget + encodeURIComponent(ckstat)
            }, 100)
        }

        $('[data-dwclick]').off('click');
        $('[data-dwhover]').off('mouseenter');

        $(document).on('click', '[data-dwclick]', function (evt) {
            sendStatistic($(this))
        })

        $(document).on('mouseenter', '[data-dwhover]', function (evt) {
            sendStatistic($(this))
        })
    }
}

$(() => {
    new mFooter
})