From 9f7120c6f647136d9a7a1e0112355cc45757bb5e Mon Sep 17 00:00:00 2001 From: Lemony Date: Sat, 22 Sep 2018 15:40:25 +0100 Subject: [PATCH 1/6] Search working, aiming to get full content on page --- data.txt | 38 +++++ index.html | 27 ++++ scripts/index.js | 129 ++++++++++++++++ styles/normalize.css | 341 +++++++++++++++++++++++++++++++++++++++++++ styles/styles.css | 333 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 868 insertions(+) create mode 100644 data.txt create mode 100644 index.html create mode 100644 scripts/index.js create mode 100644 styles/normalize.css create mode 100644 styles/styles.css diff --git a/data.txt b/data.txt new file mode 100644 index 00000000..df10500f --- /dev/null +++ b/data.txt @@ -0,0 +1,38 @@ +Title: "Guardians of the Galaxy Vol. 2", +Year: "2017", +Rated: "PG-13", +Released: "05 May 2017", +Runtime: "136 min", +Genre: "Action, Adventure, Comedy", +Director: "James Gunn", +Writer: "James Gunn, Dan Abnett (based on the Marvel comics by), Andy Lanning (based on the Marvel comics by), Steve Englehart (Star-Lord created by), Steve Gan (Star-Lord created by), Jim Starlin (Gamora and Drax created by), Stan Lee (Groot created by), Larry Lieber (Groot created by), Jack Kirby (Groot created by), Bill Mantlo (Rocket Raccoon created by), Keith Giffen (Rocket Raccoon created by), Steve Gerber (Howard the Duck created by), Val Mayerik (Howard the Duck created by)", +Actors: "Chris Pratt, Zoe Saldana, Dave Bautista, Vin Diesel", +Plot: "The Guardians must fight to keep their newfound family together as they unravel the mystery of Peter Quill's true parentage.", +Language: "English", +Country: "USA", +Awards: "Nominated for 1 Oscar. Another 12 wins & 42 nominations.", +Poster: "https://m.media-amazon.com/images/M/MV5BMTg2MzI1MTg3OF5BMl5BanBnXkFtZTgwNTU3NDA2MTI@._V1_SX300.jpg", +Ratings: [ +{ +Source: "Internet Movie Database", +Value: "7.7/10" +}, +{ +Source: "Rotten Tomatoes", +Value: "83%" +}, +{ +Source: "Metacritic", +Value: "67/100" +} +], +Metascore: "67", +imdbRating: "7.7", +imdbVotes: "408,619", +imdbID: "tt3896198", +Type: "movie", +DVD: "22 Aug 2017", +BoxOffice: "$389,804,217", +Production: "Walt Disney Pictures", +Website: "https://marvel.com/guardians", +Response: "True" \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 00000000..20528709 --- /dev/null +++ b/index.html @@ -0,0 +1,27 @@ + + + + + + + Lemony Cinema + + + + +

Lemony Movies

+
+
+
+ + + +
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/scripts/index.js b/scripts/index.js new file mode 100644 index 00000000..bdba4b6e --- /dev/null +++ b/scripts/index.js @@ -0,0 +1,129 @@ +//API RESULTS +// apikey=eabbbb71 +// http://www.omdbapi.com/?s=Jaws&apikey=eabbbb71 + +//initialize values +let searchText = ""; +let form = document.querySelector("form"); +const initialFetch = `http://www.omdbapi.com/?s=Jaws&apikey=eabbbb71` + +//querySelectors +const searchBox = document.querySelector(".search__input"); +const moviesParentNode = document.querySelector(".moviesfeed"); +const movieDetails = document.querySelector(".moviesfeed__details"); + +//Initial Fetch +fetchContent(initialFetch); + +//Listeners +form.addEventListener("submit", goSearch); + +document.addEventListener("click", event => { + if (event.target.matches(".moviesfeed__btn")) fetchFullArticle(event); +}); + +// Main search query +function goSearch(event) { + event.preventDefault(); + searchText = searchBox.value; + const APIQuery = `http://www.omdbapi.com/?s=${searchText}&apikey=eabbbb71`; + fetchContent(APIQuery) +} + +// Full article query +function fetchFullArticle(event) { + event.preventDefault(); + + let filmID = event.target.dataset.id; + const APIQuery = `http://www.omdbapi.com/?i=${filmID}&apikey=eabbbb71`; + + document.querySelectorAll('.moviesfeed__btn').forEach(item => { + let parentSection = item.closest(".moviesfeed__details").getAttribute("id"); + + if (filmID === parentSection) { + /// THIS IS WHERE I AM HAVING TROUBLE + console.log(`This ID`) + fetchFullContent(APIQuery); + console.log(`${APIQuery}`); + } + }); +} + +/* +----------------- +DISPLAY TEMPLATES +----------------- +*/ +function filmsLayoutSearchResult(item) { + // fallbacks or empty if data is null TODO + const title = `${item.Title}`; + const year = `${item.Year}`; + const id = `${item.imdbID}`; + + const posterurl = `${item.Poster}` + return ` +
+
+
+

${title}

+

${year}

+
+
`; + }; +function displaySearchList(filmArticles) { + moviesParentNode.innerHTML = ""; + filmArticles.Search.map(function(item) { + const article = document.createElement("article"); + article.innerHTML = filmsLayoutSearchResult(item); + return moviesParentNode.appendChild(article); + }); +} +function filmsLayoutFilm(item) { + // fallbacks or empty if data is null TODO + const director = `${item.Director}`; + const plot = `

${item.Plot}

`; + const actors = `

${item.Actors}

`; + return `

${director}

${plot}${actors}`; + } +function displayFullFilm(item) { + console.log(filmsLayoutFilm(item)); + movieDetails.innerHTML = filmsLayoutFilm(item); + + /// THIS IS WHERE I AM HAVING TROUBLE + return moviesParentNode.appendChild(movieDetails); +} + + +/* +-------------- +FETCH REQUESTS +-------------- +*/ +function fetchContent(APIQuery) { + fetch(APIQuery) + .then(function(response) { + return response.json(); + }) + .then(function(body) { + displaySearchList(body); + }) + .catch(function(error) { + displayErrorToUser("Server failed to return data"); + }); + } + +function fetchFullContent(APIQuery) { + fetch(APIQuery) + .then(function(response) { + return response.json(); + }) + .then(function(body) { + displayFullFilm(body); + }) + .catch(function(error) { + displayErrorToUser("Server failed to return data"); + }); + } + +function displayErrorToUser() {}; \ No newline at end of file diff --git a/styles/normalize.css b/styles/normalize.css new file mode 100644 index 00000000..3d6624cd --- /dev/null +++ b/styles/normalize.css @@ -0,0 +1,341 @@ +/*! normalize.css v8.0.0 | MIT License | github.com/necolas/normalize.css */ + +/* Document + ========================================================================== */ + +/** + * 1. Correct the line height in all browsers. + * 2. Prevent adjustments of font size after orientation changes in iOS. + */ + +html { + line-height: 1.15; /* 1 */ + -webkit-text-size-adjust: 100%; /* 2 */ +} + +/* Sections + ========================================================================== */ + +/** + * Remove the margin in all browsers. + */ + +body { + margin: 0; +} + +/** + * Correct the font size and margin on `h1` elements within `section` and + * `article` contexts in Chrome, Firefox, and Safari. + */ + +h1 { + font-size: 2em; + margin: 0.67em 0; +} + +/* Grouping content + ========================================================================== */ + +/** + * 1. Add the correct box sizing in Firefox. + * 2. Show the overflow in Edge and IE. + */ + +hr { + box-sizing: content-box; /* 1 */ + height: 0; /* 1 */ + overflow: visible; /* 2 */ +} + +/** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + +pre { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/* Text-level semantics + ========================================================================== */ + +/** + * Remove the gray background on active links in IE 10. + */ + +a { + background-color: transparent; +} + +/** + * 1. Remove the bottom border in Chrome 57- + * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari. + */ + +abbr[title] { + border-bottom: none; /* 1 */ + text-decoration: underline; /* 2 */ + text-decoration: underline dotted; /* 2 */ +} + +/** + * Add the correct font weight in Chrome, Edge, and Safari. + */ + +b, +strong { + font-weight: bolder; +} + +/** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + +code, +kbd, +samp { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/** + * Add the correct font size in all browsers. + */ + +small { + font-size: 80%; +} + +/** + * Prevent `sub` and `sup` elements from affecting the line height in + * all browsers. + */ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sub { + bottom: -0.25em; +} + +sup { + top: -0.5em; +} + +/* Embedded content + ========================================================================== */ + +/** + * Remove the border on images inside links in IE 10. + */ + +img { + border-style: none; +} + +/* Forms + ========================================================================== */ + +/** + * 1. Change the font styles in all browsers. + * 2. Remove the margin in Firefox and Safari. + */ + +button, +input, +optgroup, +select, +textarea { + font-family: inherit; /* 1 */ + font-size: 100%; /* 1 */ + line-height: 1.15; /* 1 */ + margin: 0; /* 2 */ +} + +/** + * Show the overflow in IE. + * 1. Show the overflow in Edge. + */ + +button, +input { /* 1 */ + overflow: visible; +} + +/** + * Remove the inheritance of text transform in Edge, Firefox, and IE. + * 1. Remove the inheritance of text transform in Firefox. + */ + +button, +select { /* 1 */ + text-transform: none; +} + +/** + * Correct the inability to style clickable types in iOS and Safari. + */ + +button, +[type="button"], +[type="reset"], +[type="submit"] { + -webkit-appearance: button; +} + +/** + * Remove the inner border and padding in Firefox. + */ + +button::-moz-focus-inner, +[type="button"]::-moz-focus-inner, +[type="reset"]::-moz-focus-inner, +[type="submit"]::-moz-focus-inner { + border-style: none; + padding: 0; +} + +/** + * Restore the focus styles unset by the previous rule. + */ + +button:-moz-focusring, +[type="button"]:-moz-focusring, +[type="reset"]:-moz-focusring, +[type="submit"]:-moz-focusring { + outline: 1px dotted ButtonText; +} + +/** + * Correct the padding in Firefox. + */ + +fieldset { + padding: 0.35em 0.75em 0.625em; +} + +/** + * 1. Correct the text wrapping in Edge and IE. + * 2. Correct the color inheritance from `fieldset` elements in IE. + * 3. Remove the padding so developers are not caught out when they zero out + * `fieldset` elements in all browsers. + */ + +legend { + box-sizing: border-box; /* 1 */ + color: inherit; /* 2 */ + display: table; /* 1 */ + max-width: 100%; /* 1 */ + padding: 0; /* 3 */ + white-space: normal; /* 1 */ +} + +/** + * Add the correct vertical alignment in Chrome, Firefox, and Opera. + */ + +progress { + vertical-align: baseline; +} + +/** + * Remove the default vertical scrollbar in IE 10+. + */ + +textarea { + overflow: auto; +} + +/** + * 1. Add the correct box sizing in IE 10. + * 2. Remove the padding in IE 10. + */ + +[type="checkbox"], +[type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ +} + +/** + * Correct the cursor style of increment and decrement buttons in Chrome. + */ + +[type="number"]::-webkit-inner-spin-button, +[type="number"]::-webkit-outer-spin-button { + height: auto; +} + +/** + * 1. Correct the odd appearance in Chrome and Safari. + * 2. Correct the outline style in Safari. + */ + +[type="search"] { + -webkit-appearance: textfield; /* 1 */ + outline-offset: -2px; /* 2 */ +} + +/** + * Remove the inner padding in Chrome and Safari on macOS. + */ + +[type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} + +/** + * 1. Correct the inability to style clickable types in iOS and Safari. + * 2. Change font properties to `inherit` in Safari. + */ + +::-webkit-file-upload-button { + -webkit-appearance: button; /* 1 */ + font: inherit; /* 2 */ +} + +/* Interactive + ========================================================================== */ + +/* + * Add the correct display in Edge, IE 10+, and Firefox. + */ + +details { + display: block; +} + +/* + * Add the correct display in all browsers. + */ + +summary { + display: list-item; +} + +/* Misc + ========================================================================== */ + +/** + * Add the correct display in IE 10+. + */ + +template { + display: none; +} + +/** + * Add the correct display in IE 10. + */ + +[hidden] { + display: none; +} \ No newline at end of file diff --git a/styles/styles.css b/styles/styles.css new file mode 100644 index 00000000..b06b335b --- /dev/null +++ b/styles/styles.css @@ -0,0 +1,333 @@ +/** + * Notes BEM + * http://getbem.com/naming/ + */ + +/* Variables + ========================================================================== */ + + :root { + --main-txt-color: #0a0a0a; + --light-color: #EEE8CD; + --bright-color: #FFE600; + --dark-color: #808069; + + --main-padding: 1rem; +} + +/* BASE + ========================================================================== */ + + body { + font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif; + margin: 0; + padding: 0; + background: var(--light-color); + line-height: 1.5; + color: var(--main-txt-color); + -webkit-font-smoothing: antialiased; + } + + .container { + padding-left: var(--main-padding); + padding-right: var(--main-padding); + margin: 0 auto; + } + .divider { + display: block; + padding-top: calc( 3 * var(--main-padding) ); + margin-bottom: calc( 3 * var(--main-padding) ); + border-bottom: 3px dashed #808069 + } + .menu--settings { + list-style-type: none; + padding-left: 0; + padding-right: 0; + margin: 0; + } + img { + max-width: 100%; + height: auto; + border-style: none; + } + figure { + padding: 0; + margin: 0; + } + +/* LINKS AND TYPOGRAPHY + ========================================================================== */ + + /* NOTE: Using Gill Sans stack - this is the font I use for my branding; perk is that the bold looks has a lot of personality and the regular is nicely readable */ + /* TODO: apply smooth scroll js method to animate scroll down page */ + a { + text-decoration: none; + -webkit-transition: color 0.5s; + -moz-transition: color 0.5s; + transition: color 0.5s; + } + + .siteHead__squeeze li > a, + .siteHead__nav li > a { + text-transform: uppercase; + color: var(--main-txt-color); + } + + .siteHead__nav li > a:hover { + color: var(--dark-color); + } + .siteHead__squeeze li > a { + font-weight: bold; + } + + .siteFooter__contact a { + color: var(--light-color); + font-weight: 700; + } + a.animate--squeeze { + letter-spacing: 0.5em; + -webkit-transition: all .1s ease-in; + -moz-transition: all .1s ease-in; + -ms-transition: all .1s ease-in; + -o-transition: all .1s ease-in; + transition: all .1s ease-in; + } + a.animate--squeeze:hover { + letter-spacing: 0.1em; + + } + + /* SITEHEAD + ========================================================================== */ + + .siteHead { + text-align: center; + background-color: var(--bright-color); + background-image: url(../images/white-lemons-4.png); + background-repeat: no-repeat; + background-size: auto 80%; + background-position: center center; + display: flex; + flex-flow: row wrap; + justify-content: center; + align-items: center; + position: relative; + } + .siteHead__header { + padding: calc( 2 * var(--main-padding) ); + } + .siteHead__title { + margin: 0; + } + .siteHead__subtitle { + font-size: 1.25rem; + } + .siteHead__squeeze__menu, + .siteHead__menu { + margin: 0; + display: flex; + justify-content: center; + list-style-type: none; + padding: 0; + } + .siteHead__squeeze__menu li, + .siteHead__menu li { + justify-content: center; + padding: 1rem 1rem; + order: 1; + } + + +/* MAIN + ========================================================================== */ + + .main { + padding-top: calc( 2 * var(--main-padding) ); + padding-bottom: calc( 3 * var(--main-padding) ); + } + + .main h2 { + text-align: center + } + .articlesSection__header { + padding: 0.75rem 0; + background-color: var(--dark-color); + margin: 1rem 0 2rem; + background-image: url(../images/white-lemons-2-small.png); + background-repeat: repeat; + background-size: auto 120%; + background-position: center center; + } + .articlesSection__title { + color: var(--light-color); + } + ul.contentHead-navlist, + .articlesSection { + padding-top: calc( 2 * var(--main-padding) ); + padding-bottom: var(--main-padding); + } + ul.contentHead-navlist li { + padding-bottom: var(--main-padding); + } + .myPortfolio { + display: block; + background-color: var(--bright-color); + padding: 0.75rem 0; + margin: 1rem 0 0; + text-align: center; + -webkit-transition: all 0.5s; + -moz-transition: all 0.5s; + transition: all 0.5s; + } + .myPortfolio:hover { + background-color: var(--main-txt-color); + + } + .myPortfolio__title { + color: var(--dark-color); + } + .myPortfolio:hover .myPortfolio__title { + color: var(--light-color); + } + + + /* FOOTER + ========================================================================== */ + + .siteFooter { + background-color: var(--dark-color); + background-image: url(../images/white-lemons-footer.png), url(../images/white-lemons-footer.png); + background-repeat: no-repeat, no-repeat; + background-size: 50% auto, 50% auto; + background-position: top -50px center, bottom 10px right -75px; + color: var(--light-color); + padding-top: calc( 3 * var(--main-padding) ); + padding-bottom: calc( 3 * var(--main-padding) ); + } + + + /* MEDIA QUERIES + ========================================================================== */ + + + @media (min-width: 768px) { + + /* SITEHEAD */ + .siteHead { + min-height: 100vh; + background-image: url(../images/white-lemons-1.png), url(../images/white-lemons-3.png); + background-repeat: no-repeat, no-repeat; + background-size: auto 45%, auto 35%; + background-position: bottom -30px right -20px, top -30px left -20px; + } + .siteHead__nav { + position: absolute; + top: 0.5rem; + right: 0.5rem; + } + .siteHead__title { + font-size: 2rem; + } + .siteHead__subtitle { + font-size: 1.5rem; + padding: 0 5rem; + } + + + /* MAIN */ + .contentHead { + display: flex; + flex-flow: row wrap; + } + .articlesSection__article { + display: flex; + } + .articlesSection__article section { + flex: 2; + } + .articlesSection__article section:first-of-type { + flex: 1; + } + .main__article, + .contentHead li { + width: 50%; + } + + /* FOOTER */ + .siteFooter { + background-size: 30% auto; + background-position: top -230px center; + } + .container--siteFooter { + display: flex; + } + .siteFooter__about { + flex: 2; + } + .siteFooter__contact { + flex: 1; + } + .siteFooter__contact { + text-align: right; + position: relative; + } + .siteFooter__contact p:last-of-type { + position: absolute; + right: 0; + bottom: 0; + } + + /* GRID PADDINGS */ + .contentHead__design p, .contentHead__design h2, + .contentHead__content p, .contentHead__content h2, + .siteFooter__about * { + margin-right: calc( 2 * var(--main-padding) ); + } + .contentHead__develop p, .contentHead__develop h2, + .contentHead__ux p, .contentHead__ux h2, + .siteFooter__contact > * { + margin-left: calc( 2 * var(--main-padding) ) + } + + .articlesSection__article section { + margin-right: var(--main-padding); + } + .articlesSection__article section:last-of-type { + margin-right: 0 + } + + } + + @media (min-width: 960px) { + .container {max-width: 930px} + } + + @media (min-width: 1200px) { + .container {max-width: 1170px} + .siteHead__subtitle span { + display: block + } + .siteHead__title { + font-size: 2.5rem; + } + .siteHead__subtitle, .articlesSection__title { + font-size: 1.75rem; + } + .siteFooter { + background-size: 30% auto; + background-position: top -275px center; + } + + } + + @media (min-width: 1440px) { + .container { + max-width: 1410px + } + .siteHead__title { + font-size: 2.75rem; + } + .siteHead__subtitle, .articlesSection__title { + font-size: 2rem; + } + } \ No newline at end of file From 6672a4cb486a371139d9d74b4e5f66382158942f Mon Sep 17 00:00:00 2001 From: Lemony Date: Sat, 22 Sep 2018 23:54:19 +0100 Subject: [PATCH 2/6] Full content showing on click --- index.html | 5 +- scripts/index.js | 143 +++++++++++++++++++++++++++++------------------ 2 files changed, 92 insertions(+), 56 deletions(-) diff --git a/index.html b/index.html index 20528709..762577c3 100644 --- a/index.html +++ b/index.html @@ -18,7 +18,10 @@

Lemony Movies

-
+
+ +
+
diff --git a/scripts/index.js b/scripts/index.js index bdba4b6e..3f57ebb4 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -10,42 +10,68 @@ const initialFetch = `http://www.omdbapi.com/?s=Jaws&apikey=eabbbb71` //querySelectors const searchBox = document.querySelector(".search__input"); const moviesParentNode = document.querySelector(".moviesfeed"); -const movieDetails = document.querySelector(".moviesfeed__details"); //Initial Fetch fetchContent(initialFetch); -//Listeners -form.addEventListener("submit", goSearch); - -document.addEventListener("click", event => { - if (event.target.matches(".moviesfeed__btn")) fetchFullArticle(event); -}); - -// Main search query -function goSearch(event) { +//Submit Search +form.addEventListener("submit", event => { event.preventDefault(); searchText = searchBox.value; const APIQuery = `http://www.omdbapi.com/?s=${searchText}&apikey=eabbbb71`; fetchContent(APIQuery) -} +}); + +//Load Full Content +document.addEventListener("click", event => { + if (event.target.matches(".moviesfeed__btn")) { + fetchFullArticle(event); + } +}); -// Full article query +// Load Full Query function fetchFullArticle(event) { event.preventDefault(); - let filmID = event.target.dataset.id; const APIQuery = `http://www.omdbapi.com/?i=${filmID}&apikey=eabbbb71`; - - document.querySelectorAll('.moviesfeed__btn').forEach(item => { - let parentSection = item.closest(".moviesfeed__details").getAttribute("id"); - + const moviesButtons = document.querySelectorAll('.moviesfeed__btn'); + const movieDetails = document.querySelectorAll(".moviesdetails"); + + moviesButtons.forEach(item => { + let parentSection = item.closest(".moviesfeed__full").getAttribute("id"); + let buttonClasses = item.classList; if (filmID === parentSection) { - /// THIS IS WHERE I AM HAVING TROUBLE - console.log(`This ID`) - fetchFullContent(APIQuery); - console.log(`${APIQuery}`); + // TOFIX scope of these functions - not sure how to approach + // fetchFullContent(APIQuery); + // displayFullFilm(body) + + fetch(APIQuery) + .then(function(response) { + return response.json(); + }) + .then(function(body) { + movieDetails.forEach(movie => { + console.log(buttonClasses); + console.log(movie.classList); + movie.classList.add('active'); + + let movieID = movie.dataset.id; + if (movieID === parentSection) { + movie.innerHTML = filmsLayoutFilm(body); + } + }) + }) + .catch(function(error) { + displayErrorToUser("Server failed to return data"); + }); } + + // let activeElement = document.querySelector(".active") + // if (activeElement !== null) { + // activeElement.classList.toggle("active") + // } + // item.classList.toggle("active") + }); } @@ -59,18 +85,18 @@ function filmsLayoutSearchResult(item) { const title = `${item.Title}`; const year = `${item.Year}`; const id = `${item.imdbID}`; - - const posterurl = `${item.Poster}` + // const posterurl = `${item.Poster}` + //
return ` -
-
-
-

${title}

-

${year}

-
-
`; +
+
+

${title}

${year}

+ +
+
+
`; }; + function displaySearchList(filmArticles) { moviesParentNode.innerHTML = ""; filmArticles.Search.map(function(item) { @@ -79,20 +105,27 @@ function displaySearchList(filmArticles) { return moviesParentNode.appendChild(article); }); } -function filmsLayoutFilm(item) { + +function filmsLayoutFilm(body) { // fallbacks or empty if data is null TODO - const director = `${item.Director}`; - const plot = `

${item.Plot}

`; - const actors = `

${item.Actors}

`; - return `

${director}

${plot}${actors}`; - } -function displayFullFilm(item) { - console.log(filmsLayoutFilm(item)); - movieDetails.innerHTML = filmsLayoutFilm(item); + const title = `${body.Title}`; + const director = `Director: ${body.Director}`; + const plot = `

Plot summary

${body.Plot}

`; + const actors = `

Actors: ${body.Actors}

`; + return `

${title} : ${director}

${plot}${actors}`; +} - /// THIS IS WHERE I AM HAVING TROUBLE - return moviesParentNode.appendChild(movieDetails); -} + +// function displayFullFilm(body) { +// const movieDetails = document.querySelectorAll(".moviesdetails"); +// movieDetails.forEach(movie => { + +// let movieID = movie.dataset.id; +// if (movieID === parentSection) { +// movieDetails.innerHTML = filmsLayoutFilm(body); +// } +// }) +// } /* @@ -113,17 +146,17 @@ function fetchContent(APIQuery) { }); } -function fetchFullContent(APIQuery) { - fetch(APIQuery) - .then(function(response) { - return response.json(); - }) - .then(function(body) { - displayFullFilm(body); - }) - .catch(function(error) { - displayErrorToUser("Server failed to return data"); - }); - } +// function fetchFullContent(APIQuery) { +// fetch(APIQuery) +// .then(function(response) { +// return response.json(); +// }) +// .then(function(body) { +// displayFullFilm(body); +// }) +// .catch(function(error) { +// displayErrorToUser("Server failed to return data"); +// }); +// } function displayErrorToUser() {}; \ No newline at end of file From 6da86c31c9880deddbb7f27f231a07aa7bd1a8d9 Mon Sep 17 00:00:00 2001 From: Lemony Date: Sun, 23 Sep 2018 11:39:24 +0100 Subject: [PATCH 3/6] Show-Hide Buttons working --- index.html | 7 ++----- scripts/index.js | 50 ++++++++++++++++++++++------------------------- styles/styles.css | 7 +++++++ 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/index.html b/index.html index 762577c3..aab8eb0a 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ -

Lemony Movies

+

Cool Lemons

@@ -18,10 +18,7 @@

Lemony Movies

-
- -
- +
diff --git a/scripts/index.js b/scripts/index.js index 3f57ebb4..f69e4f3c 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -5,7 +5,7 @@ //initialize values let searchText = ""; let form = document.querySelector("form"); -const initialFetch = `http://www.omdbapi.com/?s=Jaws&apikey=eabbbb71` +const initialFetch = `http://www.omdbapi.com/?s=Lemons&apikey=eabbbb71` //querySelectors const searchBox = document.querySelector(".search__input"); @@ -22,7 +22,7 @@ form.addEventListener("submit", event => { fetchContent(APIQuery) }); -//Load Full Content +//Event Listeners document.addEventListener("click", event => { if (event.target.matches(".moviesfeed__btn")) { fetchFullArticle(event); @@ -35,13 +35,16 @@ function fetchFullArticle(event) { let filmID = event.target.dataset.id; const APIQuery = `http://www.omdbapi.com/?i=${filmID}&apikey=eabbbb71`; const moviesButtons = document.querySelectorAll('.moviesfeed__btn'); - const movieDetails = document.querySelectorAll(".moviesdetails"); + const movieDetails = document.querySelectorAll(".moviesfeed__details"); moviesButtons.forEach(item => { - let parentSection = item.closest(".moviesfeed__full").getAttribute("id"); - let buttonClasses = item.classList; + const parentSection = item.closest(".moviesfeed__full").getAttribute("id"); + const parentClass = item.closest(".moviesfeed__full").classList; + const moviesButton = item.closest(".moviesfeed__btn"); + if (filmID === parentSection) { - // TOFIX scope of these functions - not sure how to approach + + // FETCHING TOFIX would like to contain as functions but issue with scope // fetchFullContent(APIQuery); // displayFullFilm(body) @@ -51,27 +54,20 @@ function fetchFullArticle(event) { }) .then(function(body) { movieDetails.forEach(movie => { - console.log(buttonClasses); - console.log(movie.classList); - movie.classList.add('active'); - - let movieID = movie.dataset.id; + let movieID = movie.dataset.id; if (movieID === parentSection) { movie.innerHTML = filmsLayoutFilm(body); } }) + // toggle details NOTE within .then to change when details loaded + parentClass.toggle('details--open'); + parentClass.contains("details--open") ? moviesButton.textContent = "Hide details" : moviesButton.textContent = "Show details"; + }) .catch(function(error) { displayErrorToUser("Server failed to return data"); }); } - - // let activeElement = document.querySelector(".active") - // if (activeElement !== null) { - // activeElement.classList.toggle("active") - // } - // item.classList.toggle("active") - }); } @@ -89,35 +85,35 @@ function filmsLayoutSearchResult(item) { //
return `
+
-

${title}

${year}

- +

${title} ${year}

+
-
+
`; }; function displaySearchList(filmArticles) { moviesParentNode.innerHTML = ""; - filmArticles.Search.map(function(item) { + filmArticles.Search.map(item => { const article = document.createElement("article"); article.innerHTML = filmsLayoutSearchResult(item); return moviesParentNode.appendChild(article); }); } - function filmsLayoutFilm(body) { // fallbacks or empty if data is null TODO const title = `${body.Title}`; - const director = `Director: ${body.Director}`; + const director = `Directed by ${body.Director}`; const plot = `

Plot summary

${body.Plot}

`; - const actors = `

Actors: ${body.Actors}

`; - return `

${title} : ${director}

${plot}${actors}`; + const actors = `

Starring: ${body.Actors}

`; + return `

${director}

${plot}${actors}`; } // function displayFullFilm(body) { -// const movieDetails = document.querySelectorAll(".moviesdetails"); +// const movieDetails = document.querySelectorAll(".moviesfeed__details"); // movieDetails.forEach(movie => { // let movieID = movie.dataset.id; diff --git a/styles/styles.css b/styles/styles.css index b06b335b..0db62472 100644 --- a/styles/styles.css +++ b/styles/styles.css @@ -55,6 +55,13 @@ margin: 0; } + .moviesfeed__full .moviesfeed__details { + display: none; + } + .moviesfeed__full.details--open .moviesfeed__details { + display: block; + } + /* LINKS AND TYPOGRAPHY ========================================================================== */ From 41f7ce6f0a379dc65b53798a6c23b3c97e57c491 Mon Sep 17 00:00:00 2001 From: Lemony Date: Sun, 23 Sep 2018 20:47:24 +0100 Subject: [PATCH 4/6] Styles added. Hide-show styles to fix. --- index.html | 21 +- scripts/index.js | 45 +++-- styles/styles.css | 490 ++++++++++++++++++---------------------------- 3 files changed, 237 insertions(+), 319 deletions(-) diff --git a/index.html b/index.html index aab8eb0a..7b84c28c 100644 --- a/index.html +++ b/index.html @@ -9,19 +9,26 @@ -

Cool Lemons

+
+

Mouldy Lemons

+

Discover the zestiest flicks

+
-
-
- - - -
+
+
+
+ +
\ No newline at end of file diff --git a/scripts/index.js b/scripts/index.js index f69e4f3c..8867372a 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -40,11 +40,12 @@ function fetchFullArticle(event) { moviesButtons.forEach(item => { const parentSection = item.closest(".moviesfeed__full").getAttribute("id"); const parentClass = item.closest(".moviesfeed__full").classList; + const articleClass = item.closest("article").classList; const moviesButton = item.closest(".moviesfeed__btn"); if (filmID === parentSection) { - // FETCHING TOFIX would like to contain as functions but issue with scope + // FETCHING TOFIX as function calls but scope issue // fetchFullContent(APIQuery); // displayFullFilm(body) @@ -59,8 +60,11 @@ function fetchFullArticle(event) { movie.innerHTML = filmsLayoutFilm(body); } }) - // toggle details NOTE within .then to change when details loaded + // toggle details + // NOTE inside .then to toggle when details loaded parentClass.toggle('details--open'); + articleClass.toggle('active'); + parentClass.contains("details--open") ? moviesButton.textContent = "Hide details" : moviesButton.textContent = "Show details"; }) @@ -81,34 +85,45 @@ function filmsLayoutSearchResult(item) { const title = `${item.Title}`; const year = `${item.Year}`; const id = `${item.imdbID}`; - // const posterurl = `${item.Poster}` - //
+ const posterurl = item.Poster !== "N/A" ? `${item.Poster}` : ""; return ` -
- +
-

${title} ${year}

- +

${title} ${year}

+ Show details
-
+
`; }; function displaySearchList(filmArticles) { + moviesParentNode.innerHTML = ""; - filmArticles.Search.map(item => { + // filter out films without posters + let searchArray = filmArticles.Search.filter(item => { + return item.Poster !== "N/A" + }); + + searchArray.map(item => { const article = document.createElement("article"); article.innerHTML = filmsLayoutSearchResult(item); return moviesParentNode.appendChild(article); }); + + } function filmsLayoutFilm(body) { // fallbacks or empty if data is null TODO - const title = `${body.Title}`; - const director = `Directed by ${body.Director}`; - const plot = `

Plot summary

${body.Plot}

`; - const actors = `

Starring: ${body.Actors}

`; - return `

${director}

${plot}${actors}`; + + const director = body.Director !== "N/A" ? `

Directed by ${body.Director}

` : ""; + const plot = body.Plot !== "N/A" ? `

${body.Plot}

` : ""; + const actors = body.Actors !== "N/A" ? `
  • Starring: ${body.Actors}
  • ` : ""; + const language = body.Language !== "N/A" ? `
  • Language: ${body.Language}
  • ` : ""; + const genre = body.Genre !== "N/A" ? `
  • Genre: ${body.Genre}
  • ` : ""; + const guidance = body.Rated !== "N/A" ? `
  • Movie Guidance: ${body.Rated}
  • ` : ""; + const rating = body.imdbRating !== "N/A" ? `

    Cool lemons? ${body.imdbRating}

    ` : ""; + + return `
    ${director}${plot}
      ${actors}${language}${genre}${guidance}
    ${rating}
    `; } diff --git a/styles/styles.css b/styles/styles.css index 0db62472..0f5f69ca 100644 --- a/styles/styles.css +++ b/styles/styles.css @@ -4,337 +4,233 @@ */ /* Variables - ========================================================================== */ + ========= */ :root { --main-txt-color: #0a0a0a; --light-color: #EEE8CD; - --bright-color: #FFE600; - --dark-color: #808069; + --bright-color: #FFC220; + --dark-color: #2D363a; --main-padding: 1rem; } -/* BASE - ========================================================================== */ +/* ==== BASE ==== */ - body { - font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif; - margin: 0; - padding: 0; - background: var(--light-color); - line-height: 1.5; - color: var(--main-txt-color); - -webkit-font-smoothing: antialiased; - } +body { + font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif; + margin: 0; + padding: 0; + background: var(--dark-color); + line-height: 1.5; + color: var(--light-color); + -webkit-font-smoothing: antialiased; +} +.container { + padding-left: var(--main-padding); + padding-right: var(--main-padding); + margin: 0 auto; +} +.menu--settings { + list-style-type: none; + padding-left: 0; + padding-right: 0; + margin: 0; +} +img { +max-width: 100%; +height: auto; +border-style: none; +} - .container { - padding-left: var(--main-padding); - padding-right: var(--main-padding); - margin: 0 auto; +/* ==== LINKS AND TYPOGRAPHY ==== */ +a { + text-decoration: none; + -webkit-transition: color 0.5s; + -moz-transition: color 0.5s; + transition: color 0.5s; } - .divider { - display: block; - padding-top: calc( 3 * var(--main-padding) ); - margin-bottom: calc( 3 * var(--main-padding) ); - border-bottom: 3px dashed #808069 - } - .menu--settings { - list-style-type: none; - padding-left: 0; - padding-right: 0; - margin: 0; - } - img { - max-width: 100%; - height: auto; - border-style: none; - } - figure { - padding: 0; - margin: 0; - } - .moviesfeed__full .moviesfeed__details { - display: none; - } - .moviesfeed__full.details--open .moviesfeed__details { - display: block; - } +/* ==== SEARCHFORM ==== */ -/* LINKS AND TYPOGRAPHY - ========================================================================== */ +.search__form { + width: 80%; + margin: 0 auto; +} +.search__input { + background: var(--light-color); + overflow: hidden; + white-space: nowrap; + padding: 0.35em 0; + text-align: center; + border: none; + font-size: 1.5rem; + text-decoration: none; + line-height: normal; + max-height: 3em; + width: 100%; +} +.search__btn { + background:var(--bright-color); + text-transform: uppercase; + color: var(-dark-color); + padding: 0.35em 0.75em; + border: none; + font-size: 1.5em; + text-decoration: none; + cursor: pointer; + width: 100%; +} +.search__btn:hover { + background: var(--main-txt-color); + color: var(--light-color); +} - /* NOTE: Using Gill Sans stack - this is the font I use for my branding; perk is that the bold looks has a lot of personality and the regular is nicely readable */ - /* TODO: apply smooth scroll js method to animate scroll down page */ - a { - text-decoration: none; - -webkit-transition: color 0.5s; - -moz-transition: color 0.5s; - transition: color 0.5s; - } +/* ==== MAIN ==== */ - .siteHead__squeeze li > a, - .siteHead__nav li > a { - text-transform: uppercase; - color: var(--main-txt-color); - } - - .siteHead__nav li > a:hover { - color: var(--dark-color); - } - .siteHead__squeeze li > a { - font-weight: bold; - } +.maincontent { + padding: var(--main-padding 0); + margin-bottom: var(--main-padding); +} +.mainheader { + text-align: center; + padding: calc( 2.5 * var(--main-padding) ) 0 ; + border-bottom: 5px dashed var(--bright-color); + border-top: 5px dashed var(--bright-color); + margin-bottom: calc( 3 * var(--main-padding) ); + margin-top: 1px; +} +.mainheader__title, +.mainheader__subtitle { + margin: 0; +} +.search { + text-align: center; + margin-bottom: calc( 3 * var(--main-padding) ); +} +.moviesfeed article { + margin-bottom: calc( 4 * var(--main-padding) ); +} +.moviesfeed__full { + background-color: var(--main-txt-color); + background-repeat: no-repeat; + background-position: center center; + padding-top: 130%; + background-size: cover; + position: relative; +} +.moviesfeed__details { + background: var(--light-color); + color: var(--main-txt-color); +} +.movie__header { + position: absolute; + bottom: 0; + left: 0; + right: 0; + } +.movie__title { + margin: 0; + padding: calc( 0.5 * var(--main-padding) ); + background-color: rgba(0, 0, 0, 0.75); +} +.movie__title em { + color: var(--bright-color); +} + +.moviesfeed__btn { + position: absolute; + bottom: -40px; + left: 0; + right: 0; + height: 30px; + line-height: 30px; + text-align: center; + padding: 5px; + text-transform: uppercase; + background-color: var(--bright-color); + color: var(--dark-color); +} - .siteFooter__contact a { - color: var(--light-color); - font-weight: 700; - } - a.animate--squeeze { - letter-spacing: 0.5em; - -webkit-transition: all .1s ease-in; - -moz-transition: all .1s ease-in; - -ms-transition: all .1s ease-in; - -o-transition: all .1s ease-in; - transition: all .1s ease-in; - } - a.animate--squeeze:hover { - letter-spacing: 0.1em; +/* show-hide */ +.moviesfeed__full .moviesfeed__details { + display: none; } +.moviesfeed__full.details--open .moviesfeed__details { + display: block; +} + +.moviesfeed__full.details--open { + background-size: auto; + padding-top: 0; +} +.moviesfeed__full.details--open .moviesfeed__content { + position: static; + background-color: var(--light-color); + color: var(--main-txt-color); + height: auto; +} - /* SITEHEAD - ========================================================================== */ +/* footer */ +.paging { + padding-top:calc( 3 * var(--main-padding) ); + border-top: 5px dashed var(--bright-color); + } - .siteHead { - text-align: center; - background-color: var(--bright-color); - background-image: url(../images/white-lemons-4.png); - background-repeat: no-repeat; - background-size: auto 80%; - background-position: center center; - display: flex; - flex-flow: row wrap; - justify-content: center; - align-items: center; - position: relative; - } - .siteHead__header { - padding: calc( 2 * var(--main-padding) ); - } - .siteHead__title { - margin: 0; - } - .siteHead__subtitle { - font-size: 1.25rem; - } - .siteHead__squeeze__menu, - .siteHead__menu { - margin: 0; - display: flex; - justify-content: center; - list-style-type: none; - padding: 0; - } - .siteHead__squeeze__menu li, - .siteHead__menu li { - justify-content: center; - padding: 1rem 1rem; - order: 1; - } - -/* MAIN - ========================================================================== */ + /* MEDIA QUERIES + ============== */ - .main { - padding-top: calc( 2 * var(--main-padding) ); - padding-bottom: calc( 3 * var(--main-padding) ); - } +@media (min-width: 768px) { - .main h2 { - text-align: center - } - .articlesSection__header { - padding: 0.75rem 0; - background-color: var(--dark-color); - margin: 1rem 0 2rem; - background-image: url(../images/white-lemons-2-small.png); - background-repeat: repeat; - background-size: auto 120%; - background-position: center center; - } - .articlesSection__title { - color: var(--light-color); - } - ul.contentHead-navlist, - .articlesSection { - padding-top: calc( 2 * var(--main-padding) ); - padding-bottom: var(--main-padding); + .search-form { + display: flex; + flex-wrap: wrap; } - ul.contentHead-navlist li { - padding-bottom: var(--main-padding); + .search__input { + width: auto; + padding: 0.35em 0.75em; + flex: 2; } - .myPortfolio { - display: block; - background-color: var(--bright-color); - padding: 0.75rem 0; - margin: 1rem 0 0; - text-align: center; - -webkit-transition: all 0.5s; - -moz-transition: all 0.5s; - transition: all 0.5s; + .search__btn { + width: auto; + flex: 1; } - .myPortfolio:hover { - background-color: var(--main-txt-color); + /* MAIN */ + .moviesfeed { + display: flex; + flex-flow: row wrap; } - .myPortfolio__title { - color: var(--dark-color); - } - .myPortfolio:hover .myPortfolio__title { - color: var(--light-color); + .moviesfeed article { + width: 25%; } - - /* FOOTER - ========================================================================== */ - - .siteFooter { - background-color: var(--dark-color); - background-image: url(../images/white-lemons-footer.png), url(../images/white-lemons-footer.png); - background-repeat: no-repeat, no-repeat; - background-size: 50% auto, 50% auto; - background-position: top -50px center, bottom 10px right -75px; - color: var(--light-color); - padding-top: calc( 3 * var(--main-padding) ); - padding-bottom: calc( 3 * var(--main-padding) ); + .moviesfeed__full.details--open .moviesfeed article { + width: 100%; } - - /* MEDIA QUERIES - ========================================================================== */ - - - @media (min-width: 768px) { - - /* SITEHEAD */ - .siteHead { - min-height: 100vh; - background-image: url(../images/white-lemons-1.png), url(../images/white-lemons-3.png); - background-repeat: no-repeat, no-repeat; - background-size: auto 45%, auto 35%; - background-position: bottom -30px right -20px, top -30px left -20px; - } - .siteHead__nav { - position: absolute; - top: 0.5rem; - right: 0.5rem; - } - .siteHead__title { - font-size: 2rem; - } - .siteHead__subtitle { - font-size: 1.5rem; - padding: 0 5rem; - } - - - /* MAIN */ - .contentHead { - display: flex; - flex-flow: row wrap; - } - .articlesSection__article { - display: flex; - } - .articlesSection__article section { - flex: 2; - } - .articlesSection__article section:first-of-type { - flex: 1; - } - .main__article, - .contentHead li { - width: 50%; - } - - /* FOOTER */ - .siteFooter { - background-size: 30% auto; - background-position: top -230px center; - } - .container--siteFooter { - display: flex; - } - .siteFooter__about { - flex: 2; - } - .siteFooter__contact { - flex: 1; - } - .siteFooter__contact { - text-align: right; - position: relative; - } - .siteFooter__contact p:last-of-type { - position: absolute; - right: 0; - bottom: 0; - } - - /* GRID PADDINGS */ - .contentHead__design p, .contentHead__design h2, - .contentHead__content p, .contentHead__content h2, - .siteFooter__about * { - margin-right: calc( 2 * var(--main-padding) ); - } - .contentHead__develop p, .contentHead__develop h2, - .contentHead__ux p, .contentHead__ux h2, - .siteFooter__contact > * { - margin-left: calc( 2 * var(--main-padding) ) - } - - .articlesSection__article section { - margin-right: var(--main-padding); - } - .articlesSection__article section:last-of-type { - margin-right: 0 - } - + /* GRID PADDINGS */ + .moviesfeed__full { + margin-right: var(--main-padding); + margin-left: var(--main-padding); } +} - @media (min-width: 960px) { - .container {max-width: 930px} - } +@media (min-width: 960px) { + .container {max-width: 930px} +} - @media (min-width: 1200px) { - .container {max-width: 1170px} - .siteHead__subtitle span { - display: block - } - .siteHead__title { - font-size: 2.5rem; - } - .siteHead__subtitle, .articlesSection__title { - font-size: 1.75rem; - } - .siteFooter { - background-size: 30% auto; - background-position: top -275px center; - } - +@media (min-width: 1200px) { + .container {max-width: 1170px} + .moviesfeed article { + width: 20%; } +} - @media (min-width: 1440px) { - .container { - max-width: 1410px - } - .siteHead__title { - font-size: 2.75rem; - } - .siteHead__subtitle, .articlesSection__title { - font-size: 2rem; - } - } \ No newline at end of file +@media (min-width: 1440px) { + .container { + max-width: 1410px + } +} \ No newline at end of file From 8306693e9d720659614e1523cf7cad66b7386d8f Mon Sep 17 00:00:00 2001 From: Lemony Date: Mon, 24 Sep 2018 09:17:05 +0100 Subject: [PATCH 5/6] Added paging. Tweak styles. --- index.html | 11 +++++++--- scripts/index.js | 52 ++++++++++++++++++++++++++++++++++++---------- styles/styles.css | 53 +++++++++++++++++++++++++++++++++++++---------- 3 files changed, 91 insertions(+), 25 deletions(-) diff --git a/index.html b/index.html index 7b84c28c..24107ee0 100644 --- a/index.html +++ b/index.html @@ -23,11 +23,16 @@

    Discover the zestiest flicks

    -
    + + + -