Интеграция baguetteBox.js для просмотра изображений во вспывающем окне

This commit is contained in:
alex committed 2025-04-05 14:47:40 +07:00
1 parent ac2bedac72
commit 512520dad4
4 files changed
+218 -13

No files matched your search

+196
View File
@@ -0,0 +1,196 @@
/*!
* baguetteBox.js
* @author feimosi
* @version %%INJECT_VERSION%%
* @url https://github.com/feimosi/baguetteBox.js
*/
#baguetteBox-overlay {
display: none;
opacity: 0;
position: fixed;
overflow: hidden;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1000000;
background-color: #222;
background-color: rgba(0,0,0,.8);
transition: opacity .5s ease;
&.visible {
opacity: 1;
}
.full-image {
display: inline-block;
position: relative;
width: 100%;
height: 100%;
text-align: center;
figure {
display: inline;
margin: 0; // needed for mobile
height: 100%; // Opera 12 image stretching fix
}
img {
// IE8 fix
display: inline-block;
width: auto;
height: auto;
max-height: 100%;
max-width: 100%;
vertical-align: middle;
box-shadow: 0 0 8px rgba(0,0,0,.6);
}
figcaption {
display: block;
position: absolute;
bottom: 0;
width: 100%;
text-align: center;
line-height: 1.8;
white-space: normal;
color: #ccc;
background-color: #000;
background-color: rgba(0,0,0,.6);
font-family: sans-serif;
}
&:before {
content: "";
display: inline-block;
height: 50%;
width: 1px;
margin-right:-1px;
}
}
}
#baguetteBox-slider {
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 100%;
white-space: nowrap;
transition: left .4s ease, transform .4s ease;
&.bounce-from-right {
animation: bounceFromRight .4s ease-out;
}
&.bounce-from-left {
animation: bounceFromLeft .4s ease-out;
}
}
@keyframes bounceFromRight{
0% { margin-left: 0; }
50% { margin-left: -30px; }
100% { margin-left: 0; }
}
@keyframes bounceFromLeft{
0% { margin-left: 0; }
50% { margin-left: 30px; }
100% { margin-left: 0; }
}
%arrow-button {
top: 50%;
top: calc(50% - 30px);
width: 44px;
height: 60px;
}
.baguetteBox-button {
position: absolute;
cursor: pointer;
outline: none;
padding: 0;
margin: 0;
border: 0;
border-radius: 15%;
background-color: #323232;
background-color: rgba(50,50,50,.5);
color: #ddd;
font: 1.6em sans-serif;
transition: background-color .4s ease;
&:focus,
&:hover {
background-color: rgba(50,50,50,.9);
}
&#next-button {
@extend %arrow-button;
right: 2%;
}
&#previous-button {
@extend %arrow-button;
left: 2%;
}
&#close-button {
top: 20px;
right: 2%;
right: calc(2% + 6px);
width: 30px;
height: 30px;
}
// Firefox fix
svg {
position: absolute;
left: 0;
top: 0;
}
}
/*
Preloader
Borrowed from http://tobiasahlin.com/spinkit/
*/
.baguetteBox-spinner {
width: 40px;
height: 40px;
display: inline-block;
position: absolute;
top: 50%;
left: 50%;
margin-top: -20px;
margin-left: -20px;
}
.baguetteBox-double-bounce1,
.baguetteBox-double-bounce2 {
width: 100%;
height: 100%;
border-radius: 50%;
background-color: #fff;
opacity: .6;
position: absolute;
top: 0;
left: 0;
animation: bounce 2s infinite ease-in-out;
}
.baguetteBox-double-bounce2 {
animation-delay: -1s;
}
@keyframes bounce {
0%, 100% {
transform: scale(0);
} 50% {
transform: scale(1);
}
}
+6 -13
View File
@@ -1,4 +1,5 @@
@import "../themes/tabi/sass/main.scss";
@import "./baguetteBox.scss";
// main.scss
@@ -34,20 +35,12 @@ article {
}
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 4fr));
grid-auto-rows: auto;
grid-auto-flow: dense;
gap: 18px;
margin-top: 4vmin;
padding: 20px 0;
}
.gallery img {
border-radius: 1rem;
box-shadow: rgba(50, 50, 93, 0.25) 0px 2px 5px -1px, rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;
transition: transform 200ms ease;
max-width: 100%;
height: auto;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
cursor: zoom-in;
}
.gallery img:hover {
+7
View File
@@ -0,0 +1,7 @@
/*!
* baguetteBox.js
* @author feimosi
* @version 1.12.0
* @url https://github.com/feimosi/baguetteBox.js
*/
!function(e,t){"use strict";"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():e.baguetteBox=t()}(this,function(){"use strict";var s,l,u,c,d,f='<svg width="44" height="60"><polyline points="30 10 10 30 30 50" stroke="rgba(255,255,255,0.5)" stroke-width="4"stroke-linecap="butt" fill="none" stroke-linejoin="round"/></svg>',g='<svg width="44" height="60"><polyline points="14 10 34 30 14 50" stroke="rgba(255,255,255,0.5)" stroke-width="4"stroke-linecap="butt" fill="none" stroke-linejoin="round"/></svg>',p='<svg width="30" height="30"><g stroke="rgb(160,160,160)" stroke-width="4"><line x1="5" y1="5" x2="25" y2="25"/><line x1="5" y1="25" x2="25" y2="5"/></g></svg>',b={},v={captions:!0,buttons:"auto",fullScreen:!1,noScrollbars:!1,bodyClass:"baguetteBox-open",titleTag:!1,async:!1,preload:2,animation:"slideIn",afterShow:null,afterHide:null,onChange:null,overlayBackgroundColor:"rgba(0,0,0,.8)",closeX:p,leftArrow:f,rightArrow:g},m={},h=[],o=0,n=!1,i={},a=!1,y=/.+\.(gif|jpe?g|png|webp)/i,w={},k=[],r=null,x=function(e){-1!==e.target.id.indexOf("baguette-img")&&X()},E=function(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0,q()},C=function(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0,j()},B=function(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0,X()},T=function(e){i.count++,1<i.count&&(i.multitouch=!0),i.startX=e.changedTouches[0].pageX,i.startY=e.changedTouches[0].pageY},A=function(e){if(!a&&!i.multitouch){e.preventDefault?e.preventDefault():e.returnValue=!1;var t=e.touches[0]||e.changedTouches[0];40<t.pageX-i.startX?(a=!0,q()):t.pageX-i.startX<-40?(a=!0,j()):100<i.startY-t.pageY&&X()}},L=function(){i.count--,i.count<=0&&(i.multitouch=!1),a=!1},N=function(){L()},H=function(e){"block"===s.style.display&&s.contains&&!s.contains(e.target)&&(e.stopPropagation(),M())};function P(e){if(w.hasOwnProperty(e)){var t=w[e].galleries;[].forEach.call(t,function(e){[].forEach.call(e,function(e){W(e.imageElement,"click",e.eventHandler)}),h===e&&(h=[])}),delete w[e]}}function S(e){switch(e.keyCode){case 37:q();break;case 39:j();break;case 27:X();break;case 36:!function t(e){e&&e.preventDefault();return D(0)}(e);break;case 35:!function n(e){e&&e.preventDefault();return D(h.length-1)}(e)}}function F(e,t){if(h!==e){for(h=e,function r(e){e=e||{};for(var t in v)b[t]=v[t],"undefined"!=typeof e[t]&&(b[t]=e[t]);l.style.transition=l.style.webkitTransition="fadeIn"===b.animation?"opacity .4s ease":"slideIn"===b.animation?"":"none","auto"===b.buttons&&("ontouchstart"in window||1===h.length)&&(b.buttons=!1);u.style.display=c.style.display=b.buttons?"":"none",d.innerHTML=b.closeX,b.buttons&&(u.innerHTML=b.leftArrow,c.innerHTML=b.rightArrow);try{s.style.backgroundColor=b.overlayBackgroundColor}catch(n){}}(t);l.firstChild;)l.removeChild(l.firstChild);for(var n,o=[],i=[],a=k.length=0;a<e.length;a++)(n=J("div")).className="full-image",n.id="baguette-img-"+a,k.push(n),o.push("baguetteBox-figure-"+a),i.push("baguetteBox-figcaption-"+a),l.appendChild(k[a]);s.setAttribute("aria-labelledby",o.join(" ")),s.setAttribute("aria-describedby",i.join(" "))}}function I(e){b.noScrollbars&&(document.documentElement.style.overflowY="hidden",document.body.style.overflowY="scroll"),"block"!==s.style.display&&(U(document,"keydown",S),i={count:0,startX:null,startY:null},Y(o=e,function(){z(o),V(o)}),R(),s.style.display="block",b.fullScreen&&function t(){s.requestFullscreen?s.requestFullscreen():s.webkitRequestFullscreen?s.webkitRequestFullscreen():s.mozRequestFullScreen&&s.mozRequestFullScreen()}(),setTimeout(function(){s.className="visible",b.bodyClass&&document.body.classList&&document.body.classList.add(b.bodyClass),b.afterShow&&b.afterShow()},50),b.onChange&&b.onChange(o,k.length),r=document.activeElement,M(),n=!0)}function M(){b.buttons?u.focus():d.focus()}function X(){b.noScrollbars&&(document.documentElement.style.overflowY="auto",document.body.style.overflowY="auto"),"none"!==s.style.display&&(W(document,"keydown",S),s.className="",setTimeout(function(){s.style.display="none",document.fullscreen&&function e(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen&&document.webkitExitFullscreen()}(),b.bodyClass&&document.body.classList&&document.body.classList.remove(b.bodyClass),b.afterHide&&b.afterHide(),r&&r.focus(),n=!1},500))}function Y(t,n){var e=k[t],o=h[t];if(void 0!==e&&void 0!==o)if(e.getElementsByTagName("img")[0])n&&n();else{var i=o.imageElement,a=i.getElementsByTagName("img")[0],r="function"==typeof b.captions?b.captions.call(h,i):i.getAttribute("data-caption")||i.title,s=function d(e){var t=e.href;if(e.dataset){var n=[];for(var o in e.dataset)"at-"!==o.substring(0,3)||isNaN(o.substring(3))||(n[o.replace("at-","")]=e.dataset[o]);for(var i=Object.keys(n).sort(function(e,t){return parseInt(e,10)<parseInt(t,10)?-1:1}),a=window.innerWidth*window.devicePixelRatio,r=0;r<i.length-1&&i[r]<a;)r++;t=n[iLine truncated
+9
View File
@@ -41,6 +41,15 @@ This variable will hold all the text strings for the language #}
{% endblock main_content %}
</div>
{% include "partials/footer.html" %}
<!-- baguetteBox JS -->
<script defer src="{{ get_url(path='js/baguetteBox.min.js', trailing_slash=false) | safe }}"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
baguetteBox.run('.gallery');
});
</script>
</body>
</html>