Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<title>New Tab - Random 48 Laws of Power</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="styles.css" type="text/css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="container">
Expand All @@ -16,9 +17,29 @@
<div id="content">
<p id="law-title"></p>
<p id="law-desc"></p>
<div>
<div id="fb-share-dialog" class="social-share-button" style="float: right;">
<span><i class="fa fa-facebook-f"></i>Share</span>
</div>
<div id="twitter-share-dialog" class="social-share-button">
<span><i class="fa fa-twitter"></i>Share</span>
</div>
</div>

</div>
</div>
</body>
<script type="text/javascript" src="laws.json"></script>
<script src="index.js"></script>
<script src="index.js"></script>
<!-- FB SDK -->
<script>
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/es_LA/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

</html>
61 changes: 58 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
(function(window){
console.log(data);
var random = Math.floor(Math.random() * 48);
document.getElementById('id').innerHTML = data[random].name;
document.getElementById('law-title').innerHTML = data[random].title;
document.getElementById('law-desc').innerHTML = data[random].desc;
document.getElementById('id').innerHTML = data[random].name;
document.getElementById('law-title').innerHTML = data[random].title;
document.getElementById('law-desc').innerHTML = data[random].desc;

window.fbAsyncInit = function () {
FB.init({
appId : '326214488180876', // App ID
status : false,
version: 'v2.0',
cookie : true,
xfbml : false // parse XFBML
});
}
document.getElementById('fb-share-dialog').onclick = function() {
var defaultUrl = "https://chrome.google.com/webstore/detail/random-48-laws-of-power/ldmplljofmghhnjapmbabolnigaeimed";
var fullQuote = getCurrentQuote();
FB.ui({
method: 'share',
display: 'popup',
href: defaultUrl,
quote: fullQuote,
}, function(response){
console.log(response);
});
}

document.getElementById('twitter-share-dialog').onclick = function() {
var defaultUrl = "https://chrome.google.com/webstore/detail/random-48-laws-of-power/ldmplljofmghhnjapmbabolnigaeimed";
var fullQuote = getCurrentQuote('twitter');
var twitterRedirectUrl = buildTwitterUrlParts(fullQuote, defaultUrl);
window.open(twitterRedirectUrl, '_blank');
}

function getCurrentQuote(type){
var type = type || 'facebook'
document.getElementById('law-desc')
var quoteId = " Law " + document.getElementById('id').textContent;
var lawTitle = " Quote: " + document.getElementById('law-title').textContent;
var lawDescription = "Description: " + document.getElementById('law-desc').textContent;
var fullQuote = quoteId + "\n" + lawTitle ;
// Since twitter only allows 140 Characters Max, it doesn't sense to
// add the description to it.
if (type !== 'twitter') {
fullQuote = fullQuote + "\n" + lawDescription;
}
return fullQuote;
}

function buildTwitterUrlParts(text, url){
var baseUrl = "https://twitter.com/intent/tweet?"
var textParam = "text="+text;
var urlParam = "url="+url;
return baseUrl+textParam+"&"+urlParam;
}

})(window)

14 changes: 14 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,18 @@ body {
#id {
font-size: 125px;
font-weight: 300;
}

.social-share-button {
width: 30%;
background-color: #131111;
font-size: 20px;
line-height: 1.5;
border-radius: 10px;
cursor: pointer;
}

.social-share-button i {
margin-right: 5px;
font-size: 17px;
}