Skip to content

Commit 0222c14

Browse files
committed
add: buttons to horizontally scroll poster row
1 parent 5c416d7 commit 0222c14

File tree

4 files changed

+86
-2
lines changed

4 files changed

+86
-2
lines changed

resources/js/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import './components/alpine/dialog';
4444
import './components/alpine/dislikeButton';
4545
import './components/alpine/likeButton';
4646
import './components/alpine/livewireDialog';
47+
import './components/alpine/posterRow';
4748
import './components/alpine/smallBookmarkButton';
4849
import './components/alpine/tabs';
4950
import './components/alpine/toggle';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
document.addEventListener('alpine:init', () => {
2+
Alpine.data('posterRow', () => ({
3+
tab: null,
4+
init() {
5+
this.tab = this.$root.dataset.defaultTab;
6+
},
7+
getPosterRow() {
8+
let panel = this.$el.closest('.panelV2');
9+
let posterRows = panel.querySelectorAll('[x-ref="posters"]');
10+
11+
let posterRow = [...posterRows].find((el) => el.checkVisibility());
12+
13+
return posterRow;
14+
},
15+
scrollLeft: {
16+
['x-on:click.prevent']() {
17+
let posterRow = this.getPosterRow();
18+
19+
let scrollBy = posterRow.offsetWidth / 2;
20+
let currentScroll = posterRow.scrollLeft;
21+
let maxScroll = posterRow.scrollWidth - posterRow.offsetWidth;
22+
23+
if (currentScroll == 0) {
24+
posterRow.scrollTo({
25+
left: maxScroll,
26+
behavior: 'smooth',
27+
});
28+
} else if (currentScroll < scrollBy) {
29+
posterRow.scrollTo({
30+
left: 0,
31+
behavior: 'smooth',
32+
});
33+
} else {
34+
posterRow.scrollBy({
35+
left: -1 * scrollBy,
36+
behavior: 'smooth',
37+
});
38+
}
39+
},
40+
},
41+
scrollRight: {
42+
['x-on:click.prevent']() {
43+
let posterRow = this.getPosterRow();
44+
45+
let scrollBy = posterRow.offsetWidth / 2;
46+
let currentScroll = posterRow.scrollLeft;
47+
let maxScroll = posterRow.scrollWidth - posterRow.offsetWidth;
48+
let remainingScroll = maxScroll - currentScroll;
49+
50+
if (remainingScroll == 0) {
51+
posterRow.scrollTo({
52+
left: 0,
53+
behavior: 'smooth',
54+
});
55+
} else if (remainingScroll < scrollBy) {
56+
posterRow.scrollTo({
57+
left: maxScroll,
58+
behavior: 'smooth',
59+
});
60+
} else {
61+
posterRow.scrollBy({
62+
left: scrollBy,
63+
behavior: 'smooth',
64+
});
65+
}
66+
},
67+
},
68+
}));
69+
});

resources/views/torrent/partials/extra_meta.blade.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
<section class="panelV2" x-data="tabs" data-default-tab="recommendations" id="tab_wrapper">
2-
<h2 class="panel__heading">Relations</h2>
2+
<header class="panel__header">
3+
<h2 class="panel__heading">Relations</h2>
4+
<div class="panel__actions" x-data="posterRow">
5+
<div class="panel__action">
6+
<button class="form__standard-icon-button" x-bind="scrollLeft">
7+
<i class="{{ \config('other.font-awesome') }} fa-angle-left"></i>
8+
</button>
9+
</div>
10+
<div class="panel__action">
11+
<button class="form__standard-icon-button" x-bind="scrollRight">
12+
<i class="{{ \config('other.font-awesome') }} fa-angle-right"></i>
13+
</button>
14+
</div>
15+
</div>
16+
</header>
317
<menu class="panel__tabs">
418
<li class="panel__tab" x-bind="tabButton" data-tab="recommendations">Recommendations</li>
519
<li class="panel__tab" x-bind="tabButton" data-tab="collection">Collection</li>

resources/views/torrent/partials/recommendations.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="panel__body">
2-
<section class="recommendations" style="max-height: 330px !important">
2+
<section class="recommendations" style="max-height: 330px !important" x-ref="posters">
33
@switch(true)
44
@case($torrent->category->movie_meta)
55
@forelse ($meta->recommendedMovies ?? [] as $movie)

0 commit comments

Comments
 (0)