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

Plugins: Defer syntax highlighting

This commit is contained in:
Jakub Vrana
2025-04-07 14:23:35 +02:00
parent b0e5c1d6e4
commit 41c71f8854
2 changed files with 98 additions and 94 deletions

View File

@@ -24,14 +24,14 @@ class AdminerCodemirror {
.CodeMirror { border: 1px inset #ccc; resize: both; } .CodeMirror { border: 1px inset #ccc; resize: both; }
</style> </style>
<?php <?php
echo Adminer\script_src("$this->root/lib/codemirror$this->minified.js"); echo Adminer\script_src("$this->root/lib/codemirror$this->minified.js", true);
echo Adminer\script_src("$this->root/addon/runmode/runmode$this->minified.js"); echo Adminer\script_src("$this->root/addon/runmode/runmode$this->minified.js", true);
echo Adminer\script_src("$this->root/addon/hint/show-hint$this->minified.js"); echo Adminer\script_src("$this->root/addon/hint/show-hint$this->minified.js", true);
echo Adminer\script_src("$this->root/mode/javascript/javascript$this->minified.js"); echo Adminer\script_src("$this->root/mode/javascript/javascript$this->minified.js", true);
$tables = array_fill_keys(array_keys($tableStatuses), array()); $tables = array_fill_keys(array_keys($tableStatuses), array());
if (Adminer\support("sql")) { if (Adminer\support("sql")) {
echo Adminer\script_src("$this->root/mode/sql/sql$this->minified.js"); echo Adminer\script_src("$this->root/mode/sql/sql$this->minified.js", true);
echo Adminer\script_src("$this->root/addon/hint/sql-hint$this->minified.js"); echo Adminer\script_src("$this->root/addon/hint/sql-hint$this->minified.js", true);
if (isset($_GET["sql"]) || isset($_GET["trigger"]) || isset($_GET["check"])) { if (isset($_GET["sql"]) || isset($_GET["trigger"]) || isset($_GET["check"])) {
foreach (Adminer\driver()->allFields() as $table => $fields) { foreach (Adminer\driver()->allFields() as $table => $fields) {
foreach ($fields as $field) { foreach ($fields as $field) {
@@ -42,6 +42,7 @@ class AdminerCodemirror {
} }
?> ?>
<script <?php echo Adminer\nonce(); ?>> <script <?php echo Adminer\nonce(); ?>>
addEventListener('DOMContentLoaded', () => {
function getCmMode(el) { function getCmMode(el) {
const match = el.className.match(/(^|\s)jush-([^ ]+)/); const match = el.className.match(/(^|\s)jush-([^ ]+)/);
if (match) { if (match) {
@@ -91,6 +92,7 @@ for (const el of qsa('textarea')) {
el.onchange = () => cm.setValue(el.value); el.onchange = () => cm.setValue(el.value);
} }
} }
});
</script> </script>
<?php <?php
return true; return true;

View File

@@ -15,9 +15,10 @@ class AdminerMonaco {
} }
function syntaxHighlighting($tableStatuses) { function syntaxHighlighting($tableStatuses) {
echo Adminer\script_src("$this->root/loader.js"); echo Adminer\script_src("$this->root/loader.js", true);
?> ?>
<script <?php echo Adminer\nonce(); ?>> <script <?php echo Adminer\nonce(); ?>>
addEventListener('DOMContentLoaded', () => {
require.config({ paths: { vs: '<?php echo $this->root; ?>' } }); require.config({ paths: { vs: '<?php echo $this->root; ?>' } });
require(['vs/editor/editor.main'], function (monaco) { require(['vs/editor/editor.main'], function (monaco) {
adminerHighlighter = els => els.forEach(el => { adminerHighlighter = els => els.forEach(el => {
@@ -65,6 +66,7 @@ function getMonacoLang(el) {
'' ''
))))); )))));
} }
});
</script> </script>
<?php <?php
return true; return true;