-
Notifications
You must be signed in to change notification settings - Fork 3
Initial photoswipe widget support #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
25d5525
Initial photoswipe widget support
zarya 443ced9
Fixed src set, fixed thumb aspect ratio
zarya ddd76dd
Added loader, use static function
zarya aab5005
This should fix the loading issues
zarya eb9f161
Fixed a few small bugs
zarya e297adf
More cleanup, also added the fix to splide
zarya def9057
Move shared code to seperate file
zarya 5bfab87
Add loader from base template, added loader to splide
zarya d78c5f7
Small bug fix (dont load file if no metadata)
zarya 95ac179
More widget styling
zarya 195678f
Added fast metadata load
zarya 8a1bc81
Added fast load to splide widget
zarya a5809dd
Fixed some pswp-caption-content styling
zarya a9d28a9
Widget view refactor
zarya a7e3a06
Merge branch 'develop' into photoswipe-widget-0
zarya c0610a7
Added iframe widget, added icons to thumbs for attribution
zarya f8ef76b
Dont forget a file
zarya c1798bb
Update src/static_src/js/photoswipe.js
tykling dfcda35
Limited searching the whole dom
zarya 464c963
Improve widget view security
zarya 1da843b
Added no files available message to widget, fixed missing value in wi…
zarya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,3 @@ | ||
.photoswipe-attribution-size { | ||
max-width: 130px; | ||
} |
This file contains hidden or 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 hidden or 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,4 +1,12 @@ | ||
<div class="image-hover {{ hoverclass }}"> | ||
<i class="fas fa-2x"></i> | ||
<img srcset="{{ url }}{{ url2x }}" src="{{ url }}" height="{{ t.height }}" width="{{ width }}" title="{{ title }}" alt="{{ alt }}" class="img-fluid img-thumbnail"> | ||
<div> | ||
<object><a class="attribution-link" href="{{ file.get_absolute_url }}"><span title="{{ file.title }} ({{ file.attribution }})" class="fa-regular fa-arrow-up-right-from-square"></span></a></object> | ||
<object><a class="text-decoration-none license-link" href="{{ file.license_url }}"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{% if file.license == "CC_ZERO_1_0" %}<span title="{{ file.license_name}}" class="fa-brands fa-creative-commons-zero"></span>{% endif %} | ||
{% if file.license == "CC_BY_4_0" %}<span title="{{ file.license_name}}" class="fa-brands fa-creative-commons-by"></span>{% endif %} | ||
{% if file.license == "CC_BY_SA_4_0" %}<span title="{{ file.license_name}}" class="fa-brands fa-creative-commons-sa"></span>{% endif %} | ||
</a></object> | ||
</div> | ||
</div> |
This file contains hidden or 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 hidden or 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,17 @@ | ||
{% extends "includes/iframe.html" %} | ||
{% load humanize static %} | ||
{% block extra_head %} | ||
<link rel="stylesheet" href="{% static 'css/vendor/photoswipe-v5.4.4.css' %}"> | ||
<link rel="stylesheet" href="{% static 'css/vendor/photoswipe-dynamic-caption-plugin-v1.2.7.css' %}"> | ||
{% endblock extra_head %} | ||
|
||
{% block main_content %} | ||
<div class="row"> | ||
{% csrf_token %} | ||
<div class="pswp-gallery" id="gallery"> | ||
{% for file in files %} | ||
{% include "includes/file_thumbnail_pswp.html" with record=file width=150 ratio="1/1" %} | ||
{% endfor %} | ||
</div> | ||
</div> | ||
{% endblock main_content %} |
This file contains hidden or 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,79 @@ | ||
// config (rendered serverside) | ||
const uuid = "{{ uuid }}"; | ||
const host = "{{ host }}"; | ||
const count = "{{ count }}"; | ||
|
||
const templateFiles = "{{ files|escapejs }}"; | ||
|
||
// custom error class | ||
class BmaNotFoundError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = "BmaNotFoundError"; | ||
} | ||
} | ||
class BmaApiError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = "BmaApiError"; | ||
} | ||
} | ||
class BmaPermissionError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = "BmaPermissionError"; | ||
} | ||
} | ||
|
||
const main_loader = document.createElement('div'); | ||
main_loader.id = "photoswipe-" + count + "-loader" | ||
main_loader.innerHTML = `<div class="spinner-grow" role="status"></div><span class="h3">Loading Gallery....</span>`; | ||
// A reference to the currently running script | ||
const bma_script = document.scripts[document.scripts.length - 1]; | ||
bma_script.parentElement.insertBefore(main_loader, bma_script); | ||
|
||
|
||
async function getFileMetadata(file_uuid) { | ||
const response = fetch("//" + host + "/api/v1/json/files/" + file_uuid + "/", {mode: 'cors'}) | ||
.then((x) => { | ||
if (!x.ok) { | ||
// handle non-2xx x code | ||
if (x.status === 404) { | ||
throw new BmaNotFoundError("File UUID " + file_uuid + " not found!"); | ||
} else if (x.status === 403) { | ||
throw new BmaPermissionError("No permission for file UUID " + file_uuid + "!"); | ||
} else { | ||
throw new BmaApiError("BMA API returned unexpected x code " + x.status); | ||
} | ||
} | ||
return x.json() | ||
}) | ||
.then((x) => ({[file_uuid]: x['bma_response']})) | ||
.catch((response) => { | ||
console.log(response); | ||
}); | ||
return response | ||
} | ||
|
||
async function getAlbumMetadata(album_uuid) { | ||
const response = fetch("//" + host + "/api/v1/json/albums/" + album_uuid + "/", {mode: 'cors'}) | ||
.then((response) => { | ||
if (!response.ok) { | ||
// handle non-2xx response code | ||
if (response.status === 404) { | ||
throw new BmaNotFoundError("Album UUID " + album_uuid + " not found!"); | ||
} else if (response.status === 403) { | ||
throw new BmaPermissionError("No permission for album UUID " + album_uuid + "!"); | ||
} else { | ||
throw new BmaApiError("BMA API returned unexpected response code " + response.status); | ||
} | ||
} | ||
return response.json(); | ||
}) | ||
.then((data) => data["bma_response"]) | ||
.catch((response) => { | ||
console.log(response); | ||
}); | ||
return response; | ||
} | ||
|
This file contains hidden or 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,52 @@ | ||
{% load static %} | ||
{% load django_bootstrap5 %} | ||
{% load django_htmx %} | ||
{% load bma_utils %} | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>{% block title %}Untitled page{% endblock %} - BornHack Media Archive</title> | ||
|
||
<!-- Bootstrap CSS --> | ||
{% bootstrap_css %} | ||
|
||
<!-- FontAwesome CSS --> | ||
<link href="{% static 'fontawesomefree/css/fontawesome.css' %}" rel="stylesheet" type="text/css"> | ||
<link href="{% static 'fontawesomefree/css/brands.css' %}" rel="stylesheet" type="text/css"> | ||
<link href="{% static 'fontawesomefree/css/solid.css' %}" rel="stylesheet" type="text/css"> | ||
|
||
<!-- Custom stylesheets --> | ||
<link href="{% static "css/bma.css" %}" rel="stylesheet"> | ||
|
||
<!-- jQuery --> | ||
<script src="{% static "js/vendor/jquery-3.6.0.min.js" %}"></script> | ||
|
||
<!-- bootstrap JS --> | ||
{% bootstrap_javascript %} | ||
|
||
<!-- Custom javascript --> | ||
<script src="{% static "js/bma.js" %}" defer></script> | ||
|
||
<!-- BMA version --> | ||
{{ bma_version|json_script:"bma-version" }} | ||
|
||
{% block extra_head %}{% endblock %} | ||
</head> | ||
|
||
<body class="d-flex flex-column min-vh-100 bma-no-js {% block body-extra-classes %}{% endblock %}"> | ||
{% block body %} | ||
<main class="flex-shrink-0"> | ||
<div class="container-fluid"> | ||
{% bootstrap_messages %} | ||
<!-- Begin page content --> | ||
{% block main_content %} | ||
<p class="lead">This is the default content of the block 'body' in the iframe.html template of the BMA widget. Please replace in templates inheriting from iframe.html</p> | ||
{% endblock main_content %} | ||
</div> | ||
</main> | ||
{% endblock body %} | ||
</body> | ||
</html> | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.