Skip to content

Commit a3fada4

Browse files
authored
Fix login page background
1 parent 1eadd42 commit a3fada4

File tree

1 file changed

+0
-70
lines changed

1 file changed

+0
-70
lines changed

source/js/login.esm.js

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,17 @@
1-
/**
2-
* @see https://unsplash.com/
3-
*/
4-
class UnsplashImage {
5-
6-
constructor(imageID, authorID, authorName) {
7-
8-
this.imageID = imageID
9-
this.imageURL = `https://source.unsplash.com/${imageID}/1920x1080`
10-
this.authorID = authorID
11-
this.authorName = authorName
12-
this.authorURL = `https://unsplash.com/@${authorID}`
13-
14-
}
15-
16-
static getRandom() {
17-
18-
const images = [
19-
new UnsplashImage('pVq6YhmDPtk', 'danranwanghao', 'hao wang'),
20-
new UnsplashImage('E8Ufcyxz514', 'fakurian', 'Fakurian Design'),
21-
new UnsplashImage('PGdW_bHDbpI', 'fakurian', 'Fakurian Design'),
22-
new UnsplashImage('26WixHTutxc', 'gradienta', 'Gradienta'),
23-
new UnsplashImage('u8Jn2rzYIps', 'fakurian', 'Fakurian Design'),
24-
new UnsplashImage('FBQcPsBL2Zo', 'fakurian', 'Fakurian Design'),
25-
new UnsplashImage('Hlkuojv_P6I', 'enginakyurt', 'engin akyurt'),
26-
new UnsplashImage('YWIOwHvRBvU', 'pawel_czerwinski', 'Pawel Czerwinski')
27-
]
28-
// Select a random image from the list above.
29-
const image = images[Math.floor(Math.random() * images.length)]
30-
31-
return image
32-
33-
}
34-
35-
}
36-
371
/**
382
* MongoDB PHP GUI login.
393
*/
404
class Login {
415

426
constructor() {
437

44-
this.background = document.getElementById('mpg-background')
45-
this.backgroundCreditLink = this.background.querySelector('.credit-link')
468
this.cardsContainer = document.getElementById('mpg-cards')
479
this.flipCardButtons = document.querySelectorAll('.mpg-flip-card-button')
4810
this.requiredInputs = document.querySelectorAll('input[required]')
4911
this.forms = document.querySelectorAll('form')
5012

5113
}
5214

53-
/**
54-
* Defines background.
55-
*/
56-
setBackground() {
57-
58-
const randomImage = UnsplashImage.getRandom()
59-
const abortController = new AbortController()
60-
61-
// We will abort fetch request if it takes more than one second.
62-
const timeoutID = setTimeout(() => abortController.abort(), 1000)
63-
64-
fetch(randomImage.imageURL, { signal: abortController.signal })
65-
.then(response => {
66-
clearTimeout(timeoutID)
67-
return response.blob()
68-
})
69-
.then(blob => {
70-
const blobURL = URL.createObjectURL(blob)
71-
this.background.style.backgroundImage = `url(${blobURL})`
72-
this.backgroundCreditLink.textContent = `Image by ${randomImage.authorName}`
73-
this.backgroundCreditLink.href = randomImage.authorURL
74-
this.cardsContainer.classList.add('reveal')
75-
})
76-
.catch(_error => {
77-
console.warn('Failed to fetch unsplash.com. Fallback to local image.')
78-
this.background.classList.add('fallback')
79-
this.cardsContainer.classList.add('reveal')
80-
})
81-
82-
}
83-
8415
/**
8516
* Adds an event listener on each "Flip card" button.
8617
*/
@@ -138,7 +69,6 @@ class Login {
13869

13970
const login = new Login()
14071

141-
login.setBackground()
14272
login.listenFlipCardButtons()
14373
login.listenRequiredInputs()
14474
login.listenForms()

0 commit comments

Comments
 (0)