From be41a815f741bbe77d8af0809524b0be46c5bb83 Mon Sep 17 00:00:00 2001 From: majid Date: Tue, 29 Jul 2025 09:57:54 +0700 Subject: [PATCH] feat(pdf-viewer): implement pdf.js with pagination and swipe controls --- resources/views/daftar-pustaka/show.blade.php | 229 +++++++++++------- 1 file changed, 148 insertions(+), 81 deletions(-) diff --git a/resources/views/daftar-pustaka/show.blade.php b/resources/views/daftar-pustaka/show.blade.php index 442e030..6a7eddc 100644 --- a/resources/views/daftar-pustaka/show.blade.php +++ b/resources/views/daftar-pustaka/show.blade.php @@ -1,98 +1,165 @@ @extends('layouts.main') @section('breadcrumbs') - {{-- {{ Breadcrumbs::render(request()->route()->getName()) }} --}} @endsection - @section('content') -
- -
- @csrf -
-
-

- {{ $daftarPustaka->judul ?? '' }} -

-
- Back -
-
-
-
-
- - @php - - $fileExtension = pathinfo($daftarPustaka->attachment, PATHINFO_EXTENSION); - // cek extension - $isPdf = $fileExtension == 'pdf'; - $imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp']; - $isImage = in_array(strtolower($fileExtension), $imageExtensions); - $fileUrl = asset('storage/' . $daftarPustaka->attachment); - @endphp - - @if ($isPdf) - - @elseif ($isImage) - - @else -

File tidak bisa ditampilkan, silakan unduh di sini.

- @endif - - -
-
- -
-
-
- {{ $daftarPustaka->deskripsi ?? '' }} -
+
+ + @csrf +
+
+

+ {{ $daftarPustaka->judul ?? '' }} +

+
- -
+
+
+
+ + + @php + $fileExtension = pathinfo($daftarPustaka->attachment, PATHINFO_EXTENSION); + $isPdf = strtolower($fileExtension) == 'pdf'; + $imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp']; + $isImage = in_array(strtolower($fileExtension), $imageExtensions); + $fileUrl = asset('storage/' . $daftarPustaka->attachment); + @endphp + + @if ($isPdf) + +
+ + Page: 1 / 0 + +
+ @elseif ($isImage) + + @else +

File tidak bisa ditampilkan, silakan + unduh di sini. +

+ @endif +
+
+ +
+
+ {{ $daftarPustaka->deskripsi ?? '' }} +
+
+
+ +
@endsection -{{-- @push('scripts') - +@push('scripts') + + + -@endpush --}} + + canvas.addEventListener('touchend', function (e) { + touchEndX = e.changedTouches[0].screenX; + handleSwipe(); + }); + + function handleSwipe() { + const swipeThreshold = 50; // min distance for swipe + if (touchEndX < touchStartX - swipeThreshold) { + onNextPage(); + } else if (touchEndX > touchStartX + swipeThreshold) { + onPrevPage(); + } + } + + pdfjsLib.getDocument(url).promise.then(function (pdfDoc_) { + pdfDoc = pdfDoc_; + document.getElementById('pageCount').textContent = pdfDoc.numPages; + renderPage(pageNum); + }); + } +}); + +@endpush