1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-16 11:34:10 +02:00

CSS: Dark mode syntax highlighting and adminer-dark.css

This commit is contained in:
Jakub Vrana
2025-03-15 01:49:42 +01:00
parent be0a485b14
commit e3515fd63f
21 changed files with 46 additions and 290 deletions

View File

@@ -94,12 +94,12 @@ class Adminer {
}
/** Print HTML code inside <head>
* @return bool true to link favicon.ico and adminer.css if exists
* @param bool dark CSS: false to disable, true to force, null to base on user preferences
* @return bool true to link favicon.ico
*/
function head() {
?>
<link rel="stylesheet" href="../externals/jush/jush.css">
<?php
function head($dark = null) {
echo "<link rel='stylesheet' href='../externals/jush/jush.css'>\n";
echo ($dark !== false ? "<link rel='stylesheet'" . ($dark ? "" : " media='(prefers-color-scheme: dark)'") . " href='../externals/jush/jush-dark.css'>\n" : "");
return true;
}
@@ -108,9 +108,11 @@ class Adminer {
*/
function css() {
$return = array();
$filename = "adminer.css";
if (file_exists($filename)) {
$return[] = "$filename?v=" . crc32(file_get_contents($filename));
foreach (array("", "-dark") as $mode) {
$filename = "adminer$mode.css";
if (file_exists($filename)) {
$return[] = "$filename?v=" . crc32(file_get_contents($filename));
}
}
return $return;
}

View File

@@ -31,17 +31,19 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
<link rel="stylesheet" href="../adminer/static/default.css">
<?php
$css = $adminer->css();
if ($css) {
foreach ($css as $val) {
echo "<link rel='stylesheet' href='" . h($val) . "'>\n";
}
} else {
$dark = ($css == array_filter($css, function ($filename) {
return preg_match('~-dark~', $filename);
}));
if ($dark) { // we need to load this before user styles
echo "<link rel='stylesheet' media='(prefers-color-scheme: dark)' href='../adminer/static/dark.css'>\n";
}
foreach ($css as $val) {
echo "<link rel='stylesheet' href='" . h($val) . "'>\n";
}
echo script_src("../adminer/static/functions.js");
echo script_src("static/editing.js");
?>
<?php if ($adminer->head()) { ?>
<?php if ($adminer->head($css ? $dark : null)) { ?>
<link rel="shortcut icon" type="image/x-icon" href="../adminer/static/favicon.ico">
<link rel="apple-touch-icon" href="../adminer/static/favicon.ico">
<?php } ?>