Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/css/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ body {
width: 380px;
overflow-x: hidden;
}

#media-container {
z-index: 3;
}

#media-image {
max-height: 44vh;
max-width: 100%;
background-color: #303030;
}
9 changes: 9 additions & 0 deletions src/html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ <h1>Django Files Options</h1>
</span>
</label>
</div>
<div class="form-check form-switch mb-2">
<input class="form-check-input" id="popupPreview" type="checkbox" role="switch">
<label class="form-check-label" for="popupPreview" aria-describedby="popupPreviewHelp">
Show Preview on Popup
<span data-bs-toggle="tooltip" data-bs-title="Display Media Preview on Popup Mouseover.">
<i class="fa-solid fa-circle-info ms-1"></i>
</span>
</label>
</div>
<div class="form-check form-switch mb-2">
<input class="form-check-input" id="checkAuth" type="checkbox" role="switch">
<label class="form-check-label" for="checkAuth" aria-describedby="checkAuthHelp">
Expand Down
4 changes: 4 additions & 0 deletions src/html/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
</head>
<body>

<div id="media-container" class="position-fixed top-0 p-1 w-100 d-none">
<img id="media-image" src="" alt="" class="img-thumbnail mw-100 rounded mx-auto d-block border-white">
</div>

<div class="container-fluid p-2">
<div class="d-flex align-items-center justify-content-center mb-1">
<img src="../media/logo32.png" class="me-2" height="32" width="32" alt="Django Files" title="Django Files">
Expand Down
66 changes: 66 additions & 0 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ async function initPopup() {
document
.querySelectorAll('a[href]')
.forEach((el) => el.addEventListener('click', popupLinks))

// Enable Popup Mouseover Preview if popupPreview
if (options.popupPreview) {
console.log('Enabling Mouseover Preview')
initPopupMouseover()
}
}

/**
Expand Down Expand Up @@ -208,6 +214,7 @@ function updateTable(data) {
'link-underline-opacity-75-hover'
)
link.target = '_blank'
link.dataset.raw = url.origin + url.pathname.replace(/^\/u\//, '/raw/')
const cell2 = row.insertCell()
cell2.classList.add('text-break')
cell2.appendChild(link)
Expand Down Expand Up @@ -261,3 +268,62 @@ async function checkSiteAuth() {
})
} catch (e) {} // eslint-disable-line no-empty
}

/**
* Initialize Popup Mouseover Preview
*/
function initPopupMouseover() {
const mediaContainer = document.getElementById('media-container')
const mediaImage = document.getElementById('media-image')
let timeoutID

mediaContainer.addEventListener('mouseover', () => {
mediaContainer.classList.add('d-none')
mediaImage.src = ''
if (timeoutID) {
clearTimeout(timeoutID)
}
})

document.querySelectorAll('.link-underline').forEach((el) => {
el.addEventListener('mouseover', onMouseOver)
el.addEventListener('mouseout', onMouseOut)
})

function onMouseOver(event) {
// console.log('onMouseOver:', event)
if (event.pageY < window.innerHeight / 2) {
mediaContainer.classList.remove('top-0')
mediaContainer.classList.add('bottom-0')
} else {
mediaContainer.classList.remove('bottom-0')
mediaContainer.classList.add('top-0')
}
// console.log('name:', event.target.innerText)
// console.log('raw:', event.target.dataset.raw)
const str = event.target.innerText
const imageExtensions = /\.(jpeg|jpg|gif|png|bmp|svg|webp)$/i
if (str.match(imageExtensions)) {
mediaImage.src = event.target.dataset.raw
mediaContainer.classList.remove('d-none')
} else {
mediaContainer.classList.add('d-none')
mediaImage.src = ''
if (timeoutID) {
clearTimeout(timeoutID)
}
}
// console.log('timeoutID:', timeoutID)
if (timeoutID) {
clearTimeout(timeoutID)
}
}

function onMouseOut() {
timeoutID = setTimeout(function () {
mediaContainer.classList.add('d-none')
mediaImage.src = ''
timeoutID = undefined
}, 3000)
}
}
1 change: 1 addition & 0 deletions src/js/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async function onInstalled(details) {
authToken: '',
recentFiles: '10',
contextMenu: true,
popupPreview: true,
showUpdate: false,
checkAuth: false,
})
Expand Down