/*
 * @Author: ***
 * @LastEditors: ***
 */
var share = {
    init: function (array) {
        if (Array.isArray(array)) {
            // $("#shareList").css("position","absolute").css("bottom",100).css("left",Util.getElementFixed(target.element).currentX);
            array.forEach(function (item) {
                share.addShareItem(item);
            });

            window.$("#shareList ul li").on('mouseover', function (event) {
                //  移入
                var children = event.target.children;
                if (children.length > 0) {
                    window.$(children[0]).addClass("hover");
                }
            }).on('mouseout', function (event) {
                //移出
                var children = event.target.children;
                if (children.length > 0) {
                    window.$(children[0]).removeClass("hover");
                }
            }).on('click', function (event) {
                var children = event.target.children;
                if (children.length > 0) {
                    children[0].click();
                }
            })
            // window.$("#shareList ul li").click(function (event) {
            //     var children = event.target.children;
            //     if (children.length > 0) {
            //         children[0].click();
            //     }
            // })
            //document.documentElement.addEventListener('click', share.hide());
        }
        // document.documentElement.addEventListener('mousedown', share.hide);
    },
    addShareItem: function (type) {
        //目前支持的站点有 新浪微博、QQ空间、QQ微博、QQ、微信（暂时无配置）
        switch (type.toLowerCase()) {
            case "sina":
                {
                    // 新浪微博
                    window.$("#shareList ul").append(`<li id="share_sina" data-sites="weibo">${window.$i18n.t("info.57")}</li>`);
                    window.$("#share_sina").share();
                    break;
                }
            case "qzone":
                {
                    // QQ空间
                    window.$("#shareList ul").append(`<li id="share_qzone" data-sites="qzone">${window.$i18n.t("info.50")}</li>`);
                    window.$("#share_qzone").share();
                    break;
                }
            case "qqconnect":
                {
                    // QQ分享
                    window.$("#shareList ul").append(`<li id="share_qqconnect" data-sites="qq">${window.$i18n.t("info.59")}</li>`);
                    window.$("#share_qqconnect").share();
                    break;
                }
            case "wechat":
                {
                    // 微信分享
                    window.$("#shareList ul").append(`<li id="share_wechat" data-sites="wechat">${window.$i18n.t("info.53")}</li>`);
                    window.$("#share_wechat").share();
                    break;
                }
            default:
                {
                    break;
                }
        }
    },
    show: function (target) {
        window.$("#shareList").css("left", Util.getElementFixed(target).currentX);
        window.$("#shareList").show();
        window.that.renderElement.addEventListener('mousedown', share.hide);
    },
    hide: function () {
        window.$("#shareList").hide();
        window.that.renderElement.removeEventListener('mousedown', share.hide);
    }
}
