-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 55c347b
Showing
3 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Library creation | ||
class Library { | ||
// books Collection | ||
constructor() { | ||
this.books = []; | ||
} | ||
|
||
// book adding function | ||
addBook(book) { | ||
this.books.push(book) | ||
} | ||
|
||
getBook() { | ||
return this.books; | ||
} | ||
getBookCount() { | ||
return this.books.length | ||
} | ||
|
||
remove(index){ | ||
this.books.splice(index,1) | ||
getLibrarydata() | ||
} | ||
} | ||
//////////////////////////////////////////////////////// | ||
// book creation | ||
|
||
class Book { | ||
constructor(title, author) { | ||
this.bookTitle = title; | ||
this.bookAuthor = author; | ||
} | ||
}; | ||
// Library calling variable | ||
const lib = new Library(); | ||
////////////////////////////////////////////////////////// | ||
|
||
// form submit function and adding input and etc.. | ||
|
||
const formEl = document.querySelector("form"); | ||
formEl.addEventListener("submit", (event) => { | ||
event.preventDefault(); | ||
const titleIN = document.querySelector("#booktitle").value; | ||
const authorIN = document.querySelector("#bookauthor").value; | ||
|
||
if (titleIN && authorIN) { | ||
const book = new Book(titleIN, authorIN); | ||
lib.addBook(book); | ||
} | ||
|
||
// geting books and list outin ui | ||
getLibrarydata() | ||
|
||
document.querySelector("#booktitle").value = ""; | ||
document.querySelector("#bookauthor").value = ""; | ||
|
||
}); | ||
////////////////////////////////////////////////////////////// | ||
/// adding function Mark As Read | ||
const resultEL = document.querySelector(".result"); | ||
|
||
function markAsRead(index) { | ||
|
||
const read = resultEL.children[index]; | ||
read.style.textDecoration = "line-through solid gray"; | ||
} | ||
//////////////////////////////////////////////////////////// | ||
|
||
// Removeing function | ||
|
||
function remove(index) { | ||
lib.remove(index) | ||
} | ||
/////////////////////////////////////////////////////////// | ||
|
||
// Adding list in ui | ||
|
||
function getLibrarydata() { | ||
const resultEL = document.querySelector(".result"); | ||
const countEl = document.querySelector(".bookCount"); | ||
const viewEl = document.querySelector(".footer") | ||
|
||
|
||
countEl.textContent = lib.getBookCount(); | ||
if(lib.getBookCount() === 0){ | ||
viewEl.style.display = "none" | ||
}else{ | ||
viewEl.style.display = "block"; | ||
} | ||
|
||
resultEL.innerHTML ="" | ||
|
||
lib.getBook().forEach((book,index) => { | ||
resultEL.innerHTML += `<li>${book.bookTitle} by ${book.bookAuthor} <button class="Read" onClick="markAsRead(${index})">Mark as Read</button><button class="Remove" onClick="remove(${index})">Remove</button></li>` | ||
}) | ||
} | ||
//////////////////////////xxxxxxx/////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Library </title> | ||
<link rel="stylesheet" href="./style.css"> | ||
</head> | ||
<body> | ||
<div class="library"> | ||
<div class="header"></div> | ||
<div class="main"> | ||
<div class="section1"><h4>Book Library</h4></div> | ||
<div class="section2"> | ||
<form action="" > | ||
<input type="text" required placeholder="Book Title" id="booktitle"> | ||
<input type="text" required placeholder="Book Author" id="bookauthor"> | ||
<button type="submit">ADD Book</button> | ||
</form> | ||
|
||
</div> | ||
</div> | ||
<div class="footer"> | ||
<div> | ||
<h4>Books List(<span class="bookCount">0</span>)</h4> | ||
</div> | ||
<ul class="result"> | ||
|
||
|
||
</ul> | ||
</div> | ||
|
||
</div> | ||
|
||
<script src="/book reading/data.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
*{ | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
body{ | ||
background-color: rgba(0, 0, 255, 0.8); | ||
font-family:Arial, Helvetica, sans-serif; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
/* main container */ | ||
|
||
.main{ | ||
width: 500px; | ||
height: 200px; | ||
background-color: white; | ||
margin-top: 40px; | ||
display: flex; | ||
flex-direction: column; | ||
padding: 20px; | ||
border-radius: 8px; | ||
font-weight: 200; | ||
} | ||
.main h4{ | ||
margin-bottom: 10px; | ||
|
||
} | ||
.section2 input{ | ||
width: 100%; | ||
padding: 10px 10px; | ||
margin: 5px 0; | ||
background-color:rgb(128, 128, 128,0.2); | ||
outline: none; | ||
border: none; | ||
border-radius: 10px; | ||
font-size: 15px; | ||
} | ||
.section2 button{ | ||
background-color: orange; | ||
outline: none; | ||
border: none; | ||
color: white; | ||
padding: 10px 30px; | ||
margin: 10px; | ||
border-radius: 10px; | ||
font-size: 14px; | ||
cursor: pointer; | ||
} | ||
.section2 button:hover{ | ||
background-color:orangered; | ||
} | ||
|
||
/* result -container */ | ||
.footer{ | ||
width: 500px; | ||
background-color: white; | ||
margin-top: 30px; | ||
padding: 20px; | ||
border-radius: 8px; | ||
display: none; | ||
} | ||
.result li{ | ||
width: 100%; | ||
background-color:rgba(255, 166, 0, 0.205); | ||
margin: 10px 0; | ||
padding: 10px; | ||
color: rgba(255, 115, 0, 0.973); | ||
list-style: none; | ||
font-size: 14px; | ||
|
||
} | ||
li button{ | ||
margin: 0 2px; | ||
padding: 3px; | ||
cursor: pointer; | ||
|
||
} | ||
.Read{ | ||
background-color: rgb(65, 105, 225,0.8); | ||
outline: none; | ||
border: none; | ||
border-radius:5px; | ||
color: white; | ||
padding: 5px 10px; | ||
} | ||
.Remove{ | ||
background-color:rgb(255, 0, 0,0.7); | ||
outline: none; | ||
border: none; | ||
border-radius:5px; | ||
color: white; | ||
padding: 5px 10px; | ||
} | ||
.Read:hover{ | ||
background-color: rgb(65, 105, 255); | ||
} | ||
.Remove:hover{ | ||
background-color: red; | ||
} |