From fe09d6b33a35b0c624000701515425305e8e181c Mon Sep 17 00:00:00 2001 From: Tom Date: Fri, 14 Sep 2018 11:07:23 +0100 Subject: [PATCH 1/2] HTML and CSS --- news_logo.png | Bin 0 -> 5317 bytes site.html | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++ sitejava.js | 0 style.css | 58 +++++++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 news_logo.png create mode 100644 site.html create mode 100644 sitejava.js create mode 100644 style.css diff --git a/news_logo.png b/news_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..a586a51ae8f0c2155b35043bdc0f18f386316606 GIT binary patch literal 5317 zcmV;$6gumPP)MT!(DZU(tT$9r8p@O5i;FQg2A2jrre z;QH{s^+@sS_&0mdRqM-{5YNB8kDky-DZ|UZepQB7;aXArlN|n)wn*`p@%KmJi!mfn zp?|~|6Udrq2~a{1eV3}U*H@l6|9L|$?pF?m@W-Wv-i6^KLCk`Z2NU*>dW1$R?a&vS zOc#QWMN*#~7QE}o$C$l3j2ZjnzuF`NX`ffmn?P#4V;sk0&LDe?zu5C-Jm-B_8pXr* ztn$P2p3x>3VIK#M`%siT4rhj$FUR+?Xw+X|ooMb_?{|0(Z<57vd zjH;^gEcr_OdE{C_NB?f$%e>l9rM0Q9V-r=V|Jzi5|xLbQBAsv)Pt#1?T@V9vE_SiGTFn)(-AT9Irc$IyX zZX{8`9-y?lKr_=OCot5;~(w&P+*m2>*I;t*G$*gl6LYuS#gPOt`0rP``8Fth|y2h=yS z#{u)ovv$Zt7yAf9zNNQ^orhsuhbD1N#YDx)Kg|7kHC6z^n zH&pbR@2Doa@et&b&^6|Op{2kuO9y>Z_hdQw{eeoN%-mC(BiB<;UWTqO7m(}H@d{qw zh2f>`M3Z?|i8$`V@XV{OnV}SSKWF#}7H z=vgRZ*e!Slz%gPJ7rwmvxnCQo9!(}e6A}a_Q-C3x!U+eTkdCLBU!g~Qx+pMU>P*x3 zzQ$HkpOor@e&*OJa(w)Jm|oNA6+gi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dj^v7&3|v7YZzBolgXiy}kXM+T zOY#VKt~3;uL^zLDJAoyUnG)Ht=eaoc+&;ker9&0&cYf@d-M=%NH5$-zH88to;NWwj z#8(nszQmOJM7gJJNdku1n;DYeMOfd^x}lvZY$HM`_${VZc;#o(j_l-ktF?EXi!D8zIHz&qkkJ`Pk2o%k)+za$`?Ht1c%fWy9Wh~=TABFHZ ztwy#*+QBd|O2Ii4y0wpnESmox9BK49_pgAvwUWlk>@vFhlsw znb7s2w_HE}6NVYT74HO5fY^5zgnWe>v^0qeC_Cm)ucV#o0gsT#C_ z-2{wb)_VL|gb%z5?cgb9D&m)@Q!r=P*MU{t40-&hcW3#1`AzpgQ48wwJ=IYrjs!8Vy6pyoQ3%dhXizxcr} zFT%?81a>i5=azB#Qtld;X#q7{~itho{>1u1Z39cTxQ@VCwz+tkPVZB)M3~Q31{FUwn|HfKR54lG=&}4P5#zf!w zeshN+qX^eb0Yfp*41)XK?`#CGW=KD*uCT(r0;egXh!~0sF?CgDPVcn%74dR?A#5X? zogu-x_%B#sg3~4Q>^#=(az7M1YebP{p8tgF-pX-{?u2z^bh^BUIoko^ z{p0q0$z%n4s{@~M7zpeWM{H|U{inWZZ`qf_J?Fqm76TmHP?1}<~|9yVXS-4`lxFcFGiI9Co{ChS2 zDgFpUqL{qmL`sn&MT%EJNJRb(@%cAcgb-fu{yzT{DP9HEZ2NQ5@6QpkK!Sg!NRi^X z_!p++zfi~9aA)ghiWDh+6@Pyg{(XiiQal50?;bJU;U`2r4CZ2_K39i8+}y=a&6ocH X$ea*R)fXe$00000NkvXXu0mjflbdnK literal 0 HcmV?d00001 diff --git a/site.html b/site.html new file mode 100644 index 0000000..5a7c22c --- /dev/null +++ b/site.html @@ -0,0 +1,129 @@ + + + + + + + The News! + + + +
+
+ News Logo + +
+
+ + +
+ + +
+
+

[test] Title of the Discussion

+
+ +
+

Here we are talking about something. and this is the short brief about it.

+ +
+ + +
+
+
+ + +
+
+

[test] Title of the Discussion

+
+ +
+

Here we are talking about something. and this is the short brief about it.

+ +
+ + +
+
+
+ + +
+
+

[test] Title of the Discussion

+
+ +
+

Here we are talking about something. and this is the short brief about it.

+ +
+ + +
+
+ diff --git a/sitejava.js b/sitejava.js new file mode 100644 index 0000000..e69de29 diff --git a/style.css b/style.css new file mode 100644 index 0000000..27b5c0b --- /dev/null +++ b/style.css @@ -0,0 +1,58 @@ +.pagehead { + display: flex; + justify-content: space-between; +} + +.navigation { + display: flex; + list-style-type: none; + padding-left: 0; + justify-content: center; + margin-top: 0; + font-size: 20px; + align-items: center; +} + +.navigation li { + padding: 0 10px; +} + +.articleBox { + display: flex; + align-items: center; + justify-content: center; + border-style: solid; + border-width: 1px; + margin-bottom: 5px; + padding-top: 15px; +} + +.articleImage { + display: none; +} + +.articleBoxContent { + display: flex; + flex-direction: column; +} + +.articleMeta { + display: flex; + justify-content: space-between; +} + +@media (min-width: 768px) { +.articleBox { + border: none; + } + +.articleImage { + display: block; + } + +.articleBoxContent { +padding-left: 20px; +} + + +} From f81213ea23b97fcfba191e150c51e38522a552f1 Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 17 Sep 2018 15:00:46 +0100 Subject: [PATCH 2/2] Final News --- site.html | 146 +++++++++++------------------------------------ sitejava.js | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++ style.css | 95 +++++++++++++++++++++++++++---- 3 files changed, 277 insertions(+), 124 deletions(-) diff --git a/site.html b/site.html index 5a7c22c..2394962 100644 --- a/site.html +++ b/site.html @@ -8,122 +8,40 @@ -
-
- News Logo - -
-
- -
- - -
-
-

[test] Title of the Discussion

-
- -
-

Here we are talking about something. and this is the short brief about it.

- -
- - -
-
-
- - -
-
-

[test] Title of the Discussion

+
+
+ News Logo +
+
+ + + + + + +
+
+
+
+ + +
+
-
-

Here we are talking about something. and this is the short brief about it.

- -
- - -
-
-
- - -
-
-

[test] Title of the Discussion

-
- -
-

Here we are talking about something. and this is the short brief about it.

- -
- - +
+
+
+
+
+
+
+
+
+ -
-
-
diff --git a/sitejava.js b/sitejava.js index e69de29..7082a75 100644 --- a/sitejava.js +++ b/sitejava.js @@ -0,0 +1,160 @@ +let fetchPromise = fetch('https://newsapi.org/v2/top-headlines?country=gb&apiKey=56887af3601845008f0dc6fa7f8b8810') //fetchs default page -news in UK + + +const Buttons = document.querySelectorAll(".normButton") +const categoryButtons = document.querySelectorAll(".categoryButton") +const paginationButton = document.querySelector(".pagButton") +const form = document.querySelector("form") +const textArea = document.querySelector(".textarea") + + +let textInBox = "" // variable to hold the value input to the text area +textArea.addEventListener("input", function(event) { + textInBox = event.target.value + console.log(textInBox) // sets varibale to equal the contents of text box +}) + +form.addEventListener("submit", function(event) { + event.preventDefault(); + console.log(textInBox) + const articleParentNode = document.querySelector(".newsfeed") + const childNewsArticle = document.querySelectorAll(".articleBox") + childNewsArticle.forEach(function(arrayValue) { + articleParentNode.removeChild(arrayValue) //removes our current news feed we loaded from deault page + }) + + fetchPromise = fetch(`https://newsapi.org/v2/everything?q=${textInBox}&page=1&apiKey=56887af3601845008f0dc6fa7f8b8810`) + + fetchPromise.then(function(response) { + return response.json() + }).then(function(body) { + console.log(body.articles) + createArticleBlock(body.articles) //calls our article create function with new fetch API + }) + +}) + + + +Buttons.forEach(function(arrayValue) { // this loop goes over the buttons + arrayValue.addEventListener("click", function(event) { // adds a listener + const articleParentNode = document.querySelector(".newsfeed") + const childNewsArticle = document.querySelectorAll(".articleBox") + console.log(childNewsArticle) + childNewsArticle.forEach(function(arrayValue) { + articleParentNode.removeChild(arrayValue) //removes our current news feed we loaded from deault page + }) + + if (event.target.textContent === "GB" || event.target.textContent === "US") { + fetchPromise = fetch(`https://newsapi.org/v2/top-headlines?country=${event.target.textContent}&apiKey=56887af3601845008f0dc6fa7f8b8810`) + } else if (event.target.textContent === "Sport") { + fetchPromise = fetch(`https://newsapi.org/v2/top-headlines?country=gb&category=${event.target.textContent.toLowerCase()}&apiKey=56887af3601845008f0dc6fa7f8b8810`) + } else { + fetchPromise = fetch(`https://newsapi.org/v2/top-headlines?country=us&category=${event.target.textContent.toLowerCase()}&apiKey=56887af3601845008f0dc6fa7f8b8810`) + } + + fetchPromise.then(function(response) { + return response.json() + }).then(function(body) { + console.log(body.articles) + createArticleBlock(body.articles) //calls our article create function with new fetch API + }) + }) +}) + +let pageCount = 1 +let isLoading = false + +window.addEventListener('scroll', function(e) { // this fires a console.log at bottom of page + if (window.scrollY + window.innerHeight >= document.body.scrollHeight) { + if (isLoading) { + console.log("Is loading") + } + + pageCount++ + + isLoading = true + + const fetchPromise = fetch(`https://newsapi.org/v2/everything?q=${textInBox}&page=${pageCount}&apiKey=56887af3601845008f0dc6fa7f8b8810`) + + fetchPromise.then(function(response) { + return response.json() + }).then(function(body) { + console.log(body.articles) + + createArticleBlock(body.articles) + + isLoading = false + }) + } + + console.log('Not bottom') + console.log(window.scrollY + window.innerHeight, document.body.scrollHeight) +}) + +fetchPromise.then(function(response) { + return response.json() +}).then(function(body) { + createArticleBlock(body.articles) +}) + + + +function createArticleBlock(newsStory) { + const articleParentNode = document.querySelector(".newsfeed") + + newsStory.forEach(function(arrayValue) { + const element = document.createElement('div') + element.className = "articleBox" + element.innerHTML = ` +
+ +
+
+
+

${arrayValue.title}

+
+
+

${arrayValue.description}

+ +
+ +
+ + ` + articleParentNode.append(element) + }) +} + + + + + + + + +/*function createCharacter(character){ + const element = document.createElement('div'); + element.innerHTML = ` + ${character.name} + + ` + return element; +} +*/ diff --git a/style.css b/style.css index 27b5c0b..55ac72b 100644 --- a/style.css +++ b/style.css @@ -3,7 +3,25 @@ justify-content: space-between; } -.navigation { +.searchsection { + display: flex; + align-items: center; +} + +.form { + display: flex; + align-items: center; + padding-top: 20px; +} + +.righthandheader { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +.btn-group { display: flex; list-style-type: none; padding-left: 0; @@ -11,10 +29,40 @@ margin-top: 0; font-size: 20px; align-items: center; + display: flex; + flex-wrap: wrap; +} + +.btn-group button { + background-color: #4CAF50; + /* Green background */ + border: 1px solid green; + /* Green border */ + color: white; + /* White text */ + padding: 10px 24px; + /* Some padding */ + cursor: pointer; + /* Pointer/hand icon */ + float: left; + /* Float the buttons side by side */ +} + +.btn-group button:not(:last-child) { + border-right: none; + /* Prevent double borders */ +} + +/* Clear floats (clearfix hack) */ +.btn-group:after { + content: ""; + clear: both; + display: table; } -.navigation li { - padding: 0 10px; +/* Add a background color on hover */ +.btn-group button:hover { + background-color: #3e8e41; } .articleBox { @@ -27,13 +75,19 @@ padding-top: 15px; } +.articleTitle { + height: auto; +} + .articleImage { display: none; + max-height: 175px; } .articleBoxContent { display: flex; flex-direction: column; + flex: 1; } .articleMeta { @@ -42,17 +96,38 @@ } @media (min-width: 768px) { -.articleBox { - border: none; + .articleBox { + border: none; } -.articleImage { - display: block; + body { + display: flex; + flex-direction: column; } -.articleBoxContent { -padding-left: 20px; -} + .mainPageContent { + display: flex; + } + .newsFeed { + flex: 3; + } + .leftColumn { + flex: 1; + } + + .rightColumn { + flex: 1 + } + + .imgDiv { + flex: 1; + display: flex; + justify-content: center; + } + + .articleImage { + display: block; + } }