/**
 * Common.js
 */

var sj = sj || {};
sj.checkBrowserCapability = function () {
    const isEdge = navigator.userAgent.indexOf('Edge') > -1;
    if (window.Device.browser.chrome && !isEdge) {
        let sVer = window.Device.browser.version;
        let s2 = sVer.substring(0, sVer.indexOf("."));
        let browserVersion = parseInt(s2);
        return browserVersion > 66;
    } else {
        return false;
    }
}
sj.checkChromuimVersion = function () {
    if (window.Device.browser.chrome &&
        window.Device.browser.version.substr(0, window.Device.browser.version.indexOf(".")) > 70)
        return true;
}
sj.showToast = function (msg, time) {
    var sjToast = $("#sjToast");
    if (sjToast[0]) {
        sjToast.stop();
        sjToast.remove();
        sjToast = null;
    }
    var sHtml = "<div id='sjToast' style='position:fixed;font-size:16px;z-index:99;top:" + (document.documentElement.scrollTop / document.documentElement.clientHeight * document.documentElement.clientHeight - 100) + "px;left:50%;transform:translate(-50%, 0);background-color:rgba(0,0,0,0.6);border-radius:10px;color:white;padding:5px 10px;word-wrap:break-word;word-break:normal; '>" + msg + "</div>"
    sjToast = $(sHtml);
    sjToast.appendTo($(document.body));
    sjToast.animate({ top: (document.documentElement.scrollTop / document.documentElement.clientHeight * document.documentElement.clientHeight - 200) + 'px' }, 500, function () {
        setTimeout(function () {
            sjToast.css("display", "none");
        }, time == undefined ? 1500 : time);
    })
}
//获取url中的参数
sj.getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
//关闭窗口
sj.close = function () {
    try {
        if (window.webkit && webkit.messageHandlers) {
            window.webkit.messageHandlers.close.postMessage({});
        }
        else if (window.CouldPlatform) {
            window.CouldPlatform.close();
        }
        else {
            close.postMessage("");
        }
        window.history.go(-1);
    } catch (e) {

    }
};

export {sj}
