js社交分享功能

/**微博转发
     * para: {id:'sohu',isNeedLoginTip:'xxxxx?',loginedMethod:getJobUserLink}
     * 默认调用方式:snsShareFun({id:'tqq',isNeedLoginTip:''})
     * 调用该方法的前提条件:
     * 1.需要为本页面的内容隐藏域:tips_mask_share_title 赋值
     * 2.需要为本页面的URL隐藏域:tips_mask_share_url 赋值
     * 3.需要在调用本方法的页面声明变量 var jobID (工作ID) 并为给变量赋值
     * 4.用到全局变量变量:isLogin,保证该值的正确性
     */
    var goUrl;
    function snsShareFun(obj){
        //微博类型
                var v_type;
        //跳转到微博的URL
                var url ;
        //新开窗口tip
                var tip ;
                //设定宽度
                var temp_width = obj.width;
            if(typeof(temp_width)=="undefined"){
                temp_width = screen.availWidth-400;
                }
            //设定高度
            var temp_height = obj.height;
            if(typeof(temp_height)=="undefined"){
                temp_height = screen.availHeight-200;
            }
            //设定分享内容
            var shareTitle = obj.shareTitle;
            if(typeof(shareTitle)=="undefined"){
                shareTitle = share_title;
                }
            //设定分享链接
                var shareUrl = obj.shareUrl;
                if(typeof(shareUrl)=="undefined"){
                        shareUrl = share_url;
                }
        if (obj.id=="sohu"){
                        url="http://t.sohu.com/third/post.jsp?url=?share_url&title=?share_title&content=utf-8";
            tip="转播到搜狐微博";
            v_type="0";
                }else if (obj.id=="tqq"){
                        url="http://v.t.qq.com/share/share.php?title=?share_title&url=?share_url&site=www.aceona.com&appkey="+encodeURI('7c3450bbecd247758089ee8df5cf546c');
            tip="转播到腾讯微博";
            v_type="1";
                }else if (obj.id=="tsina"){
                        url="http://v.t.sina.com.cn/share/share.php?title=?share_title&url=?share_url&appkey=" + 2937052444+ "&site=www.aceona.com&content=utf-8";
            tip="转播到新浪微博";
            v_type="2";
                }else if (obj.id=="qzone"){
                        url="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=?share_url&title=?share_title";
            tip="转播到QQ空间";
            v_type="3";
                }else if (obj.id=="bsh"){
                        url="http://bai.sohu.com/share/blank/add.do?link=?share_url&title=?share_title";
            tip="转播到白社会";
            v_type="4";
                }else if (obj.id=="douban"){
                        url="http://www.douban.com/recommend/?url=?share_url&title=?share_title";
            tip="转播到豆瓣网";
            v_type="5";
                }else if (obj.id=="xiaonei"){
                        url="http://share.renren.com/share/buttonshare.do?link=?share_url&title=?share_title";
            tip="转播到人人网";
            v_type="6";
                }
        goUrl = url;
                var isNeedLoginTip = obj.isNeedLoginTip;
                var loginedMethod = obj.loginedMethod;
                //判断是否需要登陆
                if(typeof(isNeedLoginTip)!="undefined")
                {
                        getCurrentUser(function(result){
                            
                            if(result.RESULT=="unauthorized"){//未登陆
                                if(isNeedLoginTip==''){
                                        isNeedLoginTip='登陆后分享可能会获得推荐奖金,确认吗?';
                                }
                                        jConfirm(isNeedLoginTip,"温馨提示",
                                         function(flag)
                                         {   
                                                 if(flag)
                                                 {
                                                     showLoginDiv();
                                                 }
                                                 else
                                                 {
                                                         commonShare(goUrl,tip,temp_width,temp_height,shareUrl,shareTitle);
                                                 }
                                });
                            }else{//已经登陆
                                        if(typeof(loginedMethod)!="undefined")
                                        {
                                                loginedMethod(v_type,callback);
                                        }else{
                                                getJobUserLink({async:false,post_id:jobID,share_type:v_type},function(data){
                                                        if(data!=null)
                                                        {
                                                                $("#tips_mask_share_url").val(data);
                                                        }
                                                        commonShare(goUrl,tip,temp_width,temp_height,shareUrl,shareTitle);
                                                });
                                        }
                                }
                    });
                }else
                {
                        commonShare(goUrl,tip,temp_width,temp_height,shareUrl,shareTitle);
                }
    } // end snsShareFun

        function commonShare(url,tip,temp_width,temp_height,shareUrl,shareTitle)
    {
                //定义新开窗口样式
            var defaultFeatures={
                scrollbars:"no",
                status:"yes",
                resizable:"no",
                titlebar:"no",
                width:temp_width,
                height:temp_height,
                top:Math.ceil(100),
                left:Math.ceil(200)
        };
        var content = url.replace("?share_url",encodeURIComponent(shareUrl)).replace("?share_title",encodeURIComponent(shareTitle));
        window.open(content,tip,defaultFeatures);
    }
    
        //获取url
        function getJobUserLink(param, method) {
                $.get("/action?UserShareAction=0&action=getShareLink", param,
                                function(data) {
                                        if (typeof method == "function") {
                                                method(data);
                                        } else {
                                                alert("method param error");
                                        }
                                });
        }

转载于:https://my.oschina.net/figoisxjs/blog/127495

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值