Skip to content

Commit

Permalink
Updated dist
Browse files Browse the repository at this point in the history
  • Loading branch information
gwagroves committed Mar 7, 2017
1 parent 5ae4560 commit 6529b58
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
46 changes: 35 additions & 11 deletions dist/ShareLinks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global define */
(function( root, factory ) {
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
Expand All @@ -10,6 +10,11 @@
}
}(this, function($) {

function getDocumentLanguage() {
var lang = $('html').attr('lang');
return lang ? lang : '';
}

function getContentData(jq) {
return jq.attr('data-content') ? jq.attr('data-content') : '';
}
Expand All @@ -22,35 +27,54 @@
window.open(url, name, opts);
}

function isMobile() {
return /Mobi/.test(navigator.userAgent);
}

function getTwitterContent(jq) {
var permalink = jq.attr('href'),
content = getContentData(jq);

return content ? encodeURIComponent(content + ' ' + permalink) : permalink;
}

var instance = {
initFacebook: function(jq) {
jq.on('click', function(ev) {
var permalink = $(this).attr('href');
ev.preventDefault();

ev.preventDefault();
doOpen('https://www.facebook.com/sharer.php?u=' + permalink, 'facebook', 'toolbar=no,width=700,height=400');
});
},

initTwitter: function(jq) {
jq.on('click', function(ev) {
var permalink = $(this).attr('href'),
content = getContentData($(this)),
fullcontent = content ? encodeURIComponent(content + ' ' + permalink) : permalink;
var fullcontent = getTwitterContent(jq);

if (isMobile()) {
jq.attr('href', 'twitter://post?message=' + fullcontent);
return;
}

jq.on('click', function(ev) {
ev.preventDefault();
doOpen('https://www.twitter.com/home?status=' + fullcontent, 'twitter', 'toolbar=no,width=700,height=400');
doOpen('https://twitter.com/intent/tweet?text=' + getTwitterContent($(this)), 'twitter', 'toolbar=no,width=700,height=400');
});
},

initWhatsapp: function(jq) {
var permalink = jq.attr('href');
jq.attr('href', 'whatsapp://send?text=' + permalink).attr('data-action', 'share/whatsapp/share');
},

initWeibo: function(jq) {
jq.on('click', function(ev) {
var permalink = $(this).attr('href');
var permalink = $(this).attr('href'),
lang = getDocumentLanguage(),
title = encodeURIComponent(getContentData($(this)));

ev.preventDefault();
$(this).attr('href', 'whatsapp://send?text=' + permalink).attr('data-action', 'share/whatsapp/share');

instance.opener($(this).prop('outerHTML'), 'whatsapp');
doOpen('http://service.weibo.com/share/share.php?url=' + permalink + '&appkey=&title=' + title + '&pic=&ralateUid=&language=' + lang, 'weibo', 'toolbar=no,width=700,height=400');
});
},

Expand Down
2 changes: 1 addition & 1 deletion dist/ShareLinks.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6529b58

Please sign in to comment.