feat(lightbox): 接入全站图片预览 #15
@@ -44,6 +44,7 @@
|
||||
!/tests/widget-system/pay-orders-filter-contract.test.cjs
|
||||
!/tests/widget-system/front-submit-editor-contract.test.cjs
|
||||
!/tests/widget-system/comment-smilies-removal-contract.test.cjs
|
||||
!/tests/widget-system/lightbox-contract.test.cjs
|
||||
!/tests/widget-system/comment-children-list-reset-contract.test.cjs
|
||||
!/tests/widget-system/pay-card-contract.test.cjs
|
||||
!/tests/widget-system/circular-button-icon-margin-contract.test.cjs
|
||||
|
||||
+196
-76
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -524,71 +524,6 @@ article.article.box-body,
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
:is(.entry-content, .wp-posts-content) .aksrt-lightbox-target {
|
||||
cursor: zoom-in;
|
||||
}
|
||||
|
||||
/* ===== 图片灯箱 ===== */
|
||||
.lightbox-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 9999;
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 24px;
|
||||
background: rgba(0, 0, 0, 0.85);
|
||||
}
|
||||
|
||||
.lightbox-overlay.is-open {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.lightbox-img {
|
||||
max-width: 90vw;
|
||||
max-height: 85vh;
|
||||
width: auto;
|
||||
height: auto;
|
||||
border-radius: 4px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.lightbox-caption {
|
||||
max-width: min(96vw, 1200px);
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
text-align: center;
|
||||
opacity: 0.92;
|
||||
}
|
||||
|
||||
.lightbox-close {
|
||||
position: absolute;
|
||||
top: 14px;
|
||||
right: 14px;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: none;
|
||||
border-radius: 999px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.lightbox-close:hover {
|
||||
background: rgba(255, 255, 255, 0.22);
|
||||
}
|
||||
|
||||
.lightbox-close i {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
:is(.entry-content, .wp-posts-content) iframe,
|
||||
:is(.entry-content, .wp-posts-content) .wp-block-embed iframe,
|
||||
:is(.entry-content, .wp-posts-content) video {
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -237,18 +237,26 @@ body.aksrt-body-scroll .aksrt-show-on-scroll {
|
||||
/* ============================================================
|
||||
* 5. 图片灯箱
|
||||
* ============================================================ */
|
||||
[data-aksrt-lightbox="1"] img:not(.no-imgbox):not(.no-lightbox),
|
||||
.aksrt-lightbox-trigger img:not(.no-imgbox):not(.no-lightbox),
|
||||
.imgbox-container img:not(.no-imgbox):not(.no-lightbox),
|
||||
.comment-content .box-img {
|
||||
cursor: zoom-in;
|
||||
}
|
||||
|
||||
.aksrt-lightbox {
|
||||
--imgbox-origin-left: 50vw;
|
||||
--imgbox-origin-top: 50vh;
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 9999;
|
||||
background: rgba(0, 0, 0, 0.85);
|
||||
z-index: 100000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(0, 0, 0, 0.88);
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: opacity 0.3s, visibility 0.3s;
|
||||
cursor: zoom-out;
|
||||
transition: opacity 0.25s ease, visibility 0.25s ease;
|
||||
}
|
||||
|
||||
.aksrt-lightbox.is-open {
|
||||
@@ -256,73 +264,103 @@ body.aksrt-body-scroll .aksrt-show-on-scroll {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__img {
|
||||
max-width: 90vw;
|
||||
max-height: 85vh;
|
||||
object-fit: contain;
|
||||
border-radius: 4px;
|
||||
transform: scale(0.9);
|
||||
transition: transform 0.3s;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.aksrt-lightbox.is-open .aksrt-lightbox__img {
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
.aksrt-lightbox__close {
|
||||
.aksrt-lightbox__stage {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
color: #fff;
|
||||
font-size: 20px;
|
||||
cursor: pointer;
|
||||
inset: 64px 72px 82px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: background 0.2s;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__close:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
.aksrt-lightbox__img {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
width: auto;
|
||||
height: auto;
|
||||
object-fit: contain;
|
||||
transform: scale(1);
|
||||
transform-origin: center;
|
||||
transition: transform 0.25s ease, opacity 0.2s ease;
|
||||
cursor: zoom-in;
|
||||
user-select: none;
|
||||
-webkit-user-drag: none;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__caption {
|
||||
.aksrt-lightbox.from-origin.is-open .aksrt-lightbox__img {
|
||||
animation: aksrt-lightbox-enter 0.3s ease both;
|
||||
}
|
||||
|
||||
.aksrt-lightbox.is-zoomed .aksrt-lightbox__img {
|
||||
cursor: zoom-out;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__toolbar {
|
||||
position: absolute;
|
||||
bottom: 16px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
z-index: 3;
|
||||
top: 14px;
|
||||
right: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__tool,
|
||||
.aksrt-lightbox__nav {
|
||||
border: 0;
|
||||
background: rgba(255, 255, 255, 0.14);
|
||||
color: #fff;
|
||||
box-shadow: none;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease, transform 0.2s ease;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__tool {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
padding: 0;
|
||||
border-radius: 999px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__tool:hover,
|
||||
.aksrt-lightbox__tool:focus-visible,
|
||||
.aksrt-lightbox__nav:hover,
|
||||
.aksrt-lightbox__nav:focus-visible {
|
||||
background: rgba(255, 255, 255, 0.28);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__tool:focus-visible,
|
||||
.aksrt-lightbox__nav:focus-visible,
|
||||
.aksrt-lightbox__thumb:focus-visible {
|
||||
outline: 2px solid #fff;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__counter {
|
||||
min-width: 48px;
|
||||
color: rgba(255, 255, 255, 0.84);
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
max-width: 80%;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__nav {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: #fff;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__nav:hover {
|
||||
background: rgba(255, 255, 255, 0.25);
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 999px;
|
||||
font-size: 22px;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
.aksrt-lightbox__nav--prev {
|
||||
@@ -333,38 +371,120 @@ body.aksrt-body-scroll .aksrt-show-on-scroll {
|
||||
right: 16px;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__counter {
|
||||
.aksrt-lightbox__caption {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
left: 16px;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
z-index: 2;
|
||||
right: 20px;
|
||||
bottom: 18px;
|
||||
left: 20px;
|
||||
color: rgba(255, 255, 255, 0.88);
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
text-align: center;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__thumbs {
|
||||
position: absolute;
|
||||
z-index: 3;
|
||||
right: 50%;
|
||||
bottom: 18px;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
max-width: min(70vw, 760px);
|
||||
padding: 6px;
|
||||
overflow-x: auto;
|
||||
border-radius: 8px;
|
||||
background: rgba(0, 0, 0, 0.38);
|
||||
transform: translateX(50%);
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__thumb {
|
||||
flex: 0 0 auto;
|
||||
width: 56px;
|
||||
height: 44px;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
border: 2px solid transparent;
|
||||
border-radius: 5px;
|
||||
background: transparent;
|
||||
opacity: 0.6;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__thumb.is-active {
|
||||
border-color: #fff;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__thumb img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__thumbs:not([hidden]) ~ .aksrt-lightbox__caption {
|
||||
bottom: 78px;
|
||||
}
|
||||
|
||||
.aksrt-lightbox [hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
@keyframes aksrt-lightbox-enter {
|
||||
from {
|
||||
transform-origin: var(--imgbox-origin-left) var(--imgbox-origin-top);
|
||||
transform: scale(0.82);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform-origin: center;
|
||||
transform: scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.aksrt-lightbox__stage {
|
||||
inset: 58px 10px 78px;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__toolbar {
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__tool {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__download {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 64px;
|
||||
.aksrt-lightbox__counter {
|
||||
min-width: 36px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__nav {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
color: #fff;
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: background 0.2s;
|
||||
background: rgba(0, 0, 0, 0.34);
|
||||
}
|
||||
|
||||
.aksrt-lightbox__download:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
.aksrt-lightbox__nav--prev {
|
||||
left: 8px;
|
||||
}
|
||||
|
||||
/* 可缩放图片的光标 */
|
||||
.aksrt-cursor-zoom-in {
|
||||
cursor: zoom-in;
|
||||
.aksrt-lightbox__nav--next {
|
||||
right: 8px;
|
||||
}
|
||||
|
||||
.aksrt-lightbox__thumbs {
|
||||
max-width: calc(100vw - 20px);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -185,71 +185,6 @@ article.article.box-body,
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
:is(.entry-content, .wp-posts-content) .aksrt-lightbox-target {
|
||||
cursor: zoom-in;
|
||||
}
|
||||
|
||||
/* ===== 图片灯箱 ===== */
|
||||
.lightbox-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 9999;
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 24px;
|
||||
background: rgba(0, 0, 0, 0.85);
|
||||
}
|
||||
|
||||
.lightbox-overlay.is-open {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.lightbox-img {
|
||||
max-width: 90vw;
|
||||
max-height: 85vh;
|
||||
width: auto;
|
||||
height: auto;
|
||||
border-radius: 4px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.lightbox-caption {
|
||||
max-width: min(96vw, 1200px);
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
text-align: center;
|
||||
opacity: 0.92;
|
||||
}
|
||||
|
||||
.lightbox-close {
|
||||
position: absolute;
|
||||
top: 14px;
|
||||
right: 14px;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: none;
|
||||
border-radius: 999px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.lightbox-close:hover {
|
||||
background: rgba(255, 255, 255, 0.22);
|
||||
}
|
||||
|
||||
.lightbox-close i {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
:is(.entry-content, .wp-posts-content) iframe,
|
||||
:is(.entry-content, .wp-posts-content) .wp-block-embed iframe,
|
||||
:is(.entry-content, .wp-posts-content) video {
|
||||
|
||||
+2
-7
@@ -7431,12 +7431,7 @@ badge.top,
|
||||
color: var(--this-bg-b);
|
||||
}
|
||||
|
||||
.imgbox {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.comment-content .box-img,
|
||||
.alone-imgbox-img,
|
||||
.cursor-zoom-in {
|
||||
cursor: zoom-in;
|
||||
}
|
||||
@@ -8109,7 +8104,7 @@ badge.top,
|
||||
|
||||
body:has(.modal.in) .float-right,
|
||||
.modal-open .float-right,
|
||||
.imgbox-show .float-right,
|
||||
.aksrt-lightbox-open .float-right,
|
||||
.scroll-down .scroll-down-hide.float-right,
|
||||
.scroll-ing .scrolling-hide.float-right {
|
||||
transform: translateX(200%);
|
||||
@@ -8117,7 +8112,7 @@ body:has(.modal.in) .float-right,
|
||||
|
||||
body:has(.modal.in) .float-right.position-center,
|
||||
.modal-open .float-right.position-center,
|
||||
.imgbox-show .float-right.position-center,
|
||||
.aksrt-lightbox-open .float-right.position-center,
|
||||
.scroll-down .scroll-down-hide.float-right.position-center,
|
||||
.scroll-ing .scrolling-hide.float-right.position-center {
|
||||
transform: translate(200%, -50%);
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -215,8 +215,6 @@
|
||||
--swiper-navigation-color: #000000;
|
||||
}
|
||||
|
||||
.swiper-thumbsbox .swiper-button-next,
|
||||
.swiper-thumbsbox .swiper-button-prev,
|
||||
.swiper-scroll .swiper-button-next,
|
||||
.swiper-scroll .swiper-button-prev {
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
@@ -633,248 +631,6 @@ button.swiper-pagination-bullet {
|
||||
}
|
||||
|
||||
/****其它*****/
|
||||
.imgbox-show {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.imgbox-show * {
|
||||
-webkit-backdrop-filter: unset !important;
|
||||
backdrop-filter: unset !important;
|
||||
-webkit-filter: unset !important;
|
||||
filter: unset !important;
|
||||
}
|
||||
|
||||
.imgbox {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.imgbox {
|
||||
z-index: 100000;
|
||||
transition: 0.4s;
|
||||
--imgbox-origin-left: center;
|
||||
--imgbox-origin-top: center;
|
||||
}
|
||||
|
||||
.imgbox-bg {
|
||||
z-index: 1;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.full-screen .imgbox-bg {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.imgbox-an {
|
||||
position: fixed;
|
||||
z-index: 3;
|
||||
top: 13px;
|
||||
right: 15px;
|
||||
}
|
||||
|
||||
.hide-but,
|
||||
.imgbox-an > a {
|
||||
color: #fff;
|
||||
background: rgba(41, 41, 41, 0.7);
|
||||
}
|
||||
|
||||
.imgbox-an > a {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
}
|
||||
|
||||
.hide-but {
|
||||
padding: 4px 20px;
|
||||
margin-right: 5px;
|
||||
border-radius: 0 0 4px 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.is-play .fa-play:before {
|
||||
content: '\f04c';
|
||||
}
|
||||
|
||||
.swiper-imgbox {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
transition: height 0.3s;
|
||||
z-index: 10001;
|
||||
}
|
||||
|
||||
.swiper-thumbsbox {
|
||||
background: rgba(41, 41, 41, 0.6);
|
||||
padding: 10px;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.swiper-thumbsbox .swiper-slide {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
margin: 0 3px;
|
||||
opacity: 0.8;
|
||||
transition: border 0.3s;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.show-thumb .swiper-imgbox {
|
||||
height: calc(100% - 120px);
|
||||
}
|
||||
|
||||
.swiper-thumbsbox .swiper-slide.swiper-slide-thumb-active {
|
||||
opacity: 1;
|
||||
border: 4px solid var(--focus-color);
|
||||
}
|
||||
|
||||
.imgbox.show {
|
||||
opacity: 1;
|
||||
-webkit-animation: fade 0.4s;
|
||||
animation: fade 0.4s;
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.imgbox.hideing {
|
||||
opacity: 0;
|
||||
visibility: visible;
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
.imgbox .swiper-slide {
|
||||
transform-origin: var(--imgbox-origin-left) var(--imgbox-origin-top);
|
||||
}
|
||||
|
||||
.imgbox.show .swiper-imgbox .swiper-slide {
|
||||
-webkit-animation: scale_in 0.6s;
|
||||
animation: scale_in 0.6s;
|
||||
-webkit-animation-timing-function: cubic-bezier(0.1, 0.73, 0.41, 1.1);
|
||||
animation-timing-function: cubic-bezier(0.1, 0.73, 0.41, 1.1);
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
.imgbox.hideing .swiper-imgbox .swiper-slide {
|
||||
-webkit-animation: scale_out 0.4s;
|
||||
animation: scale_out 0.4s;
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
.swiper-imgbox .lazyloading,
|
||||
.swiper-imgbox .lazyload {
|
||||
transform: scale(0.7);
|
||||
}
|
||||
|
||||
.swiper-imgbox .lazyloaded:not(.lazyloadafter):not(.ls-is-cached) {
|
||||
-webkit-animation: imgbox_lazy_in 0.4s;
|
||||
animation: imgbox_lazy_in 0.4s;
|
||||
}
|
||||
|
||||
@-webkit-keyframes imgbox_lazy_in {
|
||||
0% {
|
||||
transform: scale(0.7);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes imgbox_lazy_in {
|
||||
0% {
|
||||
transform: scale(0.7);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
@-webkit-keyframes scale_in {
|
||||
0% {
|
||||
transform: scale(0.2);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes scale_in {
|
||||
0% {
|
||||
transform: scale(0.2);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
@-webkit-keyframes scale_out {
|
||||
0% {
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: scale(0.2);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes scale_out {
|
||||
0% {
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: scale(0.2);
|
||||
}
|
||||
}
|
||||
|
||||
.counter-con {
|
||||
transform: none;
|
||||
top: 10px;
|
||||
}
|
||||
|
||||
.counter {
|
||||
padding: 4px 12px;
|
||||
font-size: 16px;
|
||||
margin: 10px;
|
||||
background: rgba(41, 41, 41, 0.7);
|
||||
}
|
||||
|
||||
.swiper-imgbox .swiper-slide img {
|
||||
width: auto;
|
||||
height: auto;
|
||||
max-width: 90%;
|
||||
max-height: 90%;
|
||||
transition-duration: 0s;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.swiper-imgbox .counter-con {
|
||||
transform: none;
|
||||
top: 10px;
|
||||
right: auto;
|
||||
bottom: auto;
|
||||
width: auto;
|
||||
left: 10px;
|
||||
}
|
||||
|
||||
.full-screen .swiper-slide img {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.swiper-close {
|
||||
height: 100%;
|
||||
transition: 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
|
||||
}
|
||||
|
||||
.lazyloaded + .swiper-lazy-preloader {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.swiper-pagination-bullets > .swiper-pagination-bullet {
|
||||
width: 4px;
|
||||
@@ -905,16 +661,6 @@ button.swiper-pagination-bullet {
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.imgbox.show .swiper-imgbox .swiper-slide {
|
||||
-webkit-animation: scale_in 0.4s;
|
||||
animation: scale_in 0.4s;
|
||||
}
|
||||
|
||||
.swiper-imgbox .swiper-slide img {
|
||||
max-width: calc(100% - 10px);
|
||||
max-height: calc(100% - 10px);
|
||||
}
|
||||
|
||||
.swiper-container-horizontal > .swiper-pagination-bullets,
|
||||
.swiper-pagination-custom,
|
||||
.swiper-pagination-fraction {
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+352
-253
File diff suppressed because one or more lines are too long
+350
-251
@@ -9,10 +9,6 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
/* ============================================================
|
||||
* 1. 图片灯箱 — zoom / thumbnails / slideshow / fullscreen /
|
||||
* mousewheel / origin animation / smart download
|
||||
* ============================================================ */
|
||||
var lightboxEl = null;
|
||||
var lightboxImg = null;
|
||||
var lightboxCaption = null;
|
||||
@@ -23,63 +19,111 @@
|
||||
var currentZoom = 1;
|
||||
var autoplayTimer = null;
|
||||
var isAutoplay = false;
|
||||
var EXCLUDE_SEL = '.no-imgbox,.no-lightbox,.avatar,.img-icon,.avatar-badge,.aksrt-avatar';
|
||||
var TRIGGER_SEL = '.entry-content img, .wp-posts-content img, .aksrt-lightbox-trigger img, [data-aksrt-lightbox] img, .imgbox-container img, .comment-content .box-img img, a[data-imgbox] img';
|
||||
var CONTAINER_SEL = '.entry-content, .wp-posts-content, .aksrt-lightbox-trigger, [data-aksrt-lightbox], .imgbox-container, .comment-content';
|
||||
var lastTrigger = null;
|
||||
var previousBodyOverflow = '';
|
||||
var EXCLUDE_SEL = '.no-imgbox,.no-lightbox,.avatar,.img-icon,.avatar-badge,.aksrt-avatar,[data-no-lightbox],[data-aksrt-lightbox="0"]';
|
||||
var TRIGGER_SEL = '[data-aksrt-lightbox="1"] img,.aksrt-lightbox-trigger img,.imgbox-container img,.comment-content .box-img';
|
||||
var ANCHOR_TRIGGER_SEL = 'a[data-aksrt-lightbox-trigger]';
|
||||
var GROUP_SEL = '[data-aksrt-lightbox-group],.content-gallery[data-aksrt-lightbox="1"],.aksrt-carousel-block[data-aksrt-lightbox="1"],.imgbox-container,.comment-content,.post_front_content[data-aksrt-lightbox="1"],.wp-posts-content[data-aksrt-lightbox="1"],.entry-thumb[data-aksrt-lightbox="1"],.entry-content[data-aksrt-lightbox="1"],.aksrt-lightbox-trigger,[data-aksrt-lightbox="1"]';
|
||||
var IMAGE_URL_RE = /\.(?:avif|bmp|gif|ico|jpe?g|png|svg|tiff?|webp)(?:[?#].*)?$/i;
|
||||
var MAX_ZOOM_DESKTOP = 2;
|
||||
var MAX_ZOOM_MOBILE = 3;
|
||||
|
||||
function lightboxFlag(key, fallback) {
|
||||
var w = window._win || (window.aksrtData && window.aksrtData.imgbox) || {};
|
||||
if (w[key] === undefined || w[key] === null || w[key] === '') return fallback;
|
||||
return w[key] === true || w[key] === 1 || w[key] === '1';
|
||||
}
|
||||
function lightboxEnabled() {
|
||||
return lightboxFlag('imgbox', true);
|
||||
var config = window._win || {};
|
||||
if (config[key] === undefined || config[key] === null || config[key] === '') return fallback;
|
||||
return config[key] === true || config[key] === 1 || config[key] === '1';
|
||||
}
|
||||
|
||||
function lightboxEnabled() {
|
||||
return lightboxFlag('imgbox', false);
|
||||
}
|
||||
|
||||
function normalizeFullUrl(url) {
|
||||
if (!url || url.indexOf('data:') === 0) return url || '';
|
||||
return url
|
||||
.replace(/-\d+x\d+(\.[a-z0-9]+)(?=([?#]|$))/i, '$1')
|
||||
.replace(/([?&])x-oss-process=[^#&]*&?/i, '$1')
|
||||
.replace(/[?&]$/, '');
|
||||
}
|
||||
|
||||
function resolveFullUrl(img) {
|
||||
var full = img.getAttribute('data-full-url') || img.getAttribute('data-src') || '';
|
||||
if (full) return full;
|
||||
var src = img.src || '';
|
||||
// thumbnail → original: strip -NNNxNNN suffix
|
||||
return src.replace(/-\d+x\d+(\.[a-z]+)$/i, '$1');
|
||||
var explicitFull = img.getAttribute('data-full-url') || '';
|
||||
if (explicitFull) return normalizeFullUrl(explicitFull);
|
||||
|
||||
var anchor = img.closest('a[href]');
|
||||
var href = anchor ? anchor.getAttribute('href') || '' : '';
|
||||
if (IMAGE_URL_RE.test(href)) return normalizeFullUrl(href);
|
||||
|
||||
return normalizeFullUrl(
|
||||
img.getAttribute('data-src')
|
||||
|| img.getAttribute('data-lazy-src')
|
||||
|| img.currentSrc
|
||||
|| img.getAttribute('src')
|
||||
|| ''
|
||||
);
|
||||
}
|
||||
|
||||
function resolveThumbUrl(img) {
|
||||
return img.currentSrc
|
||||
|| img.getAttribute('src')
|
||||
|| img.getAttribute('data-src')
|
||||
|| img.getAttribute('data-lazy-src')
|
||||
|| img.getAttribute('data-full-url')
|
||||
|| '';
|
||||
}
|
||||
|
||||
function resolveCaption(img) {
|
||||
var anchor = img.closest('a');
|
||||
var explicit = anchor ? anchor.getAttribute('data-caption') || '' : '';
|
||||
if (explicit.trim()) return explicit.trim();
|
||||
|
||||
var figure = img.closest('figure');
|
||||
var figcaption = figure ? figure.querySelector('figcaption') : null;
|
||||
if (figcaption && figcaption.textContent.trim()) return figcaption.textContent.trim();
|
||||
|
||||
return (img.getAttribute('alt') || '').trim();
|
||||
}
|
||||
|
||||
function isNoLightbox(img) {
|
||||
if (img.closest(EXCLUDE_SEL)) return true;
|
||||
// parent anchor that does NOT point to an image
|
||||
var parentA = img.closest('a');
|
||||
if (!img || img.closest(EXCLUDE_SEL)) return true;
|
||||
|
||||
var parentA = img.closest('a[href]');
|
||||
if (parentA) {
|
||||
var href = parentA.getAttribute('href') || '';
|
||||
if (href && !/\.(jpe?g|png|gif|webp|avif|svg|bmp)(\?|$)/i.test(href) && !parentA.hasAttribute('data-imgbox')) {
|
||||
if (href && !IMAGE_URL_RE.test(href) && !parentA.hasAttribute('data-aksrt-lightbox-trigger')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
return resolveFullUrl(img) === '';
|
||||
}
|
||||
|
||||
function createLightbox() {
|
||||
if (!lightboxEnabled()) return;
|
||||
if (lightboxEl) return;
|
||||
if (!lightboxEnabled()) return null;
|
||||
if (lightboxEl) return lightboxEl;
|
||||
|
||||
lightboxEl = document.createElement('div');
|
||||
lightboxEl.className = 'aksrt-lightbox';
|
||||
lightboxEl.setAttribute('role', 'dialog');
|
||||
lightboxEl.setAttribute('aria-modal', 'true');
|
||||
lightboxEl.setAttribute('aria-hidden', 'true');
|
||||
lightboxEl.setAttribute('aria-label', '图片预览');
|
||||
lightboxEl.setAttribute('tabindex', '-1');
|
||||
lightboxEl.innerHTML =
|
||||
'<div class="aksrt-lightbox__toolbar">' +
|
||||
'<span class="aksrt-lightbox__counter"></span>' +
|
||||
'<button type="button" class="aksrt-lightbox__tool toggle-zoom" title="缩放"><i class="fa fas fa-search-plus"></i></button>' +
|
||||
'<button type="button" class="aksrt-lightbox__tool toggle-thumbs" title="缩略图"><i class="fa fas fa-th"></i></button>' +
|
||||
'<button type="button" class="aksrt-lightbox__tool toggle-play" title="幻灯片"><i class="fa fas fa-play"></i></button>' +
|
||||
'<button type="button" class="aksrt-lightbox__tool toggle-full" title="全屏"><i class="fa fas fa-expand"></i></button>' +
|
||||
'<button type="button" class="aksrt-lightbox__tool aksrt-lightbox__download" title="下载"><i class="fa fas fa-download"></i></button>' +
|
||||
'<button type="button" class="aksrt-lightbox__tool aksrt-lightbox__close" title="关闭"><i class="fa fas fa-times"></i></button>' +
|
||||
'<span class="aksrt-lightbox__counter" aria-live="polite"></span>' +
|
||||
'<button type="button" class="aksrt-lightbox__tool toggle-zoom" title="缩放" aria-label="缩放"><i class="fa fas fa-search-plus" aria-hidden="true"></i></button>' +
|
||||
'<button type="button" class="aksrt-lightbox__tool toggle-thumbs" title="缩略图" aria-label="显示或隐藏缩略图"><i class="fa fas fa-th" aria-hidden="true"></i></button>' +
|
||||
'<button type="button" class="aksrt-lightbox__tool toggle-play" title="幻灯片" aria-label="播放幻灯片"><i class="fa fas fa-play" aria-hidden="true"></i></button>' +
|
||||
'<button type="button" class="aksrt-lightbox__tool toggle-full" title="全屏" aria-label="切换全屏"><i class="fa fas fa-expand" aria-hidden="true"></i></button>' +
|
||||
'<a class="aksrt-lightbox__tool aksrt-lightbox__download" title="下载" aria-label="下载图片" download><i class="fa fas fa-download" aria-hidden="true"></i></a>' +
|
||||
'<button type="button" class="aksrt-lightbox__tool aksrt-lightbox__close" title="关闭" aria-label="关闭"><i class="fa fas fa-times" aria-hidden="true"></i></button>' +
|
||||
'</div>' +
|
||||
'<button type="button" class="aksrt-lightbox__nav aksrt-lightbox__nav--prev" aria-label="上一张"><i class="fa fas fa-chevron-left"></i></button>' +
|
||||
'<button type="button" class="aksrt-lightbox__nav aksrt-lightbox__nav--prev" aria-label="上一张"><i class="fa fas fa-chevron-left" aria-hidden="true"></i></button>' +
|
||||
'<div class="aksrt-lightbox__stage"><img class="aksrt-lightbox__img" src="" alt=""></div>' +
|
||||
'<button type="button" class="aksrt-lightbox__nav aksrt-lightbox__nav--next" aria-label="下一张"><i class="fa fas fa-chevron-right"></i></button>' +
|
||||
'<div class="aksrt-lightbox__caption"></div>' +
|
||||
'<button type="button" class="aksrt-lightbox__nav aksrt-lightbox__nav--next" aria-label="下一张"><i class="fa fas fa-chevron-right" aria-hidden="true"></i></button>' +
|
||||
'<div class="aksrt-lightbox__caption" aria-live="polite"></div>' +
|
||||
'<div class="aksrt-lightbox__thumbs" hidden></div>';
|
||||
|
||||
document.body.appendChild(lightboxEl);
|
||||
@@ -89,223 +133,260 @@
|
||||
lightboxCounter = lightboxEl.querySelector('.aksrt-lightbox__counter');
|
||||
lightboxThumbsWrap = lightboxEl.querySelector('.aksrt-lightbox__thumbs');
|
||||
|
||||
// Apply window._win imgbox feature flags
|
||||
var zoomBtn = lightboxEl.querySelector('.toggle-zoom');
|
||||
var thumbsBtn = lightboxEl.querySelector('.toggle-thumbs');
|
||||
var playBtn = lightboxEl.querySelector('.toggle-play');
|
||||
var fullBtn = lightboxEl.querySelector('.toggle-full');
|
||||
var downBtn = lightboxEl.querySelector('.aksrt-lightbox__download');
|
||||
if (zoomBtn) zoomBtn.hidden = !lightboxFlag('imgbox_zoom', true);
|
||||
if (thumbsBtn) thumbsBtn.hidden = !lightboxFlag('imgbox_thumbs', true);
|
||||
if (playBtn) playBtn.hidden = !lightboxFlag('imgbox_play', false);
|
||||
if (fullBtn) fullBtn.hidden = !lightboxFlag('imgbox_full', true);
|
||||
if (downBtn) downBtn.hidden = !lightboxFlag('imgbox_down', false);
|
||||
|
||||
// Close
|
||||
lightboxEl.querySelector('.aksrt-lightbox__close').addEventListener('click', function (e) { e.stopPropagation(); closeLightbox(); });
|
||||
lightboxEl.addEventListener('click', function (e) { if (e.target === lightboxEl || e.target.classList.contains('aksrt-lightbox__stage')) closeLightbox(); });
|
||||
|
||||
// Nav
|
||||
lightboxEl.querySelector('.aksrt-lightbox__nav--prev').addEventListener('click', function (e) { e.stopPropagation(); navigateLightbox(-1); });
|
||||
lightboxEl.querySelector('.aksrt-lightbox__nav--next').addEventListener('click', function (e) { e.stopPropagation(); navigateLightbox(1); });
|
||||
|
||||
// Keyboard
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (!lightboxEl.classList.contains('is-open')) return;
|
||||
if (e.key === 'Escape') closeLightbox();
|
||||
if (e.key === 'ArrowLeft') navigateLightbox(-1);
|
||||
if (e.key === 'ArrowRight') navigateLightbox(1);
|
||||
lightboxEl.querySelector('.aksrt-lightbox__close').addEventListener('click', function (event) {
|
||||
event.stopPropagation();
|
||||
closeLightbox();
|
||||
});
|
||||
lightboxEl.addEventListener('click', function (event) {
|
||||
if (event.target === lightboxEl || event.target.classList.contains('aksrt-lightbox__stage')) closeLightbox();
|
||||
});
|
||||
lightboxEl.querySelector('.aksrt-lightbox__nav--prev').addEventListener('click', function (event) {
|
||||
event.stopPropagation();
|
||||
navigateLightbox(-1);
|
||||
});
|
||||
lightboxEl.querySelector('.aksrt-lightbox__nav--next').addEventListener('click', function (event) {
|
||||
event.stopPropagation();
|
||||
navigateLightbox(1);
|
||||
});
|
||||
|
||||
// Mousewheel nav
|
||||
lightboxEl.addEventListener('wheel', function (e) {
|
||||
if (!lightboxEl.classList.contains('is-open')) return;
|
||||
if (currentZoom > 1) return; // don't nav when zoomed
|
||||
e.preventDefault();
|
||||
if (e.deltaY > 0) navigateLightbox(1);
|
||||
else navigateLightbox(-1);
|
||||
document.addEventListener('keydown', function (event) {
|
||||
if (!lightboxEl || !lightboxEl.classList.contains('is-open')) return;
|
||||
if (event.key === 'Escape') closeLightbox();
|
||||
if (event.key === 'ArrowLeft') navigateLightbox(-1);
|
||||
if (event.key === 'ArrowRight') navigateLightbox(1);
|
||||
if (event.key === 'Tab') trapFocus(event);
|
||||
});
|
||||
|
||||
lightboxEl.addEventListener('wheel', function (event) {
|
||||
if (!lightboxEl.classList.contains('is-open') || currentZoom > 1 || currentGallery.length < 2) return;
|
||||
event.preventDefault();
|
||||
navigateLightbox(event.deltaY > 0 ? 1 : -1);
|
||||
}, { passive: false });
|
||||
|
||||
// Image click → toggle zoom
|
||||
lightboxImg.addEventListener('click', function (e) { e.stopPropagation(); toggleZoom(); });
|
||||
|
||||
// Double-click → zoom in
|
||||
lightboxImg.addEventListener('dblclick', function (e) {
|
||||
e.stopPropagation();
|
||||
lightboxImg.addEventListener('click', function (event) {
|
||||
event.stopPropagation();
|
||||
if (lightboxFlag('imgbox_zoom', true)) toggleZoom();
|
||||
});
|
||||
lightboxImg.addEventListener('dblclick', function (event) {
|
||||
if (!lightboxFlag('imgbox_zoom', true)) return;
|
||||
event.stopPropagation();
|
||||
var maxZoom = window.innerWidth < 768 ? MAX_ZOOM_MOBILE : MAX_ZOOM_DESKTOP;
|
||||
if (currentZoom < maxZoom) setZoom(maxZoom);
|
||||
else setZoom(1);
|
||||
setZoom(currentZoom < maxZoom ? maxZoom : 1);
|
||||
});
|
||||
|
||||
// Pinch zoom (mobile)
|
||||
bindTouchGestures();
|
||||
|
||||
lightboxEl.querySelector('.toggle-zoom').addEventListener('click', function (event) {
|
||||
event.stopPropagation();
|
||||
toggleZoom();
|
||||
});
|
||||
lightboxEl.querySelector('.toggle-thumbs').addEventListener('click', function (event) {
|
||||
event.stopPropagation();
|
||||
lightboxThumbsWrap.hidden = !lightboxThumbsWrap.hidden;
|
||||
});
|
||||
lightboxEl.querySelector('.toggle-play').addEventListener('click', function (event) {
|
||||
event.stopPropagation();
|
||||
toggleAutoplay();
|
||||
});
|
||||
lightboxEl.querySelector('.toggle-full').addEventListener('click', function (event) {
|
||||
event.stopPropagation();
|
||||
toggleFullscreen();
|
||||
});
|
||||
|
||||
document.addEventListener('fullscreenchange', syncFullscreenState);
|
||||
document.addEventListener('webkitfullscreenchange', syncFullscreenState);
|
||||
|
||||
return lightboxEl;
|
||||
}
|
||||
|
||||
function bindTouchGestures() {
|
||||
var pinchStart = 0;
|
||||
lightboxEl.addEventListener('touchstart', function (e) {
|
||||
if (e.touches.length === 2) {
|
||||
var touchStartY = 0;
|
||||
var touchStartX = 0;
|
||||
var pullDistance = 0;
|
||||
|
||||
lightboxEl.addEventListener('touchstart', function (event) {
|
||||
if (event.touches.length === 2 && lightboxFlag('imgbox_zoom', true)) {
|
||||
pinchStart = Math.hypot(
|
||||
e.touches[1].clientX - e.touches[0].clientX,
|
||||
e.touches[1].clientY - e.touches[0].clientY
|
||||
event.touches[1].clientX - event.touches[0].clientX,
|
||||
event.touches[1].clientY - event.touches[0].clientY
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (event.touches.length === 1 && currentZoom <= 1.05) {
|
||||
touchStartY = event.touches[0].clientY;
|
||||
touchStartX = event.touches[0].clientX;
|
||||
pullDistance = 0;
|
||||
}
|
||||
}, { passive: true });
|
||||
|
||||
lightboxEl.addEventListener('touchmove', function (e) {
|
||||
if (e.touches.length === 2 && pinchStart > 0) {
|
||||
var dist = Math.hypot(
|
||||
e.touches[1].clientX - e.touches[0].clientX,
|
||||
e.touches[1].clientY - e.touches[0].clientY
|
||||
lightboxEl.addEventListener('touchmove', function (event) {
|
||||
if (event.touches.length === 2 && pinchStart > 0 && lightboxFlag('imgbox_zoom', true)) {
|
||||
var distance = Math.hypot(
|
||||
event.touches[1].clientX - event.touches[0].clientX,
|
||||
event.touches[1].clientY - event.touches[0].clientY
|
||||
);
|
||||
var maxZoom = window.innerWidth < 768 ? MAX_ZOOM_MOBILE : MAX_ZOOM_DESKTOP;
|
||||
var newZoom = Math.min(maxZoom, Math.max(1, currentZoom * (dist / pinchStart)));
|
||||
setZoom(newZoom);
|
||||
pinchStart = dist;
|
||||
setZoom(Math.min(maxZoom, Math.max(1, currentZoom * (distance / pinchStart))));
|
||||
pinchStart = distance;
|
||||
return;
|
||||
}
|
||||
}, { passive: true });
|
||||
if (event.touches.length !== 1 || currentZoom > 1.05) return;
|
||||
|
||||
lightboxEl.addEventListener('touchend', function () { pinchStart = 0; }, { passive: true });
|
||||
|
||||
// Touch swipe/pull-dismiss (skip when zoomed)
|
||||
var touchStartY = 0, touchStartX = 0, isSwiping = false;
|
||||
lightboxEl.addEventListener('touchstart', function (e) {
|
||||
if (e.touches.length !== 1 || currentZoom > 1.05) return;
|
||||
touchStartY = e.touches[0].clientY;
|
||||
touchStartX = e.touches[0].clientX;
|
||||
isSwiping = false;
|
||||
}, { passive: true });
|
||||
|
||||
lightboxEl.addEventListener('touchmove', function (e) {
|
||||
if (e.touches.length !== 1 || currentZoom > 1.05) return;
|
||||
var dy = e.touches[0].clientY - touchStartY;
|
||||
var dx = e.touches[0].clientX - touchStartX;
|
||||
var dy = event.touches[0].clientY - touchStartY;
|
||||
var dx = event.touches[0].clientX - touchStartX;
|
||||
if (Math.abs(dy) > Math.abs(dx) && dy > 30) {
|
||||
isSwiping = true;
|
||||
var opacity = Math.max(0.2, (150 - dy) / 80);
|
||||
pullDistance = dy;
|
||||
lightboxImg.style.transform = 'translate3d(0, ' + dy + 'px, 0) scale(' + currentZoom + ')';
|
||||
lightboxImg.style.opacity = String(Math.min(1, opacity));
|
||||
lightboxImg.style.opacity = String(Math.max(0.2, Math.min(1, (150 - dy) / 80)));
|
||||
}
|
||||
}, { passive: true });
|
||||
|
||||
lightboxEl.addEventListener('touchend', function () {
|
||||
if (isSwiping) {
|
||||
pinchStart = 0;
|
||||
if (pullDistance > 100) {
|
||||
closeLightbox();
|
||||
lightboxImg.style.transform = '';
|
||||
} else if (pullDistance > 0) {
|
||||
setZoom(1);
|
||||
}
|
||||
lightboxImg.style.opacity = '';
|
||||
}
|
||||
isSwiping = false;
|
||||
pullDistance = 0;
|
||||
}, { passive: true });
|
||||
|
||||
// Download
|
||||
lightboxEl.querySelector('.aksrt-lightbox__download').addEventListener('click', function (e) {
|
||||
e.stopPropagation();
|
||||
var item = currentGallery[currentIndex];
|
||||
if (!item || !item.src) return;
|
||||
var a = document.createElement('a');
|
||||
var fullSrc = item.fullSrc || item.src;
|
||||
a.href = fullSrc;
|
||||
a.download = fullSrc.substring(fullSrc.lastIndexOf('/') + 1) || 'image';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
});
|
||||
|
||||
// Zoom button
|
||||
lightboxEl.querySelector('.toggle-zoom').addEventListener('click', function (e) { e.stopPropagation(); toggleZoom(); });
|
||||
|
||||
// Thumbnails toggle
|
||||
lightboxEl.querySelector('.toggle-thumbs').addEventListener('click', function (e) {
|
||||
e.stopPropagation();
|
||||
lightboxThumbsWrap.hidden = !lightboxThumbsWrap.hidden;
|
||||
});
|
||||
|
||||
// Slideshow toggle
|
||||
lightboxEl.querySelector('.toggle-play').addEventListener('click', function (e) {
|
||||
e.stopPropagation();
|
||||
toggleAutoplay();
|
||||
});
|
||||
|
||||
// Fullscreen
|
||||
lightboxEl.querySelector('.toggle-full').addEventListener('click', function (e) {
|
||||
e.stopPropagation();
|
||||
toggleFullscreen();
|
||||
});
|
||||
|
||||
document.addEventListener('fullscreenchange', function () {
|
||||
var icon = lightboxEl.querySelector('.toggle-full i');
|
||||
if (document.fullscreenElement) {
|
||||
lightboxEl.classList.add('full-screen');
|
||||
icon.className = 'fa fas fa-compress';
|
||||
} else {
|
||||
lightboxEl.classList.remove('full-screen');
|
||||
icon.className = 'fa fas fa-expand';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setZoom(z) {
|
||||
currentZoom = z;
|
||||
lightboxImg.style.transform = 'scale(' + z + ')';
|
||||
lightboxEl.classList.toggle('is-zoomed', z > 1);
|
||||
function trapFocus(event) {
|
||||
var focusable = Array.prototype.filter.call(
|
||||
lightboxEl.querySelectorAll('a[href],button:not([hidden]):not([disabled]),[tabindex]:not([tabindex="-1"])'),
|
||||
function (element) { return element.offsetParent !== null; }
|
||||
);
|
||||
if (!focusable.length) {
|
||||
event.preventDefault();
|
||||
lightboxEl.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
var first = focusable[0];
|
||||
var last = focusable[focusable.length - 1];
|
||||
if (event.shiftKey && document.activeElement === first) {
|
||||
event.preventDefault();
|
||||
last.focus();
|
||||
} else if (!event.shiftKey && document.activeElement === last) {
|
||||
event.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
}
|
||||
|
||||
function setZoom(zoom) {
|
||||
if (!lightboxImg || !lightboxEl) return;
|
||||
currentZoom = zoom;
|
||||
lightboxImg.style.transform = 'scale(' + zoom + ')';
|
||||
lightboxEl.classList.toggle('is-zoomed', zoom > 1);
|
||||
}
|
||||
|
||||
function toggleZoom() {
|
||||
if (!lightboxFlag('imgbox_zoom', true)) return;
|
||||
var maxZoom = window.innerWidth < 768 ? MAX_ZOOM_MOBILE : MAX_ZOOM_DESKTOP;
|
||||
setZoom(currentZoom > 1 ? 1 : maxZoom);
|
||||
}
|
||||
|
||||
function toggleAutoplay() {
|
||||
if (!lightboxEl) return;
|
||||
var icon = lightboxEl.querySelector('.toggle-play i');
|
||||
if (isAutoplay) {
|
||||
clearInterval(autoplayTimer);
|
||||
autoplayTimer = null;
|
||||
isAutoplay = false;
|
||||
icon.className = 'fa fas fa-play';
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (currentGallery.length < 2) return;
|
||||
|
||||
isAutoplay = true;
|
||||
icon.className = 'fa fas fa-pause';
|
||||
autoplayTimer = setInterval(function () { navigateLightbox(1); }, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleFullscreen() {
|
||||
var rfs = lightboxEl.requestFullscreen || lightboxEl.webkitRequestFullscreen || lightboxEl.msRequestFullscreen;
|
||||
if (document.fullscreenElement || document.webkitFullscreenElement) {
|
||||
(document.exitFullscreen || document.webkitExitFullscreen || document.msExitFullscreen).call(document);
|
||||
} else if (rfs) {
|
||||
rfs.call(lightboxEl);
|
||||
if (!lightboxEl || !lightboxFlag('imgbox_full', true)) return;
|
||||
var fullscreenElement = document.fullscreenElement || document.webkitFullscreenElement;
|
||||
if (fullscreenElement) {
|
||||
var exit = document.exitFullscreen || document.webkitExitFullscreen;
|
||||
if (exit) exit.call(document);
|
||||
return;
|
||||
}
|
||||
|
||||
var request = lightboxEl.requestFullscreen || lightboxEl.webkitRequestFullscreen;
|
||||
if (request) request.call(lightboxEl);
|
||||
}
|
||||
|
||||
function syncFullscreenState() {
|
||||
if (!lightboxEl) return;
|
||||
var active = Boolean(document.fullscreenElement || document.webkitFullscreenElement);
|
||||
var icon = lightboxEl.querySelector('.toggle-full i');
|
||||
lightboxEl.classList.toggle('full-screen', active);
|
||||
icon.className = active ? 'fa fas fa-compress' : 'fa fas fa-expand';
|
||||
}
|
||||
|
||||
function buildThumbnails() {
|
||||
if (!lightboxThumbsWrap) return;
|
||||
lightboxThumbsWrap.innerHTML = '';
|
||||
currentGallery.forEach(function (item, i) {
|
||||
currentGallery.forEach(function (item, index) {
|
||||
var button = document.createElement('button');
|
||||
var thumb = document.createElement('img');
|
||||
thumb.src = item.src;
|
||||
thumb.className = 'aksrt-lightbox__thumb' + (i === currentIndex ? ' is-active' : '');
|
||||
thumb.addEventListener('click', function (e) {
|
||||
e.stopPropagation();
|
||||
showLightboxImage(i);
|
||||
button.type = 'button';
|
||||
button.className = 'aksrt-lightbox__thumb' + (index === currentIndex ? ' is-active' : '');
|
||||
button.setAttribute('aria-label', '查看第 ' + (index + 1) + ' 张图片');
|
||||
thumb.src = item.thumbSrc || item.src;
|
||||
thumb.alt = '';
|
||||
button.appendChild(thumb);
|
||||
button.addEventListener('click', function (event) {
|
||||
event.stopPropagation();
|
||||
showLightboxImage(index);
|
||||
});
|
||||
lightboxThumbsWrap.appendChild(thumb);
|
||||
lightboxThumbsWrap.appendChild(button);
|
||||
});
|
||||
}
|
||||
|
||||
function syncThumbActive() {
|
||||
if (!lightboxThumbsWrap) return;
|
||||
var thumbs = lightboxThumbsWrap.querySelectorAll('.aksrt-lightbox__thumb');
|
||||
thumbs.forEach(function (t, i) { t.classList.toggle('is-active', i === currentIndex); });
|
||||
thumbs.forEach(function (thumb, index) {
|
||||
thumb.classList.toggle('is-active', index === currentIndex);
|
||||
});
|
||||
var active = thumbs[currentIndex];
|
||||
if (active) active.scrollIntoView({ inline: 'center', block: 'nearest', behavior: 'smooth' });
|
||||
if (active) active.scrollIntoView({ inline: 'center', block: 'nearest' });
|
||||
}
|
||||
|
||||
function syncControls() {
|
||||
if (!lightboxEl) return;
|
||||
var multiple = currentGallery.length > 1;
|
||||
var fullscreenAvailable = Boolean(
|
||||
lightboxEl.requestFullscreen
|
||||
|| lightboxEl.webkitRequestFullscreen
|
||||
|| document.fullscreenEnabled
|
||||
|| document.webkitFullscreenEnabled
|
||||
);
|
||||
var thumbsEnabled = multiple && lightboxFlag('imgbox_thumbs', true);
|
||||
|
||||
lightboxEl.querySelector('.toggle-zoom').hidden = !lightboxFlag('imgbox_zoom', true);
|
||||
lightboxEl.querySelector('.toggle-thumbs').hidden = !thumbsEnabled;
|
||||
lightboxEl.querySelector('.toggle-play').hidden = !multiple || !lightboxFlag('imgbox_play', false);
|
||||
lightboxEl.querySelector('.toggle-full').hidden = !lightboxFlag('imgbox_full', true) || !fullscreenAvailable;
|
||||
lightboxEl.querySelector('.aksrt-lightbox__download').hidden = !lightboxFlag('imgbox_down', false);
|
||||
lightboxEl.querySelector('.aksrt-lightbox__nav--prev').hidden = !multiple;
|
||||
lightboxEl.querySelector('.aksrt-lightbox__nav--next').hidden = !multiple;
|
||||
lightboxThumbsWrap.hidden = !thumbsEnabled;
|
||||
}
|
||||
|
||||
function openLightbox(src, caption, gallery, index, originEl) {
|
||||
createLightbox();
|
||||
if (!lightboxEnabled() || !createLightbox()) return false;
|
||||
|
||||
currentGallery = gallery || [{ src: src, caption: caption || '' }];
|
||||
currentIndex = index || 0;
|
||||
currentGallery = gallery && gallery.length ? gallery : [{ src: src, fullSrc: src, thumbSrc: src, caption: caption || '' }];
|
||||
currentIndex = Number.isInteger(index) ? index : 0;
|
||||
currentZoom = 1;
|
||||
lastTrigger = originEl || document.activeElement;
|
||||
|
||||
// Origin animation
|
||||
if (originEl) {
|
||||
if (originEl && typeof originEl.getBoundingClientRect === 'function') {
|
||||
var rect = originEl.getBoundingClientRect();
|
||||
lightboxEl.style.setProperty('--imgbox-origin-top', (rect.top + rect.height / 2) + 'px');
|
||||
lightboxEl.style.setProperty('--imgbox-origin-left', (rect.left + rect.width / 2) + 'px');
|
||||
@@ -314,16 +395,22 @@
|
||||
lightboxEl.classList.remove('from-origin');
|
||||
}
|
||||
|
||||
showLightboxImage(currentIndex);
|
||||
buildThumbnails();
|
||||
syncControls();
|
||||
showLightboxImage(currentIndex);
|
||||
|
||||
lightboxEl.classList.add('is-open');
|
||||
lightboxEl.setAttribute('aria-hidden', 'false');
|
||||
previousBodyOverflow = document.body.style.overflow;
|
||||
document.body.style.overflow = 'hidden';
|
||||
|
||||
document.body.classList.add('aksrt-lightbox-open');
|
||||
lightboxEl.querySelector('.aksrt-lightbox__close').focus();
|
||||
lightboxEl.dispatchEvent(new CustomEvent('aksrt:lightbox-open', { bubbles: true }));
|
||||
return true;
|
||||
}
|
||||
|
||||
function showLightboxImage(index) {
|
||||
if (!currentGallery.length || !lightboxImg) return;
|
||||
if (index < 0) index = currentGallery.length - 1;
|
||||
if (index >= currentGallery.length) index = 0;
|
||||
currentIndex = index;
|
||||
@@ -333,88 +420,113 @@
|
||||
lightboxImg.src = item.fullSrc || item.src;
|
||||
lightboxImg.alt = item.caption || '';
|
||||
lightboxCaption.textContent = item.caption || '';
|
||||
lightboxCaption.style.display = item.caption ? '' : 'none';
|
||||
lightboxCaption.hidden = !item.caption;
|
||||
|
||||
if (currentGallery.length > 1) {
|
||||
lightboxCounter.textContent = (currentIndex + 1) + ' / ' + currentGallery.length;
|
||||
lightboxCounter.style.display = '';
|
||||
lightboxCounter.hidden = false;
|
||||
} else {
|
||||
lightboxCounter.style.display = 'none';
|
||||
lightboxCounter.textContent = '';
|
||||
lightboxCounter.hidden = true;
|
||||
}
|
||||
|
||||
var download = lightboxEl.querySelector('.aksrt-lightbox__download');
|
||||
var fullSrc = item.fullSrc || item.src;
|
||||
download.href = fullSrc;
|
||||
download.download = fullSrc.substring(fullSrc.lastIndexOf('/') + 1).split(/[?#]/)[0] || 'image';
|
||||
syncThumbActive();
|
||||
}
|
||||
|
||||
function navigateLightbox(dir) {
|
||||
showLightboxImage(currentIndex + dir);
|
||||
function navigateLightbox(direction) {
|
||||
if (currentGallery.length < 2) return;
|
||||
showLightboxImage(currentIndex + direction);
|
||||
}
|
||||
|
||||
function closeLightbox() {
|
||||
if (!lightboxEl) return;
|
||||
if (!lightboxEl || !lightboxEl.classList.contains('is-open')) return;
|
||||
if (isAutoplay) toggleAutoplay();
|
||||
lightboxEl.classList.remove('is-open', 'is-zoomed', 'from-origin');
|
||||
document.body.style.overflow = '';
|
||||
lightboxEl.setAttribute('aria-hidden', 'true');
|
||||
document.body.style.overflow = previousBodyOverflow;
|
||||
document.body.classList.remove('aksrt-lightbox-open');
|
||||
lightboxThumbsWrap.hidden = true;
|
||||
if (document.fullscreenElement) {
|
||||
(document.exitFullscreen || document.webkitExitFullscreen || document.msExitFullscreen).call(document);
|
||||
lightboxImg.src = '';
|
||||
lightboxImg.alt = '';
|
||||
|
||||
var fullscreenElement = document.fullscreenElement || document.webkitFullscreenElement;
|
||||
var exit = document.exitFullscreen || document.webkitExitFullscreen;
|
||||
if (fullscreenElement && exit) exit.call(document);
|
||||
|
||||
if (lastTrigger && typeof lastTrigger.focus === 'function' && document.contains(lastTrigger)) {
|
||||
lastTrigger.focus({ preventScroll: true });
|
||||
}
|
||||
lastTrigger = null;
|
||||
}
|
||||
|
||||
function buildGallery(img) {
|
||||
var container = img.closest(GROUP_SEL);
|
||||
if (!container || container.closest('[data-no-lightbox],[data-aksrt-lightbox="0"]')) return null;
|
||||
|
||||
var gallery = [];
|
||||
var foundIndex = -1;
|
||||
container.querySelectorAll('img').forEach(function (candidate) {
|
||||
if (!candidate.matches(TRIGGER_SEL) || isNoLightbox(candidate)) return;
|
||||
var fullSrc = resolveFullUrl(candidate);
|
||||
var thumbSrc = resolveThumbUrl(candidate) || fullSrc;
|
||||
if (!fullSrc) return;
|
||||
|
||||
if (candidate === img) foundIndex = gallery.length;
|
||||
gallery.push({
|
||||
src: thumbSrc,
|
||||
thumbSrc: thumbSrc,
|
||||
fullSrc: fullSrc,
|
||||
caption: resolveCaption(candidate),
|
||||
});
|
||||
});
|
||||
|
||||
if (foundIndex < 0 || !gallery.length) return null;
|
||||
return { items: gallery, index: foundIndex };
|
||||
}
|
||||
|
||||
function openImage(img) {
|
||||
if (isNoLightbox(img)) return false;
|
||||
var gallery = buildGallery(img);
|
||||
if (!gallery) return false;
|
||||
var item = gallery.items[gallery.index];
|
||||
return openLightbox(item.fullSrc, item.caption, gallery.items, gallery.index, img);
|
||||
}
|
||||
|
||||
// Auto-bind: expanded trigger scope + exclusion rules
|
||||
function initLightbox() {
|
||||
document.addEventListener('click', function (e) {
|
||||
// Also support a[data-imgbox]
|
||||
var anchor = e.target.closest('a[data-imgbox]');
|
||||
if (anchor) {
|
||||
e.preventDefault();
|
||||
var href = anchor.getAttribute('href') || anchor.getAttribute('data-imgbox');
|
||||
openLightbox(href, '', [{ src: href, fullSrc: href, caption: '' }], 0, anchor);
|
||||
document.addEventListener('click', function (event) {
|
||||
if (!lightboxEnabled() || !(event.target instanceof Element)) return;
|
||||
|
||||
var anchor = event.target.closest(ANCHOR_TRIGGER_SEL);
|
||||
if (anchor && !anchor.closest(EXCLUDE_SEL)) {
|
||||
var anchorImage = anchor.querySelector('img');
|
||||
if (anchorImage && openImage(anchorImage)) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
var img = e.target.closest(TRIGGER_SEL);
|
||||
if (!img) return;
|
||||
if (img.width < 100 || img.height < 100) return;
|
||||
if (!lightboxEnabled() || isNoLightbox(img)) return;
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var container = img.closest(CONTAINER_SEL);
|
||||
if (!container) return;
|
||||
|
||||
var allImages = container.querySelectorAll('img');
|
||||
var gallery = [];
|
||||
var foundIndex = 0;
|
||||
|
||||
allImages.forEach(function (el) {
|
||||
if (el.width < 100 || el.height < 100) return;
|
||||
if (isNoLightbox(el)) return;
|
||||
var full = resolveFullUrl(el);
|
||||
var caption = el.alt || '';
|
||||
var figcaption = el.closest('figure') ? el.closest('figure').querySelector('figcaption') : null;
|
||||
if (figcaption) caption = figcaption.textContent;
|
||||
gallery.push({ src: el.dataset.src || el.src, fullSrc: full, caption: caption });
|
||||
if (el === img) foundIndex = gallery.length - 1;
|
||||
});
|
||||
|
||||
if (gallery.length > 0) {
|
||||
openLightbox(img.dataset.src || img.src, img.alt, gallery, foundIndex, img);
|
||||
var href = anchor.getAttribute('href') || '';
|
||||
if (IMAGE_URL_RE.test(href) && openLightbox(href, anchor.getAttribute('data-caption') || '', null, 0, anchor)) {
|
||||
event.preventDefault();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var img = event.target.closest(TRIGGER_SEL);
|
||||
if (img && openImage(img)) event.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
// 暴露到全局
|
||||
window.AksrtLightbox = {
|
||||
open: openLightbox,
|
||||
close: closeLightbox,
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
* 2. 滚动方向感知
|
||||
* ============================================================ */
|
||||
// Scroll direction is now handled by aksrt-runtime.js body scroll bus
|
||||
// (body.scroll-down / body.scroll-up / body.body-scroll).
|
||||
// This stub syncs the legacy aksrt-* prefixed classes for backward compat.
|
||||
// Scroll direction is handled by aksrt-runtime.js. Keep the prefixed
|
||||
// classes in sync for the remaining CSS consumers.
|
||||
function initScrollDirection() {
|
||||
var body = document.body;
|
||||
|
||||
@@ -430,26 +542,13 @@
|
||||
}, 300);
|
||||
}
|
||||
|
||||
function onScroll() {
|
||||
window.addEventListener('scroll', function () {
|
||||
requestAnimationFrame(sync);
|
||||
}, { passive: true });
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', onScroll, { passive: true });
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
* 3. 导航溢出折叠
|
||||
* 由 legacy main.js 的 navFolding 负责。
|
||||
* 此处不再重复实现,避免两套逻辑争抢 .aksrt-nav-more 节点
|
||||
* 触发 NotFoundError: insertBefore (moreLi 已被对方 remove)。
|
||||
* ============================================================ */
|
||||
|
||||
/* ============================================================
|
||||
* 初始化入口
|
||||
* ============================================================ */
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
initLightbox();
|
||||
initScrollDirection();
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* AKSRT Page Template
|
||||
*
|
||||
* Handles template-scoped content interactions: lightbox,
|
||||
* expandable article bodies, and one-shot query cleanup banners.
|
||||
* Handles template-scoped content interactions: expandable article bodies
|
||||
* and one-shot query cleanup banners.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
@@ -10,69 +10,6 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function initLightbox() {
|
||||
var overlay = document.getElementById('lightbox-overlay');
|
||||
var content = document.querySelector(".wp-posts-content[data-aksrt-lightbox='1'], .entry-content[data-aksrt-lightbox='1']");
|
||||
if (!overlay || !content || overlay.dataset.aksrtLightboxBound === '1') return;
|
||||
|
||||
overlay.dataset.aksrtLightboxBound = '1';
|
||||
|
||||
var image = overlay.querySelector('.lightbox-img');
|
||||
var caption = overlay.querySelector('.lightbox-caption');
|
||||
var closeBtn = overlay.querySelector('.lightbox-close');
|
||||
|
||||
function close() {
|
||||
overlay.classList.remove('is-open');
|
||||
overlay.setAttribute('aria-hidden', 'true');
|
||||
document.body.style.overflow = '';
|
||||
if (image) {
|
||||
image.src = '';
|
||||
image.alt = '';
|
||||
}
|
||||
}
|
||||
|
||||
content.querySelectorAll('img').forEach(function (img) {
|
||||
var link = img.closest('a[href]');
|
||||
var linkHref = link ? link.href : '';
|
||||
var linksToImage = /\.(?:avif|gif|jpe?g|png|svg|webp)(?:[?#].*)?$/i.test(linkHref);
|
||||
if (img.closest('[data-no-lightbox]') || (link && !linksToImage)) return;
|
||||
|
||||
img.classList.add('aksrt-lightbox-target');
|
||||
img.addEventListener('click', function (event) {
|
||||
if (!image) return;
|
||||
if (linksToImage) event.preventDefault();
|
||||
|
||||
image.src = linksToImage
|
||||
? linkHref
|
||||
: (img.getAttribute('data-src') || img.getAttribute('data-lazy-src') || img.currentSrc || img.src);
|
||||
image.alt = img.alt || '';
|
||||
|
||||
if (caption) {
|
||||
var figure = img.closest('figure');
|
||||
var figureCaption = figure ? figure.querySelector('figcaption') : null;
|
||||
caption.textContent = img.alt || (figureCaption ? figureCaption.textContent : '') || '';
|
||||
}
|
||||
|
||||
overlay.classList.add('is-open');
|
||||
overlay.setAttribute('aria-hidden', 'false');
|
||||
document.body.style.overflow = 'hidden';
|
||||
if (closeBtn) closeBtn.focus();
|
||||
});
|
||||
});
|
||||
|
||||
overlay.addEventListener('click', function (event) {
|
||||
if (event.target === overlay || event.target === closeBtn || (event.target.closest && event.target.closest('.lightbox-close'))) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function (event) {
|
||||
if (event.key === 'Escape' && overlay.classList.contains('is-open')) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initContentExpand() {
|
||||
// legacy-style: inject .read-more inside .limit-height and expand on click.
|
||||
document.querySelectorAll('.wp-posts-content.limit-height, .limit-height[data-nav]').forEach(function (content) {
|
||||
@@ -150,7 +87,6 @@
|
||||
}
|
||||
|
||||
function init() {
|
||||
initLightbox();
|
||||
initContentExpand();
|
||||
initFlashQueryCleanup();
|
||||
}
|
||||
|
||||
@@ -1,567 +0,0 @@
|
||||
(function ($, window) {
|
||||
'use strict';
|
||||
|
||||
var Miniimgbox = function (img_selector, container_selector) {
|
||||
return _Miniimgbox(img_selector, container_selector, Miniimgbox.options);
|
||||
};
|
||||
|
||||
Miniimgbox.options = {
|
||||
group: true,
|
||||
thumbs: true,
|
||||
down: true,
|
||||
play: true,
|
||||
zoom: true,
|
||||
full: true,
|
||||
exclude: '.no-imgbox,.avatar,.img-icon,.avatar-badge', //排除
|
||||
};
|
||||
|
||||
Miniimgbox.swiper = '';
|
||||
Miniimgbox.thumbs_swiper = '';
|
||||
window.Miniimgbox = Miniimgbox;
|
||||
|
||||
function _Miniimgbox(img_selector, container_selector, options) {
|
||||
var imgbox_calss = 'mini-imgbox imgbox';
|
||||
var imgbox_id = 'mini-imgbox';
|
||||
var data_key = 'imgbox_data';
|
||||
var imgbox_selector = '#' + imgbox_id;
|
||||
var _imgbox = $(imgbox_selector);
|
||||
var Miniimgbox = window.Miniimgbox;
|
||||
var imgbox_swiper = Miniimgbox.swiper;
|
||||
var imgbox_thumbs_swiper = Miniimgbox.thumbs_swiper;
|
||||
var _body = $('body');
|
||||
var _fixed = $('.nav-fixed header');
|
||||
|
||||
if (!options.group) {
|
||||
options.thumbs = false;
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
function init() {
|
||||
add_dom();
|
||||
|
||||
if (options.exclude) {
|
||||
img_selector += ':not(' + options.exclude + ')';
|
||||
}
|
||||
|
||||
var all_img_selector = container_selector ? container_selector + ' ' + img_selector : img_selector;
|
||||
container_selector = options.group ? container_selector : false;
|
||||
|
||||
setTimeout(function () {
|
||||
update_all_slide_data(img_selector, container_selector); //更新dom数据
|
||||
}, 1000);
|
||||
|
||||
//只绑定一次
|
||||
if (!_body.data('imgbox-ison-' + all_img_selector)) {
|
||||
_body.on('click', all_img_selector, function () {
|
||||
var _this = $(this);
|
||||
imgbox_open(_this, container_selector);
|
||||
});
|
||||
_body.data('imgbox-ison-' + all_img_selector, true);
|
||||
}
|
||||
}
|
||||
|
||||
function imgbox_open(_this, container_s) {
|
||||
var slide_lists = get_slide_lists(_this, container_s);
|
||||
|
||||
//没有则退出
|
||||
if (!slide_lists.slide) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (slide_lists.node_length > 1) {
|
||||
$('.imgbox-an .toggle-palay').show();
|
||||
} else {
|
||||
$('.imgbox-an .toggle-palay').hide();
|
||||
}
|
||||
|
||||
$(imgbox_selector + ' .swiper-imgbox .swiper-wrapper').html(slide_lists.slide);
|
||||
|
||||
if (options.thumbs) {
|
||||
$(imgbox_selector + ' .swiper-thumbsbox .swiper-wrapper').html(slide_lists.thumbs);
|
||||
}
|
||||
|
||||
var index = ~~_this.attr('imgbox-index') || 0;
|
||||
|
||||
setTimeout(function () {
|
||||
if (options.thumbs) {
|
||||
imgbox_thumbs_swiper.update();
|
||||
}
|
||||
imgbox_swiper.update();
|
||||
imgbox_swiper.slideTo(index, 2);
|
||||
imgbox_swiper.autoplay.stop();
|
||||
thumb_open();
|
||||
}, 16);
|
||||
|
||||
show(_this);
|
||||
}
|
||||
|
||||
function get_slide_lists(_this, container_s) {
|
||||
var data = _this.data(data_key);
|
||||
if (data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
var _container = container_s ? $(_this.parents(container_s)[0]) : {};
|
||||
|
||||
if (_container.length) {
|
||||
var _data = _container.data(data_key);
|
||||
if (_data && _data.node_length == get_node_length(_container)) {
|
||||
return _data;
|
||||
}
|
||||
}
|
||||
|
||||
return update_slide_data(_this, _container);
|
||||
}
|
||||
|
||||
//获取节点数量
|
||||
function get_node_length(_container) {
|
||||
return _container.find(img_selector).length;
|
||||
}
|
||||
|
||||
function update_all_slide_data(img_selector, container_s) {
|
||||
if (container_s) {
|
||||
$(container_s).each(function () {
|
||||
var each_this = $(this);
|
||||
if (!each_this.data(data_key)) {
|
||||
update_slide_data(each_this.find(img_selector).eq(0), each_this);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$(img_selector).each(function () {
|
||||
var each_this = $(this);
|
||||
if (!each_this.data(data_key)) {
|
||||
update_slide_data(each_this, {});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//将数据保存到节点
|
||||
function update_slide_data(_this, _container) {
|
||||
var data = {
|
||||
slide: '',
|
||||
thumbs: '',
|
||||
length: 0,
|
||||
};
|
||||
|
||||
if (_container.length) {
|
||||
var index = 0;
|
||||
_container.find(img_selector).each(function (i) {
|
||||
if (i == 0) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
var each_this = $(this);
|
||||
if (!is_no(each_this)) {
|
||||
each_this.attr('imgbox-index', index);
|
||||
data.slide += get_slide(each_this);
|
||||
data.length = index + 1;
|
||||
//缩略图
|
||||
if (options.thumbs) data.thumbs += get_thumbs(each_this);
|
||||
index++;
|
||||
}
|
||||
});
|
||||
|
||||
data.node_length = get_node_length(_container);
|
||||
_container.data(data_key, data);
|
||||
} else {
|
||||
if (!is_no(_this) && !_this.find('img').length) {
|
||||
data.slide = get_slide(_this);
|
||||
data.length = index;
|
||||
if (!_this.attr('imgbox-no-cache')) {
|
||||
_this.data(data_key, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
//加载dom
|
||||
function add_dom() {
|
||||
if (_imgbox.length) return;
|
||||
|
||||
var swiper = '<div class="swiper-imgbox"><div class="swiper-wrapper"></div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div><div class="abs-left counter-con"></div></div>';
|
||||
var thumbs_swiper = '<div class="swiper-thumbsbox"><div class="swiper-wrapper">' + '' + '</div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div><div class="abs-center right-top"><i class="hide-but fa fas fa-angle-down em12"></i></div></div>';
|
||||
|
||||
var button = options.down ? '<a href="javascript:;" download class="img-down toggle-radius mr6" title="' + aksrt__('imgbox_download') + '"><i class="fa fas fa-download"></i></a>' : '';
|
||||
if (options.group) {
|
||||
button += options.play ? '<a href="javascript:;" class="toggle-palay toggle-radius mr6" title="' + aksrt__('imgbox_play') + '"><i class="fa fas fa-play"></i></a>' : '';
|
||||
if (options.thumbs) {
|
||||
button += '<a href="javascript:;" class="toggle-thumbs toggle-radius mr6" title="' + aksrt__('imgbox_view_more') + '"><i class="fa fas fa-th-large"></i></a>';
|
||||
swiper += thumbs_swiper;
|
||||
}
|
||||
}
|
||||
|
||||
button += options.zoom ? '<a href="javascript:;" class="toggle-zoom toggle-radius mr6" title="' + aksrt__('imgbox_toggle_zoom') + '"><i class="fa fas fa-search"></i></a>' : '';
|
||||
button += options.full ? '<a href="javascript:;" class="hide-sm toggle-full toggle-radius mr6" title="' + aksrt__('imgbox_toggle_full') + '"><i class="fa fas fa-expand"></i></a>' : '';
|
||||
button += '<a href="javascript:;" title="' + aksrt__('close') + '" class="icon-close toggle-radius"><svg viewBox="0 0 1024 1024" class="icon em12"><path d="M573.44 512.128l237.888 237.696a43.328 43.328 0 0 1 0 59.712 43.392 43.392 0 0 1-59.712 0L513.728 571.84 265.856 819.712a44.672 44.672 0 0 1-61.568 0 44.672 44.672 0 0 1 0-61.568L452.16 510.272 214.208 272.448a43.328 43.328 0 0 1 0-59.648 43.392 43.392 0 0 1 59.712 0l237.952 237.76 246.272-246.272a44.672 44.672 0 0 1 61.568 0 44.672 44.672 0 0 1 0 61.568L573.44 512.128z"></path></svg></a>';
|
||||
|
||||
_body.append('<div class="' + imgbox_calss + '" id="' + imgbox_id + '"><div class="modal-backdrop imgbox-bg"></div><div class="imgbox-an">' + button + '</div>' + swiper + '</div>');
|
||||
|
||||
_imgbox = $(imgbox_selector);
|
||||
|
||||
new_swiper();
|
||||
imgbox_on();
|
||||
}
|
||||
|
||||
function new_swiper() {
|
||||
var selector = imgbox_selector + ' .swiper-imgbox';
|
||||
var speed = ~~(($(window).width() + 1600) / 600);
|
||||
var option = {};
|
||||
// option['init'] = false;
|
||||
option['mousewheel'] = {
|
||||
speed: 10,
|
||||
};
|
||||
option['speed'] = speed * 100;
|
||||
|
||||
option['zoom'] = {
|
||||
maxRatio: $(window).width() < 769 ? 3 : 2,
|
||||
};
|
||||
|
||||
option['autoplay'] = {
|
||||
disableOnInteraction: false,
|
||||
};
|
||||
option['grabCursor'] = true;
|
||||
option['navigation'] = {
|
||||
nextEl: selector + ' .swiper-button-next',
|
||||
prevEl: selector + ' .swiper-button-prev',
|
||||
};
|
||||
option['keyboard'] = {
|
||||
enabled: !0,
|
||||
onlyInViewport: !1,
|
||||
};
|
||||
option['pagination'] = {
|
||||
el: selector + ' .counter-con',
|
||||
type: 'custom',
|
||||
renderCustom: function (swiper, current, total) {
|
||||
if (total > 1) {
|
||||
return '<badge class="b-black counter">' + current + '/' + total + '</badge>';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
};
|
||||
if (options.thumbs && options.group) {
|
||||
new_thumbs_swiper();
|
||||
option['thumbs'] = {
|
||||
swiper: imgbox_thumbs_swiper,
|
||||
autoScrollOffset: ~~(speed / 1.6),
|
||||
};
|
||||
}
|
||||
|
||||
Miniimgbox.swiper = imgbox_swiper = new Swiper(selector, option);
|
||||
}
|
||||
|
||||
function new_thumbs_swiper() {
|
||||
var selector = imgbox_selector + ' .swiper-thumbsbox';
|
||||
var option = {};
|
||||
// option['init'] = true;
|
||||
option['watchSlidesVisibility'] = true; //防止不可点击
|
||||
option['navigation'] = {
|
||||
nextEl: selector + ' .swiper-button-next',
|
||||
prevEl: selector + ' .swiper-button-prev',
|
||||
};
|
||||
option.slidesPerView = 'auto';
|
||||
option.freeMode = true;
|
||||
option.freeModeSticky = true;
|
||||
Miniimgbox.thumbs_swiper = imgbox_thumbs_swiper = new Swiper(selector, option);
|
||||
}
|
||||
|
||||
//绑定执行
|
||||
function imgbox_on() {
|
||||
//仅绑定一次
|
||||
if (_imgbox.data('is_on')) return;
|
||||
|
||||
//下滑关闭
|
||||
touch_close();
|
||||
|
||||
//关闭灯箱
|
||||
_imgbox.on('click', '.img-close,.imgbox-bg,.imgbox-an .icon-close', close);
|
||||
|
||||
//切换thumb
|
||||
_imgbox.on('click', '.imgbox-an .toggle-thumbs,.hide-but', function () {
|
||||
_imgbox.toggleClass('show-thumb');
|
||||
});
|
||||
|
||||
//下载图片
|
||||
_imgbox.on('click', '.imgbox-an .img-down', function () {
|
||||
var _this = $(this);
|
||||
var img = _imgbox.find('.swiper-imgbox .swiper-slide-active img');
|
||||
var src = img.attr('data-src') || img.attr('src');
|
||||
var down_name = src.substring(src.lastIndexOf('/') + 1) || src;
|
||||
|
||||
_this.attr('href', src).attr('download', down_name);
|
||||
});
|
||||
|
||||
//播放图片
|
||||
_imgbox.on('click', '.imgbox-an .toggle-palay', function () {
|
||||
var _this = $(this);
|
||||
|
||||
_this.hasClass('is-play') ? imgbox_swiper.autoplay.stop() : imgbox_swiper.autoplay.start();
|
||||
_this.toggleClass('is-play');
|
||||
});
|
||||
|
||||
//按钮切换放大缩小
|
||||
_imgbox.on('click', '.imgbox-an .toggle-zoom', function () {
|
||||
var _this = $(this);
|
||||
imgbox_swiper.zoom.toggle();
|
||||
_this.toggleClass('is-zoom');
|
||||
});
|
||||
|
||||
//切换全屏
|
||||
_imgbox.on('click', '.imgbox-an .toggle-full', function () {
|
||||
if (!document.fullscreenElement) {
|
||||
//进入页面全屏
|
||||
full_in();
|
||||
} else {
|
||||
full_out();
|
||||
}
|
||||
});
|
||||
|
||||
_imgbox.data('is_on', true);
|
||||
}
|
||||
|
||||
//全屏
|
||||
function full_in() {
|
||||
var docElm = document.documentElement;
|
||||
if (docElm.requestFullscreen) {
|
||||
docElm.requestFullscreen();
|
||||
} else if (docElm.msRequestFullscreen) {
|
||||
docElm.msRequestFullscreen();
|
||||
} else if (docElm.mozRequestFullScreen) {
|
||||
docElm.mozRequestFullScreen();
|
||||
} else if (docElm.webkitRequestFullScreen) {
|
||||
docElm.webkitRequestFullScreen();
|
||||
}
|
||||
$(imgbox_selector + ' .imgbox-an .toggle-full .fa')
|
||||
.removeClass('fa-expand')
|
||||
.addClass('fa-compress');
|
||||
$(imgbox_selector + '.show').addClass('full-screen'); //全屏
|
||||
}
|
||||
|
||||
//退出全屏
|
||||
function full_out() {
|
||||
if (document.fullscreenElement) {
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
} else if (document.msExitFullscreen) {
|
||||
document.msExitFullscreen();
|
||||
} else if (document.mozCancelFullScreen) {
|
||||
document.mozCancelFullScreen();
|
||||
} else if (document.webkitCancelFullScreen) {
|
||||
document.webkitCancelFullScreen();
|
||||
}
|
||||
}
|
||||
|
||||
$(imgbox_selector + ' .imgbox-an .toggle-full .fa')
|
||||
.removeClass('fa-compress')
|
||||
.addClass('fa-expand');
|
||||
_imgbox.removeClass('full-screen'); //全屏
|
||||
}
|
||||
|
||||
//链接处理
|
||||
function link_replace(link) {
|
||||
return link.indexOf('base64,') == -1 && link.length < 300 ? link.replace(/(.*\/)(.*)(-\d+x\d+\.)(.*)/g, '$1$2.$4').replace(/\??x-oss-process(.*)/, '') : link;
|
||||
}
|
||||
|
||||
//定位show_style
|
||||
function show_style(_this) {
|
||||
var offset = _this.offset();
|
||||
var offset_top = offset.top;
|
||||
var offset_left = offset.left;
|
||||
var scrollTop = $(document).scrollTop();
|
||||
var height = _this.height();
|
||||
var width = _this.width();
|
||||
|
||||
var s_top = offset_top - scrollTop + height / 2;
|
||||
var s_left = offset_left + width / 2;
|
||||
|
||||
_imgbox.attr('style', '--imgbox-origin-top:' + s_top + 'px;--imgbox-origin-left:' + s_left + 'px;');
|
||||
}
|
||||
|
||||
function thumb_open() {
|
||||
var _thumb_btn = $(imgbox_selector + ' .imgbox-an .toggle-thumbs,.hide-but');
|
||||
|
||||
if (options.thumbs && _thumb_btn.length) {
|
||||
if (imgbox_swiper.slides.length > 1) {
|
||||
_thumb_btn.show();
|
||||
} else {
|
||||
_imgbox.removeClass('show-thumb');
|
||||
_thumb_btn.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkScrollbar() {
|
||||
var fullWindowWidth = window.innerWidth;
|
||||
if (!fullWindowWidth) {
|
||||
// 兼容IE8
|
||||
var documentElementRect = document.documentElement.getBoundingClientRect();
|
||||
fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left);
|
||||
}
|
||||
return document.body.clientWidth < fullWindowWidth;
|
||||
}
|
||||
|
||||
function measureScrollbar() {
|
||||
var scrollbarWidthData = _body.data('scrollbar-width');
|
||||
if (scrollbarWidthData !== undefined) {
|
||||
return scrollbarWidthData;
|
||||
}
|
||||
// thx walsh
|
||||
var scrollDiv = document.createElement('div');
|
||||
scrollDiv.className = 'modal-scrollbar-measure';
|
||||
_body.append(scrollDiv);
|
||||
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
|
||||
_body[0].removeChild(scrollDiv);
|
||||
_body.data('scrollbar-width', scrollbarWidth);
|
||||
return scrollbarWidth;
|
||||
}
|
||||
|
||||
function setScrollbar() {
|
||||
var bodyPad = parseInt(_body.css('padding-right') || 0, 10);
|
||||
var scrollbarWidth = measureScrollbar();
|
||||
if (checkScrollbar()) {
|
||||
_body.css('padding-right', bodyPad + scrollbarWidth);
|
||||
_fixed.each(function (index, element) {
|
||||
var actualPadding = element.style.paddingRight;
|
||||
var calculatedPadding = $(element).css('padding-right');
|
||||
$(element)
|
||||
.data('padding-right', actualPadding)
|
||||
.css('transition', 'none')
|
||||
.css('padding-right', parseFloat(calculatedPadding) + scrollbarWidth + 'px');
|
||||
});
|
||||
}
|
||||
}
|
||||
//显示
|
||||
function show(_this) {
|
||||
setScrollbar();
|
||||
_body.addClass('imgbox-show');
|
||||
//$(".modal").modal("hide");
|
||||
show_style(_this);
|
||||
_imgbox.addClass('show').removeClass('hide');
|
||||
}
|
||||
|
||||
function close() {
|
||||
_body.removeClass('imgbox-show').css('padding-right', '');
|
||||
//等待动画结束,延迟
|
||||
_fixed.css('padding-right', '');
|
||||
setTimeout(function () {
|
||||
_fixed.css('transition', '');
|
||||
}, 10);
|
||||
_imgbox.addClass('hideing').removeClass('show');
|
||||
full_out(); //退出全屏
|
||||
|
||||
setTimeout(function () {
|
||||
_imgbox.removeClass('hideing').addClass('hide').attr('style', '');
|
||||
|
||||
$('.toggle-palay.is-play').removeClass('is-play'); //停止播放
|
||||
|
||||
try {
|
||||
imgbox_swiper.zoom.out(); //恢复放大缩小
|
||||
imgbox_swiper.autoplay.stop(); //停止播放
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
//恢复下滑关闭
|
||||
$(imgbox_selector + ' .swiper-close').css({
|
||||
opacity: '',
|
||||
transform: '',
|
||||
});
|
||||
}, 300);
|
||||
}
|
||||
|
||||
//滑动关闭
|
||||
function touch_close() {
|
||||
_imgbox.on('touchmove pointermove MSPointerMove', function (e) {
|
||||
e.preventDefault ? e.preventDefault() : (e.returnValue = !1);
|
||||
});
|
||||
|
||||
_imgbox.minitouch({
|
||||
direction: 'bottom',
|
||||
selector: '.swiper-close',
|
||||
depreciation: 100,
|
||||
onStart: false,
|
||||
stop: function (_e, _this) {
|
||||
var scale = _this
|
||||
.find('img')
|
||||
.css('transform')
|
||||
.replace(/[^0-9\-,]/g, '')
|
||||
.split(',')[0];
|
||||
return scale && scale > 1;
|
||||
},
|
||||
onIng: function (_e, _this, distanceX, distanceY) {
|
||||
var set_opacity = (150 - distanceY) / 80;
|
||||
set_opacity = set_opacity < 1 && set_opacity > 0.2 && set_opacity;
|
||||
_this.css('opacity', set_opacity);
|
||||
},
|
||||
inEnd: function (_e, _this) {
|
||||
_this.css({
|
||||
opacity: '',
|
||||
});
|
||||
},
|
||||
onEnd: function (_e, _this) {
|
||||
_imgbox.attr('style', '--imgbox-origin-top:' + t_h + 'px;--imgbox-origin-left:conter;');
|
||||
var t_h = _this.height();
|
||||
_this.css({
|
||||
transform: 'translate3D(0px, ' + t_h + 'px, 0px)',
|
||||
transition: '.2s linear',
|
||||
opacity: 0,
|
||||
});
|
||||
// close();
|
||||
setTimeout(close, 150);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function get_slide(each_this) {
|
||||
var thumbs_src = each_this.attr('src') || each_this.attr('box-img');
|
||||
var data_src = each_this.attr('data-src');
|
||||
|
||||
if (!thumbs_src && !data_src) return '';
|
||||
|
||||
var full_src = each_this.attr('data-full-url') || link_replace(data_src || thumbs_src);
|
||||
var main_img = '<img src="' + thumbs_src + '" data-src="' + full_src + '" class="lazyload"><div class="swiper-lazy-preloader"></div>';
|
||||
var main_img_html = '<div class="swiper-slide"><div class="swiper-close"><div class="swiper-zoom-container"><div class="absolute img-close"></div>' + main_img + '</div></div></div>';
|
||||
return main_img_html;
|
||||
}
|
||||
|
||||
function get_thumbs(each_this) {
|
||||
var thumbs_src_b = each_this.attr('data-src') || each_this.attr('src');
|
||||
if (!thumbs_src_b) return '';
|
||||
var thumbs_img = '<img data-src="' + thumbs_src_b + '" class="lazyload fit-cover">';
|
||||
var thumbs_img_html = '<div class="swiper-slide">' + thumbs_img + '</div>';
|
||||
return thumbs_img_html;
|
||||
}
|
||||
|
||||
function is_no(_this) {
|
||||
//判断上级是否有链接,且不是链接到原图
|
||||
var src = _this.attr('data-src') || _this.attr('src');
|
||||
if (!src) return false;
|
||||
|
||||
src = link_replace(src);
|
||||
var parent = _this.parent('a');
|
||||
if (!parent.length) return false;
|
||||
var href = parent.attr('box-img') || parent.attr('href');
|
||||
href = link_replace(href);
|
||||
return href && (href.indexOf(src) == -1 || src.indexOf(href) == -1);
|
||||
}
|
||||
}
|
||||
|
||||
tbquire(['swiper'], function () {
|
||||
$('link#swiper').length || $('head').append('<link type="text/css" id="swiper" rel="stylesheet" href="' + _win.uri + '/css/swiper.min.css?ver=' + _win.ver + '">');
|
||||
|
||||
Miniimgbox.options.group = _win.imgbox_type === 'group';
|
||||
Miniimgbox.options.thumbs = _win.imgbox_thumbs;
|
||||
Miniimgbox.options.down = _win.imgbox_down;
|
||||
Miniimgbox.options.play = _win.imgbox_play;
|
||||
Miniimgbox.options.zoom = _win.imgbox_zoom;
|
||||
Miniimgbox.options.full = _win.imgbox_full;
|
||||
|
||||
Miniimgbox('.alone-imgbox-img,a[data-imgbox]');
|
||||
Miniimgbox('img', '.wp-posts-content');
|
||||
Miniimgbox('img', '.imgbox-container');
|
||||
Miniimgbox('.box-img', '.comment-content');
|
||||
});
|
||||
})(jQuery, window);
|
||||
Vendored
-1
File diff suppressed because one or more lines are too long
@@ -59,8 +59,8 @@ tbquire.config({
|
||||
'translate' : 'libs/translate.min',
|
||||
'waterfall' : 'waterfall.min',
|
||||
'enlighterjs' : 'enlighter/enlighterjs.min',
|
||||
'imgbox' : 'imgbox.min',
|
||||
'section-navs' : 'section-navs.min',
|
||||
|
||||
'poster-share' : 'poster-share.min',
|
||||
'comment' : 'comment.min',
|
||||
'page-template' : 'page-template.min',
|
||||
|
||||
@@ -2504,9 +2504,6 @@ function z_auto_fun() {
|
||||
theme: _win.highlight_zt,
|
||||
});
|
||||
});
|
||||
|
||||
//图片灯箱
|
||||
_win.imgbox && jQuery('.alone-imgbox-img,a[data-imgbox],.comment-content .box-img,.wp-posts-content img,.imgbox-container').length && tbquire(['imgbox']);
|
||||
}
|
||||
|
||||
//页面滚动监听函数
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,13 +1,6 @@
|
||||
<?php
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
// window._win runtime bridge (legacy aksrt_win_var)
|
||||
add_action('wp_head', static function () {
|
||||
if (function_exists('aksrt_print_win_var')) {
|
||||
aksrt_print_win_var();
|
||||
}
|
||||
}, 1);
|
||||
|
||||
// 前端隐藏 WordPress Admin Bar
|
||||
// ============================================================
|
||||
|
||||
|
||||
@@ -226,7 +226,8 @@ add_action('init', function () {
|
||||
|
||||
if (empty($slides)) return '';
|
||||
|
||||
return '<div class="aksrt-carousel-block swiper" data-autoplay="' . $autoplay . '" data-delay="' . $delay . '" data-effect="' . $effect . '">'
|
||||
return '<div class="aksrt-carousel-block swiper aksrt-lightbox-trigger" data-aksrt-lightbox="1" data-autoplay="' . $autoplay . '" data-delay="' . $delay . '" data-effect="' . $effect . '">'
|
||||
|
||||
. '<div class="swiper-wrapper">' . $slides . '</div>'
|
||||
. '<div class="swiper-pagination"></div>'
|
||||
. '<div class="swiper-button-prev"></div><div class="swiper-button-next"></div>'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Float button commerce types + runtime window._win bridge (legacy parity).
|
||||
* Float button commerce types.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
@@ -76,61 +76,3 @@ if (!function_exists('aksrt_get_float_pay_vip_html')) :
|
||||
. '</a>';
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_get_win_runtime_config')) :
|
||||
/**
|
||||
* Build window._win payload (legacy aksrt_win_var subset).
|
||||
*
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
function aksrt_get_win_runtime_config(): array {
|
||||
$post_display = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_post_page_settings()
|
||||
: [];
|
||||
$is_mobile = wp_is_mobile();
|
||||
$list_style = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_post_list_style_settings()
|
||||
: [];
|
||||
$signin = function_exists('aksrt_get_login_url')
|
||||
? aksrt_get_login_url(function_exists('aksrt_get_current_url') ? aksrt_get_current_url() : home_url('/'))
|
||||
: wp_login_url();
|
||||
$signup = function_exists('aksrt_get_register_url')
|
||||
? aksrt_get_register_url()
|
||||
: wp_registration_url();
|
||||
|
||||
$views = 0;
|
||||
if (is_singular()) {
|
||||
$views = (int) get_queried_object_id();
|
||||
}
|
||||
|
||||
return [
|
||||
'views' => $views,
|
||||
'www' => home_url('/'),
|
||||
'uri' => get_template_directory_uri(),
|
||||
'ver' => defined('AKSRT_VERSION') ? AKSRT_VERSION : '3.4.0-dev',
|
||||
'imgbox' => !isset($post_display['lightbox']) || !empty($post_display['lightbox']) ? '1' : '',
|
||||
'imgbox_type' => 'group',
|
||||
'imgbox_thumbs' => !isset($post_display['lightbox_thumbs']) || !empty($post_display['lightbox_thumbs']) ? '1' : '',
|
||||
'imgbox_zoom' => !isset($post_display['lightbox_zoom']) || !empty($post_display['lightbox_zoom']) ? '1' : '',
|
||||
'imgbox_full' => !isset($post_display['lightbox_full']) || !empty($post_display['lightbox_full']) ? '1' : '',
|
||||
'imgbox_play' => !empty($post_display['lightbox_play']) ? '1' : '',
|
||||
'imgbox_down' => !empty($post_display['lightbox_down']) ? '1' : '',
|
||||
'sign_type' => class_exists('\AKSRT\Settings\Settings')
|
||||
? (string) (\AKSRT\Settings\Settings::get_all()['user_sign_type'] ?? 'page')
|
||||
: 'page',
|
||||
'signin_url' => $signin,
|
||||
'signup_url' => $signup,
|
||||
'ajax_url' => admin_url('admin-ajax.php'),
|
||||
'ajaxpager' => '1',
|
||||
'ajax_trigger' => (string) ($list_style['ajax_trigger'] ?? '<i class="fa fas fa-angle-right"></i>加载更多'),
|
||||
'ajax_nomore' => (string) ($list_style['ajax_nomore'] ?? __('没有更多内容了', 'aksrt')),
|
||||
'qj_loading' => __('加载中...', 'aksrt'),
|
||||
'is_mobile' => $is_mobile ? '1' : '',
|
||||
'is_logged_in' => is_user_logged_in() ? '1' : '',
|
||||
'user_id' => get_current_user_id(),
|
||||
'rest_url' => esc_url_raw(rest_url('aksrt/v1')),
|
||||
'rest_nonce' => wp_create_nonce('wp_rest'),
|
||||
'nonce' => wp_create_nonce('aksrt_public_nonce'),
|
||||
];
|
||||
}
|
||||
endif;
|
||||
|
||||
@@ -31,7 +31,7 @@ if (!function_exists('aksrt_single_render_cover')) :
|
||||
?>
|
||||
<div class="single-head-cover">
|
||||
<div class="single-video">
|
||||
<div class="graphic single-cover single-cover--video imgbox-container" style="padding-bottom:<?php echo esc_attr((string) $video_scale); ?>%;">
|
||||
<div class="graphic single-cover single-cover--video" style="padding-bottom:<?php echo esc_attr((string) $video_scale); ?>%;">
|
||||
<div class="aksrt-video single-cover__player" data-aksrt-video data-src="<?php echo esc_url($ctx['cover_url']); ?>"<?php echo $poster !== '' ? ' data-poster="' . esc_url($poster) . '"' : ''; ?> style="position:absolute;inset:0;width:100%;height:100%;"></div>
|
||||
</div>
|
||||
<div class="single-video-footer dplayer-featured">
|
||||
@@ -631,7 +631,8 @@ if (!function_exists('aksrt_single_render_article')) :
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($ctx['front_content'] !== '') : ?>
|
||||
<div class="post_front_content theme-box box-body"><?php echo wp_kses_post((string) $ctx['front_content']); ?></div>
|
||||
<div class="post_front_content theme-box box-body"<?php echo !empty($settings['lightbox']) ? ' data-aksrt-lightbox="1"' : ''; ?>><?php echo wp_kses_post((string) $ctx['front_content']); ?></div>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="theme-box wp-posts-content<?php echo $maxheight > 0 ? ' limit-height' : ''; ?>"
|
||||
|
||||
@@ -63,7 +63,8 @@ $show_sidebar = function_exists('aksrt_is_show_sidebar') ? aksrt_is_show_sidebar
|
||||
<?php get_template_part('templates/parts/page-header', null, $header_args); ?>
|
||||
|
||||
<?php if (has_post_thumbnail()) : ?>
|
||||
<figure class="entry-thumb">
|
||||
<figure class="entry-thumb" data-aksrt-lightbox="<?php echo !empty($page_settings['lightbox']) ? '1' : '0'; ?>">
|
||||
|
||||
<?php the_post_thumbnail('large'); ?>
|
||||
</figure>
|
||||
<?php endif; ?>
|
||||
@@ -106,13 +107,5 @@ $show_sidebar = function_exists('aksrt_is_show_sidebar') ? aksrt_is_show_sidebar
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($page_settings['lightbox'])) : ?>
|
||||
<div class="lightbox-overlay" id="lightbox-overlay" role="dialog" aria-modal="true" aria-label="<?php esc_attr_e('图片预览', 'aksrt'); ?>">
|
||||
<button type="button" class="lightbox-close" aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fa fas fa-times"></i></button>
|
||||
<img src="" alt="" class="lightbox-img">
|
||||
<div class="lightbox-caption" aria-live="polite"></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
get_footer();
|
||||
|
||||
+1
-8
@@ -72,14 +72,7 @@ while (have_posts()) :
|
||||
?>
|
||||
</main>
|
||||
|
||||
<?php if (!empty($settings['lightbox'])) : ?>
|
||||
<div class="lightbox-overlay" id="lightbox-overlay" role="dialog" aria-modal="true" aria-label="<?php esc_attr_e('图片预览', 'aksrt'); ?>" aria-hidden="true">
|
||||
<button type="button" class="lightbox-close" aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fa fas fa-times" aria-hidden="true"></i></button>
|
||||
<img src="" alt="" class="lightbox-img">
|
||||
<div class="lightbox-caption" aria-live="polite"></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endwhile; ?>
|
||||
|
||||
|
||||
<?php get_footer(); ?>
|
||||
|
||||
@@ -135,7 +135,7 @@ trait ScriptsPart1c {
|
||||
$requirements['needs_breadcrumb'] = $is_article && !empty($settings['breadcrumbs']);
|
||||
$requirements['needs_comments'] = $has_comments;
|
||||
$requirements['needs_comment_tools'] = $can_use_comment_form;
|
||||
$requirements['needs_page_template'] = !empty($settings['lightbox']) || !empty($settings['maxheight_enabled']);
|
||||
$requirements['needs_page_template'] = !empty($settings['maxheight_enabled']);
|
||||
$requirements['needs_reward'] = $is_article && !empty($settings['rewards_enabled']);
|
||||
$requirements['needs_yiyan'] = $has_yiyan;
|
||||
$requirements['needs_share'] = $is_article && !empty($settings['share_enabled']);
|
||||
@@ -152,6 +152,18 @@ trait ScriptsPart1c {
|
||||
$runtime_main_path = get_template_directory() . '/assets/js/runtime/main.min.js';
|
||||
$runtime_version = file_exists($runtime_main_path) ? (string) filemtime($runtime_main_path) : $version;
|
||||
$public_runtime_path = get_template_directory() . '/assets/js/build/public.js';
|
||||
$post_page_settings = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_post_page_settings()
|
||||
: [];
|
||||
$lightbox_enabled = !isset($post_page_settings['lightbox']) || !empty($post_page_settings['lightbox']);
|
||||
$lightbox_settings = [
|
||||
'imgbox' => $lightbox_enabled,
|
||||
'imgbox_thumbs' => $lightbox_enabled && (!isset($post_page_settings['lightbox_thumbs']) || !empty($post_page_settings['lightbox_thumbs'])),
|
||||
'imgbox_zoom' => $lightbox_enabled && (!isset($post_page_settings['lightbox_zoom']) || !empty($post_page_settings['lightbox_zoom'])),
|
||||
'imgbox_full' => $lightbox_enabled && (!isset($post_page_settings['lightbox_full']) || !empty($post_page_settings['lightbox_full'])),
|
||||
'imgbox_play' => $lightbox_enabled && !empty($post_page_settings['lightbox_play']),
|
||||
'imgbox_down' => $lightbox_enabled && !empty($post_page_settings['lightbox_down']),
|
||||
];
|
||||
wp_enqueue_script(
|
||||
'aksrt-runtime',
|
||||
$base_uri . '/assets/js/build/public.js',
|
||||
@@ -169,13 +181,13 @@ trait ScriptsPart1c {
|
||||
'ver' => $runtime_version,
|
||||
'pay_mark' => '¥',
|
||||
'pay_currency_unit' => __('元', 'aksrt'),
|
||||
'imgbox' => false,
|
||||
'imgbox_type' => 'group',
|
||||
'imgbox_thumbs' => false,
|
||||
'imgbox_zoom' => false,
|
||||
'imgbox_full' => false,
|
||||
'imgbox_play' => false,
|
||||
'imgbox_down' => false,
|
||||
'imgbox' => $lightbox_settings['imgbox'],
|
||||
'imgbox_thumbs' => $lightbox_settings['imgbox_thumbs'],
|
||||
'imgbox_zoom' => $lightbox_settings['imgbox_zoom'],
|
||||
'imgbox_full' => $lightbox_settings['imgbox_full'],
|
||||
'imgbox_play' => $lightbox_settings['imgbox_play'],
|
||||
'imgbox_down' => $lightbox_settings['imgbox_down'],
|
||||
|
||||
'ajax_url' => admin_url('admin-ajax.php'),
|
||||
'ajaxpager' => '',
|
||||
'ajax_trigger' => __('加载更多', 'aksrt'),
|
||||
|
||||
@@ -23,7 +23,7 @@ $lightbox = $args['lightbox'] ?? true;
|
||||
if (empty($images)) return;
|
||||
?>
|
||||
|
||||
<div class="content-gallery content-gallery--<?php echo esc_attr($layout); ?>" style="--gallery-columns: <?php echo $columns; ?>;">
|
||||
<div class="content-gallery content-gallery--<?php echo esc_attr($layout); ?><?php echo $lightbox ? ' aksrt-lightbox-trigger' : ''; ?>" data-aksrt-lightbox="<?php echo $lightbox ? '1' : '0'; ?>" style="--gallery-columns: <?php echo $columns; ?>;">
|
||||
<?php foreach ($images as $index => $img) :
|
||||
$src = $img['src'] ?? '';
|
||||
$alt = $img['alt'] ?? '';
|
||||
@@ -33,7 +33,7 @@ if (empty($images)) return;
|
||||
<figure class="content-gallery__item" data-index="<?php echo $index; ?>">
|
||||
<a href="<?php echo esc_url($src); ?>"
|
||||
class="content-gallery__link"
|
||||
<?php echo $lightbox ? 'data-lightbox="gallery"' : ''; ?>
|
||||
<?php echo $lightbox ? 'data-aksrt-lightbox-trigger="1"' : ''; ?>
|
||||
data-caption="<?php echo esc_attr($caption); ?>">
|
||||
<img<?php echo aksrt_get_lazy_attr('lazy_posts_content', (string) $src, 'content-gallery__img', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
alt="<?php echo esc_attr($alt); ?>"
|
||||
|
||||
@@ -24,8 +24,6 @@ test('comment smilie assets and their runtime chain stay removed', () => {
|
||||
'assets/js/build/public.js',
|
||||
'assets/js/comment-tools.js',
|
||||
'assets/js/enhancements.js',
|
||||
'assets/js/runtime/imgbox.js',
|
||||
'assets/js/runtime/imgbox.min.js',
|
||||
'assets/js/runtime/main.js',
|
||||
'assets/js/runtime/main.min.js',
|
||||
'inc/helpers/aksrt-comments.php',
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const test = require('node:test');
|
||||
|
||||
const root = path.resolve(__dirname, '..', '..');
|
||||
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
|
||||
|
||||
test('runtime exposes the article media settings to the single lightbox owner', () => {
|
||||
const scripts = read('src/Core/ScriptsPart1c.php');
|
||||
const enhancements = read('assets/js/enhancements.js');
|
||||
|
||||
assert.match(scripts, /Settings::get_post_page_settings\(\)/);
|
||||
for (const key of ['lightbox', 'lightbox_thumbs', 'lightbox_zoom', 'lightbox_full', 'lightbox_play', 'lightbox_down']) {
|
||||
assert.match(scripts, new RegExp(`['"]${key}['"]`));
|
||||
}
|
||||
assert.doesNotMatch(scripts, /'imgbox'\s*=>\s*false/);
|
||||
assert.match(enhancements, /window\._win/);
|
||||
assert.doesNotMatch(enhancements, /aksrtData\.imgbox/);
|
||||
});
|
||||
|
||||
test('the modern lightbox owns content, galleries and explicit links without a hard size gate', () => {
|
||||
const enhancements = read('assets/js/enhancements.js');
|
||||
const gallery = read('templates/parts/content-gallery.php');
|
||||
|
||||
assert.match(enhancements, /data-aksrt-lightbox-trigger/);
|
||||
assert.match(enhancements, /data-caption/);
|
||||
assert.match(enhancements, /data-lazy-src/);
|
||||
assert.doesNotMatch(enhancements, /img\.width\s*<\s*100/);
|
||||
assert.doesNotMatch(enhancements, /img\.height\s*<\s*100/);
|
||||
assert.match(gallery, /data-aksrt-lightbox/);
|
||||
});
|
||||
|
||||
test('legacy overlay and imgbox entry points are no longer enqueued or built', () => {
|
||||
const scripts = read('src/Core/ScriptsPart1c.php');
|
||||
const build = read('tools/build-public-assets.mjs');
|
||||
const loader = read('assets/js/runtime/loader.js');
|
||||
const part2 = read('inc/core-hooks/part-2.php');
|
||||
const single = read('single.php');
|
||||
const page = read('page.php');
|
||||
|
||||
assert.doesNotMatch(scripts, /needs_page_template[^\n]*lightbox/);
|
||||
assert.doesNotMatch(read('assets/js/page-template.js'), /function initLightbox|lightbox-overlay/);
|
||||
assert.doesNotMatch(build, /assets\/js\/runtime\/imgbox/);
|
||||
assert.doesNotMatch(loader, /['"]imgbox['"]\s*:/);
|
||||
assert.doesNotMatch(part2, /aksrt_print_win_var/);
|
||||
assert.doesNotMatch(single, /id="lightbox-overlay"/);
|
||||
assert.doesNotMatch(page, /id="lightbox-overlay"/);
|
||||
});
|
||||
|
||||
test('non-navigational page media and carousel images opt into the shared contract', () => {
|
||||
const page = read('page.php');
|
||||
const carousel = read('inc/core-hooks/part-3.php');
|
||||
|
||||
assert.match(page, /entry-thumb[^>]*data-aksrt-lightbox/);
|
||||
assert.match(carousel, /data-aksrt-lightbox/);
|
||||
});
|
||||
Reference in New Issue
Block a user