Skip to content
This repository has been archived by the owner on May 11, 2023. It is now read-only.

Commit

Permalink
Add escape keydown and backdrop click as close event triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
Marttin Notta committed Aug 30, 2021
1 parent 1b69dbb commit b1367eb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
8 changes: 7 additions & 1 deletion resources/js/components/MediaBrowsingModal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<od-modal ref="isModalOpen" v-if="isModalOpen" :name="'isModalOpen'" :align="'flex justify-end'" width="1315">
<od-modal ref="isModalOpen" v-if="isModalOpen" @onClose="hideMediaLibrary" :name="'isModalOpen'" :align="'flex justify-end'" width="1315">
<div slot="container">
<div class="modal-header flex flex-wrap justify-between mb-6">
<h2 class="text-90 font-normal text-xl">
Expand Down Expand Up @@ -497,6 +497,12 @@ export default {
this.$emit('update:isModalOpen', true);
this.$emit('update:showUploadArea', false);
},
hideMediaLibrary() {
this.listenUploadArea = false;
this.$emit('update:isModalOpen', false);
this.$emit('update:showUploadArea', false);
},
},
};
</script>
Expand Down
27 changes: 22 additions & 5 deletions resources/js/components/Modal.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<portal to="modals" :name="name">
<transition name="fade">
<div class="od-modal-container">
<div class="od-modal-container" @click="onBackdropClick">
<modal>
<div class="bg-white rounded-lg shadow-lg od-modal" :style="style">
<div class="bg-white rounded-lg shadow-lg od-modal" ref="container" :style="style">
<div class="p-8"><slot name="container"></slot></div>

<div class="bg-30 px-6 py-3 flex">
Expand Down Expand Up @@ -36,9 +36,26 @@ export default {
},
},
data: () => ({
//
}),
mounted() {
document.addEventListener('keydown', this.listenEscEvent)
},
unmounted() {
document.removeEventListener('keydown', this.listenEscEvent)
},
methods: {
onBackdropClick(e) {
if (this.$refs.container && !this.$refs.container.contains(e.target)) {
this.$emit('onClose')
}
},
listenEscEvent(e) {
if (e.key?.toLowerCase() === 'esc' || e.key?.toLowerCase() === 'escape') {
this.$emit('onClose')
}
}
},
computed: {
style() {
Expand Down
17 changes: 9 additions & 8 deletions src/Classes/MediaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use FFMpeg\FFMpeg;
use GuzzleHttp\Client;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use FFMpeg\Coordinate\TimeCode;
Expand Down Expand Up @@ -32,7 +33,7 @@ public function __construct()
* @param Request $request
* @param string $key Used to access Request file upload value
* @return Media
* @throws \Exception
* @throws Exception
*/
public static function createFromRequest(Request $request, $key = 'file'): Media
{
Expand All @@ -58,8 +59,8 @@ public static function createFromRequest(Request $request, $key = 'file'): Media
*
* @param $filepath - Full path to file
* @return Media
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \Exception
* @throws BindingResolutionException
* @throws Exception
*/
public static function createFromFile($filepath): Media
{
Expand Down Expand Up @@ -195,7 +196,7 @@ public function generateImageSizes($tempFilePath, $path, $mimeType, $disk): arra
'webp_size' => $disk->size(dirname($path) . '/' . $webpFilename),
]);
}
} catch (\Intervention\Image\Exception\NotSupportedException $e) {
} catch (\Intervention\ImageException\NotSupportedException $e) {
continue;
}
}
Expand Down Expand Up @@ -231,20 +232,20 @@ public function getDisk()
*
* @param $fileData
* @return array
* @throws \Exception
* @throws Exception
*/
protected function validateFileInput($fileData)
{
if (is_array($fileData) && !(isset($fileData['name']) && isset($fileData['path']))) {
throw new \Exception('Cannot store file, missing file name or path!');
throw new Exception('Cannot store file, missing file name or path!');
}

$isString = is_string($fileData);
$isBase64 = $isString && $this->isValid64base($fileData);
$fileExists = $isString && file_exists($fileData);

if ($isString && !$fileExists && !$isBase64) {
throw new \Exception('Cannot store file, invalid file path or data!');
throw new Exception('Cannot store file, invalid file path or data!');
}

$mimeType = 'text/plain';
Expand Down Expand Up @@ -294,7 +295,7 @@ private function isValid64base($str)
* @param $fileData
* @param $disk
* @return Media
* @throws \Exception
* @throws Exception
*/
protected function storeFile($fileData, $disk): Media
{
Expand Down

0 comments on commit b1367eb

Please sign in to comment.