(function ($) {
if ($(".g-pic").length > 0 && sessionStorage.getItem("gallery") == null) {
$.ajax({
method: 'GET',
dataType: 'text',
url: loadFrom,
}).catch(function (jqXHR) {
return jqXHR.responseText;
}).then(function (htmlText) {
const links = [];
$(htmlText).find('.gallery a').each(function (idx, link) {
links.push($(link).attr('href'));
});
setPrevNext(links);
});
}
const paddingArrows = 80;
const textDefaultPadding = $(".g-text").css("padding");
function resizePic() {
$(".g-pic").css("height", "").css("width", "");
$(".g-pic").parents(".panel-grid-cell").css("width", "");
$(".g-pic-wrap").css("flex-direction", "");
var nw = $(".g-pic img").get(0).naturalWidth;
var nh = $(".g-pic img").get(0).naturalHeight;
$(".g-pic img").css("width", "100%");
$(".g-pic").css("aspect-ratio", nw + "/" + nh).css("height", $(window).height());
$(".g-pic").parents(".panel-grid-cell").css("width", $(window).height() * nw / nh - 15);
$(".g-text").parents(".panel-grid-cell").css("width", $(window).outerWidth() - $(".g-pic img").outerWidth() - 15);
$(".g-pic-wrap").css("padding-left", paddingArrows).css("padding-right", paddingArrows);
if (!$(".arrow-left").length) {
$(".g-pic-wrap").append('<div class="arrow-left"></div><div class="arrow-right"></div>');
if (sessionStorage.getItem("gallery") != null) {
setPrevNext("");
}
}
if ($(window).width() < 1450) {
$(".g-pic").css("height", "");
$(".g-pic-wrap").css("flex-direction", "column");
$(".g-pic").parents(".panel-grid-cell").css("width", "100%");
$(".g-text").parents(".panel-grid-cell").css("width", "100%");
$(".g-text").css("width", "100%").css("padding", "0px");
} else {
$(".g-text").css("width", $(window).outerWidth() - $(".g-pic").outerWidth() - 15 - paddingArrows);
$(".g-text").css("width", "100%").css("padding", textDefaultPadding);
}
}
if ($(".g-pic").length > 0) {
const gPicSrc = $(".g-pic img").attr("src");
const gImg = new Image();
gImg.src = gPicSrc;
$(gImg).on("load", function () {
resizePic();
});
}
$(".gallery a").click(function () {
const aLinks = [];
$(".gallery a").each(function (index) {
aLinks.push($(this).attr("href"));
});
const myJSON = JSON.stringify(aLinks);
sessionStorage.setItem("gallery", myJSON);
});
function setPrevNext(links) {
$(".arrow-left,.arrow-right").show();
if (JSON.parse(sessionStorage.getItem("gallery") != null)) {
var pLinks = JSON.parse(sessionStorage.getItem("gallery"));
} else {
pLinks = links;
}
var urlIndex;
var currentUrl = window.location.href;
for (i = 0; i < pLinks.length; i++) {
if (currentUrl == pLinks[i]) {
urlIndex = i;
}
}
var prev = urlIndex - 1;
if (prev == -1) {
prev = pLinks.length - 1;
}
var next = urlIndex + 1;
if (next > pLinks.length - 1) {
next = 0;
}
$(".arrow-left").wrap('<a href="' + pLinks[prev] + '" </a>');
$(".arrow-right").wrap('<a href="' + pLinks[next] + '" </a>');
}
$(window).resize(function () {
if ($(".g-pic").length > 0) {
resizePic();
}
});
})(jQuery);