zoukankan      html  css  js  c++  java
  • share js 分享代码

    (function(){
    var $doc = $(document);

    var shareHandlers = {
    'twitter': function(prop,shareUrl){
    var D=550,A=450,C=screen.height,B=screen.width,H=Math.round((B/2)-(D/2)),G=0;
    if(C>A){G=Math.round((C/2)-(A/2))}
    window.open(shareUrl,'','left='+H+',top='+G+',width='+D+',height='+A+',personalbar=0,toolbar=0,scrollbars=1,resizable=1');
    },
    'facebook': function(prop,shareUrl){
    var D=550,A=450,C=screen.height,B=screen.width,H=Math.round((B/2)-(D/2)),G=0;
    if(C>A){G=Math.round((C/2)-(A/2))}
    window.open(shareUrl,'','left='+H+',top='+G+',width='+D+',height='+A+',personalbar=0,toolbar=0,scrollbars=1,resizable=1');
    },
    'googleplus': function(prop,shareUrl){
    var D=600,A=460,C=screen.height,B=screen.width,H=Math.round((B/2)-(D/2)),G=0;
    if(C>A){G=Math.round((C/2)-(A/2))}
    window.open(shareUrl, 'Share to Google+','left='+H+',top='+G+',width='+D+',height='+A+',menubar=no,location=no,status=no');
    },
    'weibo': null,
    'tencentweibo': null,
    'qzone': null
    }

    $doc.on('click', '.sns-share-list .share-btn[data-sns]', shareClickHandler);
    $doc.on('click', '.djieventsbtn[data-sns]', shareClickHandler);
    $doc.on('click', '.newssharebtn[data-sns]', shareClickHandler);

    function shareClickHandler(e){
    var $target = $(e.currentTarget),
    type = $target.data('sns'),
    props = {
    id: $target.data('id'),
    img: $target.data('img'),
    title: $target.data('title'),
    description: $target.data('description'),
    url: $target.data('url'),
    docTitle: document.title
    };

    //线上环境为裸协议,某些SNS平台解析错误,所以针对这种情况统一使用http协议
    if(/^///.test(props.img)){
    props.img = 'http:' + props.img;
    }

    //添加平台追踪链接
    props.url = addPlatform(props.url,type);

    var shareUrl = getShareUrl(type, props);

    if(shareHandlers[type]){
    shareHandlers[type](props,shareUrl);
    }else{
    window.open(shareUrl, '', '');
    }
    }
    function getShareUrl(type, origin_props){
    var url = '';

    var props = {
    id: origin_props.id,
    img: encodeURIComponent( origin_props.img ),
    title: encodeURIComponent( origin_props.title ),
    description: encodeURIComponent( origin_props.description ),
    url: encodeURIComponent( origin_props.url ),
    docTitle: document.title
    };

    switch(type){
    case 'twitter':
    url = '//twitter.com/intent/tweet?url='+ props.url +'&text='+ props.description;
    break;
    case 'facebook':
    url = '//www.facebook.com/sharer/sharer.php?p[url]='+ props.url;
    break;
    case 'googleplus':
    url = '//plus.google.com/share?url='+ props.url;
    break;
    case 'weibo':
    url = 'http://service.weibo.com/share/share.php?url='+ props.url +'&title='+ props.title +' '+ props.description +'&pic='+ props.img +'&searchPic=false';
    break;
    case 'tencentweibo':
    url = 'http://share.v.t.qq.com/index.php?c=share&a=index&url='+ props.url +'&title='+ props.description +'&pic='+ props.img;
    break;
    case 'qzone':
    url = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+ props.url +'&title='+ props.docTitle +'&summary='+ props.description +'&pics='+ props.img;
    break;
    }

    return url;
    }

    function addPlatform(url,platform){
    var qsReg = /(?[^#.]*)/,
    hashReg = /(#.*)/,
    hasHash = hashReg.test(url),
    hash = '',
    platform = platform ? platform : 'copy';

    if(hasHash){
    url = url.replace(hashReg, function(macthedHash){
    hash = macthedHash;
    return macthedHash = '';
    });
    }
    if(qsReg.test(url)){
    url = url.replace(qsReg, '$1&p='+ platform);
    } else {
    url += '?p='+ platform;
    }

    return url + hash;
    }
    $("#apply h3").click(function(){

    $(this).next("#apply .boxs").slideToggle("slow")
    .siblings("#apply .boxs:visible").slideToggle("slow");
    $(this).toggleClass("current");
    $(this).siblings("#apply h3").removeClass("current");
    return false;
    });

    })();

  • 相关阅读:
    TCP粘包的拆包处理
    字节序列化
    同步,异步,阻塞和非阻塞
    用Doxygen生成文档
    Visual Studio新建的源文件的默认编码
    Boost编程之获取可执行文件的当前路径
    特征点寻找的基础数据结构和函数
    寻找Harris、Shi-Tomasi和亚像素角点
    特征点的基本概念和如何找到它们
    工业相机与普通相机的差别
  • 原文地址:https://www.cnblogs.com/zhuliming-java/p/5405509.html
Copyright © 2011-2022 走看看