Initial dev export (exclude uploads/runtime)
This commit is contained in:
638
modules/admin/views/layout.php
Normal file
638
modules/admin/views/layout.php
Normal file
@@ -0,0 +1,638 @@
|
||||
<?php
|
||||
/** @var string $pageTitle */
|
||||
/** @var string $content */
|
||||
use Core\Services\Auth;
|
||||
use Core\Services\Settings;
|
||||
use Core\Services\Plugins;
|
||||
use Core\Services\Updater;
|
||||
|
||||
$faUrl = Settings::get('fontawesome_pro_url', '');
|
||||
if ($faUrl === '') {
|
||||
$faUrl = Settings::get('fontawesome_url', '');
|
||||
}
|
||||
$faEnabled = $faUrl !== '';
|
||||
$role = Auth::role();
|
||||
$isAuthed = Auth::check();
|
||||
$pluginNav = Plugins::adminNav();
|
||||
$userName = Auth::name();
|
||||
$updateStatus = ['ok' => false, 'update_available' => false];
|
||||
if ($isAuthed) {
|
||||
try {
|
||||
$updateStatus = Updater::getStatus(false);
|
||||
} catch (Throwable $e) {
|
||||
$updateStatus = ['ok' => false, 'update_available' => false];
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title><?= htmlspecialchars($pageTitle ?? 'Admin', ENT_QUOTES, 'UTF-8') ?></title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Syne:wght@500;600;700&family=IBM+Plex+Mono:wght@400;600&display=swap" rel="stylesheet">
|
||||
<?php if ($faEnabled): ?>
|
||||
<link rel="stylesheet" href="<?= htmlspecialchars($faUrl, ENT_QUOTES, 'UTF-8') ?>">
|
||||
<?php endif; ?>
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--bg: #0b0b0c;
|
||||
--panel: #1b1c1f;
|
||||
--panel-2: #232427;
|
||||
--text: #f3f4f8;
|
||||
--muted: #a2a7b3;
|
||||
--accent: #22a7ff;
|
||||
--accent-2: #22f2a5;
|
||||
--stroke: rgba(255,255,255,0.1);
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Syne', sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
}
|
||||
a { color: inherit; text-decoration: none; }
|
||||
.shell { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
|
||||
.admin-wrapper {
|
||||
max-width: 1280px;
|
||||
margin: 24px auto;
|
||||
padding: 0 18px;
|
||||
}
|
||||
.admin-shell {
|
||||
display: grid;
|
||||
grid-template-columns: 240px 1fr;
|
||||
min-height: 100vh;
|
||||
background: rgba(14,14,16,0.98);
|
||||
border: 1px solid rgba(255,255,255,0.06);
|
||||
border-radius: 24px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 30px 70px rgba(0,0,0,0.45);
|
||||
}
|
||||
.auth-shell {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
min-height: 70vh;
|
||||
align-items: center;
|
||||
}
|
||||
.sidebar {
|
||||
border-right: 1px solid var(--stroke);
|
||||
background: rgba(10,10,12,0.98);
|
||||
padding: 24px 18px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
height: 100vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.sidebar-user {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 6px 16px;
|
||||
border-bottom: 1px solid rgba(255,255,255,0.08);
|
||||
}
|
||||
.sidebar-user .icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 12px;
|
||||
background: rgba(255,255,255,0.06);
|
||||
display: grid;
|
||||
place-items: center;
|
||||
font-size: 18px;
|
||||
color: var(--accent-2);
|
||||
}
|
||||
.sidebar-user .hello {
|
||||
font-size: 12px;
|
||||
color: rgba(255,255,255,0.55);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.2em;
|
||||
}
|
||||
.sidebar-user .name {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.sidebar-section {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
}
|
||||
.sidebar-title {
|
||||
font-size: 10px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.3em;
|
||||
color: rgba(255,255,255,0.4);
|
||||
margin-top: 10px;
|
||||
}
|
||||
.sidebar a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 12px;
|
||||
border-radius: 12px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.12em;
|
||||
text-transform: uppercase;
|
||||
background: rgba(255,255,255,0.03);
|
||||
border: 1px solid var(--stroke);
|
||||
color: var(--muted);
|
||||
}
|
||||
.sidebar a.active,
|
||||
.sidebar a:hover {
|
||||
color: var(--text);
|
||||
background: rgba(255,255,255,0.08);
|
||||
}
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
font-weight: 600;
|
||||
font-size: 18px;
|
||||
}
|
||||
.brand-badge {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(135deg, var(--accent), var(--accent-2));
|
||||
display: grid;
|
||||
place-items: center;
|
||||
color: #071016;
|
||||
font-weight: 700;
|
||||
}
|
||||
.badge {
|
||||
font-family: 'IBM Plex Mono', monospace;
|
||||
text-transform: uppercase;
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.3em;
|
||||
color: rgba(255,255,255,0.5);
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 16px;
|
||||
border-radius: 999px;
|
||||
background: var(--accent);
|
||||
color: #041018;
|
||||
font-weight: 600;
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.25em;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn.outline {
|
||||
background: transparent;
|
||||
color: var(--text);
|
||||
border: 1px solid rgba(255,255,255,0.18);
|
||||
}
|
||||
.btn.small {
|
||||
padding: 4px 10px;
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.18em;
|
||||
border-radius: 999px;
|
||||
line-height: 1.4;
|
||||
min-height: 26px;
|
||||
}
|
||||
.modal-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0,0,0,0.6);
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
z-index: 50;
|
||||
}
|
||||
.modal {
|
||||
background: #17181d;
|
||||
border: 1px solid rgba(255,255,255,0.1);
|
||||
border-radius: 18px;
|
||||
padding: 16px;
|
||||
width: min(900px, 92vw);
|
||||
max-height: 80vh;
|
||||
overflow: hidden;
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
.media-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
|
||||
gap: 10px;
|
||||
overflow: auto;
|
||||
padding-right: 4px;
|
||||
}
|
||||
.media-thumb {
|
||||
border-radius: 12px;
|
||||
border: 1px solid rgba(255,255,255,0.12);
|
||||
background: rgba(0,0,0,0.35);
|
||||
padding: 8px;
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.media-thumb img {
|
||||
width: 100%;
|
||||
aspect-ratio: 1 / 1;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.media-meta {
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
word-break: break-word;
|
||||
}
|
||||
.modal-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
.modal-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.2em;
|
||||
}
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.media-empty {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
padding: 12px;
|
||||
}
|
||||
.input {
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--stroke);
|
||||
background: rgba(12,12,14,0.9);
|
||||
color: var(--text);
|
||||
}
|
||||
.label {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.2em;
|
||||
}
|
||||
.admin-header {
|
||||
border-bottom: 1px solid var(--stroke);
|
||||
background: rgba(10,10,12,0.9);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
.admin-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 18px 0;
|
||||
}
|
||||
.admin-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
.admin-content {
|
||||
padding: 28px 0 64px;
|
||||
}
|
||||
.admin-main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
}
|
||||
.admin-container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 28px;
|
||||
width: 100%;
|
||||
}
|
||||
.admin-card {
|
||||
background: rgba(255,255,255,0.04);
|
||||
border: 1px solid rgba(255,255,255,0.1);
|
||||
border-radius: 20px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 18px 40px rgba(0,0,0,0.35);
|
||||
}
|
||||
.pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 14px;
|
||||
border-radius: 999px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.2em;
|
||||
border: 1px solid rgba(255,255,255,0.12);
|
||||
background: rgba(255,255,255,0.04);
|
||||
color: var(--muted);
|
||||
}
|
||||
@media (max-width: 1200px) {
|
||||
.admin-container { max-width: 1040px; }
|
||||
}
|
||||
@media (max-width: 1024px) {
|
||||
.admin-shell { grid-template-columns: 210px 1fr; }
|
||||
.admin-container { padding: 0 20px; }
|
||||
}
|
||||
@media (max-width: 880px) {
|
||||
.admin-wrapper { margin: 16px auto; }
|
||||
.admin-shell { grid-template-columns: 1fr; min-height: auto; }
|
||||
.sidebar {
|
||||
position: relative;
|
||||
height: auto;
|
||||
border-right: none;
|
||||
border-bottom: 1px solid var(--stroke);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="admin-wrapper">
|
||||
<div class="<?= $isAuthed ? 'admin-shell' : 'auth-shell' ?>">
|
||||
<?php if ($isAuthed): ?>
|
||||
<aside class="sidebar">
|
||||
<div class="sidebar-user">
|
||||
<div class="icon">
|
||||
<?php if ($faEnabled): ?>
|
||||
<i class="fa-duotone fa-head-side-headphones"></i>
|
||||
<?php else: ?>
|
||||
AC
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div>
|
||||
<div class="hello">Hello</div>
|
||||
<div class="name"><?= htmlspecialchars($userName, ENT_QUOTES, 'UTF-8') ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sidebar-section">
|
||||
<div class="sidebar-title">Core</div>
|
||||
<a href="/admin" class="<?= ($pageTitle ?? '') === 'Admin' ? 'active' : '' ?>">
|
||||
<?php if ($faEnabled): ?><i class="fa-solid fa-house"></i><?php endif; ?>
|
||||
Dashboard
|
||||
</a>
|
||||
<?php if (in_array($role, ['admin', 'manager', 'editor'], true)): ?>
|
||||
<a href="/admin/pages" class="<?= ($pageTitle ?? '') === 'Pages' ? 'active' : '' ?>">
|
||||
<?php if ($faEnabled): ?><i class="fa-solid fa-file-lines"></i><?php endif; ?>
|
||||
Pages
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if (in_array($role, ['admin', 'manager'], true)): ?>
|
||||
<a href="/admin/media" class="<?= ($pageTitle ?? '') === 'Media' ? 'active' : '' ?>">
|
||||
<?php if ($faEnabled): ?><i class="fa-solid fa-photo-film"></i><?php endif; ?>
|
||||
Media
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if (in_array($role, ['admin', 'manager'], true)): ?>
|
||||
<a href="/admin/navigation" class="<?= ($pageTitle ?? '') === 'Navigation' ? 'active' : '' ?>">
|
||||
<?php if ($faEnabled): ?><i class="fa-solid fa-sitemap"></i><?php endif; ?>
|
||||
Navigation
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if (in_array($role, ['admin', 'manager'], true)): ?>
|
||||
<div class="sidebar-section">
|
||||
<div class="sidebar-title">Content</div>
|
||||
<a href="/admin/posts" class="<?= ($pageTitle ?? '') === 'Posts' ? 'active' : '' ?>">
|
||||
<?php if ($faEnabled): ?><i class="fa-solid fa-newspaper"></i><?php endif; ?>
|
||||
Blog
|
||||
</a>
|
||||
<a href="/admin/newsletter" class="<?= ($pageTitle ?? '') === 'Newsletter' ? 'active' : '' ?>">
|
||||
<?php if ($faEnabled): ?><i class="fa-solid fa-envelope"></i><?php endif; ?>
|
||||
Newsletter
|
||||
</a>
|
||||
<a href="/admin/shortcodes" class="<?= ($pageTitle ?? '') === 'Shortcodes' ? 'active' : '' ?>">
|
||||
<?php if ($faEnabled): ?><i class="fa-solid fa-code"></i><?php endif; ?>
|
||||
Shortcodes
|
||||
</a>
|
||||
<a href="/admin/updates" class="<?= ($pageTitle ?? '') === 'Updates' ? 'active' : '' ?>">
|
||||
<?php if ($faEnabled): ?><i class="fa-solid fa-download"></i><?php endif; ?>
|
||||
Updates
|
||||
<?php if (!empty($updateStatus['update_available'])): ?>
|
||||
<span style="margin-left:auto; width:8px; height:8px; border-radius:999px; background:#22f2a5;"></span>
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($pluginNav): ?>
|
||||
<div class="sidebar-section">
|
||||
<div class="sidebar-title">Plugins</div>
|
||||
<?php foreach ($pluginNav as $item): ?>
|
||||
<?php
|
||||
$roles = $item['roles'] ?? [];
|
||||
if ($roles && !in_array($role, $roles, true)) {
|
||||
continue;
|
||||
}
|
||||
$itemUrl = (string)$item['url'];
|
||||
$itemLabel = (string)$item['label'];
|
||||
$itemIcon = (string)$item['icon'];
|
||||
$activeClass = (($pageTitle ?? '') === $itemLabel) ? 'active' : '';
|
||||
?>
|
||||
<a href="<?= htmlspecialchars($itemUrl, ENT_QUOTES, 'UTF-8') ?>" class="<?= $activeClass ?>">
|
||||
<?php if ($faEnabled && $itemIcon): ?><i class="<?= htmlspecialchars($itemIcon, ENT_QUOTES, 'UTF-8') ?>"></i><?php endif; ?>
|
||||
<?= htmlspecialchars($itemLabel, ENT_QUOTES, 'UTF-8') ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($role === 'admin'): ?>
|
||||
<div class="sidebar-section">
|
||||
<div class="sidebar-title">Admin</div>
|
||||
<a href="/admin/accounts" class="<?= ($pageTitle ?? '') === 'Accounts' ? 'active' : '' ?>">
|
||||
<?php if ($faEnabled): ?><i class="fa-solid fa-user-shield"></i><?php endif; ?>
|
||||
Accounts
|
||||
</a>
|
||||
<a href="/admin/plugins" class="<?= ($pageTitle ?? '') === 'Plugins' ? 'active' : '' ?>">
|
||||
<?php if ($faEnabled): ?><i class="fa-solid fa-plug"></i><?php endif; ?>
|
||||
Plugins
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</aside>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="admin-main">
|
||||
<?php if ($isAuthed): ?>
|
||||
<header class="admin-header">
|
||||
<div class="admin-container">
|
||||
<div class="admin-top">
|
||||
<div class="brand">
|
||||
<div class="brand-badge">AC</div>
|
||||
<div>
|
||||
<div>AudioCore Admin</div>
|
||||
<div class="badge">V1.5</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-actions">
|
||||
<a href="/admin/updates" class="btn outline" style="<?= !empty($updateStatus['update_available']) ? 'border-color: rgba(34,242,165,.6); color:#9ff8d8;' : '' ?>">
|
||||
<?php if ($faEnabled): ?><i class="fa-solid fa-download"></i><?php endif; ?>
|
||||
<?= !empty($updateStatus['update_available']) ? 'Update Available' : 'Updates' ?>
|
||||
</a>
|
||||
<a href="/admin/settings" class="btn outline">
|
||||
<?php if ($faEnabled): ?><i class="fa-solid fa-gear"></i><?php endif; ?>
|
||||
Settings
|
||||
</a>
|
||||
<a href="/admin/logout" class="btn outline">
|
||||
<?php if ($faEnabled): ?><i class="fa-solid fa-right-from-bracket"></i><?php endif; ?>
|
||||
Logout
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<?php endif; ?>
|
||||
<main class="admin-content">
|
||||
<div class="admin-container">
|
||||
<?= $content ?? '' ?>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="mediaPickerBackdrop" class="modal-backdrop" aria-hidden="true">
|
||||
<div class="modal" role="dialog" aria-modal="true" aria-label="Media picker">
|
||||
<div class="modal-header">
|
||||
<div class="modal-title">Media Picker</div>
|
||||
<div class="modal-actions">
|
||||
<input id="mediaPickerSearch" class="input" placeholder="Search media..." style="max-width: 320px;">
|
||||
<button type="button" class="btn outline small" id="mediaPickerClose">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="mediaPickerGrid" class="media-grid"></div>
|
||||
<div id="mediaPickerEmpty" class="media-empty" style="display:none;">No images available.</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
(function () {
|
||||
const backdrop = document.getElementById('mediaPickerBackdrop');
|
||||
const grid = document.getElementById('mediaPickerGrid');
|
||||
const empty = document.getElementById('mediaPickerEmpty');
|
||||
const search = document.getElementById('mediaPickerSearch');
|
||||
const closeBtn = document.getElementById('mediaPickerClose');
|
||||
if (!backdrop || !grid || !search || !closeBtn) {
|
||||
return;
|
||||
}
|
||||
|
||||
let items = [];
|
||||
let activeTarget = null;
|
||||
|
||||
function insertAtCursor(textarea, text) {
|
||||
const start = textarea.selectionStart || 0;
|
||||
const end = textarea.selectionEnd || 0;
|
||||
const value = textarea.value || '';
|
||||
textarea.value = value.slice(0, start) + text + value.slice(end);
|
||||
const next = start + text.length;
|
||||
textarea.setSelectionRange(next, next);
|
||||
textarea.focus();
|
||||
}
|
||||
|
||||
function renderGrid(filterText) {
|
||||
const q = (filterText || '').toLowerCase();
|
||||
const filtered = items.filter(item => {
|
||||
const name = String(item.file_name || '').toLowerCase();
|
||||
const isImage = String(item.file_type || '').startsWith('image/');
|
||||
return isImage && (!q || name.includes(q));
|
||||
});
|
||||
|
||||
grid.innerHTML = '';
|
||||
if (!filtered.length) {
|
||||
empty.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
empty.style.display = 'none';
|
||||
|
||||
filtered.forEach(item => {
|
||||
const card = document.createElement('button');
|
||||
card.type = 'button';
|
||||
card.className = 'media-thumb';
|
||||
card.innerHTML = `
|
||||
<img src="${item.file_url}" alt="">
|
||||
<div class="media-meta">${item.file_name || ''}</div>
|
||||
`;
|
||||
card.addEventListener('click', function () {
|
||||
const target = activeTarget ? document.getElementById(activeTarget) : null;
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
if (activeMode === 'url') {
|
||||
insertAtCursor(target, item.file_url);
|
||||
} else {
|
||||
insertAtCursor(target, '<img src="' + item.file_url + '" alt="">');
|
||||
}
|
||||
closePicker();
|
||||
});
|
||||
grid.appendChild(card);
|
||||
});
|
||||
}
|
||||
|
||||
let activeMode = 'html';
|
||||
|
||||
function openPicker(targetId, mode) {
|
||||
activeTarget = targetId;
|
||||
activeMode = mode || 'html';
|
||||
backdrop.style.display = 'flex';
|
||||
backdrop.setAttribute('aria-hidden', 'false');
|
||||
search.value = '';
|
||||
fetch('/admin/media/picker', { credentials: 'same-origin' })
|
||||
.then(resp => resp.ok ? resp.json() : Promise.reject())
|
||||
.then(data => {
|
||||
items = Array.isArray(data.items) ? data.items : [];
|
||||
renderGrid('');
|
||||
})
|
||||
.catch(() => {
|
||||
items = [];
|
||||
renderGrid('');
|
||||
});
|
||||
}
|
||||
|
||||
function closePicker() {
|
||||
backdrop.style.display = 'none';
|
||||
backdrop.setAttribute('aria-hidden', 'true');
|
||||
activeTarget = null;
|
||||
}
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
const btn = event.target.closest('[data-media-picker]');
|
||||
if (!btn) {
|
||||
return;
|
||||
}
|
||||
const targetId = btn.getAttribute('data-media-picker');
|
||||
const mode = btn.getAttribute('data-media-picker-mode');
|
||||
if (targetId) {
|
||||
openPicker(targetId, mode);
|
||||
}
|
||||
});
|
||||
|
||||
search.addEventListener('input', function () {
|
||||
renderGrid(search.value);
|
||||
});
|
||||
|
||||
closeBtn.addEventListener('click', closePicker);
|
||||
|
||||
backdrop.addEventListener('click', function (event) {
|
||||
if (event.target === backdrop) {
|
||||
closePicker();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function (event) {
|
||||
if (event.key === 'Escape' && backdrop.style.display === 'flex') {
|
||||
closePicker();
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user