-
Notifications
You must be signed in to change notification settings - Fork 1
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
4 changed files
with
100 additions
and
1 deletion.
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
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
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,46 @@ | ||
.gfl-magnifiable { | ||
cursor: pointer; | ||
} | ||
|
||
.gfl-modal { | ||
display: none; | ||
position: fixed; | ||
z-index: 1; | ||
padding-top: 5rem; | ||
left: 0; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
overflow: auto; | ||
background-color: rgb(0, 0, 0); | ||
background-color: rgba(0, 0, 0, 0.4); | ||
} | ||
|
||
.gfl-modal-content { | ||
margin: auto; | ||
display: block; | ||
cursor: pointer; | ||
width: 80%; | ||
max-width: 90%; | ||
border: 1rem solid rgb(240, 240, 240); | ||
background: white; | ||
} | ||
|
||
#gfl-caption { | ||
margin: auto; | ||
display: block; | ||
text-align: center; | ||
color: #bbb; | ||
padding: 1rem 0; | ||
height: 10rem; | ||
} | ||
|
||
.gfl-modal-content, #gfl-caption { | ||
animation-name: zoom; | ||
animation-duration: 0.6s; | ||
} | ||
|
||
@keyframes zoom { | ||
from {transform:scale(0)} | ||
to {transform:scale(1)} | ||
} |
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,45 @@ | ||
function enrichImage(img, modal) { | ||
const innerImg = modal.getElementsByTagName('img')[0]; | ||
const caption = modal.getElementsByTagName('div')[0]; | ||
img.classList.add('gfl-magnifiable'); | ||
const src = img.src; | ||
img.addEventListener('click', () => { | ||
modal.style.display = 'block'; | ||
innerImg.src = src; | ||
console.log(innerImg.src); | ||
caption.innerHTML = img.alt; | ||
}); | ||
} | ||
|
||
const container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
container.classList.add('gfl-modal') | ||
|
||
const innerImg = document.createElement('img'); | ||
container.appendChild(innerImg); | ||
innerImg.classList.add('gfl-modal-content') | ||
|
||
const caption = document.createElement('div'); | ||
caption.id = 'gfl-caption'; | ||
container.appendChild(caption); | ||
|
||
const content = document.getElementsByTagName('qgoda-content')[0]; | ||
for (var img of content.getElementsByTagName('img')) { | ||
if (!img.classList.contains('gfl-modal-content')) { | ||
if (img.naturalWidth > img.width) { | ||
enrichImage(img, container); | ||
} else { | ||
img.width = img.naturalWidth; | ||
} | ||
} | ||
} | ||
|
||
container.onclick = function() { | ||
container.style.display = 'none'; | ||
} | ||
|
||
innerImg.onclick = (event) => { | ||
event.stopPropagation(); | ||
container.style.display = 'none'; | ||
window.open(innerImg.src); | ||
}; |