1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-07 23:27:17 +02:00

Defer syntax highlighting

This commit is contained in:
Jakub Vrana
2025-04-07 14:12:44 +02:00
parent 7d3d46e509
commit b0e5c1d6e4
4 changed files with 57 additions and 57 deletions

View File

@@ -1005,13 +1005,13 @@ class Adminer {
*/ */
function syntaxHighlighting(array $tables): void { function syntaxHighlighting(array $tables): void {
// this is matched by compile.php // this is matched by compile.php
echo script_src("../externals/jush/modules/jush.js"); echo script_src("../externals/jush/modules/jush.js", true);
echo script_src("../externals/jush/modules/jush-autocomplete-sql.js"); echo script_src("../externals/jush/modules/jush-autocomplete-sql.js", true);
echo script_src("../externals/jush/modules/jush-textarea.js"); echo script_src("../externals/jush/modules/jush-textarea.js", true);
echo script_src("../externals/jush/modules/jush-txt.js"); echo script_src("../externals/jush/modules/jush-txt.js", true);
echo script_src("../externals/jush/modules/jush-js.js"); echo script_src("../externals/jush/modules/jush-js.js", true);
if (support("sql")) { if (support("sql")) {
echo script_src("../externals/jush/modules/jush-" . JUSH . ".js"); echo script_src("../externals/jush/modules/jush-" . JUSH . ".js", true);
echo "<script" . nonce() . ">\n"; echo "<script" . nonce() . ">\n";
if ($tables) { if ($tables) {
$links = array(); $links = array();
@@ -1028,13 +1028,11 @@ class Adminer {
$tablesColumns[$table][] = $field["field"]; $tablesColumns[$table][] = $field["field"];
} }
} }
echo "autocompleter = jush.autocompleteSql('" . idf_escape("") . "', " . json_encode($tablesColumns) . ");\n"; echo "addEventListener('DOMContentLoaded', () => { autocompleter = jush.autocompleteSql('" . idf_escape("") . "', " . json_encode($tablesColumns) . "); });\n";
} }
echo "</script>\n"; echo "</script>\n";
} }
echo script("syntaxHighlighting('" . preg_replace('~^(\d\.?\d).*~s', '\1', connection()->server_info) . "'" echo script("syntaxHighlighting('" . preg_replace('~^(\d\.?\d).*~s', '\1', connection()->server_info) . "', '" . connection()->flavor . "');");
. (connection()->flavor == 'maria' ? ", 'maria'" : (connection()->flavor == 'cockroach' ? ", 'cockroach'" : "")) . ");"
);
} }
/** Print databases list in menu */ /** Print databases list in menu */

View File

@@ -7,8 +7,8 @@ function script(string $source, string $trailing = "\n"): string {
} }
/** Return <script src> element */ /** Return <script src> element */
function script_src(string $url): string { function script_src(string $url, bool $defer = false): string {
return "<script src='" . h($url) . "'" . nonce() . "></script>\n"; return "<script src='" . h($url) . "'" . nonce() . ($defer ? " defer" : "") . "></script>\n";
} }
/** Get a nonce="" attribute with CSP nonce */ /** Get a nonce="" attribute with CSP nonce */

View File

@@ -7,6 +7,7 @@ let autocompleter; // set in adminer.inc.php
* @param [string] * @param [string]
*/ */
function syntaxHighlighting(version, vendor) { function syntaxHighlighting(version, vendor) {
addEventListener('DOMContentLoaded', () => {
if (window.jush) { if (window.jush) {
jush.create_links = 'target="_blank" rel="noreferrer noopener"'; jush.create_links = 'target="_blank" rel="noreferrer noopener"';
if (version) { if (version) {
@@ -57,6 +58,7 @@ function syntaxHighlighting(version, vendor) {
} }
} }
} }
});
} }
/** Get value of dynamically created form field /** Get value of dynamically created form field

View File

@@ -334,7 +334,7 @@ if ($_SESSION["lang"]) {
$file = str_replace('<?php echo LANG; ?>', $_SESSION["lang"], $file); $file = str_replace('<?php echo LANG; ?>', $_SESSION["lang"], $file);
} }
$file = str_replace('echo script_src("static/editing.js");' . "\n", "", $file); // merged into functions.js $file = str_replace('echo script_src("static/editing.js");' . "\n", "", $file); // merged into functions.js
$file = preg_replace('~\s+echo script_src\("\.\./externals/jush/modules/jush-(autocomplete-sql|textarea|txt|js|" \. JUSH \. ")\.js"\);~', '', $file); // merged into jush.js $file = preg_replace('~\s+echo script_src\("\.\./externals/jush/modules/jush-(autocomplete-sql|textarea|txt|js|" \. JUSH \. ")\.js", true\);~', '', $file); // merged into jush.js
$file = preg_replace('~echo .*/jush(-dark)?.css\'>.*~', '', $file); // merged into default.css or dark.css $file = preg_replace('~echo .*/jush(-dark)?.css\'>.*~', '', $file); // merged into default.css or dark.css
if (function_exists('stripTypes')) { if (function_exists('stripTypes')) {
$file = stripTypes($file); $file = stripTypes($file);