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
160 changes: 56 additions & 104 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,112 +1,64 @@
<!doctype html>
<html class="no-js" lang="">

<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Feedr @ GA</title>
<link rel="stylesheet" href="styles/normalize.css" media="screen" charset="utf-8">
<link rel="stylesheet" href="styles/html5bp.css" media="screen" charset="utf-8">
<link rel="stylesheet" href="styles/style.css" media="screen" charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Feedr @ GA</title>
<link rel="stylesheet" href="styles/normalize.css" media="screen" charset="utf-8">
<link rel="stylesheet" href="styles/html5bp.css" media="screen" charset="utf-8">
<link rel="stylesheet" href="styles/style.css" media="screen" charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

</head>
<body>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<header>
<section class="container">
<a id="home" href="#"><h1>Feedr</h1></a>
<nav>
<ul>
<li><a href="#">News Source: <span>Source Name</span></a>
<ul>
<li><a data-filter="nyt" href="#">New York Times</a></li>
<li><a data-filter="wpo" href="#">Washington Post</a></li>
<li><a data-filter="bb" href="#">Bloomberg</a></li>
</ul>
</li>
</ul>
<section id="search">
<input type="text" name="name" value="">
<!-- Changed ID to <a> instead of section -->
<!-- So clicking the input doesn't cause the search bar to close -->
<!-- Actually nevermind -->
<a href="#"><img src="images/search.png" alt="" /></a>
</section>
</nav>
<div class="clearfix"></div>
</section>
</header>

<body>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div id="popUp" class="loader hidden">
<a href="#" class="closePopUp">X</a>
<div class="container">
<h1>Article title here</h1>
<p>Article description/content here.</p>
<a href="#" class="popUpAction" target="_blank">Read more from source</a>
</div>
</div>

<header>
<section class="container">
<a href="#"><h1>Feedr</h1></a>
<nav>
<ul>
<li><a href="#">News Source: <span>Source Name</span></a>
<ul>
<li><a href="#">Source 1</a></li>
<li><a href="#">Source 2</a></li>
<li><a href="#">Source 3</a></li>
</ul>
</li>
</ul>
<section id="search">
<input type="text" name="name" value="">
<a href="#"><img src="images/search.png" alt="" /></a>
</section>
</nav>
<div class="clearfix"></div>
</section>
</header>
<div id="popUp" class="loader hidden">
<a href="#" class="closePopUp">X</a>
<div class="container">
<h1>Article title here</h1>
<p>
Article description/content here.
</p>
<a href="#" class="popUpAction" target="_blank">Read more from source</a>
</div>
</div>
<section id="main" class="container">
<article class="article">
<section class="featuredImage">
<img src="images/article_placeholder_1.jpg" alt="" />
</section>
<section class="articleContent">
<a href="#"><h3>Test article title</h3></a>
<h6>Lifestyle</h6>
</section>
<section class="impressions">
526
</section>
<div class="clearfix"></div>
</article>
<article class="article">
<section class="featuredImage">
<img src="images/article_placeholder_2.jpg" alt="" />
</section>
<section class="articleContent">
<a href="#"><h3>Test article title</h3></a>
<h6>Lifestyle</h6>
</section>
<section class="impressions">
526
</section>
<div class="clearfix"></div>
</article>
<article class="article">
<section class="featuredImage">
<img src="images/article_placeholder_2.jpg" alt="" />
</section>
<section class="articleContent">
<a href="#"><h3>Test article title</h3></a>
<h6>Lifestyle</h6>
</section>
<section class="impressions">
526
</section>
<div class="clearfix"></div>
</article>
<article class="article">
<section class="featuredImage">
<img src="images/article_placeholder_1.jpg" alt="" />
</section>
<section class="articleContent">
<a href="#"><h3>Test article title</h3></a>
<h6>Lifestyle</h6>
</section>
<section class="impressions">
526
</section>
<div class="clearfix"></div>
</article>
</section>
<section id="main" class="container">
<div class="loader"></div>
</section>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.3.min.js"><\/script>')</script>
<script src="js/app.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/vendor/jquery-1.11.3.min.js"><\/script>')
</script>
<script src="js/app.js"></script>
</body>

</body>
</html>
</html>
185 changes: 185 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,188 @@
/*
Please add all Javascript code to this file.
GA JS-SF-8 Ian
*/

const API_KEY_NYT = "49384f9a1a4f4a30803f51d2ff1a26f0";
const API_KEY_NPI = "fb5d233e64d94275b9021245ac114ed0";
const ARTICLES_NYT = {};
const ARTICLES_WPO = {};
const ARTICLES_BB = {};

function nytSaveData(array) {
for (var article in array) {
var key = array[article].slug_name;
ARTICLES_NYT[key] = array[article];
}
}

function npiSaveData(array, source) {
for (var article in array) {
var key = array[article].publishedAt;
source[key] = array[article];
}
}

function initSearch() {
$("#search").on("click", function() {
$(this).toggleClass("active");
});
}

function initPopup() {
$(".closePopUp").on("click", function() {
$("#popUp").addClass("hidden");
});
}

function initPopupLinks(source) {
$("article a").on("click", function(event) {
event.preventDefault();
showPopup($(this).attr("href"), source);
});
}

function showLoaderMain() {
$("#main").html("<div class=\"loader\"></div>");
}

function initHome() {
$("#home").on("click", function(event) {
event.preventDefault();
showLoaderMain();
getNYT();
});
}

function initNYT() {
$("[data-filter=nyt]").on("click", function() {
showLoaderMain();
getNYT();
});
}

function initWPO() {
$("[data-filter=wpo]").on("click", function() {
showLoaderMain();
getWPO();
});
}

function initBB() {
$("[data-filter=bb]").on("click", function() {
showLoaderMain();
getBB();
});
}

function initPage() {
initSearch();
initPopup();
initHome();
initNYT();
initWPO();
initBB();
}

function showPopup(slug, source) {
var article = source[slug];
$("#popUp").removeClass("loader hidden");
$("#popUp h1").html(article.title);
if (source == ARTICLES_NYT) {
$("#popUp p").html(article.abstract);
} else {
$("#popUp p").html(article.description);
}
$("#popUp .popUpAction").attr("href", article.url);
}

function nytDisplayArticles(articles) {
var html = `${articles.map(article =>
`<article class='article'>
<section class='featuredImage'>
<img src='${article.thumbnail_standard ? `${article.thumbnail_standard}`: `images/article_placeholder_1.jpg`}' alt='' />
</section>
<section class='articleContent'>
<a href=${article.slug_name}><h3>${article.title}</h3></a>
<h6>${article.section}</h6>
</section>
<div class='clearfix'></div>
</article>`
).join("")}`;
$("#main").empty().append(html);
initPopupLinks(ARTICLES_NYT);
}

function npiDisplayArticles(articles, source) {
var html = `${articles.map(article =>
`<article class='article'>
<section class='featuredImage'>
<img src='${article.urlToImage ? `${article.urlToImage}`: `images/article_placeholder_1.jpg`}' alt='' />
</section>
<section class='articleContent'>
<a href=${article.publishedAt}><h3>${article.title}</h3></a>
<h6></h6>
</section>
<div class='clearfix'></div>
</article>`
).join("")}`;
$("#main").empty().append(html);
initPopupLinks(source);
}

function getNYT(numArticles) {
$.ajax({
async: true,
crossDomain: true,
url: `http://api.nytimes.com/svc/news/v3/content/all/all.json?limit=${numArticles}&api-key=${API_KEY_NYT}`,
method: "GET",
// success: function(msg) {},
error: function(msg) {
alert("Oops. That did not go as planned. Refresh the page and try again?");
},
// complete: function(msg) {}
}).done(function (response) {
var articles = response.results;
nytSaveData(articles);
nytDisplayArticles(articles);
});
}

function getWPO() {
$.ajax({
async: true,
crossDomain: true,
url: `https://accesscontrolalloworiginall.herokuapp.com/https://newsapi.org/v1/articles?source=the-washington-post&apiKey=${API_KEY_NPI}`,
method: "GET",
// success: function(msg) {},
error: function(msg) {
alert("Oops. That did not go as planned. Refresh the page and try again?");
},
// complete: function(msg) {}
}).done(function (response) {
var articles = response.articles;
npiSaveData(articles, ARTICLES_WPO);
npiDisplayArticles(articles, ARTICLES_WPO);
});
}

function getBB() {
$.ajax({
async: true,
crossDomain: true,
url: `https://accesscontrolalloworiginall.herokuapp.com/https://newsapi.org/v1/articles?source=bloomberg&apiKey=${API_KEY_NPI}`,
method: "GET",
// success: function(msg) {},
error: function(msg) {
alert("Oops. That did not go as planned. Refresh the page and try again?");
},
// complete: function(msg) {}
}).done(function (response) {
var articles = response.articles;
npiSaveData(articles, ARTICLES_BB);
npiDisplayArticles(articles, ARTICLES_BB);
});
}

initPage();
getNYT();
15 changes: 9 additions & 6 deletions styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
margin: 0 auto;
}

.loader {
width: 100%;
height: 100vh;
max-height: 100%;
background-image: url(../images/ajax_loader.gif);
background-repeat: no-repeat;
background-position: center center;
}

#popUp {
opacity: 0.95;
position: absolute;
Expand All @@ -23,12 +32,6 @@
text-decoration: none;
}

#popUp.loader {
background-image: url(../images/ajax_loader.gif);
background-repeat: no-repeat;
background-position: center center;
}

#popUp.loader .container {
display: none;
}
Expand Down