Skip to content

Commit c1552fb

Browse files
committed
Attachments: Drag and drop video support
Supports dragging and dropping video attahchments to embed them in the editor as HTML video tags.
1 parent 91d8d6e commit c1552fb

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

app/Uploads/Attachment.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,30 @@ public function getUrl($openInline = false): string
7777
}
7878

7979
/**
80-
* Generate a HTML link to this attachment.
80+
* Get the representation of this attachment in a format suitable for the page editors.
81+
* Detects and adapts video content to use an inline video embed.
82+
*/
83+
public function editorContent(): array
84+
{
85+
$videoExtensions = ['mp4', 'webm', 'mkv', 'ogg', 'avi'];
86+
if (in_array(strtolower($this->extension), $videoExtensions)) {
87+
$html = '<video src="' . e($this->getUrl(true)) . '" controls width="480" height="270"></video>';
88+
return ['text/html' => $html, 'text/plain' => $html];
89+
}
90+
91+
return ['text/html' => $this->htmlLink(), 'text/plain' => $this->markdownLink()];
92+
}
93+
94+
/**
95+
* Generate the HTML link to this attachment.
8196
*/
8297
public function htmlLink(): string
8398
{
8499
return '<a target="_blank" href="' . e($this->getUrl()) . '">' . e($this->name) . '</a>';
85100
}
86101

87102
/**
88-
* Generate a markdown link to this attachment.
103+
* Generate a MarkDown link to this attachment.
89104
*/
90105
public function markdownLink(): string
91106
{

resources/views/attachments/manager-list.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div component="ajax-delete-row"
55
option:ajax-delete-row:url="{{ url('/attachments/' . $attachment->id) }}"
66
data-id="{{ $attachment->id }}"
7-
data-drag-content="{{ json_encode(['text/html' => $attachment->htmlLink(), 'text/plain' => $attachment->markdownLink()]) }}"
7+
data-drag-content="{{ json_encode($attachment->editorContent()) }}"
88
class="card drag-card">
99
<div class="handle">@icon('grip')</div>
1010
<div class="py-s">

0 commit comments

Comments
 (0)