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分享插件,集成了我们公司常用的几个分享平台. 但是总感觉之前的结构上很不理想,样式,行为揉成一起,心里想的做的完美,实际上总是很多的偏差,所以这次我对其进行了改版. ...
随机推荐
- UVa 129 Krypton Factor困难的串 (dfs 递归搜索)
回溯法,只需要判断当前串的后缀,而不是所有的子串 #include<iostream> #include<cstdio> using namespace std; ]; int ...
- iOS开发——OC篇&特殊数据类型
一些特殊的数据类型 id.nil.Nil.SEL ,IMP Objective-C中有一些很有趣的数据类型经常会被错误地理解.他们中的大多数都可以在/usr/include/objc/objc.h或者 ...
- (推荐)jquery.pagination.js分页
序言 本来想自己对这个分页使用做一些总结的,但发现大神们已经总结的很好了.所以给推荐一下. 转自:http://www.cnblogs.com/knowledgesea/archive/2013/01 ...
- 朗科U903 低级格式化后,量产错误:read onlypage (控制器芯片群联2251-03)的解决方案
1. 下载群联量产工作 MPALL v3.63.0D for Netac 2. 在Setting页面,选择如下(红色矩形选中): 3. 然后执行量产,量产完成后,重新插拔就能看到U盘.
- ViewPage和ActionBar打造滑动视图
滑动效果非常流畅,可以将页签放置到ActionBar上,点击页签可以切换ViewPage,滑动ViewPage会同步更显Tabs. main.xml <?xml version="1. ...
- android 多线程断点续传下载
今天跟大家一起分享下Android开发中比较难的一个环节,可能很多人看到这个标题就会感觉头很大,的确如果没有良好的编码能力和逻辑思维,这块是很难搞明白的,前面2次总结中已经为大家分享过有关技术的一些基 ...
- 设计模式(三): FACTORY工厂模式 -- 创建型模式
1.定义 定义一个用于创建对象的接口,让子类决定实例化哪一个类,Factory Method使一个类的实例化延迟到了子类. 2.适用场景 1.第一种情况是对于某个产品,调用者清楚地知道应该使用哪个具体 ...
- Pascal's Triangle II —LeetCode
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- 用Jpush极光推送实现抓取特定某个用户Log到七牛云服务器
场景 我们的app常常会出现某个特定用户的手机出现异常情况,(注意不是所有用户,特定机型特定用户)如果用友盟,那么多log你也抓不完 ,看不到log就无法解决问题. 那么问题来了,如何实现对特定某个用 ...
- F - Truck History - poj 1789
有一个汽车公司有很多年的汽车制造历史,所以他们会有很多的车型,现在有一些历史学者来研究他们的历史,发现他们的汽车编号很有意思都是有7个小写字母组成的,而且这些小写字母具有一些特别的意义,比如说一个汽车 ...