generated from filamentphp/plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20d23d4
commit af93466
Showing
3 changed files
with
84 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,65 @@ | ||
@if(method_exists(static::class, 'getContextMenuActions') and count(static::getContextMenuActions()) and static::isContextMenuEnabled()) | ||
<div id="contextMenu" | ||
class="flex z-50 min-w-48 max-w-2xl text-neutral-800 rounded-md ring-1 ring-gray-950/5 transition bg-white text-sm fixed p-2 shadow-md dark:text-gray-200 dark:bg-gray-900 dark:ring-white/10" | ||
style="display: none;"> | ||
@foreach(static::getCachedContextMenuActions() as $action) | ||
@if($action instanceof \AymanAlhattami\FilamentContextMenu\ContextMenuDivider) | ||
<x-filament-context-menu::divider /> | ||
@endif | ||
|
||
@if($action instanceof \Filament\Actions\Action and !$action instanceof \AymanAlhattami\FilamentContextMenu\ContextMenuDivider) | ||
@if($action->isVisible()) | ||
<div @class([ | ||
@if(method_exists(static::class, 'getContextMenuActions')) | ||
@if(count(static::getContextMenuActions()) and static::isContextMenuEnabled()) | ||
<div id="contextMenu" | ||
class="flex z-50 min-w-48 max-w-2xl text-neutral-800 rounded-md ring-1 ring-gray-950/5 transition bg-white text-sm fixed p-2 shadow-md dark:text-gray-200 dark:bg-gray-900 dark:ring-white/10" | ||
style="display: none;"> | ||
@foreach(static::getCachedContextMenuActions() as $action) | ||
@if($action instanceof \AymanAlhattami\FilamentContextMenu\ContextMenuDivider) | ||
<x-filament-context-menu::divider /> | ||
@endif | ||
|
||
@if($action instanceof \Filament\Actions\Action and !$action instanceof \AymanAlhattami\FilamentContextMenu\ContextMenuDivider) | ||
@if($action->isVisible()) | ||
<div @class([ | ||
'context-menu-filament-action flex gap-x-4 select-none group justify-between rounded px-2 py-1.5 hover:bg-neutral-100 outline-none pl-8 data-[disabled]:opacity-50 data-[disabled]:pointer-events-none dark:hover:bg-white/5', | ||
'mt-1' => !$loop->first | ||
])> | ||
{{ $action }} | ||
</div> | ||
{{ $action }} | ||
</div> | ||
@endif | ||
@endif | ||
@endif | ||
@endforeach | ||
</div> | ||
|
||
<script> | ||
document.addEventListener('DOMContentLoaded', function () { | ||
var contextMenu = document.getElementById('contextMenu'); | ||
var contextMenuTrigger = document.getElementsByClassName('fi-main')[0]; | ||
contextMenuTrigger.addEventListener('contextmenu', function (event) { | ||
event.preventDefault(); | ||
contextMenu.style.display = 'block'; // Show the context menu | ||
contextMenu.style.opacity = '0'; | ||
setTimeout(function () { | ||
calculateContextMenuPosition(event); | ||
contextMenu.style.opacity = '1'; | ||
}, 0); // Similar to $nextTick | ||
}); | ||
@endforeach | ||
</div> | ||
|
||
document.addEventListener('click', function (event) { | ||
if (!contextMenu.contains(event.target)) { | ||
contextMenu.style.display = 'none'; // Hide the context menu | ||
} | ||
}); | ||
<script> | ||
document.addEventListener('DOMContentLoaded', function () { | ||
var contextMenu = document.getElementById('contextMenu'); | ||
var contextMenuTrigger = document.getElementsByClassName('fi-main')[0]; | ||
window.addEventListener('resize', function (event) { | ||
contextMenu.style.display = 'none'; | ||
}); | ||
contextMenuTrigger.addEventListener('contextmenu', function (event) { | ||
event.preventDefault(); | ||
contextMenu.style.display = 'block'; // Show the context menu | ||
contextMenu.style.opacity = '0'; | ||
function calculateContextMenuPosition(clickEvent) { | ||
var menuHeight = contextMenu.offsetHeight; | ||
var menuWidth = contextMenu.offsetWidth; | ||
setTimeout(function () { | ||
calculateContextMenuPosition(event); | ||
contextMenu.style.opacity = '1'; | ||
}, 0); // Similar to $nextTick | ||
}); | ||
var top = window.innerHeight < clickEvent.clientY + menuHeight ? | ||
(window.innerHeight - menuHeight) : clickEvent.clientY; | ||
var left = window.innerWidth < clickEvent.clientX + menuWidth ? | ||
(clickEvent.clientX - menuWidth) : clickEvent.clientX; | ||
document.addEventListener('click', function (event) { | ||
if (!contextMenu.contains(event.target)) { | ||
contextMenu.style.display = 'none'; // Hide the context menu | ||
} | ||
}); | ||
contextMenu.style.top = top + 'px'; | ||
contextMenu.style.left = left + 'px'; | ||
} | ||
}); | ||
</script> | ||
window.addEventListener('resize', function (event) { | ||
contextMenu.style.display = 'none'; | ||
}); | ||
function calculateContextMenuPosition(clickEvent) { | ||
var menuHeight = contextMenu.offsetHeight; | ||
var menuWidth = contextMenu.offsetWidth; | ||
var top = window.innerHeight < clickEvent.clientY + menuHeight ? | ||
(window.innerHeight - menuHeight) : clickEvent.clientY; | ||
var left = window.innerWidth < clickEvent.clientX + menuWidth ? | ||
(clickEvent.clientX - menuWidth) : clickEvent.clientX; | ||
contextMenu.style.top = top + 'px'; | ||
contextMenu.style.left = left + 'px'; | ||
} | ||
}); | ||
</script> | ||
@endif | ||
@endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters