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..24107ee0 --- /dev/null +++ b/index.html @@ -0,0 +1,39 @@ + + + + + + + Lemony Cinema + + + + +
+

Mouldy Lemons

+

Discover the zestiest flicks

+
+
+
+ +
+
+
+ + +
+
+ + + + \ No newline at end of file diff --git a/scripts/index.js b/scripts/index.js new file mode 100644 index 00000000..2df602c5 --- /dev/null +++ b/scripts/index.js @@ -0,0 +1,203 @@ +//API RESULTS +// apikey=eabbbb71 +// http://www.omdbapi.com/?s=Jaws&apikey=eabbbb71 + +//Initialize values +let page = 1; +let searchText = ""; +const initialFetch = `http://www.omdbapi.com/?s=Lemonade&apikey=eabbbb71` + +//querySelectors +const searchBox = document.querySelector(".search__input"); +let form = document.querySelector("form"); +const moviesParentNode = document.querySelector(".moviesfeed"); + +//Initial Fetch +fetchContent(initialFetch); + +//Submit Search +form.addEventListener("submit", event => { + event.preventDefault(); + searchText = form.search.value; + const APIQuery = `http://www.omdbapi.com/?s=${searchText}&apikey=eabbbb71`; + fetchContent(APIQuery) +}); + +//Event Listeners +document.addEventListener("click", event => { + if (event.target.matches(".moviesfeed__btn")) { + fetchFullArticle(event); + } + if (event.target.matches('.paging__previous')) { + clickPrevious(event); + } + if (event.target.matches('.paging__next')) { + clickNext(event); + } +}); + +// Load Full Query +function fetchFullArticle(event) { + event.preventDefault(); + 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(".moviesfeed__details"); + + 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 as function calls (below) - address scope issue + fetch(APIQuery) + .then(function(response) { + return response.json(); + }) + .then(function(body) { + movieDetails.forEach(movie => { + let movieID = movie.dataset.id; + if (movieID === parentSection) { + movie.innerHTML = filmsLayoutFilm(body); + } + }) + // toggle details + parentClass.toggle('details--open'); + articleClass.toggle('active'); + + parentClass.contains("details--open") ? moviesButton.textContent = "Hide details" : moviesButton.textContent = "Show details"; + + }) + .catch(function(error) { + displayErrorToUser("Server failed to return data"); + }); + } + }); +} + +/* +----------------- +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 !== "N/A" ? `${item.Poster}` : ""; + return ` +
+
+

${title} ${year}

+ Show details +
+
X
+
`; + }; + +function displaySearchList(filmArticles) { + + moviesParentNode.innerHTML = ""; + // 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 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" ? `

    Moudy lemons score: ${body.imdbRating}

    ` : ""; + + return `
    ${director}${plot}${rating}
    `; +} + + +// function displayFullFilm(body) { +// const movieDetails = document.querySelectorAll(".moviesfeed__details"); +// movieDetails.forEach(movie => { + +// let movieID = movie.dataset.id; +// if (movieID === parentSection) { +// movieDetails.innerHTML = filmsLayoutFilm(body); +// } +// }) +// } + + +/* +------ +PAGING +------ +*/ + +//Functions: next page +function clickNext(event) { + event.preventDefault(); + page++; + const searchText = form.search.value; + console.log(form.search.value); + // const searchQuery = formRef.search.value; + const APIQuery = `http://www.omdbapi.com/?s=${searchText}&page=${page}&apikey=eabbbb71`; + fetchContent(APIQuery); +} + +//Functions: previous page +function clickPrevious(event) { + event.preventDefault(); + if (page > 1) { + page--; + const searchText = form.search.value; + const APIQuery = `http://www.omdbapi.com/?s=${searchText}&page=${page}&apikey=eabbbb71`; + fetchContent(APIQuery); + } +} + +/* +-------------- +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..bb448a1d --- /dev/null +++ b/styles/styles.css @@ -0,0 +1,267 @@ +/** + * Notes BEM + * http://getbem.com/naming/ + */ + +/* Variables + ========= */ + + :root { + --main-txt-color: #0a0a0a; + --light-color: #EEE8CD; + --bright-color: #FFC220; + --dark-color: #2D363a; + + --main-padding: 1rem; +} + +/* ==== BASE ==== */ + +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; +} + +/* ==== LINKS AND TYPOGRAPHY ==== */ +a { + text-decoration: none; + -webkit-transition: color 0.5s; + -moz-transition: color 0.5s; + transition: color 0.5s; + } + +/* ==== SEARCHFORM ==== */ + +.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); +} + +/* ==== MAIN ==== */ + +.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); + padding: var(--main-padding); +} +.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); +} + +/* show-hide */ +.moviesfeed__full .moviesfeed__details { + display: none; + } +.moviesfeed__full.details--open .moviesfeed__details { + display: block; +} +.moviesfeed__full.details--open .moviesfeed__content, +.moviesfeed__full.details--open .movie__header { + position: static; +} +.moviesfeed__full.details--open .moviesfeed__btn { + left: auto; + right: 0px; + bottom: auto; + top: 0px; + +} +.moviesfeed__full.details--open .moviesfeed__content, +.moviesfeed__full.details--open .movie__title { + background-color: var(--light-color); + color: var(--main-txt-color); + height: auto; + } +.moviesfeed__full.details--open .movie__title { +font-size: 1.75rem; +} + +/* paging */ +.paging { + text-align: center; + margin: var(--main-padding) 0 calc( 3 * var(--main-padding) ); +} +.paging__previous, .paging__next { + display: inline-block; + padding: var(--main-padding); + background: var(--light-color); + color: var(--dark-color); + font-weight: bold; +} +.paging__previous:hover, .paging__next:hover { + background: var(--bright-color); +} + +/* footer */ +.footer { + padding:calc( 2 * var(--main-padding) ) 0; + border-top: 5px dashed var(--bright-color); + color: var(--bright-color); + text-align: center; + } + + + /* MEDIA QUERIES + ============== */ + +@media (min-width: 768px) { + + .search-form { + display: flex; + flex-wrap: wrap; + } + .search__input { + width: auto; + padding: 0.35em 0.75em; + flex: 2; + } + .search__btn { + width: auto; + flex: 1; + } + + /* MAIN */ + .moviesfeed { + display: flex; + flex-flow: row wrap; + } + .moviesfeed article { + width: 25%; + } + .moviesfeed article.active { + width: 100%; + } + /* remove background image */ + .moviesfeed__full.details--open { + background-size: auto; + background-image: none; + padding-top: 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: 1200px) { + .container {max-width: 1170px} + .moviesfeed article { + width: 20%; + } +} + +@media (min-width: 1440px) { + .container { + max-width: 1410px + } +} \ No newline at end of file