Skip to content

Commit

Permalink
Added buttons to rotate the image when shown in lightbox
Browse files Browse the repository at this point in the history
  • Loading branch information
berrnd committed Apr 14, 2023
1 parent 8042263 commit 387aac2
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
Binary file modified .github/publication_assets/lightbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions localization/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ msgstr "Dur wirst in %1$s Sekunden zur Startseite weitergeleitet"

msgid "Today"
msgstr "Heute"

msgid "Rotate image to the left"
msgstr "Bild nach links drehen"

msgid "Rotate image to the right"
msgstr "Bild nach rechts drehen"
6 changes: 6 additions & 0 deletions localization/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ msgstr "You will be redirected to the default page in %1$s seconds"

msgid "Today"
msgstr "Today"

msgid "Rotate image to the left"
msgstr "Rotate image to the left"

msgid "Rotate image to the right"
msgstr "Rotate image to the right"
6 changes: 6 additions & 0 deletions localization/strings.pot
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,9 @@ msgstr ""

msgid "Today"
msgstr ""

msgid "Rotate image to the left"
msgstr ""

msgid "Rotate image to the right"
msgstr ""
46 changes: 45 additions & 1 deletion public/piksi.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,19 @@ $(document).on("click", ".show-as-dialog-image", function(e)
<i class="fa-solid fa-left-long"></i> ' + __t('Back') + ' \
</button> \
</div> \
<img class="img-fluid close-bootbox" src="' + $(e.currentTarget).attr("href") + '"></img>';
<img class="img-fluid close-bootbox" src="' + $(e.currentTarget).attr("href") + '"></img> \
<div class="row mt-2"> \
<div class="col"> \
<button class="btn btn-light w-100 rotate-image-button" data-rotation-factor="-90"> \
<i class="fa-solid fa-rotate-left"></i> ' + __t('Rotate image to the left') + ' \
</button> \
</div> \
<div class="col"> \
<button class="btn btn-light w-100 rotate-image-button" data-rotation-factor="90"> \
<i class="fa-solid fa-rotate-right"></i> ' + __t('Rotate image to the right') + ' \
</button> \
</div> \
</div>';

bootbox.dialog({
"message": dialogHtml,
Expand Down Expand Up @@ -218,3 +230,35 @@ bootbox.setDefaults({
"closeButton": false,
"centerVertical": true
})

RotateImage = function(img, rotationFactor)
{
var currentRotation = 0
if (img.hasAttr("data-current-rotation"))
{
currentRotation = Number.parseInt(img.attr("data-current-rotation"))
}

currentRotation += rotationFactor;
if (Math.abs(currentRotation) == 360)
{
currentRotation = 0;
}

var scale = 1;
if (Math.abs(currentRotation) == 90 || Math.abs(currentRotation) == 270)
{
scale = img.get(0).naturalHeight / img.get(0).naturalWidth;
}

img.attr("data-current-rotation", currentRotation);
img.css("transform", `rotate(${currentRotation}deg) scale(${scale})`);
}

$(document).on("click", ".rotate-image-button", function(e)
{
e.preventDefault();

var button = $(e.currentTarget);
RotateImage(button.parent().parent().parent().find("img"), Number.parseInt(button.attr("data-rotation-factor")));
});

0 comments on commit 387aac2

Please sign in to comment.