Skip to content

Commit

Permalink
Add URL input to fetch image from external source
Browse files Browse the repository at this point in the history
  • Loading branch information
LebCit committed Dec 1, 2023
1 parent 54845a6 commit f163be1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 8 deletions.
12 changes: 11 additions & 1 deletion static/scripts/imagesModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,23 @@ export function imagesModal(modal) {

// Check/Mark the current image in the gallery
const currentImage = allCheckInputs.filter((el) => el.value == hiddenInput.value)
currentImage[0].checked = true
if (currentImage.length) {
currentImage[0].checked = true
} else {
const urlRadio = modalBody.querySelector(".input-group-text").firstElementChild
urlRadio.checked = true
const urlInput = modalBody.querySelector(".input-group").lastElementChild
urlInput.value = hiddenInput.value
}
})

let selectedImage
modalBody.addEventListener("change", (event) => {
if (event.target.classList.contains("form-imagecheck-input")) {
selectedImage = event.target.value
} else {
const urlInput = modalBody.querySelector(".input-group").lastElementChild
selectedImage = urlInput.value
}
})

Expand Down
13 changes: 13 additions & 0 deletions views/admin/components/modals/faviconModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ <h5 class="modal-title" id="faviconModalLabel">Select</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<small>Enter an https:// URL of an image:</small>
<div class="input-group mb-3">
<div class="input-group-text">
<input class="form-check-input mt-0" type="radio" name="modalSelectedFavicon" />
</div>
<input
type="url"
class="form-control"
placeholder="https://an-image-url.com"
pattern="https://.*"
aria-label="URL input with radio button"
/>
</div>
<div class="row g-2">
<div class="col-2">
<label class="form-imagecheck mb-2">
Expand Down
13 changes: 13 additions & 0 deletions views/admin/components/modals/pageImageModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ <h5 class="modal-title" id="pageModalLabel">Select</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<small>Enter an https:// URL of an image:</small>
<div class="input-group mb-3">
<div class="input-group-text">
<input class="form-check-input mt-0" type="radio" name="modalSelectedPageImage" />
</div>
<input
type="url"
class="form-control"
placeholder="https://an-image-url.com"
pattern="https://.*"
aria-label="URL input with radio button"
/>
</div>
<div class="row g-2">
<div class="col-2">
<label class="form-imagecheck mb-2">
Expand Down
13 changes: 13 additions & 0 deletions views/admin/components/modals/postImageModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ <h5 class="modal-title" id="postModalLabel">Select</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<small>Enter an https:// URL of an image:</small>
<div class="input-group mb-3">
<div class="input-group-text">
<input class="form-check-input mt-0" type="radio" name="modalSelectedPostImage" />
</div>
<input
type="url"
class="form-control"
placeholder="https://an-image-url.com"
pattern="https://.*"
aria-label="URL input with radio button"
/>
</div>
<div class="row g-2">
<div class="col-2">
<label class="form-imagecheck mb-2">
Expand Down
17 changes: 17 additions & 0 deletions views/admin/components/modals/postPreviewFallbackImageModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ <h5 class="modal-title" id="postPreviewFallbackImageModalLabel">Select</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<small>Enter an https:// URL of an image:</small>
<div class="input-group mb-3">
<div class="input-group-text">
<input
class="form-check-input mt-0"
type="radio"
name="modalSelectedPostPreviewFallbackImage"
/>
</div>
<input
type="url"
class="form-control"
placeholder="https://an-image-url.com"
pattern="https://.*"
aria-label="URL input with radio button"
/>
</div>
<div class="row g-2">
<div class="col-2">
<label class="form-imagecheck mb-2">
Expand Down
12 changes: 6 additions & 6 deletions views/themes/default/components/head.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<head>
<% /* Metadata */ %>
<!-- Metadata -->
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="<%= it.data.description %>" />

<% /* Favicon */ %>
<link rel="shortcut icon" href="<%= `/static/${it.data.favicon}` %>" type="image/x-icon" />

<% /* Title */ %>
<!-- Favicon -->
<link rel="shortcut icon" href="<%= it.data.favicon.startsWith("https") ? it.data.favicon :
`/static/${it.data.favicon}` %>" type="image/x-icon" />
<!-- Title -->
<title><%= it.siteTitle %> | <%= it.data.title %></title>

<% /* Stylesheets*/ %>
<!-- Stylesheets -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/purecss/build/pure-min.min.css" />
<link rel="stylesheet" href="/static/styles/styles.min.css" />
<% if (it.mdRoute) { %>
Expand Down
2 changes: 1 addition & 1 deletion views/themes/default/layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div
class="photo"
style="
background-image: url('<%= postFeaturedImage.startsWith(`https://`) ? postFeaturedImage : postFeaturedImage.startsWith(`images/`) ? `/static/${postFeaturedImage}` : `/static/${it.postPreviewFallbackImage}` %>');
background-image: url('<%= postFeaturedImage.startsWith(`https://`) ? postFeaturedImage : postFeaturedImage.startsWith(`images/`) ? `/static/${postFeaturedImage}` : it.postPreviewFallbackImage.startsWith(`https://`) ? it.postPreviewFallbackImage : `/static/${it.postPreviewFallbackImage}` %>');
"
></div>

Expand Down

0 comments on commit f163be1

Please sign in to comment.