Skip to content

Commit

Permalink
reference generator.js
Browse files Browse the repository at this point in the history
  • Loading branch information
bradvin committed Nov 8, 2013
1 parent cf02992 commit 270e8a8
Showing 1 changed file with 3 additions and 145 deletions.
148 changes: 3 additions & 145 deletions generator.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3,151 +3,9 @@
<html>
<head>
<title>Social Network Link Generator</title>
<!-- <script src="js/app.js" type="text/javascript"></script>
<link href="css/app.css" rel="stylesheet"/> -->
<script src="http://cdn.jsdelivr.net/zepto/1.0rc1/zepto.min.js" type="text/javascript"></script>
<script src="generator.js" type="text/javascript"></script>
<link rel="stylesheet" href="font.css">
<script>
// create social networking pop-ups
(function() {

var Networks = [
{
name: 'Facebook',
class: 'facebook',
url: 'http://www.facebook.com/sharer.php?s=100&p[url]={url}&p[images][0]={img}&p[title]={title}&p[summary]={desc}'
},
{
name: 'Facebook (feed dialog)',
class: 'facebook',
url: 'https://www.facebook.com/dialog/feed?app_id={app_id}&link={url}&picture={img}&name={title}&caption={desc}&redirect_uri={redirect_url}'
},
{
name: 'Twitter',
class: 'twitter',
url: 'https://twitter.com/share?url={url}&text={title}&via={via}&hashtags={hashtags}'
},
{
name: 'Google+',
class: 'google',
url: 'https://plus.google.com/share?url={url}',
},
{
name: 'Pinterest',
class: 'pinterest',
url: 'https://pinterest.com/pin/create/bookmarklet/?media={img}&url={url}&is_video={is_video}&description={title}',
},
{
name: 'Linked In',
class: 'linkedin',
url: 'http://www.linkedin.com/shareArticle?url={url}&title={title}',
},
{
name: 'Buffer',
class: 'buffer',
url: 'http://bufferapp.com/add?text={title}&url={url}',
},
{
name: 'Digg',
class: 'digg',
url: 'http://digg.com/submit?url={url}&title={title}',
},
{
name: 'Tumblr',
class: 'tumblr',
url: 'http://www.tumblr.com/share/link?url={url}&name={title}&description={desc}',
},
{
name: 'Reddit',
class: 'reddit',
url: 'http://reddit.com/submit?url={url}&title={title}',
},
{
name: 'StumbleUpon',
class: 'stumbleupon',
url: 'http://www.stumbleupon.com/submit?url={url}&title={title}',
},
{
name: 'Delicious',
class: 'delicious',
url: 'https://delicious.com/save?v=5&provider={provider}&noui&jump=close&url={url}&title={title}',
}
];

this.generateUrl = function(url, opt) {
var prop, arg, arg_ne;
for (prop in opt) {
arg = '{' + prop + '}';
if (url.indexOf(arg) !== -1) {
url = url.replace(new RegExp(arg, 'g'), encodeURIComponent(opt[prop]));
}
arg_ne = '{' + prop + '-ne}';
if (url.indexOf(arg_ne) !== -1) {
url = url.replace(new RegExp(arg_ne, 'g'), opt[prop]);
}
}
return this.cleanUrl(url);
};

this.cleanUrl = function(fullUrl) {
//firstly, remove any expressions we may have left in the url
fullUrl = fullUrl.replace(/\{([^{}]*)}/g, '');

//then remove any empty parameters left in the url
var params = fullUrl.match(/[^\=\&\?]+=[^\=\&\?]+/g),
url = fullUrl.split("?")[0];
if (params && params.length > 0) {
url += "?" + params.join("&");
}

return url;
};

var _this = this;

window.generateSocialUrls = function(opt) {
if (typeof opt !== 'object') { return false; }
var links = [], network;
for (var i = 0; i < Networks.length; i++) {
network = Networks[i];
links.push({
name : network.name,
class : network.class,
url : _this.generateUrl(network.url, opt)
});
}
return links;
};

window.doPopup = function(e) {
e = (e ? e : window.event);
var t = (e.target ? e.target : e.srcElement),
width = t.data-width || 800,
height = t.data-height || 500;


// popup position
var
px = Math.floor(((screen.availWidth || 1024) - width) / 2),
py = Math.floor(((screen.availHeight || 700) - height) / 2);

// open popup
var popup = window.open(t.href, "social",
"width="+width+",height="+height+
",left="+px+",top="+py+
",location=0,menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1");

if (popup) {
popup.focus();
if (e.preventDefault) e.preventDefault();
e.returnValue = false;
}

return !!popup;
};

}());
</script>
</head>
<body>
<h1>Social Link Generator</h1>
Expand All @@ -174,7 +32,7 @@ <h1>Social Link Generator</h1>
via: $('#input_via').val(),
hashtags: $('#input_hashtags').val()
},
links = window.generateSocialUrls(params),
links = SocialShare.generateSocialUrls(params),
$target = $('#share_target');

$target.html(''); //clear!
Expand All @@ -184,7 +42,7 @@ <h1>Social Link Generator</h1>
$target.append('<a class="soc ' + link.class + '" target="_blank" href="' + link.url + '" title="' + link.name + '"></a>');
}

$target.find('a').on('click', window.doPopup);
$target.find('a').on('click', SocialShare.doPopup);
});
});
</script>
Expand Down

0 comments on commit 270e8a8

Please sign in to comment.