diff --git a/public/css/marhun-registrations-webcam.css b/public/css/marhun-registrations-webcam.css new file mode 100644 index 00000000..d15cf51e --- /dev/null +++ b/public/css/marhun-registrations-webcam.css @@ -0,0 +1,64 @@ + +#video { +border: 1px solid black; +box-shadow: 2px 2px 3px black; +width: 320px; +height: 240px; +} + +#photo { +border: 1px solid black; +box-shadow: 2px 2px 3px black; +width: 320px; +/* height: 240px; */ +} + +#canvas { +display: none; +} + +.camera { +width: 340px; +display: inline-block; +} + +.output { +width: 340px; +display: inline-block; +vertical-align: top; +} + +#startbutton { +display: block; +position: relative; +margin-left: auto; +margin-right: auto; +bottom: 32px; +background-color: rgba(0, 150, 0, 0.5); +border: 1px solid rgba(255, 255, 255, 0.7); +box-shadow: 0px 0px 1px 2px rgba(0, 0, 0, 0.2); +font-size: 14px; +font-family: "Lucida Grande", "Arial", sans-serif; +color: rgba(255, 255, 255, 1); +} + +.contentarea { +font-size: 16px; +font-family: "Lucida Grande", "Arial", sans-serif; +width: 760px; +} + +#image-tag-container{ +height: 320px; +overflow: hidden; +} + +#image-tag{ +height: 320px; +} + +img.marhun-uploaded { +cursor: -moz-zoom-in; +cursor: -webkit-zoom-in; +cursor: zoom-in; +} diff --git a/public/img/camera-shutter.svg b/public/img/camera-shutter.svg new file mode 100644 index 00000000..bec038f4 --- /dev/null +++ b/public/img/camera-shutter.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/img/no-image.png b/public/img/no-image.png new file mode 100644 index 00000000..e86053a0 Binary files /dev/null and b/public/img/no-image.png differ diff --git a/public/img/pngtree-diamond-wedding-ring.png b/public/img/pngtree-diamond-wedding-ring.png new file mode 100644 index 00000000..5f748966 Binary files /dev/null and b/public/img/pngtree-diamond-wedding-ring.png differ diff --git a/public/js/marhun-photo-capture-reload-https.js b/public/js/marhun-photo-capture-reload-https.js new file mode 100644 index 00000000..ebe88f21 --- /dev/null +++ b/public/js/marhun-photo-capture-reload-https.js @@ -0,0 +1,31 @@ +function marhunPhotoCapturerReloadHttpsFactory() { + + return { + + reload: function reload() { + + const params = new Proxy(new URLSearchParams(window.location.search), { + get: (searchParams, prop) => searchParams.get(prop), + }); + + const isCameraActivate = params.isCameraActivate; + const locationProtocol = location.protocol; + + if (isCameraActivate == 'true' && locationProtocol == 'https:') { + return; + } + + if (locationProtocol == 'https:') { + return; + } + + new_location = new URL(location); + new_location.protocol = "https:"; + new_location.searchParams.append('isCameraActivate', 'true') + window.location.replace(new_location); + + } + + } + +} diff --git a/public/js/marhun-photo-capture.js b/public/js/marhun-photo-capture.js new file mode 100644 index 00000000..795de07c --- /dev/null +++ b/public/js/marhun-photo-capture.js @@ -0,0 +1,177 @@ + +function marhunPhotoCapturerFactory(modal_selector) { + + return { + + constraints: { "video": { width: { exact: 1080 } } }, + + imageCapturer: null, + + start: function start() { + navigator.mediaDevices.getUserMedia(this.constraints) + .then(this.gotMedia) + .catch(e => { console.error('getUserMedia() failed: ', e); }); + }, + + gotMedia: function (mediastream) { + + let modal = document.querySelector(modal_selector); + let videoTag = modal.querySelector('.video-tag-overallmarhun'); + + videoTag.srcObject = mediastream; + + let videoTrack = mediastream.getVideoTracks()[0]; + this.imageCapturer = new ImageCapture(videoTrack); + + + // Timeout needed in Chrome, see https://crbug.com/711524 + setTimeout(() => { + const capabilities = videoTrack.getCapabilities() + console.log(capabilities) + + // Check whether zoom is supported or not. + if (!capabilities.zoom) { + return; + } + + }, 500); + + }, + + captureMedia: function (mediastream) { + + let videoTrack = mediastream.getVideoTracks()[0]; + let imageCapturer = new ImageCapture(videoTrack); + + let modal = document.querySelector(modal_selector); + let imageTag = modal.querySelector('.image-tag-overallmarhun'); + + + + let setMarhunPhotoInputToCapturedPhoto = function (blob) { + const modal = document.querySelector(modal_selector); + const marhunPhotoInput = modal.querySelector('#inputGroupFile04'); + + + const marhunPhotoFile = new File([blob], 'marhun_photo.png', { + type: 'image/png', + lastModified: new Date().getTime(), + }); + + + const dataTransfer = new DataTransfer(); + dataTransfer.items.add(marhunPhotoFile); + marhunPhotoInput.files = dataTransfer.files; + + }; + + imageCapturer.takePhoto() + .then((blob) => { + imageTag.src = URL.createObjectURL(blob); + imageTag.classList.add('marhun-uploaded'); + + + modal.querySelector('.video-tag-overallmarhun').classList.add('d-none'); + + modal.querySelector('.camera-shutter').classList.remove('d-none'); + modal.querySelector('.camera-shutter').classList.add('d-flex'); + + window.setTimeout(() => { + modal.querySelector('.image-tag-overallmarhun').classList.remove('d-none'); + modal.querySelector('.camera-shutter').classList.remove('d-flex'); + modal.querySelector('.camera-shutter').classList.add('d-none'); + modal.querySelector('.camera-button').classList.add('d-none') + }, 1500); + + modal.querySelector('button[type="submit"]').disabled = false; + + return blob; + + }) + .then(blob => setMarhunPhotoInputToCapturedPhoto(blob)) + .catch((err) => { + console.error("takePhoto() failed: ", err); + }); + + }, + + + takePhoto: function () { + navigator.mediaDevices.getUserMedia(this.constraints) + .then(this.captureMedia) + .catch(e => { console.error('getUserMedia() failed: ', e); }); + }, + + viewCapturedPhoto: function () { + + let imageTag = document.getElementById('image-tag'); + + if (!imageTag.classList.contains('marhun-uploaded')) { + + Swal.fire({ + icon: 'error', + title: 'Amaran!', + text: 'Sila ambil gambar marhun' + }); + + return; + } + + displayInNewTab(imageTag.src); + }, + + displayInNewTab: function (src) { + let image = new Image(); + image.src = src; + + let w = window.open(""); + w.document.write(image.outerHTML); + }, + + initiateTakeMarhunPhoto: function () { + + navigator.mediaDevices.getUserMedia(this.constraints) + .then(this.gotMedia) + .catch(e => { console.error('getUserMedia() failed: ', e); }); + + let modal = document.querySelector(modal_selector); + + modal.querySelector('.video-tag-overallmarhun').classList.remove('d-none'); + modal.querySelector('.image-tag-overallmarhun').classList.add('d-none'); + modal.querySelector('.camera-shutter').classList.add('d-none'); + modal.querySelector('.camera-button').classList.remove('d-none'); + modal.querySelector('button[type="submit"]').disabled = true; + + $(modal_selector).modal('show'); + }, + + + initiateUploadMarhunPhoto: function () { + let file_marhun_photo = document.getElementById('marhun_photo'); + let image_tag = document.getElementById('image-tag'); + + let displayUploadFileToImageTag = (event) => { + let selectedFile = event.target.files[0]; + let reader = new FileReader(); + + image_tag.title = selectedFile.name; + + reader.onload = function (event) { + image_tag.src = event.target.result; + }; + + reader.readAsDataURL(selectedFile); + + this.removeEventListener('change', displayUploadFileToImageTag); + + }; + + file_marhun_photo.addEventListener('change', displayUploadFileToImageTag); + + image_tag.classList.add('marhun-uploaded'); + + file_marhun_photo.click(); + } + } + +} diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index ef0071e2..e8b4d799 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -83,6 +83,9 @@ } + + @stack('additional_scripts') + + @stack('additional_styles') +
{{ $message }}
-Tiada Data
- - @endif +@push('additional_styles') + +@endpush + +@include('marhun.partials.camera_modals_per_marhun') +@include('marhun.partials.camera_modals') + +@section('content') +{{ $message }}
+Tiada Data
+ + + + @endif +