{"size": 2500, "ext": "js", "max_stars_repo_path": "source-src/js/util.js", "max_stars_repo_name": "dcalsky/hexo-theme-archer", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source-src/js/util.js", "max_issues_repo_name": "dcalsky/hexo-theme-archer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source-src/js/util.js", "max_forks_repo_name": "dcalsky/hexo-theme-archer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.6455696203, "max_line_length": 124, "alphanum_fraction": 0.4516}
var archerUtil = {
    backTop: function () {
        let topTimer = setInterval(function () {
            let currTop = document.body.scrollTop;
            document.body.scrollTop -= Math.max(Math.ceil(currTop / 9) + 2);
            if (currTop === 0) {
                clearInterval(topTimer);
            }
        }, 20);
    },

    getScrollTop: function () {
        return document.documentElement.scrollTop || document.body.scrollTop;
    },

    // 获取元素在页面上相对左上角的位置
    getAbsPosition: function (e) {
        let x = e.offsetLeft,
            y = e.offsetTop;
        while (e = e.offsetParent) {
            x += e.offsetLeft;
            y += e.offsetTop;
        }
        return {
            'x': x,
            'y': y
        };
    },
    dateFormater: function (date, fmt) {
        var o = {
            'M+': date.getMonth() + 1, //月份 
            'd+': date.getDate(), //日 
            'h+': date.getHours(), //小时 
            'm+': date.getMinutes(), //分 
            's+': date.getSeconds(), //秒 
            'q+': Math.floor((date.getMonth() + 3) / 3), //季度 
            'S': date.getMilliseconds() //毫秒 
        };
        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp('(' + k + ')').test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)));
            }
        }
        return fmt;
    },
    toggler: function (target, eventName, btn, addClassName, removeClassName, optEvent) {
        if (!(target && typeof window !== 'undefined' && (target === window || target.nodeType))) {
            return;
        }
        btn.addEventListener(eventName, function (eve) {
            if (addClassName) {
                let classNameArr = addClassName.split(/[, ]/);
                let length = classNameArr.length;
                while (length--) {
                    target.classList.add(classNameArr[length]);
                }
            }
            if (removeClassName) {
                let classNameArr = removeClassName.split(/[, ]/);
                let length = classNameArr.length;
                while (length--) {
                    target.classList.remove(classNameArr[length]);
                }
            }
            if (optEvent) {
                optEvent(eve);
            }
        });
    }


};

export {
    archerUtil
};