From 8b89d9026e4ef6a586ba94f63fbf65d31aa2164c Mon Sep 17 00:00:00 2001 From: holdbracha <0527161548a@gmail.com> Date: Mon, 13 Sep 2021 09:01:23 +0300 Subject: [PATCH 01/15] Improving functions and adding other needed element Adding all of necessary functions and checking of their work in the browser --- scripts/index.js | 128 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 118 insertions(+), 10 deletions(-) diff --git a/scripts/index.js b/scripts/index.js index 6842c794..4d8a6485 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -5,26 +5,33 @@ * @param {String} songId - the ID of the song to play */ function playSong(songId) { - // Your code here + for (let song of player.songs){ + document.getElementById(song.id).style.background="white" + if(song.id===songId){ + document.getElementById(song.id).style.background="lightblue" + } + } } /** * Creates a song DOM element based on a song object. */ function createSongElement({ id, title, album, artist, duration, coverArt }) { - const children = [] - const classes = [] - const attrs = { onclick: `playSong(${id})` } + const song=arguments[0] + const children = songChildrenlist(song) + const classes = ["song"] + const attrs = { onclick: `playSong(${id})`,cursor:"pointer",id: id } return createElement("div", children, classes, attrs) } /** * Creates a playlist DOM element based on a playlist object. */ -function createPlaylistElement({ id, name, songs }) { - const children = [] - const classes = [] - const attrs = {} + function createPlaylistElement({ id, name, songs }) { + const playlist=arguments[0] + const children = playlistChildrenlist(playlist) + const classes = ["playlist"] + const attrs = {id: id} return createElement("div", children, classes, attrs) } @@ -41,7 +48,108 @@ function createPlaylistElement({ id, name, songs }) { * @param {Object} attributes - the attributes for the new element */ function createElement(tagName, children = [], classes = [], attributes = {}) { - // Your code here + let element = document.createElement(tagName) + classes.forEach(сlass =>element.classList.add("class") ) + const attribute=Object.keys(attributes) + for(let i=0;i x.id===id); + if (songObj===undefined){ + throw "Not a Valid ID" + } + return songObj; +} + +function songIndex(song){ + let index=player.songs.indexOf(song); + return index +} + +function sortArray(songA, songB){ + return songA.title.localeCompare(songB.title); +} + +player.songs.sort(sortArray); +const listOfSongs=document.getElementById("songs"); +for(let i=0;i Date: Mon, 13 Sep 2021 15:50:35 +0300 Subject: [PATCH 02/15] Improving code Making code more readable and effective. Improving function of CreateElement and making player --- index.html | 2 + scripts/index.js | 123 +++++++++++++++++++++-------------------------- style.css | 1 - 3 files changed, 57 insertions(+), 69 deletions(-) diff --git a/index.html b/index.html index c55fb482..900f051d 100644 --- a/index.html +++ b/index.html @@ -9,10 +9,12 @@ +

Songs

+

Playlists

diff --git a/scripts/index.js b/scripts/index.js index 4d8a6485..5ce3add8 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -17,8 +17,14 @@ function playSong(songId) { * Creates a song DOM element based on a song object. */ function createSongElement({ id, title, album, artist, duration, coverArt }) { - const song=arguments[0] - const children = songChildrenlist(song) + const titleEL=createElement("p",[title],["titleOfSong"]) + const albumEL=createElement("p",[album]) + const artistEL=createElement("p",["Artist: "+artist]) + const durationEL=createElement("p",[toCorrectDuration(duration)],["durationOfSongs"]) + const coverArtURL=coverArt + const coverArtEL=createElement("img",[],["coverArtOfSong"],{ src : coverArtURL}) + const textElement=createElement("div",[titleEL, albumEL, artistEL, durationEL],[]) + const children = [coverArtEL, textElement] const classes = ["song"] const attrs = { onclick: `playSong(${id})`,cursor:"pointer",id: id } return createElement("div", children, classes, attrs) @@ -28,8 +34,11 @@ function createSongElement({ id, title, album, artist, duration, coverArt }) { * Creates a playlist DOM element based on a playlist object. */ function createPlaylistElement({ id, name, songs }) { - const playlist=arguments[0] - const children = playlistChildrenlist(playlist) + const nameEL=createElement("p",[name],["NameOfPlaylist"]) + const songsEl=createElement("p",["Number of songs in playlist: "+songs.length]) + const durationOfPlaylist=toCorrectDuration(playlistDuration(songs)) + const durationEL=createElement("p",[durationOfPlaylist],["durationOfSongs"]) + const children = [nameEL, songsEl, durationEL] const classes = ["playlist"] const attrs = {id: id} return createElement("div", children, classes, attrs) @@ -47,63 +56,24 @@ function createSongElement({ id, title, album, artist, duration, coverArt }) { * @param {Array} classes - the class list of the new element * @param {Object} attributes - the attributes for the new element */ + function createElement(tagName, children = [], classes = [], attributes = {}) { - let element = document.createElement(tagName) - classes.forEach(сlass =>element.classList.add("class") ) - const attribute=Object.keys(attributes) - for(let i=0;i x.id===id); if (songObj===undefined){ throw "Not a Valid ID" @@ -144,12 +114,29 @@ function sortArray(songA, songB){ return songA.title.localeCompare(songB.title); } -player.songs.sort(sortArray); -const listOfSongs=document.getElementById("songs"); -for(let i=0;i Date: Mon, 13 Sep 2021 18:41:34 +0300 Subject: [PATCH 03/15] Adding Css Adding styles in CSS working with elements classes and id --- index.html | 2 +- scripts/index.js | 8 +++--- style.css | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 900f051d..4c122fb8 100644 --- a/index.html +++ b/index.html @@ -13,8 +13,8 @@

Songs

+

Playlists

-

Playlists

diff --git a/scripts/index.js b/scripts/index.js index 5ce3add8..cff98843 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -6,9 +6,9 @@ */ function playSong(songId) { for (let song of player.songs){ - document.getElementById(song.id).style.background="white" + document.getElementById(song.id).style.background="GreenYellow"; if(song.id===songId){ - document.getElementById(song.id).style.background="lightblue" + document.getElementById(song.id).style.background="LimeGreen"; } } } @@ -19,8 +19,8 @@ function playSong(songId) { function createSongElement({ id, title, album, artist, duration, coverArt }) { const titleEL=createElement("p",[title],["titleOfSong"]) const albumEL=createElement("p",[album]) - const artistEL=createElement("p",["Artist: "+artist]) - const durationEL=createElement("p",[toCorrectDuration(duration)],["durationOfSongs"]) + const artistEL=createElement("p",["Artist: "+artist],["artist"]) + const durationEL=createElement("p",[toCorrectDuration(duration)],["durationOfSongs"],{}) const coverArtURL=coverArt const coverArtEL=createElement("img",[],["coverArtOfSong"],{ src : coverArtURL}) const textElement=createElement("div",[titleEL, albumEL, artistEL, durationEL],[]) diff --git a/style.css b/style.css index e69de29b..f36a1b4f 100644 --- a/style.css +++ b/style.css @@ -0,0 +1,72 @@ +* { + box-sizing: border-box; + + } + +body{ + background: rgb(24,17,226); + background: linear-gradient(90deg, rgba(24,17,226,1) 0%, rgba(5,188,230,1) 50%, rgba(0,255,115,1) 100%); + } + +div.song{ + display: flex; + justify-content: flex-start; + align-content: stretch; + width: 420px; + margin: 15px; + font-family: "Gill Sans", sans-serif, cursive; + font-size: 20px; + border: 3px solid; + border-radius: 20px; + background-color: GreenYellow; +} + +div.playlist{ + display: flex; + justify-content: space-between; + text-align: center; + font-size: 20px; + font-weight: 600; + font-family: "Gill Sans", sans-serif, cursive; + border: 4px solid; + border-radius: 20px; + width: 50%; + margin: 25px 25%; + padding: 0px 20px; + background-color: GreenYellow; +} + +img{ + max-height: 200px; + margin: 15px; +} + +.heading{ + font-family: Lucida Handwriting; + font-size: 60px; + font-weight: 900; + text-align: center; + margin-top: 60px; + margin-bottom: 25px; +} + +.titleOfSong{ + font-weight: bold; + font-size: larger; + font-style: italic; +} + +.artist{ + font-style: italic; +} + +#songs{ + display: flex; + flex-wrap: wrap; + justify-content: space-evenly; +} + +#playlists{ + margin-bottom: 150px; +} + From 39546b67195be99d5fee63bc0ea6c59f16b358cf Mon Sep 17 00:00:00 2001 From: holdbracha <0527161548a@gmail.com> Date: Tue, 14 Sep 2021 13:21:57 +0300 Subject: [PATCH 04/15] Deleting of useless comments --- scripts/index.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/scripts/index.js b/scripts/index.js index cff98843..06bb6448 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -40,7 +40,7 @@ function createSongElement({ id, title, album, artist, duration, coverArt }) { const durationEL=createElement("p",[durationOfPlaylist],["durationOfSongs"]) const children = [nameEL, songsEl, durationEL] const classes = ["playlist"] - const attrs = {id: id} + const attrs = {} return createElement("div", children, classes, attrs) } @@ -114,21 +114,6 @@ function sortArray(songA, songB){ return songA.title.localeCompare(songB.title); } -// player.songs.sort(sortArray); -// const headingSong=createElement("h1") -// headingSong.textContent="Songs:" -// const listOfSongs=document.getElementById("songs"); -// listOfSongs.appendChild(headingSong) -// for(let i=0;i Date: Tue, 14 Sep 2021 16:56:09 +0300 Subject: [PATCH 05/15] Improving CSS and bonus task Adding bonus task that duration of the song has different colors that depends of durations(less than 2 minute or more than 7) --- scripts/index.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++- style.css | 15 ++++++++++----- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/scripts/index.js b/scripts/index.js index 06bb6448..dda81590 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -13,6 +13,33 @@ function playSong(songId) { } } +function durationLong(duration){ + if(duration<120){ + return element.style.color="green"; + } + else if(duration>420){ + return element.style.color="red" + } + else{ + return element.style.color="blue" + } +} + + + + + + + +// function playDuration(songId) { +// for (let song of player.songs){ +// document.getElementById(song.id).getElementsByClassName("durationOfSongs")[0].style.color = "black"; +// if(song.id===songId){ +// document.getElementById(song.id).getElementsByClassName("durationOfSongs")[0].style.color = "blue"; +// } +// } +// } + /** * Creates a song DOM element based on a song object. */ @@ -20,7 +47,8 @@ function createSongElement({ id, title, album, artist, duration, coverArt }) { const titleEL=createElement("p",[title],["titleOfSong"]) const albumEL=createElement("p",[album]) const artistEL=createElement("p",["Artist: "+artist],["artist"]) - const durationEL=createElement("p",[toCorrectDuration(duration)],["durationOfSongs"],{}) + const durationEL=createElement("p",[toCorrectDuration(duration)],["durationOfSongs"]) + durationEL.style.color=reflectColor(duration); const coverArtURL=coverArt const coverArtEL=createElement("img",[],["coverArtOfSong"],{ src : coverArtURL}) const textElement=createElement("div",[titleEL, albumEL, artistEL, durationEL],[]) @@ -114,11 +142,31 @@ function sortArray(songA, songB){ return songA.title.localeCompare(songB.title); } +function reflectColor(duration){ + if(duration<=120){ + return "lime" + } + else if(duration>=420){ + return "red" + } + else{ + let r=0; + let g=255; + let b=0; + let durationDifference=duration-120; + r+=Math.floor(durationDifference*0.85) + g-=Math.floor(durationDifference*0.85) + let rgbColor = `rgb(${r},${g},${b})` + return rgbColor + } +} + const songsListEl=document.getElementById("songs") player.songs.sort(sortArray) for(const song of player.songs){ const songEl=createSongElement(song) songsListEl.append(songEl) + // document.getElementById(song.id).getElementsByClassName("durationOfSongs")[0].style.color = "rgb(155, 102, 102)"; } const playlistsListEl=document.getElementById("playlists") for(const playlist of player.playlists){ diff --git a/style.css b/style.css index f36a1b4f..5aae8990 100644 --- a/style.css +++ b/style.css @@ -13,9 +13,10 @@ div.song{ justify-content: flex-start; align-content: stretch; width: 420px; - margin: 15px; + margin: 15px; font-family: "Gill Sans", sans-serif, cursive; - font-size: 20px; + font-size: 18px; + font-weight: 500; border: 3px solid; border-radius: 20px; background-color: GreenYellow; @@ -37,10 +38,14 @@ div.playlist{ } img{ - max-height: 200px; + max-height: 120px; margin: 15px; } +p{ + margin: 10px; +} + .heading{ font-family: Lucida Handwriting; font-size: 60px; @@ -52,8 +57,8 @@ img{ .titleOfSong{ font-weight: bold; - font-size: larger; - font-style: italic; + font-size: 20px; + margin-top: 15px; } .artist{ From d242878b12c877fda7182872ea7a45956e7d3ad4 Mon Sep 17 00:00:00 2001 From: holdbracha <0527161548a@gmail.com> Date: Wed, 15 Sep 2021 20:01:28 +0300 Subject: [PATCH 06/15] Starting new project I copied all functions from index.js that I used before to new javascript file Making all css file in comment because it is useless at the moment --- index.new.html | 4 +- scripts/index.js | 39 ++----------- scripts/index.new.js | 134 +++++++++++++++++++++++++++++++++++++++---- style.css | 8 +-- 4 files changed, 135 insertions(+), 50 deletions(-) diff --git a/index.new.html b/index.new.html index eba39f17..cd6a4485 100644 --- a/index.new.html +++ b/index.new.html @@ -22,7 +22,7 @@

Add a new song

-

Songs

+

Songs