From 330d5257e7a6da1a7da120b66b10e4b1977d3ab2 Mon Sep 17 00:00:00 2001 From: WKHAllen Date: Sun, 2 Aug 2020 14:43:22 -0400 Subject: [PATCH] Make entire cards clickable on index page --- src/static/css/main.css | 4 ++ src/static/js/index.js | 109 +++++++++++++++++++++------------------- 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/src/static/css/main.css b/src/static/css/main.css index 171af9a..7173e3d 100644 --- a/src/static/css/main.css +++ b/src/static/css/main.css @@ -157,6 +157,10 @@ footer .footer-list-link { padding: 0px 20px; } +#index .card-link { + text-decoration: none; +} + #index .thumbnail { width: 250px; height: 250px; diff --git a/src/static/js/index.js b/src/static/js/index.js index 2e7629f..73c638d 100644 --- a/src/static/js/index.js +++ b/src/static/js/index.js @@ -14,62 +14,67 @@ function deleteLastBook() { function addBook(book) { var courseNumber = book.coursenumber ? ' ' + book.coursenumber : ''; //
- var newBook = document.createElement('div'); - newBook.classList.add('card-container', 'col-12', 'col-md-6', 'col-lg-4', 'mb-4'); - //
- var newCard = document.createElement('div'); - newCard.classList.add('card'); - newCard.style = 'width: 18rem;'; - var imgLink = document.createElement('a'); - imgLink.href = `/book/${book.bookid}` - newCard.appendChild(imgLink) - // ... - var newImg = document.createElement('img'); - newImg.src = book.imageurl; - newImg.classList.add('card-img-top', 'thumbnail', 'p-1', 'pt-3'); - newImg.alt = '...'; - imgLink.appendChild(newImg); - //
- var cardBody = document.createElement('div'); - cardBody.classList.add('card-body'); - //
- var spaceBetween = document.createElement('div'); - spaceBetween.classList.add('space-between'); - // - var bookLink = document.createElement('a'); - bookLink.href = `/book/${book.bookid}`; - // ${book.title} - var bookTitle = document.createElement('span'); - bookTitle.classList.add('title'); - bookTitle.innerText = book.title; + var newBookLink = document.createElement('a'); + newBookLink.classList.add('card-link'); + newBookLink.href = `/book/${book.bookid}`; + var newBook = document.createElement('div'); + newBook.classList.add('card-container', 'col-12', 'col-md-6', 'col-lg-4', 'mb-4'); + //
+ var newCard = document.createElement('div'); + newCard.classList.add('card'); + newCard.style = 'width: 18rem;'; + var imgLink = document.createElement('a'); + imgLink.href = `/book/${book.bookid}`; + newCard.appendChild(imgLink); + // ... + var newImg = document.createElement('img'); + newImg.src = book.imageurl; + newImg.classList.add('card-img-top', 'thumbnail', 'p-1', 'pt-3'); + newImg.alt = '...'; + imgLink.appendChild(newImg); + //
+ var cardBody = document.createElement('div'); + cardBody.classList.add('card-body'); + //
+ var spaceBetween = document.createElement('div'); + spaceBetween.classList.add('space-between'); + // + var bookLink = document.createElement('a'); + bookLink.href = `/book/${book.bookid}`; + // ${book.title} + var bookTitle = document.createElement('span'); + bookTitle.classList.add('title'); + bookTitle.innerText = book.title; + // + bookLink.appendChild(bookTitle); + // + spaceBetween.appendChild(bookLink); + // $${book.price} + var cardPrice = document.createElement('span'); + cardPrice.classList.add('card-price'); + cardPrice.innerText = `$${book.price}`; // - bookLink.appendChild(bookTitle); - // - spaceBetween.appendChild(bookLink); - // $${book.price} - var cardPrice = document.createElement('span'); - cardPrice.classList.add('card-price'); - cardPrice.innerText = `$${book.price}`; - // - spaceBetween.appendChild(cardPrice); + spaceBetween.appendChild(cardPrice); + //
+ cardBody.appendChild(spaceBetween); + //
By: ${book.author} + var authorDiv = document.createElement('div'); + authorDiv.innerText = `By: ${book.author}`; + //
+ cardBody.appendChild(authorDiv); + //
${book.department}${courseNumber} + var departmentDiv = document.createElement('div'); + departmentDiv.innerText = book.department + courseNumber; + //
+ cardBody.appendChild(departmentDiv); //
- cardBody.appendChild(spaceBetween); - //
By: ${book.author} - var authorDiv = document.createElement('div'); - authorDiv.innerText = `By: ${book.author}`; - //
- cardBody.appendChild(authorDiv); - //
${book.department}${courseNumber} - var departmentDiv = document.createElement('div'); - departmentDiv.innerText = book.department + courseNumber; - //
- cardBody.appendChild(departmentDiv); + newCard.appendChild(cardBody); //
- newCard.appendChild(cardBody); + newBook.appendChild(newCard); //
- newBook.appendChild(newCard); - //
- document.getElementById('index').appendChild(newBook); + newBookLink.appendChild(newBook); + // + document.getElementById('index').appendChild(newBookLink); } // Load more books using AJAX