• 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;
    });

    })();

  • 相关阅读:
    Android开发之基本控件和详解四种布局方式
    Android开发之Activity的创建跳转及传值
    设计模式(十三):从“FQ”中来认识代理模式(Proxy Pattern)
    设计模式(十二):通过ATM取款机来认识“状态模式”(State Pattern)
    设计模式(十一):从文Finder中认识"组合模式"(Composite Pattern)
    设计模式(十):从电影院中认识"迭代器模式"(Iterator Pattern)
    设计模式(八): 从“小弟”中来类比"外观模式"(Facade Pattern)
    设计模式(六):控制台中的“命令模式”(Command Pattern)
    设计模式(三):“花瓶+鲜花”中的装饰者模式(Decorator Pattern)
    设计模式(一):“穿越火线”中的“策略模式”(Strategy Pattern)
  • 原文地址:https://www.cnblogs.com/zhuliming-java/p/5405509.html
Copyright © 2020-2023  润新知