This repository has been archived by the owner on Sep 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Showing
1 changed file
with
35 additions
and
33 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 |
---|---|---|
@@ -1,33 +1,35 @@ | ||
// selecting the download button in the wallpapers page | ||
|
||
const downloadButtons = document.getElementsByClassName("wallpaper-download"); | ||
|
||
for(let i = 0; i < downloadButtons.length; i++){ | ||
const button = downloadButtons[i] | ||
const filename = button.name | ||
button.addEventListener("click", () =>{downloadFile(filename)}) | ||
|
||
} | ||
// downloadButtons.forEach(button => { | ||
// const filename = button.name | ||
// button.addEventListner("click", () =>{donwloadFile(filename)}) | ||
// }); | ||
|
||
|
||
// defining the downloadFile function | ||
function downloadFile(fileName){ | ||
const filePath = "../img/wallpapers/" + fileName; | ||
|
||
const downloadFileName = fileName; | ||
|
||
const a = document.createElement("a"); | ||
|
||
a.href = filePath; | ||
|
||
a.download = downloadFileName; | ||
|
||
a.click() | ||
console.log("downloading in progress.") | ||
document.body.removeChild(a); | ||
|
||
} | ||
// selecting the download button in the wallpapers page | ||
|
||
const downloadButtons = document.getElementsByClassName("wallpaper-download"); | ||
|
||
for (let i = 0; i < downloadButtons.length; i++) { | ||
const button = downloadButtons[i]; | ||
const filename = button.name; | ||
button.addEventListener("click", () => { | ||
downloadFile(filename); | ||
}); | ||
} | ||
|
||
// defining the downloadFile function | ||
function downloadFile(fileName) { | ||
const filePath = "/img/wallpapers/" + fileName; | ||
|
||
const downloadFileName = fileName; | ||
|
||
const a = document.createElement("a"); | ||
a.style.display = "none"; | ||
a.href = filePath; | ||
a.download = downloadFileName; | ||
|
||
// add link to the DOM, so it can be clicked | ||
document.body.appendChild(a); | ||
|
||
a.click(); | ||
console.log("downloading in progress."); | ||
|
||
// To make this work on Firefox we need to wait | ||
// a little while before removing it. | ||
setTimeout(() => { | ||
document.body.removeChild(a); | ||
}, 500); | ||
} |