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;
});
})();
share js 分享代码的更多相关文章
- js 分享代码--完整示例代码
<div class="bdsharebuttonbox" data-tag="share_1"> <a class="bds_ms ...
- js分享代码
<<!DOCTYPE html><html><head> <title></title></head> <body& ...
- JS实现页面分享代码share,不需要第三方接口
在开发一个页面的时候常常会有这么一个小功能,就是分享该页面中的信息. 常见的分享代码有百度分享,JiaThis分享插件(现在貌似不能用了),bshare分享插件等,我主要分享一下自定义分享代码,如下: ...
- js快速分享代码
这是一款简单易用的文章分享工具,您只需将下面的html代码拷贝到模板中就可以实现文章快速分享功能.如果您想分享你的博客.个人网站或者企业网站等等,下面是两款不错的分享工具,值得拥有! 1. <d ...
- 页面分享代码share
在开发一个页面的时候常常会有这么一个小功能,就是分享该页面中的信息. 常见的分享代码有百度分享,JiaThis分享插件,bshare分享插件等,我主要分享一下自定义分享代码,如下: function ...
- 百度分享share.js插件
//百度分享window._bd_share_config = { common : { bdText : '分享标题', bdDesc : '分享描述', bdUrl : '分享链接', bdPic ...
- share.js轻松分享/邀请
GitHub地址 https://github.com/overtrue/share.js 安装 安装的方法很多,大家选择自己合适的进行安装就好. clone $ git clone https:// ...
- share.js一键分享到微博、QQ空间、QQ好友、微信、腾讯微博、豆瓣、Facebook、Twitter、Linkedin、Google+、点点等
官网上面 https://github.com/overtrue/share.js非常详细的介绍了share.js他的使用 使用方式有:第一:使用 npm npm install social-sha ...
- 自己封装的一个JS分享组件
因为工作的需求之前也封装过一个JS分享插件,集成了我们公司常用的几个分享平台. 但是总感觉之前的结构上很不理想,样式,行为揉成一起,心里想的做的完美,实际上总是很多的偏差,所以这次我对其进行了改版. ...
随机推荐
- 12100 Printer Queue(优先队列)
12100 Printer Queue12 The only printer in the computer science students’ union is experiencing an ex ...
- "类名.this"与"this"的区别
"this"是指(或者说:所代表的是)当前这段代码所在的类的对象.而"类名.this"是指"类名"的对象(一般在匿名类或内部类中使用来调用外 ...
- linux ftp 搭建和相关问题解决
1. 查看是否安装vsftprpm –qa|grep vsftpd如果出现 vsftpd-2.0.5-16.el5_5.1 说明已经安装 vsftp 安装vsftpyum -y install vsf ...
- 转:PHP include()和require()方法的区别
文章来自于:http://developer.51cto.com/art/200909/153687.htm 本文总结了PHP的include()和require()两种包含外部文件的方法的不同之处. ...
- poj 2886Who Gets the Most Candies?
http://poj.org/problem?id=2886 #include <cstdio> #include <cstring> #include <algorit ...
- ISO14443-4块传输协议的实现
ISO1444-3块传输协议主要用于应用数据的传输,其实现如下: unsigned char Apdu(unsigned char *comm,unsigned short len,unsigned ...
- Bellman_ford最短路
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> ...
- fastjson将bean转成字符串时首字母变小写问题
一个项目需求要求返回值为JSON格式,且大多数字段是首字母大写,还有些是类似N_TX这样的格式,在输出这样的结果时遇到了问题,由于时间紧,就直接拷贝需要的结果字段建立JavaBean类,本以为最后直接 ...
- Visual Studio创建跨平台移动应用_01.Cordova&Xamarin
目前开发移动应用有三种模式:Native.Hybird.Web,若要开发跨平台的移动应用,又希望与本地API交互,那么Hybird是一个非常好的选择. 作为一个.Net程序员, ...
- HDU 4828 - Grids (Catalan数)
题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=4828 Catalan数的公式为 C[n+1] = C[n] * (4 * n + 2) / (n ...